Skip to content

Commit

Permalink
Merge branch 'tui1016'
Browse files Browse the repository at this point in the history
see updated Record's vesion (epoch/tid) at upsert
for project-tsurugi/tsurugi-issues#1016
  • Loading branch information
ban-nobuhiro committed Nov 8, 2024
2 parents 44129c9 + b618f00 commit 7c015d1
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/concurrency_control/interface/short_tx/termination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ Status write_lock(session* ti, tid_word& commit_tid) {
return Status::ERR_KVS;
}
}
// check Record version to update
if (!rec_ptr->get_tidw_ref().get_absent()) {
commit_tid = std::max(commit_tid, rec_ptr->get_tidw_ref());
}
return Status::OK;
}
if (rc == Status::ERR_CC) {
Expand Down
27 changes: 27 additions & 0 deletions test/tid_word/tid_word_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,31 @@ TEST_F(tid_word_test, tid_keeps_ordered) {
}
}

TEST_F(tid_word_test, tid_is_stronger_than_lock) {
tid_word t1{}, t2{};
t1.set_tid(1);
t1.set_lock(true);
t2.set_tid(2);
t2.set_lock(false);
EXPECT_LT(t1, t2);
}

TEST_F(tid_word_test, tid_is_stronger_than_absent) {
tid_word t1{}, t2{};
t1.set_tid(1);
t1.set_absent(true);
t2.set_tid(2);
t2.set_absent(false);
EXPECT_LT(t1, t2);
}

TEST_F(tid_word_test, absent_is_stronger_than_lock) {
tid_word t1{}, t2{};
t1.set_lock(true);
t1.set_absent(false);
t2.set_lock(false);
t2.set_absent(true);
EXPECT_LT(t1, t2);
}

} // namespace shirakami::testing
92 changes: 92 additions & 0 deletions test/tsurugi_issues/tsurugi_issue1016_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

#include "test_tool.h"

#include "concurrency_control/include/epoch.h"
#include "concurrency_control/include/garbage.h"
#include "concurrency_control/include/session.h"

#include "shirakami/interface.h"
#include "index/yakushima/include/interface.h"

#include "glog/logging.h"
#include "gtest/gtest.h"

using namespace shirakami;

// tsurugi issue #1016: upserting the Record (which is written in same epoch) may not change tid_word

namespace shirakami::testing {

class tsurugi_issue1016_test : public ::testing::Test {
public:
static void call_once_f() {
google::InitGoogleLogging("shirakami-test-tsurugi_issues-tsurugi_issue1016_test");
// FLAGS_stderrthreshold = 0;
}

void SetUp() override {
std::call_once(init_, call_once_f);
init();
}

void TearDown() override { fin(); }

private:
static inline std::once_flag init_;
};

TEST_F(tsurugi_issue1016_test, modify_by_upsert_must_change_tidword) {
// expect
// OCC1: begin -> OK
// OCC2: begin -> OK
// OCC3: begin -> OK
// wait epoch; to do next 3 lines (OCC1 commit - OCC3 commit) in the same epoch
// OCC1: upsert A 1, commit -> OK
// OCC2: search_key A -> OK, reads A=1
// OCC3: upsert A 3, commit -> OK
// OCC2: commit -> ERR_CC by read verify

// before ti#1016 fix
// OCC1: begin -> OK
// OCC2: begin -> OK
// OCC3: begin -> OK
// wait epoch; to do next 3 lines (OCC1 commit - OCC3 commit) in the same epoch
// OCC1: upsert A 1, commit -> OK
// OCC2: search_key A -> OK, reads A=1
// OCC3: upsert A 3 -> OK
// OCC3: commit -> OK <- sometime use same tid as previous
// OCC2: commit -> OK <- wrong, read_verify doesn't work

Storage st{};
ASSERT_OK(create_storage("", st));
Token s1{};
Token s2{};
Token s3{};
ASSERT_OK(enter(s1));
ASSERT_OK(enter(s2));
ASSERT_OK(enter(s3));

ASSERT_OK(tx_begin({s1, transaction_options::transaction_type::SHORT}));
ASSERT_OK(tx_begin({s2, transaction_options::transaction_type::SHORT}));
ASSERT_OK(tx_begin({s3, transaction_options::transaction_type::SHORT}));

wait_epoch_update();

ASSERT_OK(upsert(s1, st, "A", "1"));
ASSERT_OK(commit(s1));

std::string buf{};
ASSERT_OK(search_key(s2, st, "A", buf));
ASSERT_EQ(buf, "1");

ASSERT_OK(upsert(s3, st, "A", "3"));
ASSERT_OK(commit(s3));

ASSERT_EQ(commit(s2), Status::ERR_CC);

ASSERT_OK(leave(s1));
ASSERT_OK(leave(s2));
ASSERT_OK(leave(s3));
}

} // namespace shirakami::testing

0 comments on commit 7c015d1

Please sign in to comment.