summaryrefslogtreecommitdiffstats
path: root/storageapi
diff options
context:
space:
mode:
authorGeir Storli <geirst@oath.com>2017-11-16 10:23:36 +0000
committerGeir Storli <geirst@oath.com>2017-11-16 10:35:35 +0000
commit82768432f24d2d1d412120eaff9da2b057d0c225 (patch)
tree49bf6a0dd10785f65f0e95cd3a248983f8b6658e /storageapi
parent6fac1dceb62f0142cbd9a862c932558a14e38cea (diff)
Add API function to decode a bucket to reduce direct use of placeholder bucket space.
Diffstat (limited to 'storageapi')
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/protocolserialization.h2
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/protocolserialization4_2.cpp36
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.cpp19
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.h1
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_1.cpp9
5 files changed, 29 insertions, 38 deletions
diff --git a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization.h b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization.h
index e32942d0303..b422afa812d 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization.h
+++ b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization.h
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
+#include <vespa/document/bucket/bucket.h>
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/messagebus/routable.h>
#include <vespa/storageapi/mbusprot/storagemessage.h>
@@ -176,6 +177,7 @@ protected:
virtual SCmd::UP onDecodeBatchPutRemoveCommand(BBuf&) const = 0;
virtual SRep::UP onDecodeBatchPutRemoveReply(const SCmd&, BBuf&) const = 0;
+ virtual document::Bucket getBucket(document::ByteBuffer& buf) const = 0;
virtual api::BucketInfo getBucketInfo(document::ByteBuffer& buf) const = 0;
virtual void putBucketInfo(const api::BucketInfo& info, vespalib::GrowableByteBuffer& buf) const = 0;
diff --git a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization4_2.cpp b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization4_2.cpp
index e4993a1ee7b..75a95956f9a 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization4_2.cpp
+++ b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization4_2.cpp
@@ -52,8 +52,7 @@ ProtocolSerialization4_2::onDecodeMultiOperationCommand(BBuf& buf) const
std::vector<char> buffer(length);
buf.getBytes(&buffer[0], length);
bool keepTimestamps = SH::getBoolean(buf);
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::MultiOperationCommand::UP msg(
new api::MultiOperationCommand(getTypeRepoSp(),
bucket, buffer, keepTimestamps));
@@ -101,8 +100,7 @@ api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeBatchPutRemoveCommand(BBuf& buf) const
{
SH::getByte(buf);
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
std::unique_ptr<api::BatchPutRemoveCommand> cmd(new api::BatchPutRemoveCommand(bucket));
int length = SH::getInt(buf);
@@ -174,8 +172,7 @@ api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeGetCommand(BBuf& buf) const
{
document::DocumentId did(SH::getString(buf));
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::Timestamp beforeTimestamp(SH::getLong(buf));
bool headerOnly(SH::getBoolean(buf));
api::GetCommand::UP msg(
@@ -197,8 +194,7 @@ api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeRemoveCommand(BBuf& buf) const
{
document::DocumentId did(SH::getString(buf));
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::Timestamp timestamp(SH::getLong(buf));
api::RemoveCommand::UP msg(new api::RemoveCommand(bucket, did, timestamp));
onDecodeBucketInfoCommand(buf, *msg);
@@ -219,8 +215,7 @@ void ProtocolSerialization4_2::onEncode(
api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeRevertCommand(BBuf& buf) const
{
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
std::vector<api::Timestamp> tokens(SH::getInt(buf));
for (uint32_t i=0, n=tokens.size(); i<n; ++i) {
tokens[i] = SH::getLong(buf);
@@ -240,8 +235,7 @@ void ProtocolSerialization4_2::onEncode(
api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeCreateBucketCommand(BBuf& buf) const
{
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::CreateBucketCommand::UP msg(new api::CreateBucketCommand(bucket));
onDecodeBucketInfoCommand(buf, *msg);
return api::StorageCommand::UP(msg.release());
@@ -265,8 +259,7 @@ api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeMergeBucketCommand(BBuf& buf) const
{
typedef api::MergeBucketCommand::Node Node;
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
uint16_t nodeCount = SH::getShort(buf);
std::vector<Node> nodes;
nodes.reserve(nodeCount);
@@ -305,8 +298,7 @@ api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeGetBucketDiffCommand(BBuf& buf) const
{
typedef api::MergeBucketCommand::Node Node;
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
uint16_t nodeCount = SH::getShort(buf);
std::vector<Node> nodes;
nodes.reserve(nodeCount);
@@ -363,8 +355,7 @@ api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeApplyBucketDiffCommand(BBuf& buf) const
{
typedef api::MergeBucketCommand::Node Node;
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
uint16_t nodeCount = SH::getShort(buf);
std::vector<Node> nodes;
nodes.reserve(nodeCount);
@@ -448,8 +439,7 @@ void ProtocolSerialization4_2::onEncode(
api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeNotifyBucketChangeCommand(BBuf& buf) const
{
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::BucketInfo info(getBucketInfo(buf));
api::NotifyBucketChangeCommand::UP msg(
new api::NotifyBucketChangeCommand(bucket, info));
@@ -487,8 +477,7 @@ void ProtocolSerialization4_2::onEncode(
api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeSplitBucketCommand(BBuf& buf) const
{
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::SplitBucketCommand::UP msg(new api::SplitBucketCommand(bucket));
msg->setMinSplitBits(SH::getByte(buf));
msg->setMaxSplitBits(SH::getByte(buf));
@@ -646,8 +635,7 @@ api::StorageCommand::UP
ProtocolSerialization4_2::onDecodeRemoveLocationCommand(BBuf& buf) const
{
vespalib::stringref documentSelection = SH::getString(buf);
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::RemoveLocationCommand::UP msg;
msg.reset(new api::RemoveLocationCommand(documentSelection, bucket));
diff --git a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.cpp b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.cpp
index 22f58ebc58b..97d75079dd8 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.cpp
+++ b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.cpp
@@ -12,6 +12,13 @@ using document::BucketSpace;
namespace storage {
namespace mbusprot {
+document::Bucket
+ProtocolSerialization5_0::getBucket(document::ByteBuffer& buf) const
+{
+ document::BucketId bucketId(SH::getLong(buf));
+ return document::Bucket(BucketSpace::placeHolder(), bucketId);
+}
+
api::BucketInfo
ProtocolSerialization5_0::getBucketInfo(document::ByteBuffer& buf) const
{
@@ -103,8 +110,7 @@ api::StorageCommand::UP
ProtocolSerialization5_0::onDecodePutCommand(BBuf& buf) const
{
document::Document::SP doc(SH::getDocument(buf, getTypeRepo()));
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::Timestamp ts(SH::getLong(buf));
api::PutCommand::UP msg(new api::PutCommand(bucket, doc, ts));
msg->setUpdateTimestamp(SH::getLong(buf));
@@ -224,8 +230,7 @@ ProtocolSerialization5_0::onDecodeUpdateCommand(BBuf& buf) const
SERIALIZE_HEAD));
}
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::Timestamp timestamp(SH::getLong(buf));
api::UpdateCommand::UP msg(
new api::UpdateCommand(bucket, update, timestamp));
@@ -278,8 +283,7 @@ ProtocolSerialization5_0::onEncode(
api::StorageCommand::UP
ProtocolSerialization5_0::onDecodeDeleteBucketCommand(BBuf& buf) const
{
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::DeleteBucketCommand::UP msg(new api::DeleteBucketCommand(bucket));
onDecodeBucketInfoCommand(buf, *msg);
if (buf.getRemaining() >= SH::BUCKET_INFO_SERIALIZED_SIZE) {
@@ -507,8 +511,7 @@ ProtocolSerialization5_0::onEncode(
api::StorageCommand::UP
ProtocolSerialization5_0::onDecodeJoinBucketsCommand(BBuf& buf) const
{
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::JoinBucketsCommand::UP msg(new api::JoinBucketsCommand(bucket));
uint32_t size = SH::getInt(buf);
if (size > buf.getRemaining()) {
diff --git a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.h b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.h
index ff9f08d38a9..1f42bea0c58 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.h
+++ b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_0.h
@@ -15,6 +15,7 @@ public:
ProtocolSerialization5_0(const document::DocumentTypeRepo::SP&,
const documentapi::LoadTypeSet& loadTypes);
+ document::Bucket getBucket(document::ByteBuffer& buf) const override;
api::BucketInfo getBucketInfo(document::ByteBuffer& buf) const override;
void putBucketInfo(const api::BucketInfo& info, vespalib::GrowableByteBuffer& buf) const override;
diff --git a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_1.cpp b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_1.cpp
index dc97742b733..099be20074e 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_1.cpp
+++ b/storageapi/src/vespa/storageapi/mbusprot/protocolserialization5_1.cpp
@@ -72,8 +72,7 @@ void ProtocolSerialization5_1::onEncode(
api::StorageCommand::UP
ProtocolSerialization5_1::onDecodeSetBucketStateCommand(BBuf& buf) const
{
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::SetBucketStateCommand::BUCKET_STATE state(
static_cast<api::SetBucketStateCommand::BUCKET_STATE>(
SH::getByte(buf)));
@@ -113,8 +112,7 @@ api::StorageCommand::UP
ProtocolSerialization5_1::onDecodeGetCommand(BBuf& buf) const
{
document::DocumentId did(SH::getString(buf));
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
api::Timestamp beforeTimestamp(SH::getLong(buf));
std::string fieldSet(SH::getString(buf));
api::GetCommand::UP msg(
@@ -216,8 +214,7 @@ void ProtocolSerialization5_1::onEncode(
api::StorageCommand::UP
ProtocolSerialization5_1::onDecodeCreateBucketCommand(BBuf& buf) const
{
- document::BucketId bucketId(SH::getLong(buf));
- document::Bucket bucket(BucketSpace::placeHolder(), bucketId);
+ document::Bucket bucket = getBucket(buf);
bool setActive = SH::getBoolean(buf);
api::CreateBucketCommand::UP msg(new api::CreateBucketCommand(bucket));
msg->setActive(setActive);