// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "bootstrapconfigmanager.h" #include "bootstrapconfig.h" #include #include #include #include #include #include #include #include #include LOG_SETUP(".proton.server.bootstrapconfigmanager"); using namespace vespa::config::search; using namespace config; using document::DocumentTypeRepo; using search::TuneFileDocumentDB; using vespa::config::search::core::ProtonConfig; using cloud::config::filedistribution::FiledistributorrpcConfig; using vespa::config::content::core::BucketspacesConfig; using document::DocumentTypeRepoFactory; using BucketspacesConfigSP = std::shared_ptr; namespace proton { BootstrapConfigManager::BootstrapConfigManager(const vespalib::string & configId) : _pendingConfigSnapshot(), _configId(configId), _pendingConfigMutex() { } BootstrapConfigManager::~BootstrapConfigManager() = default; const ConfigKeySet BootstrapConfigManager::createConfigKeySet() const { return ConfigKeySet().add(_configId) .add(_configId) .add(_configId) .add(_configId); } std::shared_ptr BootstrapConfigManager::getConfig() const { std::lock_guard lock(_pendingConfigMutex); return _pendingConfigSnapshot; } void BootstrapConfigManager::update(const ConfigSnapshot & snapshot) { using ProtonConfigSP = BootstrapConfig::ProtonConfigSP; using DocumenttypesConfigSP = BootstrapConfig::DocumenttypesConfigSP; ProtonConfigSP newProtonConfig; BootstrapConfig::FiledistributorrpcConfigSP newFiledistRpcConfSP; TuneFileDocumentDB::SP newTuneFileDocumentDB; DocumenttypesConfigSP newDocumenttypesConfig; std::shared_ptr newRepo; BucketspacesConfigSP newBucketspacesConfig; int64_t currentGen = -1; BootstrapConfig::SP current = _pendingConfigSnapshot; if (current) { newProtonConfig = current->getProtonConfigSP(); newFiledistRpcConfSP = current->getFiledistributorrpcConfigSP(); newTuneFileDocumentDB = current->getTuneFileDocumentDBSP(); newDocumenttypesConfig = current->getDocumenttypesConfigSP(); newRepo = current->getDocumentTypeRepoSP(); newBucketspacesConfig = current->getBucketspacesConfigSP(); currentGen = current->getGeneration(); } if (snapshot.isChanged(_configId, currentGen)) { LOG(spam, "Proton config is changed"); std::unique_ptr protonConfig = snapshot.getConfig(_configId); auto tuneFileDocumentDB = std::make_shared(); TuneFileDocumentDB &tune = *tuneFileDocumentDB; ProtonConfig &conf = *protonConfig; tune._index._indexing._write.setFromConfig(conf.indexing.write.io); tune._index._indexing._read.setFromConfig(conf.indexing.read.io); tune._attr._write.setFromConfig(conf.attribute.write.io); tune._index._search._read.setWantMemoryMap(); tune._index._search._read.setFromMmapConfig(conf.search.mmap); tune._summary._write.setFromConfig(conf.summary.write.io); tune._summary._seqRead.setFromConfig(conf.summary.read.io); tune._summary._randRead.setFromConfig(conf.summary.read.io, conf.summary.read.mmap); newProtonConfig = ProtonConfigSP(protonConfig.release()); newTuneFileDocumentDB = tuneFileDocumentDB; } if (snapshot.isChanged(_configId, currentGen)) { LOG(info, "Filedistributorrpc config is changed"); newFiledistRpcConfSP = snapshot.getConfig(_configId); } if (snapshot.isChanged(_configId, currentGen)) { LOG(spam, "Documenttypes config is changed"); newDocumenttypesConfig = snapshot.getConfig(_configId); newRepo = DocumentTypeRepoFactory::make(*newDocumenttypesConfig); } if (snapshot.isChanged(_configId, currentGen)) { LOG(spam, "Bucketspaces config is changed"); newBucketspacesConfig = snapshot.getConfig(_configId); } assert(newProtonConfig); assert(newFiledistRpcConfSP); assert(newBucketspacesConfig); assert(newTuneFileDocumentDB); assert(newDocumenttypesConfig); assert(newRepo); const ProtonConfig &protonConfig = *newProtonConfig; const auto &hwDiskCfg = protonConfig.hwinfo.disk; const auto &hwMemoryCfg = protonConfig.hwinfo.memory; const auto &hwCpuCfg = protonConfig.hwinfo.cpu; HwInfoSampler::Config samplerCfg(hwDiskCfg.size, hwDiskCfg.writespeed, hwDiskCfg.slowwritespeedlimit, hwDiskCfg.samplewritesize, hwDiskCfg.shared, hwMemoryCfg.size, hwCpuCfg.cores); std::filesystem::create_directories(std::filesystem::path(protonConfig.basedir)); HwInfoSampler sampler(protonConfig.basedir, samplerCfg); auto newSnapshot(std::make_shared(snapshot.getGeneration(), newDocumenttypesConfig, newRepo, newProtonConfig, newFiledistRpcConfSP, newBucketspacesConfig, newTuneFileDocumentDB, sampler.hwInfo())); assert(newSnapshot->valid()); { std::lock_guard lock(_pendingConfigMutex); _pendingConfigSnapshot = newSnapshot; } } } // namespace proton