Skip to content

Commit

Permalink
fix: structure of read area to prepare handling detail info
Browse files Browse the repository at this point in the history
  • Loading branch information
thawk105 committed Jan 30, 2024
1 parent 7d9696e commit e68e124
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/concurrency_control/include/read_plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ class session;
class read_plan {
public:
using read_area_type = transaction_options::read_area;
using cont_type = std::map<std::size_t, read_area_type>;
/**
* @details std::tuple: read area, whether commit was requested, left of
* read range, right of read range
*/
using cont_type =
std::map<std::size_t, std::tuple<read_area_type, bool, std::string,
std::string>>;

static void clear() {
std::lock_guard<std::shared_mutex> lk{get_mtx_cont()};
Expand All @@ -37,7 +43,7 @@ class read_plan {

static void add_elem(std::size_t const tx_id, read_area_type const& ra) {
std::lock_guard<std::shared_mutex> lk{get_mtx_cont()};
get_cont()[tx_id] = ra;
get_cont()[tx_id] = std::make_tuple(ra, false, "", "");
}

static void remove_elem(std::size_t const tx_id) {
Expand All @@ -54,7 +60,7 @@ class read_plan {
auto itr = get_cont().find(tx_id);
if (itr != get_cont().end()) {
// found
return itr->second;
return std::get<0>(itr->second);
}
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "may be some error.";
return {};
Expand Down
4 changes: 2 additions & 2 deletions src/concurrency_control/read_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ bool read_plan::check_potential_read_anti(
}
if (elem.first == tx_id) { return false; }
// elem is high priori tx
auto plist = elem.second.get_positive_list();
auto nlist = elem.second.get_negative_list();
auto plist = std::get<0>(elem.second).get_positive_list();
auto nlist = std::get<0>(elem.second).get_negative_list();

// cond1 empty and empty
if (plist.empty() && nlist.empty()) {
Expand Down
24 changes: 12 additions & 12 deletions test/concurrency_control/long_tx/read_area/read_area_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ TEST_F(read_area_test, register_same_st) { // NOLINT
std::shared_lock<std::shared_mutex> lk{read_plan::get_mtx_cont()};
ASSERT_EQ(read_plan::get_cont().size(), 1);
auto ra = *read_plan::get_cont().begin();
ASSERT_EQ(ra.second.get_positive_list().size(), 1);
ASSERT_EQ(ra.second.get_negative_list().size(), 1);
ASSERT_EQ(std::get<0>(ra.second).get_positive_list().size(), 1);
ASSERT_EQ(std::get<0>(ra.second).get_negative_list().size(), 1);
}

// check local worker info
Expand Down Expand Up @@ -97,8 +97,8 @@ TEST_F(read_area_test, register_and_remove_posi_only_commit) { // NOLINT
std::shared_lock<std::shared_mutex> lk{read_plan::get_mtx_cont()};
ASSERT_EQ(read_plan::get_cont().size(), 1);
auto ra = *read_plan::get_cont().begin();
ASSERT_EQ(ra.second.get_positive_list().size(), 1);
ASSERT_EQ(ra.second.get_negative_list().size(), 0);
ASSERT_EQ(std::get<0>(ra.second).get_positive_list().size(), 1);
ASSERT_EQ(std::get<0>(ra.second).get_negative_list().size(), 0);
}

// commit erase above info
Expand Down Expand Up @@ -130,8 +130,8 @@ TEST_F(read_area_test, register_and_remove_nega_only_commit) { // NOLINT
std::shared_lock<std::shared_mutex> lk{read_plan::get_mtx_cont()};
ASSERT_EQ(read_plan::get_cont().size(), 1);
auto ra = *read_plan::get_cont().begin();
ASSERT_EQ(ra.second.get_positive_list().size(), 0);
ASSERT_EQ(ra.second.get_negative_list().size(), 1);
ASSERT_EQ(std::get<0>(ra.second).get_positive_list().size(), 0);
ASSERT_EQ(std::get<0>(ra.second).get_negative_list().size(), 1);
}

// commit erase above info
Expand Down Expand Up @@ -162,8 +162,8 @@ TEST_F(read_area_test, register_and_remove_posi_only_abort) { // NOLINT
std::shared_lock<std::shared_mutex> lk{read_plan::get_mtx_cont()};
ASSERT_EQ(read_plan::get_cont().size(), 1);
auto ra = *read_plan::get_cont().begin();
ASSERT_EQ(ra.second.get_positive_list().size(), 1);
ASSERT_EQ(ra.second.get_negative_list().size(), 0);
ASSERT_EQ(std::get<0>(ra.second).get_positive_list().size(), 1);
ASSERT_EQ(std::get<0>(ra.second).get_negative_list().size(), 0);
}

// commit erase above info
Expand Down Expand Up @@ -195,8 +195,8 @@ TEST_F(read_area_test, register_and_remove_nega_only_abort) { // NOLINT
std::shared_lock<std::shared_mutex> lk{read_plan::get_mtx_cont()};
ASSERT_EQ(read_plan::get_cont().size(), 1);
auto ra = *read_plan::get_cont().begin();
ASSERT_EQ(ra.second.get_positive_list().size(), 0);
ASSERT_EQ(ra.second.get_negative_list().size(), 1);
ASSERT_EQ(std::get<0>(ra.second).get_positive_list().size(), 0);
ASSERT_EQ(std::get<0>(ra.second).get_negative_list().size(), 1);
}

// commit erase above info
Expand Down Expand Up @@ -235,8 +235,8 @@ TEST_F(read_area_test, conflict_positive_negative) { // NOLINT
std::shared_lock<std::shared_mutex> lk{read_plan::get_mtx_cont()};
ASSERT_EQ(read_plan::get_cont().size(), 1);
auto ra = *read_plan::get_cont().begin();
ASSERT_EQ(ra.second.get_positive_list().size(), 1);
ASSERT_EQ(ra.second.get_negative_list().size(), 2);
ASSERT_EQ(std::get<0>(ra.second).get_positive_list().size(), 1);
ASSERT_EQ(std::get<0>(ra.second).get_negative_list().size(), 2);
}

// check local worker info
Expand Down

0 comments on commit e68e124

Please sign in to comment.