diff options
author | Tor Egge <Tor.Egge@oath.com> | 2017-12-08 11:42:20 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2017-12-08 11:42:20 +0000 |
commit | e8a0630402efe79b352802e8ee326330ec91a468 (patch) | |
tree | e66097f0b2eb264a41d33239b35ee12e430034c0 /searchcore/src | |
parent | ed0b3edafaaeb707fb8a8603c332488937c19d68 (diff) |
Remember document type repo below SPI in proton for 10 minutes.
Diffstat (limited to 'searchcore/src')
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp | 25 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h | 9 |
2 files changed, 32 insertions, 2 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp index 710b0ad228c..adb52583a58 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp @@ -24,7 +24,9 @@ ProtonConfigFetcher::ProtonConfigFetcher(const config::ConfigUri & configUri, IP _owner(owner), _mutex(), _dbManagerMap(), - _threadPool(128 * 1024, 1) + _threadPool(128 * 1024, 1), + _oldDocumentTypeRepos(), + _currentDocumentTypeRepo() { } @@ -100,10 +102,11 @@ ProtonConfigFetcher::reconfigure() assert(insres.first->second->getGeneration() == generation); } } - auto configSnapshot = std::make_shared<ProtonConfigSnapshot>(std::move(bootstrapConfig), std::move(dbConfigs)); + auto configSnapshot = std::make_shared<ProtonConfigSnapshot>(bootstrapConfig, std::move(dbConfigs)); LOG(debug, "Reconfiguring proton with gen %" PRId64, generation); _owner.reconfigure(std::move(configSnapshot)); LOG(debug, "Reconfigured proton with gen %" PRId64, generation); + rememberDocumentTypeRepo(bootstrapConfig->getDocumentTypeRepoSP()); } void @@ -189,4 +192,22 @@ ProtonConfigFetcher::getDocumentDBConfig(const DocTypeName & docTypeName) const return it->second->getConfig(); } +void +ProtonConfigFetcher::rememberDocumentTypeRepo(std::shared_ptr<document::DocumentTypeRepo> repo) +{ + // Ensure that previous document type repo is kept alive, and also + // any document type repo that was current within last 10 minutes. + using namespace std::chrono_literals; + if (repo == _currentDocumentTypeRepo) { + return; // no change + } + auto &repos = _oldDocumentTypeRepos; + TimePoint now = Clock::now(); + while (!repos.empty() && repos.front().first < now) { + repos.pop_front(); + } + repos.emplace_back(now + 10min, _currentDocumentTypeRepo); + _currentDocumentTypeRepo = repo; +} + } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h index 9adbabbc174..fa1f75ebe91 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h +++ b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h @@ -9,6 +9,9 @@ #include "bootstrapconfigmanager.h" #include "documentdbconfigmanager.h" #include "i_document_db_config_owner.h" +#include <chrono> + +namespace document { class DocumentTypeRepo; } namespace proton { @@ -47,6 +50,9 @@ public: private: typedef std::map<DocTypeName, DocumentDBConfigManager::SP> DBManagerMap; + using Clock = std::chrono::steady_clock; + using TimePoint = std::chrono::time_point<Clock>; + using OldDocumentTypeRepo = std::pair<TimePoint, std::shared_ptr<document::DocumentTypeRepo>>; BootstrapConfigManager _bootstrapConfigManager; config::ConfigRetriever _retriever; @@ -57,11 +63,14 @@ private: DBManagerMap _dbManagerMap; FastOS_ThreadPool _threadPool; + std::deque<OldDocumentTypeRepo> _oldDocumentTypeRepos; + std::shared_ptr<document::DocumentTypeRepo> _currentDocumentTypeRepo; void fetchConfigs(); void updateDocumentDBConfigs(const BootstrapConfigSP & config, const config::ConfigSnapshot & snapshot); void reconfigure(); const config::ConfigKeySet pruneManagerMap(const BootstrapConfigSP & config); + void rememberDocumentTypeRepo(std::shared_ptr<document::DocumentTypeRepo> repo); }; |