Skip to content

Commit

Permalink
feat mongo: multimongo secdist update handling
Browse files Browse the repository at this point in the history
commit_hash:8e41c046ec478914caf9f9cc605db9c1290c63e2
  • Loading branch information
segoon committed Dec 13, 2024
1 parent d09b427 commit 4c4701f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mongo/include/userver/storages/mongo/multi_mongo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MultiMongo {
/// @cond
MultiMongo(
std::string name,
const storages::secdist::Secdist& secdist,
storages::secdist::Secdist& secdist,
storages::mongo::PoolConfig pool_config,
clients::dns::Resolver* dns_resolver,
dynamic_config::Source config_source
Expand Down Expand Up @@ -89,6 +89,8 @@ class MultiMongo {
private:
void OnConfigUpdate(const dynamic_config::Snapshot& config);

void OnSecdistUpdate(const storages::secdist::SecdistConfig& secdist);

storages::mongo::PoolPtr FindPool(const std::string& dbalias) const;

const std::string name_;
Expand All @@ -99,6 +101,7 @@ class MultiMongo {
rcu::Variable<PoolMap> pool_map_;
// config_subscriber_ must be the last field.
concurrent::AsyncEventSubscriberScope config_subscriber_;
concurrent::AsyncEventSubscriberScope secdist_subscriber_;
};

} // namespace storages::mongo
Expand Down
11 changes: 10 additions & 1 deletion mongo/src/storages/mongo/multi_mongo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void MultiMongo::PoolSet::Activate() { target_->pool_map_.Assign(*pool_map_ptr_)

MultiMongo::MultiMongo(
std::string name,
const storages::secdist::Secdist& secdist,
storages::secdist::Secdist& secdist,
storages::mongo::PoolConfig pool_config,
clients::dns::Resolver* dns_resolver,
dynamic_config::Source config_source
Expand All @@ -83,6 +83,7 @@ MultiMongo::MultiMongo(
pool_config_(std::move(pool_config)),
dns_resolver_(dns_resolver) {
config_subscriber_ = config_source_.UpdateAndListen(this, "multi_mongo", &MultiMongo::OnConfigUpdate);
secdist_subscriber_ = secdist.UpdateAndListen(this, "multi_mongo", &MultiMongo::OnSecdistUpdate);
}

storages::mongo::PoolPtr MultiMongo::GetPool(const std::string& dbalias) const {
Expand Down Expand Up @@ -142,6 +143,14 @@ storages::mongo::PoolPtr MultiMongo::FindPool(const std::string& dbalias) const
return it->second;
}

void MultiMongo::OnSecdistUpdate(const storages::secdist::SecdistConfig& secdist) {
const auto pool_map = pool_map_.Read();
for (const auto& [dbalias, pool] : *pool_map) {
auto conn_string = secdist::GetSecdistConnectionString(secdist, dbalias);
pool->SetConnectionString(conn_string);
}
}

} // namespace storages::mongo

USERVER_NAMESPACE_END

0 comments on commit 4c4701f

Please sign in to comment.