Skip to content

Commit

Permalink
add guard for updating wp at commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thawk105 committed Jul 28, 2023
1 parent 1f736f9 commit b956546
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/concurrency_control/interface/long_tx/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ void update_wp_at_commit(session* const ti, std::set<Storage> const& sts) {
* 小さくできるなら小さくすることで、他Txへの影響を軽減する。
* */
for (auto itr = ti->get_wp_set().begin(); itr != ti->get_wp_set().end();) {
// check the storage is valid yet
Storage target_st{itr->first};
wp::page_set_meta* target_psm_ptr{};
auto ret = wp::find_page_set_meta(target_st, target_psm_ptr);
if (ret != Status::OK ||
// check the ptr was not changed
(ret == Status::OK &&
itr->second != target_psm_ptr->get_wp_meta_ptr())) {
LOG(ERROR) << log_location_prefix
<< "Error. Suspected mix of DML and DDL";
++itr;
continue;
}

bool hit_actual{false};
for (auto actual_write_storage : sts) {
if (actual_write_storage == itr->first) {
Expand All @@ -90,8 +104,7 @@ void update_wp_at_commit(session* const ti, std::set<Storage> const& sts) {
*/
{
itr->second->get_wp_lock().lock();
auto ret =
itr->second->remove_wp_without_lock(ti->get_long_tx_id());
ret = itr->second->remove_wp_without_lock(ti->get_long_tx_id());
if (ret == Status::OK) {
// 縮退成功
itr = ti->get_wp_set().erase(itr);
Expand Down
8 changes: 4 additions & 4 deletions test/concurrency_control/ongoing_tx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace shirakami::testing {
class ongoing_tx_test : public ::testing::Test { // NOLINT
public:
static void call_once_f() {
google::InitGoogleLogging("shirakami-test-concurrency_control-wp-"
google::InitGoogleLogging("shirakami-test-concurrency_control-"
"ongoing_tx_test");
FLAGS_stderrthreshold = 0; // output more than INFO
}
Expand All @@ -38,10 +38,10 @@ TEST_F(ongoing_tx_test, exist_wait_for_test) { // NOLINT
ti->set_long_tx_id(2);
ti->set_valid_epoch(2);
Storage st{};
wp::wp_meta wp_meta{};
wp::wp_meta* wp_meta{};
ti->get_wp_set().emplace_back(
std::make_pair(st, &wp_meta)); // the pair is dummy
std::get<0>(ti->get_overtaken_ltx_set()[&wp_meta])
std::make_pair(st, wp_meta)); // the pair is dummy
std::get<0>(ti->get_overtaken_ltx_set()[wp_meta])
.insert(1); // wp_meta is dummy
ASSERT_EQ(ongoing_tx::exist_wait_for(ti), true);
ongoing_tx::remove_id(1);
Expand Down

0 comments on commit b956546

Please sign in to comment.