Skip to content

Commit 158df5b

Browse files
committed
refactor: follow to limestone API migration
for developer convenience, allow integration with both old and new limestone.
1 parent 6d5e05a commit 158df5b

File tree

8 files changed

+106
-16
lines changed

8 files changed

+106
-16
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 ()

src/concurrency_control/interface/start_up.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ static Status create_datastore(database_options options) { // NOLINT
9191

9292
// create datastore
9393
std::string data_location_str(log_dir);
94-
boost::filesystem::path data_location(data_location_str);
95-
std::vector<boost::filesystem::path> data_locations;
96-
data_locations.emplace_back(data_location);
97-
std::string metadata_dir{log_dir + "m"};
98-
boost::filesystem::path metadata_path(metadata_dir);
9994
try {
100-
auto limestone_config = limestone::api::configuration(data_locations, metadata_path);
95+
#if HAVE_LIMESTONE_CONFIG_CTOR_NONE && HAVE_LIMESTONE_CONFIG_SET_DATA_LOCATION_STDFSPATH
96+
auto limestone_config = limestone::api::configuration{};
97+
limestone_config.set_data_location(data_location_str);
98+
#else
99+
auto limestone_config = limestone::api::configuration{{data_location_str}, log_dir + "m"};
100+
#endif
101101
if (int max_para = options.get_recover_max_parallelism();
102102
max_para > 0) {
103103
limestone_config.set_recover_max_parallelism(max_para);
@@ -167,7 +167,11 @@ static Status init_body(database_options options, void* datastore) { // NOLINT
167167
/**
168168
* This executes create_channel and pass it to shirakami's executor.
169169
*/
170+
#ifdef HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_NONE
171+
datastore::init_about_session_table();
172+
#else
170173
datastore::init_about_session_table(log_dir);
174+
#endif
171175

172176
// datastore ready
173177
VLOG(log_debug_timing_event) << log_location_prefix_timing_event << "startup:start_datastore_ready";

src/datastore/limestone/datastore.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@ namespace shirakami::datastore {
2222

2323
#if defined(PWAL)
2424

25+
#ifdef HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_NONE
26+
void init_about_session_table() {
27+
for (auto&& elem : session_table::get_session_table()) {
28+
elem.get_lpwal_handle().set_log_channel_ptr(
29+
create_channel(get_datastore()));
30+
}
31+
}
32+
#else
2533
void init_about_session_table(std::string_view log_dir_path) {
2634
boost::filesystem::path log_dir{std::string(log_dir_path)};
2735
for (auto&& elem : session_table::get_session_table()) {
2836
elem.get_lpwal_handle().set_log_channel_ptr(
2937
create_channel(get_datastore(), log_dir));
3038
}
3139
}
40+
#endif
3241

3342
static void recovery_storage_meta(std::vector<Storage>& st_list) {
3443
std::sort(st_list.begin(), st_list.end());

src/datastore/limestone/include/datastore.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ create_datastore(limestone::api::configuration const& conf) {
4444
/**
4545
* @brief It executes create_channel and pass it to shirakami's executor.
4646
*/
47+
#ifdef HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_NONE
48+
void init_about_session_table();
49+
#else
4750
void init_about_session_table(std::string_view log_dir_path);
51+
#endif
4852

4953
/**
5054
* @brief recovery from datastore

src/datastore/limestone/include/limestone_api_helper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ namespace shirakami {
1616

1717
// datastore
1818

19+
#ifdef HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_NONE
20+
limestone::api::log_channel*
21+
create_channel(limestone::api::datastore* ds);
22+
#else
1923
limestone::api::log_channel*
2024
create_channel(limestone::api::datastore* ds,
2125
boost::filesystem::path const& location);
26+
#endif
2227

2328
std::unique_ptr<limestone::api::snapshot>
2429
get_snapshot(limestone::api::datastore* ds);

src/datastore/limestone/limestone_api_helper.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ namespace shirakami {
2020

2121
// datastore
2222

23+
#if HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_NONE
24+
limestone::api::log_channel*
25+
create_channel(limestone::api::datastore* ds) {
26+
if (ds == nullptr) {
27+
LOG_FIRST_N(ERROR, 1) << log_location_prefix << "unreachable path";
28+
return nullptr;
29+
}
30+
shirakami_log_entry << "datastore::create_channel()";
31+
auto& ret = ds->create_channel();
32+
shirakami_log_exit << "datastore::create_channel(): ret: " << &ret;
33+
return &ret;
34+
}
35+
#else
2336
limestone::api::log_channel*
2437
create_channel(limestone::api::datastore* ds,
2538
boost::filesystem::path const& location) {
@@ -29,9 +42,10 @@ create_channel(limestone::api::datastore* ds,
2942
}
3043
shirakami_log_entry << "datastore::create_channel(): location: " << location;
3144
auto& ret = ds->create_channel(location);
32-
shirakami_log_exit << "datastore::create_channel()";
45+
shirakami_log_exit << "datastore::create_channel(): ret: " << &ret;
3346
return &ret;
3447
}
48+
#endif
3549

3650
std::unique_ptr<limestone::api::snapshot>
3751
get_snapshot(limestone::api::datastore* ds) {

test/datastore/limestone_unit_test.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ std::size_t dir_size(boost::filesystem::path& path) {
7575
return total_file_size;
7676
}
7777

78+
static limestone::api::configuration create_limestone_config(const std::string& path) {
79+
#if HAVE_LIMESTONE_CONFIG_CTOR_NONE && HAVE_LIMESTONE_CONFIG_SET_DATA_LOCATION_STDFSPATH
80+
auto limestone_config = limestone::api::configuration{};
81+
limestone_config.set_data_location(path);
82+
#else
83+
auto limestone_config = limestone::api::configuration({path}, path + "m");
84+
#endif
85+
return limestone_config;
86+
}
87+
7888
TEST_F(limestone_unit_test, logging_and_recover) { // NOLINT
7989
// decide test dir name
8090
int tid = syscall(SYS_gettid); // NOLINT
@@ -107,15 +117,18 @@ TEST_F(limestone_unit_test, logging_and_recover) { // NOLINT
107117

108118
// allocate datastore
109119
std::unique_ptr<limestone::api::datastore> datastore;
110-
datastore = std::make_unique<limestone::api::datastore>(
111-
limestone::api::configuration({data_location}, metadata_path));
120+
datastore = std::make_unique<limestone::api::datastore>(create_limestone_config(data_dir));
112121
set_data_log_dir(data_dir);
113122
set_metadata_log_dir(metadata_dir);
114123
limestone::api::datastore* d_ptr{datastore.get()};
115124
d_ptr->add_persistent_callback(set_limestone_durable_epoch);
116125

117126
//create log_channel
127+
#ifdef HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_NONE
128+
limestone::api::log_channel* lc{&d_ptr->create_channel()};
129+
#else
118130
limestone::api::log_channel* lc{&d_ptr->create_channel(data_location)};
131+
#endif
119132

120133
// start datastore
121134
d_ptr->ready();
@@ -176,8 +189,7 @@ TEST_F(limestone_unit_test, logging_and_recover) { // NOLINT
176189
d_ptr->shutdown();
177190

178191
// start datastore
179-
datastore = std::make_unique<limestone::api::datastore>(
180-
limestone::api::configuration({data_location}, metadata_path));
192+
datastore = std::make_unique<limestone::api::datastore>(create_limestone_config(data_dir));
181193
datastore->recover();
182194
datastore->ready();
183195
d_ptr = datastore.get();
@@ -232,8 +244,7 @@ TEST_F(limestone_unit_test, persistent_callback) { // NOLINT
232244

233245
// allocate datastore
234246
std::unique_ptr<limestone::api::datastore> datastore;
235-
datastore = std::make_unique<limestone::api::datastore>(
236-
limestone::api::configuration({data_location}, metadata_path));
247+
datastore = std::make_unique<limestone::api::datastore>(create_limestone_config(data_dir));
237248
set_data_log_dir(data_dir);
238249
set_metadata_log_dir(metadata_dir);
239250
limestone::api::datastore* d_ptr{datastore.get()};

test/start/start_test.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ TEST_F(start_test, valid_recovery_invalid_log_directory) { // NOLINT
4242
fin();
4343
}
4444

45+
static limestone::api::configuration create_limestone_config(const std::string& path) {
46+
#if HAVE_LIMESTONE_CONFIG_CTOR_NONE && HAVE_LIMESTONE_CONFIG_SET_DATA_LOCATION_STDFSPATH
47+
auto limestone_config = limestone::api::configuration{};
48+
limestone_config.set_data_location(path);
49+
#else
50+
auto limestone_config = limestone::api::configuration({path}, path + "m");
51+
#endif
52+
return limestone_config;
53+
}
54+
4555
TEST_F(start_test, borrow_datastore) { // NOLINT
46-
auto limestone_config = limestone::api::configuration({"/tmp/shirakamitest"}, "/tmp/shirakamitest-m");
56+
auto limestone_config = create_limestone_config("/tmp/shirakamitest");
4757
auto datastore = new limestone::api::datastore(limestone_config);
4858
// transitional: need log_directory_path for now
4959
ASSERT_EQ(init({database_options::open_mode::RESTORE, "/tmp/shirakamitest"}, datastore), Status::OK);
@@ -54,7 +64,7 @@ TEST_F(start_test, borrow_datastore) { // NOLINT
5464
}
5565

5666
TEST_F(start_test, error_when_borrow_ds_and_maintenance) { // NOLINT
57-
auto limestone_config = limestone::api::configuration({"/tmp/shirakamitest"}, "/tmp/shirakamitest-m");
67+
auto limestone_config = create_limestone_config("/tmp/shirakamitest");
5868
auto datastore = new limestone::api::datastore(limestone_config);
5969
ASSERT_EQ(init({database_options::open_mode::MAINTENANCE, "/tmp/shirakamitest"}, datastore), Status::ERR_INVALID_CONFIGURATION);
6070
(void)datastore->last_epoch(); // check (by ASAN): datastore is not freed

0 commit comments

Comments
 (0)