summaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2023-05-03 10:45:43 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2023-05-03 10:45:43 +0000
commitfe9cf07808713cdbd87899cc7bc54eaea01357b0 (patch)
tree12147121917a1d673bb6c72f554df18be3c3b8c1 /storage
parentb83cc57a23c24cba060e884ade5f056cd46c5a82 (diff)
wire create flag
Diffstat (limited to 'storage')
-rw-r--r--storage/src/tests/storageapi/mbusprot/storageprotocoltest.cpp12
-rw-r--r--storage/src/vespa/storageapi/mbusprot/protobuf/feed.proto1
-rw-r--r--storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp2
-rw-r--r--storage/src/vespa/storageapi/message/persistence.h4
4 files changed, 17 insertions, 2 deletions
diff --git a/storage/src/tests/storageapi/mbusprot/storageprotocoltest.cpp b/storage/src/tests/storageapi/mbusprot/storageprotocoltest.cpp
index ec8d6855abc..72bb6cf9fb5 100644
--- a/storage/src/tests/storageapi/mbusprot/storageprotocoltest.cpp
+++ b/storage/src/tests/storageapi/mbusprot/storageprotocoltest.cpp
@@ -176,6 +176,7 @@ TEST_P(StorageProtocolTest, put) {
EXPECT_EQ(*_testDoc, *cmd2->getDocument());
EXPECT_EQ(Timestamp(14), cmd2->getTimestamp());
EXPECT_EQ(Timestamp(13), cmd2->getUpdateTimestamp());
+ EXPECT_EQ(false, cmd2->get_create_if_non_existent());
auto reply = std::make_shared<PutReply>(*cmd2);
ASSERT_TRUE(reply->hasDocument());
@@ -803,6 +804,15 @@ TEST_P(StorageProtocolTest, put_command_with_condition) {
EXPECT_EQ(cmd->getCondition().getSelection(), cmd2->getCondition().getSelection());
}
+TEST_P(StorageProtocolTest, put_command_with_create_flag) {
+ auto cmd = std::make_shared<PutCommand>(_bucket, _testDoc, 14);
+ EXPECT_EQ(false, cmd->get_create_if_non_existent());
+ cmd->set_create_if_non_existent(true);
+ EXPECT_EQ(true, cmd->get_create_if_non_existent());
+ auto cmd2 = copyCommand(cmd);
+ EXPECT_EQ(cmd->get_create_if_non_existent(), cmd2->get_create_if_non_existent());
+}
+
TEST_P(StorageProtocolTest, update_command_with_condition) {
auto update = std::make_shared<document::DocumentUpdate>(
_docMan.getTypeRepo(), *_testDoc->getDataType(), _testDoc->getId());
@@ -877,7 +887,7 @@ TEST_P(StorageProtocolTest, track_memory_footprint_for_some_messages) {
EXPECT_EQ(sizeof(BucketCommand), sizeof(StorageCommand) + 24);
EXPECT_EQ(sizeof(BucketInfoCommand), sizeof(BucketCommand));
EXPECT_EQ(sizeof(TestAndSetCommand), sizeof(BucketInfoCommand) + sizeof(vespalib::string));
- EXPECT_EQ(sizeof(PutCommand), sizeof(TestAndSetCommand) + 32);
+ EXPECT_EQ(sizeof(PutCommand), sizeof(TestAndSetCommand) + 40);
EXPECT_EQ(sizeof(UpdateCommand), sizeof(TestAndSetCommand) + 32);
EXPECT_EQ(sizeof(RemoveCommand), sizeof(TestAndSetCommand) + 112);
EXPECT_EQ(sizeof(GetCommand), sizeof(BucketInfoCommand) + sizeof(TestAndSetCondition) + 184);
diff --git a/storage/src/vespa/storageapi/mbusprot/protobuf/feed.proto b/storage/src/vespa/storageapi/mbusprot/protobuf/feed.proto
index b02e1eab0aa..b115cca8263 100644
--- a/storage/src/vespa/storageapi/mbusprot/protobuf/feed.proto
+++ b/storage/src/vespa/storageapi/mbusprot/protobuf/feed.proto
@@ -17,6 +17,7 @@ message PutRequest {
uint64 new_timestamp = 3;
uint64 expected_old_timestamp = 4; // If zero; no expectation.
TestAndSetCondition condition = 5;
+ bool create_if_non_existent = 6;
}
message PutResponse {
diff --git a/storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp b/storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp
index f2dcf07c01a..3f1ab1e5fe1 100644
--- a/storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp
+++ b/storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp
@@ -421,6 +421,7 @@ void ProtocolSerialization7::onEncode(GBBuf& buf, const api::PutCommand& msg) co
if (msg.getDocument()) {
set_document(*req.mutable_document(), *msg.getDocument());
}
+ req.set_create_if_non_existent(msg.get_create_if_non_existent());
});
}
@@ -438,6 +439,7 @@ api::StorageCommand::UP ProtocolSerialization7::onDecodePutCommand(BBuf& buf) co
if (req.has_condition()) {
cmd->setCondition(get_tas_condition(req.condition()));
}
+ cmd->set_create_if_non_existent(req.create_if_non_existent());
return cmd;
});
}
diff --git a/storage/src/vespa/storageapi/message/persistence.h b/storage/src/vespa/storageapi/message/persistence.h
index d010c295ca7..e6f2023fa48 100644
--- a/storage/src/vespa/storageapi/message/persistence.h
+++ b/storage/src/vespa/storageapi/message/persistence.h
@@ -48,7 +48,7 @@ class PutCommand : public TestAndSetCommand {
DocumentSP _doc;
Timestamp _timestamp;
Timestamp _updateTimestamp;
-
+ bool _create_if_non_existent = false;
public:
PutCommand(const document::Bucket &bucket, const DocumentSP&, Timestamp);
~PutCommand() override;
@@ -67,6 +67,8 @@ public:
const document::DocumentId& getDocumentId() const override;
Timestamp getTimestamp() const { return _timestamp; }
const document::DocumentType * getDocumentType() const override;
+ void set_create_if_non_existent(bool value) noexcept { _create_if_non_existent = value; }
+ bool get_create_if_non_existent() const noexcept { return _create_if_non_existent; }
vespalib::string getSummary() const override;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;