Skip to content

Commit e078cb9

Browse files
committed
Merge pull request #183 from project-tsurugi/borrow-limestone-datastore-cleanup
cleanup after change of limestone handling
2 parents da59c27 + 8ea69e8 commit e078cb9

File tree

39 files changed

+289
-345
lines changed

39 files changed

+289
-345
lines changed

cmake/CompileOptions.cmake

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2019 tsurugi project.
1+
# Copyright 2019-2026 Project Tsurugi.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -58,6 +58,39 @@ message("It uses yakushima as index structure.")
5858

5959
set(logging_set 0)
6060
if (BUILD_PWAL)
61+
# Begin : Limestone API check
62+
# For developer convenience, allow integration with both old and new limestone.
63+
include(CheckCXXSourceCompiles)
64+
65+
set(CMAKE_REQUIRED_LIBRARIES limestone)
66+
set(AVAILABLE_LIMESTONE_API_DEFINE "")
67+
function(check_limestone_api varname method_call)
68+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # to avoid troubles around linking ASAN
69+
check_cxx_source_compiles(
70+
"#include <limestone/api/datastore.h>
71+
int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]){
72+
(void)${method_call};
73+
return 0;
74+
}"
75+
${varname})
76+
if(${varname})
77+
set(AVAILABLE_LIMESTONE_API_DEFINE "${AVAILABLE_LIMESTONE_API_DEFINE} -D${varname}=1" PARENT_SCOPE)
78+
endif()
79+
endfunction()
80+
81+
#check_limestone_api(HAVE_LIMESTONE_CONFIG_CTOR_VECBOOSTFSPATH_BOOSTFSPATH
82+
# "limestone::api::configuration{{boost::filesystem::path{\"/tmp\"}}, boost::filesystem::path{\"/tmp\"}}")
83+
check_limestone_api(HAVE_LIMESTONE_CONFIG_CTOR_NONE
84+
"limestone::api::configuration{}")
85+
check_limestone_api(HAVE_LIMESTONE_CONFIG_SET_DATA_LOCATION_STDFSPATH
86+
"[](limestone::api::configuration* conf){conf->set_data_location(std::filesystem::path{\"/tmp\"});}")
87+
#check_limestone_api(HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_BOOSTFSPATH
88+
# "[](limestone::api::datastore* ds){ds->create_channel(boost::filesystem::path{\"/tmp\"});}")
89+
check_limestone_api(HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_NONE
90+
"[](limestone::api::datastore* ds){ds->create_channel();}")
91+
add_definitions(${AVAILABLE_LIMESTONE_API_DEFINE})
92+
# End : Limestone API check
93+
6194
if (logging_set)
6295
message(FATAL_ERROR "It can select only one logging method.")
6396
endif ()

include/shirakami/database_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class database_options final {
1111
CREATE = 0x001,
1212
RESTORE = 0x002,
1313
CREATE_OR_RESTORE = 0x003,
14-
MAINTENANCE = 0x004,
14+
MAINTENANCE = 0x004, // deprecated
1515
};
1616

1717
database_options() = default; // NOLINT

src/concurrency_control/include/lpwal.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
#pragma once
1313

1414
#include <atomic>
15+
#include <filesystem>
1516
#include <mutex>
1617
#include <string_view>
1718
#include <thread>
1819

19-
#include <boost/filesystem.hpp>
20-
2120
#include "concurrency_control/include/epoch.h"
2221

2322
#include "shirakami/log_record.h"
@@ -299,11 +298,10 @@ class handler {
299298
}
300299

301300
[[maybe_unused]] static void remove_under_log_dir() {
302-
std::string ld{get_log_dir()};
303-
const boost::filesystem::path path(ld);
301+
const std::filesystem::path path(get_log_dir());
304302
try {
305-
boost::filesystem::remove_all(path);
306-
} catch (boost::filesystem::filesystem_error& ex) {
303+
std::filesystem::remove_all(path);
304+
} catch (std::filesystem::filesystem_error& ex) {
307305
LOG_FIRST_N(ERROR, 1)
308306
<< log_location_prefix << "file system error: " << ex.what()
309307
<< " : " << path;

src/concurrency_control/interface/shut_down.cpp

Lines changed: 70 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -61,108 +61,83 @@ static void fin_body([[maybe_unused]] bool force_shut_down_logging) try {
6161
// set flag
6262
set_is_shutdowning(true);
6363

64-
if (get_used_database_options().get_open_mode() !=
65-
database_options::open_mode::MAINTENANCE) {
66-
67-
/**
68-
* about back ground worker about commit
69-
* background worker about commit may access global data (object), so it
70-
* must execute before cleanup environment.
71-
*/
72-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
73-
<< "shutdown:start_bg_commit";
74-
bg_work::bg_commit::fin();
75-
VLOG(log_debug_timing_event)
76-
<< log_location_prefix_timing_event << "shutdown:end_bg_commit";
77-
78-
// about datastore
64+
/**
65+
* about back ground worker about commit
66+
* background worker about commit may access global data (object), so it
67+
* must execute before cleanup environment.
68+
*/
69+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:start_bg_commit";
70+
bg_work::bg_commit::fin();
71+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:end_bg_commit";
72+
73+
// about datastore
7974
#if defined(PWAL)
80-
VLOG(log_debug_timing_event)
81-
<< log_location_prefix_timing_event
82-
<< "shutdown:start_send_txlog_wait_durable";
83-
lpwal::fin(); // stop daemon
84-
if (!force_shut_down_logging) {
85-
// flush remaining log
86-
lpwal::flush_remaining_log(); // (*1)
87-
epoch::epoch_t ce{epoch::get_global_epoch()};
88-
// (*1)'s log must be before ce timing.
89-
// wait durable above flushing
90-
for (;;) {
91-
if (epoch::get_datastore_durable_epoch() >= ce) { break; }
92-
_mm_pause();
93-
}
75+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:start_send_txlog_wait_durable";
76+
lpwal::fin(); // stop daemon
77+
if (!force_shut_down_logging) {
78+
// flush remaining log
79+
lpwal::flush_remaining_log(); // (*1)
80+
epoch::epoch_t ce{epoch::get_global_epoch()};
81+
// (*1)'s log must be before ce timing.
82+
// wait durable above flushing
83+
for (;;) {
84+
if (epoch::get_datastore_durable_epoch() >= ce) { break; }
85+
_mm_pause();
9486
}
95-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
96-
<< "shutdown:end_send_txlog_wait_durable";
87+
}
88+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:end_send_txlog_wait_durable";
9789

9890
#endif
99-
// about callbacks
100-
clear_durability_callbacks();
101-
102-
// about tx engine
103-
VLOG(log_debug_timing_event)
104-
<< log_location_prefix_timing_event << "shutdown:start_gc";
105-
garbage::fin();
106-
VLOG(log_debug_timing_event)
107-
<< log_location_prefix_timing_event << "shutdown:end_gc";
108-
epoch::fin();
91+
// about callbacks
92+
clear_durability_callbacks();
93+
94+
// about tx engine
95+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:start_gc";
96+
garbage::fin();
97+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:end_gc";
98+
epoch::fin();
10999
#ifdef PWAL
110-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
111-
<< "shutdown:start_shutdown_datastore";
112-
datastore::get_datastore()->remove_persistent_callback();
113-
datastore::get_datastore()->shutdown().wait(); // this should after epoch::fin();
114-
datastore::release_datastore();
115-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
116-
<< "shutdown:end_shutdown_datastore";
117-
// cleanup about limestone
118-
if (datastore::get_own_datastore() && !lpwal::get_log_dir_pointed()) {
119-
// log dir was not pointed. So remove log dir
120-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
121-
<< "shutdown:start_cleanup_logdir";
122-
lpwal::remove_under_log_dir();
123-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
124-
<< "shutdown:end_cleanup_logdir";
125-
}
126-
lpwal::clean_up_metadata();
100+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:start_shutdown_datastore";
101+
datastore::get_datastore()->remove_persistent_callback();
102+
datastore::get_datastore()->shutdown().wait(); // this should after epoch::fin();
103+
datastore::release_datastore();
104+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:end_shutdown_datastore";
105+
// cleanup about limestone
106+
if (datastore::get_own_datastore() && !lpwal::get_log_dir_pointed()) {
107+
// log dir was not pointed. So remove log dir
108+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:start_cleanup_logdir";
109+
lpwal::remove_under_log_dir();
110+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:end_cleanup_logdir";
111+
}
112+
lpwal::clean_up_metadata();
127113
#endif
128-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
129-
<< "shutdown:start_delete_all_records";
130-
bool fast_shutdown = is_fast_shutdown();
131-
if (fast_shutdown) {
132-
LOG(INFO) << log_location_prefix << "skipped delete_all_records";
133-
} else {
134-
delete_all_records(); // This should be before wp::fin();
135-
}
136-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
137-
<< "shutdown:end_delete_all_records";
138-
wp::fin(); // note: this use yakushima.
139-
storage::fin(); // note: this use yakushima. delete meta storage.
140-
141-
// about index
142-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
143-
<< "shutdown:start_shutdown_yakushima";
144-
if (fast_shutdown) {
145-
yakushima::storage::get_storages()->store_root_ptr(nullptr);
146-
LOG(INFO) << log_location_prefix << "skipping yakushima destroy";
147-
}
148-
yakushima::fin();
149-
VLOG(log_debug_timing_event) << log_location_prefix_timing_event
150-
<< "shutdown:end_shutdown_yakushima";
151-
152-
//// about thread pool
153-
//VLOG(log_debug_timing_event) << log_location_prefix_timing_event
154-
// << "shutdown:start_shutdown_thread_pool";
155-
//thread_pool::fin();
156-
//VLOG(log_debug_timing_event) << log_location_prefix_timing_event
157-
// << "shutdown:end_shutdown_thread_pool";
158-
159-
// about read area
160-
read_plan::fin();
114+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:start_delete_all_records";
115+
bool fast_shutdown = is_fast_shutdown();
116+
if (fast_shutdown) {
117+
LOG(INFO) << log_location_prefix << "skipped delete_all_records";
161118
} else {
162-
#ifdef PWAL
163-
datastore::release_datastore();
164-
#endif
119+
delete_all_records(); // This should be before wp::fin();
120+
}
121+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:end_delete_all_records";
122+
wp::fin(); // note: this use yakushima.
123+
storage::fin(); // note: this use yakushima. delete meta storage.
124+
125+
// about index
126+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:start_shutdown_yakushima";
127+
if (fast_shutdown) {
128+
yakushima::storage::get_storages()->store_root_ptr(nullptr);
129+
LOG(INFO) << log_location_prefix << "skipping yakushima destroy";
165130
}
131+
yakushima::fin();
132+
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:end_shutdown_yakushima";
133+
134+
//// about thread pool
135+
//VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:start_shutdown_thread_pool";
136+
//thread_pool::fin();
137+
//VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "shutdown:end_shutdown_thread_pool";
138+
139+
// about read area
140+
read_plan::fin();
166141

167142
// set flag
168143
set_is_shutdowning(false);
@@ -175,8 +150,7 @@ static void fin_body([[maybe_unused]] bool force_shut_down_logging) try {
175150
}
176151

177152
void fin([[maybe_unused]] bool force_shut_down_logging) {
178-
shirakami_log_entry << "fin, force_shut_down_logging: "
179-
<< force_shut_down_logging;
153+
shirakami_log_entry << "fin, force_shut_down_logging: " << force_shut_down_logging;
180154
fin_body(force_shut_down_logging);
181155
shirakami_log_exit << "fin";
182156
}

0 commit comments

Comments
 (0)