aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@verizonmedia.com>2019-09-24 14:07:46 +0000
committerTor Brede Vekterli <vekterli@verizonmedia.com>2019-09-27 09:10:32 +0000
commit1692827e9aadba4581a9b56cdb691a2990080318 (patch)
treeffc79c88695686d8afc5e81e5fa7cb768222d2e5
parentb7eaa075e3875debb02f2af8b9ef30ca8835afc1 (diff)
Let GetOperation take in explicit database read guard
Use a `shared_ptr` to enable multiple operations to share the same logical snapshot.
-rw-r--r--storage/src/tests/distributor/getoperationtest.cpp5
-rw-r--r--storage/src/vespa/storage/distributor/externaloperationhandler.cpp4
-rw-r--r--storage/src/vespa/storage/distributor/operations/external/getoperation.cpp7
-rw-r--r--storage/src/vespa/storage/distributor/operations/external/getoperation.h11
-rw-r--r--storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp3
5 files changed, 19 insertions, 11 deletions
diff --git a/storage/src/tests/distributor/getoperationtest.cpp b/storage/src/tests/distributor/getoperationtest.cpp
index 7c308e152db..99d7c12551d 100644
--- a/storage/src/tests/distributor/getoperationtest.cpp
+++ b/storage/src/tests/distributor/getoperationtest.cpp
@@ -3,6 +3,8 @@
#include <vespa/config/helper/configgetter.h>
#include <vespa/document/config/config-documenttypes.h>
#include <vespa/document/repo/documenttyperepo.h>
+#include <vespa/storage/bucketdb/bucketdatabase.h>
+#include <vespa/storage/distributor/distributor_bucket_space.h>
#include <vespa/storage/distributor/externaloperationhandler.h>
#include <vespa/storage/distributor/distributor.h>
#include <vespa/storage/distributor/distributormetricsset.h>
@@ -31,7 +33,7 @@ struct GetOperationTest : Test, DistributorTestUtil {
std::unique_ptr<Operation> op;
GetOperationTest();
- ~GetOperationTest();
+ ~GetOperationTest() override;
void SetUp() override {
_repo.reset(
@@ -53,6 +55,7 @@ struct GetOperationTest : Test, DistributorTestUtil {
auto msg = std::make_shared<api::GetCommand>(makeDocumentBucket(document::BucketId(0)), docId, "[all]");
op = std::make_unique<GetOperation>(
getExternalOperationHandler(), getDistributorBucketSpace(),
+ getDistributorBucketSpace().getBucketDatabase().acquire_read_guard(),
msg, getDistributor().getMetrics(). gets[msg->getLoadType()]);
op->start(_sender, framework::MilliSecTime(0));
}
diff --git a/storage/src/vespa/storage/distributor/externaloperationhandler.cpp b/storage/src/vespa/storage/distributor/externaloperationhandler.cpp
index 1b88f02cac6..f1f786d84ac 100644
--- a/storage/src/vespa/storage/distributor/externaloperationhandler.cpp
+++ b/storage/src/vespa/storage/distributor/externaloperationhandler.cpp
@@ -284,8 +284,8 @@ IMPL_MSG_COMMAND_H(ExternalOperationHandler, Get)
document::Bucket bucket(cmd->getBucket().getBucketSpace(), getBucketId(cmd->getDocumentId()));
auto& metrics = getMetrics().gets[cmd->getLoadType()];
bounce_or_invoke_read_only_op(*cmd, bucket, metrics, [&](auto& bucket_space_repo) {
- _op = std::make_shared<GetOperation>(*this, bucket_space_repo.get(cmd->getBucket().getBucketSpace()),
- cmd, metrics);
+ auto& space = bucket_space_repo.get(cmd->getBucket().getBucketSpace());
+ _op = std::make_shared<GetOperation>(*this, space, space.getBucketDatabase().acquire_read_guard(), cmd, metrics);
});
return true;
}
diff --git a/storage/src/vespa/storage/distributor/operations/external/getoperation.cpp b/storage/src/vespa/storage/distributor/operations/external/getoperation.cpp
index 6cfc688db0e..768da935fd2 100644
--- a/storage/src/vespa/storage/distributor/operations/external/getoperation.cpp
+++ b/storage/src/vespa/storage/distributor/operations/external/getoperation.cpp
@@ -46,6 +46,7 @@ GetOperation::GroupId::operator==(const GroupId& other) const
GetOperation::GetOperation(DistributorComponent& manager,
DistributorBucketSpace &bucketSpace,
+ std::shared_ptr<BucketDatabase::ReadGuard> read_guard,
std::shared_ptr<api::GetCommand> msg,
PersistenceOperationMetricSet& metric)
: Operation(),
@@ -58,7 +59,7 @@ GetOperation::GetOperation(DistributorComponent& manager,
_metric(metric),
_operationTimer(manager.getClock())
{
- assignTargetNodeGroups();
+ assignTargetNodeGroups(*read_guard);
}
void
@@ -213,13 +214,13 @@ GetOperation::sendReply(DistributorMessageSender& sender)
}
void
-GetOperation::assignTargetNodeGroups()
+GetOperation::assignTargetNodeGroups(const BucketDatabase::ReadGuard& read_guard)
{
document::BucketIdFactory bucketIdFactory;
document::BucketId bid = bucketIdFactory.getBucketId(_msg->getDocumentId());
std::vector<BucketDatabase::Entry> entries;
- _bucketSpace.getBucketDatabase().acquire_read_guard()->find_parents_and_self(bid, entries);
+ read_guard.find_parents_and_self(bid, entries);
for (uint32_t j = 0; j < entries.size(); ++j) {
const BucketDatabase::Entry& e = entries[j];
diff --git a/storage/src/vespa/storage/distributor/operations/external/getoperation.h b/storage/src/vespa/storage/distributor/operations/external/getoperation.h
index 3936f13077e..8d0fdb0c2bb 100644
--- a/storage/src/vespa/storage/distributor/operations/external/getoperation.h
+++ b/storage/src/vespa/storage/distributor/operations/external/getoperation.h
@@ -3,7 +3,7 @@
#include <vespa/storageapi/defs.h>
#include <vespa/storage/distributor/operations/operation.h>
-#include <vespa/storage/bucketdb/bucketcopy.h>
+#include <vespa/storage/bucketdb/bucketdatabase.h>
#include <vespa/storageapi/messageapi/storagemessage.h>
#include <vespa/storageframework/generic/clock/timer.h>
@@ -23,8 +23,11 @@ class DistributorBucketSpace;
class GetOperation : public Operation
{
public:
- GetOperation(DistributorComponent& manager, DistributorBucketSpace &bucketSpace,
- std::shared_ptr<api::GetCommand> msg, PersistenceOperationMetricSet& metric);
+ GetOperation(DistributorComponent& manager,
+ DistributorBucketSpace &bucketSpace,
+ std::shared_ptr<BucketDatabase::ReadGuard> read_guard,
+ std::shared_ptr<api::GetCommand> msg,
+ PersistenceOperationMetricSet& metric);
void onClose(DistributorMessageSender& sender) override;
void onStart(DistributorMessageSender& sender) override;
@@ -89,7 +92,7 @@ private:
void sendReply(DistributorMessageSender& sender);
bool sendForChecksum(DistributorMessageSender& sender, const document::BucketId& id, GroupVector& res);
- void assignTargetNodeGroups();
+ void assignTargetNodeGroups(const BucketDatabase::ReadGuard& read_guard);
bool copyIsOnLocalNode(const BucketCopy&) const;
/**
* Returns the vector index of the target to send to, or -1 if none
diff --git a/storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp b/storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp
index b7ebafc114c..b3326a43be2 100644
--- a/storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp
+++ b/storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp
@@ -178,7 +178,8 @@ TwoPhaseUpdateOperation::startSafePathUpdate(DistributorMessageSender& sender)
document::Bucket bucket(_updateCmd->getBucket().getBucketSpace(), document::BucketId(0));
auto get = std::make_shared<api::GetCommand>(bucket, _updateCmd->getDocumentId(),"[all]");
copyMessageSettings(*_updateCmd, *get);
- auto getOperation = std::make_shared<GetOperation>(_manager, _bucketSpace, get, _getMetric);
+ auto getOperation = std::make_shared<GetOperation>(
+ _manager, _bucketSpace, _bucketSpace.getBucketDatabase().acquire_read_guard(), get, _getMetric);
GetOperation & op = *getOperation;
IntermediateMessageSender intermediate(_sentMessageMap, std::move(getOperation), sender);
op.start(intermediate, _manager.getClock().getTimeInMillis());