From 338a5b17f5aefc18580b69fb09c19eb93339a630 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Wed, 3 May 2023 12:50:39 +0000 Subject: propagate create flag to test-and-set helper --- storage/src/tests/persistence/testandsettest.cpp | 22 ++++++++++++++++++++++ .../src/vespa/storage/persistence/asynchandler.cpp | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'storage') 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(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(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(); -- cgit v1.2.3