aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2021-05-19 15:58:03 +0000
committerHåvard Pettersen <havardpe@oath.com>2021-05-19 15:58:03 +0000
commit58c6c0405e588908df90801e69ed7931ddc577e9 (patch)
tree2e308664b26ea35acc15302b6bf86c077fabad4e /searchcore
parent2c4b4e1283cda6ee2d89d4decf8b8b756bb3f054 (diff)
refactor out common code
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp57
1 files changed, 24 insertions, 33 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp
index c61e67facbf..fb154081963 100644
--- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp
@@ -21,6 +21,7 @@
#include <vespa/searchlib/index/schemautil.h>
#include <vespa/searchsummary/config/config-juniperrc.h>
#include <vespa/vespalib/time/time_box.h>
+#include <vespa/vespalib/util/stringfmt.h>
#include <thread>
#include <cassert>
@@ -47,6 +48,8 @@ using search::WriteableFileChunk;
using std::make_shared;
using std::make_unique;
+using vespalib::make_string_short::fmt;
+
namespace proton {
const ConfigKeySet
@@ -267,6 +270,21 @@ build_alloc_config(const ProtonConfig& proton_config, const vespalib::string& do
distribution_config.redundancy, distribution_config.searchablecopies);
}
+vespalib::string resolve_file(config::RpcFileAcquirer &fileAcquirer, vespalib::TimeBox &timeBox,
+ const vespalib::string &desc, const vespalib::string &fileref)
+{
+ vespalib::string filePath;
+ LOG(info, "Waiting for file acquirer (%s, ref='%s')", desc.c_str(), fileref.c_str());
+ while (timeBox.hasTimeLeft() && (filePath == "")) {
+ filePath = fileAcquirer.wait_for(fileref, timeBox.timeLeft());
+ if (filePath == "") {
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ }
+ }
+ LOG(info, "Got file path from file acquirer: '%s' (%s, ref='%s')", filePath.c_str(), desc.c_str(), fileref.c_str());
+ return filePath;
+}
+
}
void
@@ -334,17 +352,8 @@ DocumentDBConfigManager::update(const ConfigSnapshot &snapshot)
config::RpcFileAcquirer fileAcquirer(spec);
vespalib::TimeBox timeBox(5*60, 5);
for (const RankingConstantsConfig::Constant &rc : newRankingConstantsConfig->constant) {
- vespalib::string filePath;
- LOG(info, "Waiting for file acquirer (name='%s', type='%s', ref='%s')",
- rc.name.c_str(), rc.type.c_str(), rc.fileref.c_str());
- while (timeBox.hasTimeLeft() && (filePath == "")) {
- filePath = fileAcquirer.wait_for(rc.fileref, timeBox.timeLeft());
- if (filePath == "") {
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- }
- }
- LOG(info, "Got file path from file acquirer: '%s' (name='%s', type='%s', ref='%s')",
- filePath.c_str(), rc.name.c_str(), rc.type.c_str(), rc.fileref.c_str());
+ auto desc = fmt("name='%s', type='%s'", rc.name.c_str(), rc.type.c_str());
+ vespalib::string filePath = resolve_file(fileAcquirer, timeBox, desc, rc.fileref);
constants.emplace_back(rc.name, rc.type, filePath);
}
}
@@ -359,17 +368,8 @@ DocumentDBConfigManager::update(const ConfigSnapshot &snapshot)
config::RpcFileAcquirer fileAcquirer(spec);
vespalib::TimeBox timeBox(5*60, 5);
for (const RankingExpressionsConfig::Expression &rc : newRankingExpressionsConfig->expression) {
- vespalib::string filePath;
- LOG(info, "Waiting for file acquirer (name='%s', ref='%s')",
- rc.name.c_str(), rc.fileref.c_str());
- while (timeBox.hasTimeLeft() && (filePath == "")) {
- filePath = fileAcquirer.wait_for(rc.fileref, timeBox.timeLeft());
- if (filePath == "") {
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- }
- }
- LOG(info, "Got file path from file acquirer: '%s' (name='%s', ref='%s')",
- filePath.c_str(), rc.name.c_str(), rc.fileref.c_str());
+ auto desc = fmt("name='%s'", rc.name.c_str());
+ vespalib::string filePath = resolve_file(fileAcquirer, timeBox, desc, rc.fileref);
expressions.add(rc.name, filePath);
}
}
@@ -384,17 +384,8 @@ DocumentDBConfigManager::update(const ConfigSnapshot &snapshot)
config::RpcFileAcquirer fileAcquirer(spec);
vespalib::TimeBox timeBox(5*60, 5);
for (const OnnxModelsConfig::Model &rc : newOnnxModelsConfig->model) {
- vespalib::string filePath;
- LOG(info, "Waiting for file acquirer (name='%s', ref='%s')",
- rc.name.c_str(), rc.fileref.c_str());
- while (timeBox.hasTimeLeft() && (filePath == "")) {
- filePath = fileAcquirer.wait_for(rc.fileref, timeBox.timeLeft());
- if (filePath == "") {
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- }
- }
- LOG(info, "Got file path from file acquirer: '%s' (name='%s', ref='%s')",
- filePath.c_str(), rc.name.c_str(), rc.fileref.c_str());
+ auto desc = fmt("name='%s'", rc.name.c_str());
+ vespalib::string filePath = resolve_file(fileAcquirer, timeBox, desc, rc.fileref);
models.emplace_back(rc.name, filePath);
OnnxModels::configure(rc, models.back());
}