Skip to content

Commit

Permalink
fix: test and gc about enter without leave for yakushima
Browse files Browse the repository at this point in the history
  • Loading branch information
thawk105 committed Feb 7, 2024
1 parent 041e2b9 commit 10f663f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 46 deletions.
26 changes: 15 additions & 11 deletions src/concurrency_control/garbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void work_manager() {
if (min_step_epoch != epoch::max_epoch) {
// find some living tx
if (min_step_epoch < epoch::initial_epoch) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << log_location_prefix
<< "epoch error";
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< log_location_prefix << "epoch error";
}
set_min_step_epoch(min_step_epoch);
} else {
Expand Down Expand Up @@ -89,7 +89,7 @@ version* find_latest_invisible_version_from_batch(
if (ver == nullptr) {
// assert. unreachable path
LOG_FIRST_N(ERROR, 1) << log_location_prefix << log_location_prefix
<< "unreachable path";
<< "unreachable path";
}
// gathering stats info
++average_version_list_size;
Expand Down Expand Up @@ -194,10 +194,11 @@ inline Status unhooking_key(yakushima::Token ytk, Storage st, Record* rec_ptr) {
rec_ptr->get_key(kb);
rc = remove(ytk, st, kb);
if (rc != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "unreachable path: it can't find the record on yakushima,"
"it is unexpected. yakushima return code: "
<< rc;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "unreachable path: it can't find the record on yakushima,"
"it is unexpected. yakushima return code: "
<< rc;
return Status::ERR_FATAL;
}

Expand All @@ -221,8 +222,9 @@ void unhooking_keys_and_pruning_versions(
return;
}
if (rc == Status::ERR_FATAL) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "unreachable path: it may be programming error.";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "unreachable path: it may be programming error.";
return;
}

Expand Down Expand Up @@ -272,7 +274,10 @@ inline void unhooking_keys_and_pruning_versions_at_the_storage(
std::vector<std::tuple<std::string, Record**, std::size_t>> scan_res;
yakushima::scan(st_view, "", yakushima::scan_endpoint::INF, "",
yakushima::scan_endpoint::INF, scan_res);
if (scan_res.empty()) { return; } // empty by current action
if (scan_res.empty()) {
yakushima::leave(ytk);
return;
} // empty by current action
// not empty

// gathering stats info
Expand Down Expand Up @@ -405,7 +410,6 @@ void work_cleaner() {
// sleep
sleepUs(epoch::get_global_epoch_time_us());
}

force_release_key_memory();
}

Expand Down
2 changes: 2 additions & 0 deletions src/concurrency_control/include/garbage.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "concurrency_control/include/record.h"
#include "concurrency_control/include/version.h"

#include "database/include/logging.h"

#include "shirakami/storage_options.h"

#include "glog/logging.h"
Expand Down
60 changes: 37 additions & 23 deletions src/concurrency_control/interface/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ void write_storage_metadata(std::string_view key, Storage st,
value.append(payload);
auto ret = tx_begin({s, transaction_options::transaction_type::SHORT});
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "library programming error.";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << "library programming error.";
}
ret = upsert(s, storage::meta_storage, key, value);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "library programming error.";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << "library programming error.";
return;
}
if (commit(s) == Status::OK) {
Expand All @@ -59,14 +61,16 @@ void remove_storage_metadata(std::string_view key) {
std::string value{};
auto ret = tx_begin({s, transaction_options::transaction_type::SHORT});
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "library programming error.";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << "library programming error.";
}
ret = delete_record(s, storage::meta_storage, key);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "unreachable path, It can't find the record which must "
"exist.: "
<< s << ", " << storage::meta_storage << ", " << key;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "unreachable path, It can't find the record which must "
"exist.: "
<< s << ", " << storage::meta_storage << ", " << key;
return;
}
if (commit(s) == Status::OK) {
Expand Down Expand Up @@ -181,13 +185,15 @@ Status storage_get_options_body(Storage storage, storage_option& options) {
for (;;) {
ret = tx_begin({s, transaction_options::transaction_type::SHORT});
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "library programming error.";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << "library programming error.";
}
ret = search_key(s, storage::meta_storage, key, value);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "unreachable path: " << s
<< ", " << storage::meta_storage << ", " << key << ", "
<< value << ret;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << "unreachable path: " << s << ", "
<< storage::meta_storage << ", " << key << ", " << value
<< ret;
return Status::ERR_FATAL;
}
if (commit(s) == Status::OK) { break; } // NOLINT
Expand Down Expand Up @@ -247,8 +253,8 @@ Status storage_set_options_body(Storage storage,
// store and log information
ret = tx_begin({s, transaction_options::transaction_type::SHORT});
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "library programming error. "
<< ret;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << "library programming error. " << ret;
}
ret = upsert(s, storage::meta_storage, key, value);
if (ret != Status::OK) {
Expand All @@ -259,7 +265,8 @@ Status storage_set_options_body(Storage storage,
leave(s);
return Status::OK;
} // else
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "library programming error.";
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "library programming error.";
return Status::ERR_FATAL;
}

Expand Down Expand Up @@ -300,12 +307,15 @@ Status storage::register_storage(Storage storage, storage_option options) {
storage_view, &page_set_meta_ptr,
sizeof(page_set_meta_ptr)); // NOLINT
if (yakushima::status::OK != rc) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << rc << ", unreachable path";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << rc << ", unreachable path";
yakushima::leave(ytoken);
return Status::ERR_FATAL_INDEX;
}
rc = yakushima::leave(ytoken);
if (yakushima::status::OK != rc) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << rc << ", unreachable path";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << rc << ", unreachable path";
return Status::ERR_FATAL_INDEX;
}
}
Expand Down Expand Up @@ -423,9 +433,10 @@ Status storage::delete_storage(Storage storage) {
sizeof(page_set_meta_storage)},
storage_view, out)};
if (rc != yakushima::status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "missing error" << std::endl
<< " " << page_set_meta_storage << " " << storage
<< std::endl;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << "missing error" << std::endl
<< " " << page_set_meta_storage << " " << storage
<< std::endl;
return Status::ERR_FATAL;
}
delete reinterpret_cast<wp::page_set_meta*>(out.first); // NOLINT
Expand All @@ -436,18 +447,21 @@ Status storage::delete_storage(Storage storage) {
sizeof(page_set_meta_storage)},
storage_view);
if (yakushima::status::OK != rc) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << rc << ", unreachable path";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << rc << ", unreachable path";
return Status::ERR_FATAL;
}
rc = yakushima::leave(ytoken);
if (yakushima::status::OK != rc) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << rc << ", unreachable path";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << rc << ", unreachable path";
return Status::ERR_FATAL;
}
}
auto rc = yakushima::delete_storage(storage_view);
if (yakushima::status::OK != rc) { // NOLINT
LOG_FIRST_N(ERROR, 1) << log_location_prefix << rc << ", unreachable path";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix << rc << ", unreachable path";
return Status::ERR_FATAL;
}

Expand All @@ -459,7 +473,7 @@ Status storage::list_storage(std::vector<Storage>& out) {
yakushima::list_storages(rec);
if (rec.empty()) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "There must be wp meta storage at least.";
<< "There must be wp meta storage at least.";
return Status::ERR_FATAL;
}
out.clear();
Expand Down
9 changes: 0 additions & 9 deletions src/datastore/limestone/datastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ void recovery_from_datastore() {
/**
* The cursor point the first entry at calling first next().
*/
yakushima::Token tk{};
if (yakushima::enter(tk) != yakushima::status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "yakushima enter error.";
}
std::vector<Storage> st_list{};

auto cursor = ss->get_cursor();
Expand Down Expand Up @@ -197,11 +193,6 @@ void recovery_from_datastore() {
// recovery storage meta
if (!st_list.empty()) { recovery_storage_meta(st_list); }
// recovery epoch info
// TODO
if (yakushima::leave(tk) != yakushima::status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "unreachable path";
return;
}
}

void scan_all_and_logging() {
Expand Down
9 changes: 6 additions & 3 deletions test/database_options/database_options_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "concurrency_control/include/epoch.h"

#include "database/include/logging.h"

#include "shirakami/interface.h"

#include "gtest/gtest.h"
Expand All @@ -17,7 +19,8 @@ using namespace shirakami;
class database_options_test : public ::testing::Test { // NOLINT
public:
static void call_once_f() {
google::InitGoogleLogging("shirakami-test-start-database_options_test");
google::InitGoogleLogging(
"shirakami-test-database_options-database_options_test");
// FLAGS_stderrthreshold = 0;
}

Expand All @@ -34,8 +37,8 @@ TEST_F(database_options_test, print_out_object) { // NOLINT
// check compile and running.
LOG(INFO) << options;
options.set_open_mode(database_options::open_mode::RESTORE);
std::filesystem::path ldp{"hogehoge"};
options.set_log_directory_path(ldp);
//std::filesystem::path ldp{"hogehoge"};
//options.set_log_directory_path(ldp);
LOG(INFO) << options;
options.set_epoch_time(100); // NOLINT
LOG(INFO) << options;
Expand Down

0 comments on commit 10f663f

Please sign in to comment.