diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2023-05-03 12:50:39 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2023-05-03 13:20:32 +0000 |
commit | 338a5b17f5aefc18580b69fb09c19eb93339a630 (patch) | |
tree | a157bd573349cb29e4c69f88e2cd23b3c792128b /storage | |
parent | 940d95124995063779200c6d292e2d13b49f6f60 (diff) |
propagate create flag to test-and-set helper
Diffstat (limited to 'storage')
-rw-r--r-- | storage/src/tests/persistence/testandsettest.cpp | 22 | ||||
-rw-r--r-- | storage/src/vespa/storage/persistence/asynchandler.cpp | 2 |
2 files changed, 23 insertions, 1 deletions
diff --git a/storage/src/tests/persistence/testandsettest.cpp b/storage/src/tests/persistence/testandsettest.cpp index 1aa359de634..b17837d67c5 100644 --- a/storage/src/tests/persistence/testandsettest.cpp +++ b/storage/src/tests/persistence/testandsettest.cpp @@ -123,6 +123,28 @@ TEST_F(TestAndSetTest, conditional_put_executed_on_condition_match) { assertTestDocumentFoundAndMatchesContent(NEW_CONTENT); } +TEST_F(TestAndSetTest, conditional_put_not_executed_when_no_document_and_no_create) { + api::Timestamp putTimestamp = 200; + testDoc->setValue(testDoc->getField("content"), NEW_CONTENT); + auto putUp = std::make_shared<api::PutCommand>(BUCKET, testDoc, putTimestamp); + setTestCondition(*putUp); + + ASSERT_EQ(fetchResult(asyncHandler->handlePut(*putUp, createTracker(putUp, BUCKET))).getResult(), api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); + EXPECT_EQ("", dumpBucket(BUCKET_ID)); +} + +TEST_F(TestAndSetTest, conditional_put_executed_when_no_document_but_create_is_enabled) { + api::Timestamp putTimestamp = 200; + testDoc->setValue(testDoc->getField("content"), NEW_CONTENT); + auto putUp = std::make_shared<api::PutCommand>(BUCKET, testDoc, putTimestamp); + setTestCondition(*putUp); + putUp->set_create_if_non_existent(true); + + ASSERT_EQ(fetchResult(asyncHandler->handlePut(*putUp, createTracker(putUp, BUCKET))).getResult(), api::ReturnCode::Result::OK); + EXPECT_EQ(expectedDocEntryString(putTimestamp, testDocId), dumpBucket(BUCKET_ID)); + assertTestDocumentFoundAndMatchesContent(NEW_CONTENT); +} + TEST_F(TestAndSetTest, conditional_remove_not_executed_on_condition_mismatch) { // Put document with mismatching header api::Timestamp timestampOne = 0; diff --git a/storage/src/vespa/storage/persistence/asynchandler.cpp b/storage/src/vespa/storage/persistence/asynchandler.cpp index 60c6d507416..42d44394f3a 100644 --- a/storage/src/vespa/storage/persistence/asynchandler.cpp +++ b/storage/src/vespa/storage/persistence/asynchandler.cpp @@ -159,7 +159,7 @@ AsyncHandler::handlePut(api::PutCommand& cmd, MessageTracker::UP trackerUP) cons tracker.setMetric(metrics); metrics.request_size.addValue(cmd.getApproxByteSize()); - if (tasConditionExists(cmd) && !tasConditionMatches(cmd, tracker, tracker.context())) { + if (tasConditionExists(cmd) && !tasConditionMatches(cmd, tracker, tracker.context(), cmd.get_create_if_non_existent())) { // Will also count condition parse failures etc as TaS failures, but // those results _will_ increase the error metrics as well. metrics.test_and_set_failed.inc(); |