diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-11-26 13:42:23 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-11-26 13:42:23 +0000 |
commit | 17de07f29c707e204749fd6c366825a0f04136c0 (patch) | |
tree | 0a7131a609dbb55f7c41f93d3e05bc48f587d29a | |
parent | 8236c60ded3e9ae63363750851fd89359d286a01 (diff) |
Use MonitoredRefCount/RetainGuard instead of atomic/sleep
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp | 23 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/server/proton_configurer.h | 4 |
2 files changed, 11 insertions, 16 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp b/searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp index 25918d32049..2c891927fa3 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp @@ -12,6 +12,7 @@ #include <vespa/document/bucket/fixed_bucket_spaces.h> #include <vespa/config-bucketspaces.h> #include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/util/retain_guard.h> #include <vespa/vespalib/stllike/asciistream.h> #include <future> @@ -54,27 +55,23 @@ ProtonConfigurer::ProtonConfigurer(vespalib::ThreadExecutor &executor, _mutex(), _allowReconfig(false), _componentConfig(), - _diskLayout(diskLayout), - _pendingReconfigureTasks(0) + _diskLayout(diskLayout) { } class ProtonConfigurer::ReconfigureTask : public vespalib::Executor::Task { public: ReconfigureTask(ProtonConfigurer & configurer) - : _configurer(configurer) - { - _configurer._pendingReconfigureTasks++; - } - ~ReconfigureTask() { - _configurer._pendingReconfigureTasks--; - } + : _configurer(configurer), + _retainGuard(configurer._pendingReconfigureTasks) + {} void run() override { _configurer.performReconfigure(); } private: - ProtonConfigurer & _configurer; + ProtonConfigurer & _configurer; + vespalib::RetainGuard _retainGuard; }; ProtonConfigurer::~ProtonConfigurer() = default; @@ -89,14 +86,12 @@ ProtonConfigurer::setAllowReconfig(bool allowReconfig) _allowReconfig = allowReconfig; if (allowReconfig) { // Ensure that pending config is applied - _executor.execute(makeLambdaTask([this]() { performReconfigure(); })); + _executor.execute(std::make_unique<ReconfigureTask>(*this)); } } if (!allowReconfig) { // drain queued performReconfigure tasks - while ( _pendingReconfigureTasks > 0) { - std::this_thread::sleep_for(1ms); - } + _pendingReconfigureTasks.waitForZeroRefCount(); } } diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_configurer.h b/searchcore/src/vespa/searchcore/proton/server/proton_configurer.h index b59af6c347a..ddb9c1bed92 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_configurer.h +++ b/searchcore/src/vespa/searchcore/proton/server/proton_configurer.h @@ -7,9 +7,9 @@ #include <vespa/document/bucket/bucketspace.h> #include <vespa/searchcore/proton/common/doctypename.h> #include <vespa/vespalib/net/simple_component_config_producer.h> +#include <vespa/vespalib/util/monitored_refcount.h> #include <map> #include <mutex> -#include <atomic> namespace proton { @@ -38,7 +38,7 @@ class ProtonConfigurer : public IProtonConfigurer bool _allowReconfig; vespalib::SimpleComponentConfigProducer _componentConfig; const std::unique_ptr<IProtonDiskLayout> &_diskLayout; - std::atomic<uint64_t> _pendingReconfigureTasks; + vespalib::MonitoredRefCount _pendingReconfigureTasks; void performReconfigure(); bool skipConfig(const ProtonConfigSnapshot *configSnapshot, bool initialConfig); |