summaryrefslogtreecommitdiffstats
path: root/documentapi
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2023-10-17 15:51:30 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2023-10-17 15:51:30 +0000
commita6d24b3ac1d0416847dddbfd686e953552ca68f6 (patch)
tree0ea0766c2cf3b2f3b6860b2158e35a0e9afd8e41 /documentapi
parentd39b461d4259dc3b4d8f405ac730334e13002ee2 (diff)
Use `shared_mutex` to allow non-contending reads (common case)
Diffstat (limited to 'documentapi')
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp10
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h4
2 files changed, 7 insertions, 7 deletions
diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp
index c13f32f2df5..ea27d42e790 100644
--- a/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp
+++ b/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp
@@ -103,7 +103,7 @@ void
ContentPolicy::configure(std::unique_ptr<vespa::config::content::StorDistributionConfig> config)
{
try {
- std::lock_guard guard(_lock);
+ std::lock_guard guard(_rw_lock);
_distribution = std::make_unique<storage::lib::Distribution>(*config);
} catch (const std::exception& e) {
LOG(warning, "Got exception when configuring distribution, config id was %s", _clusterConfigId.c_str());
@@ -235,7 +235,7 @@ void
ContentPolicy::updateStateFromReply(WrongDistributionReply& wdr)
{
auto newState = std::make_unique<storage::lib::ClusterState>(wdr.getSystemState());
- std::lock_guard guard(_lock);
+ std::lock_guard guard(_rw_lock);
if (!_state || newState->getVersion() >= _state->getVersion()) {
if (_state) {
wdr.getTrace().trace(1, make_string("System state changed from version %u to %u",
@@ -256,14 +256,14 @@ ContentPolicy::updateStateFromReply(WrongDistributionReply& wdr)
ContentPolicy::StateSnapshot
ContentPolicy::internal_state_snapshot()
{
- std::lock_guard guard(_lock);
+ std::shared_lock guard(_rw_lock);
return {_state, _distribution};
}
std::shared_ptr<const storage::lib::ClusterState>
ContentPolicy::getSystemState() const noexcept
{
- std::lock_guard guard(_lock);
+ std::shared_lock guard(_rw_lock);
return _state;
}
@@ -273,7 +273,7 @@ ContentPolicy::reset_state()
// It's possible for the caller to race between checking and resetting the state,
// but this should never lead to a worse outcome than sending to a random distributor
// as if no state had been cached prior.
- std::lock_guard guard(_lock);
+ std::lock_guard guard(_rw_lock);
_state.reset();
}
diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h
index 182b35a0e98..7a3675c3001 100644
--- a/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h
+++ b/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h
@@ -6,7 +6,7 @@
#include <vespa/vdslib/distribution/distribution.h>
#include <vespa/document/bucket/bucketidfactory.h>
#include <vespa/messagebus/routing/hop.h>
-#include <mutex>
+#include <shared_mutex>
namespace config {
class ICallback;
@@ -24,7 +24,7 @@ class ContentPolicy : public ExternSlobrokPolicy
{
private:
document::BucketIdFactory _bucketIdFactory;
- mutable std::mutex _lock;
+ mutable std::shared_mutex _rw_lock;
std::shared_ptr<const storage::lib::ClusterState> _state;
string _clusterName;
string _clusterConfigId;