Skip to content

Commit

Permalink
increment current persisitent format version
Browse files Browse the repository at this point in the history
  • Loading branch information
ban-nobuhiro committed Aug 22, 2024
1 parent 9545ed7 commit 313a23a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 23 deletions.
17 changes: 10 additions & 7 deletions src/limestone/datastore_format.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2023 Project Tsurugi.
* Copyright 2023-2024 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,17 +31,17 @@ using namespace limestone::api;

// setup log-dir with no data
void setup_initial_logdir(const boost::filesystem::path& logdir) {
nlohmann::json manifest_v1 = {
nlohmann::json manifest_current = {
{ "format_version", "1.0" },
{ "persistent_format_version", 1 }
{ "persistent_format_version", current_persistent_format_version }
};
boost::filesystem::path config = logdir / std::string(manifest_file_name);
FILE* strm = fopen(config.c_str(), "w"); // NOLINT(*-owning-memory)
if (!strm) {
LOG_LP(ERROR) << "fopen for write failed, errno = " << errno;
throw std::runtime_error("I/O error");
}
std::string manifest_str = manifest_v1.dump(4);
std::string manifest_str = manifest_current.dump(4);
auto ret = fwrite(manifest_str.c_str(), manifest_str.length(), 1, strm);
if (ret != 1) {
LOG_LP(ERROR) << "fwrite failed, errno = " << errno;
Expand Down Expand Up @@ -75,10 +75,13 @@ int is_supported_version(const boost::filesystem::path& manifest_path, std::stri
istrm >> manifest;
auto version = manifest["persistent_format_version"];
if (version.is_number_integer()) {
if (version == 1) {
if (version == current_persistent_format_version) {
return 1; // supported
}
errmsg = "version mismatch: version " + version.dump() + ", server supports version 1";
// if versions other than current_persistent_format_version are supported, add here

// unsupported
errmsg = "version mismatch: version " + version.dump() + ", server supports version " + std::to_string(current_persistent_format_version);
return 0;
}
errmsg = "invalid manifest file, invalid persistent_format_version: " + version.dump();
Expand All @@ -94,7 +97,7 @@ void check_logdir_format(const boost::filesystem::path& logdir) {
boost::filesystem::path manifest_path = logdir / std::string(manifest_file_name);
if (!boost::filesystem::exists(manifest_path)) {
VLOG_LP(log_info) << "no manifest file in logdir, maybe v0";
LOG(ERROR) << version_error_prefix << " (version mismatch: version 0, server supports version 1)";
LOG(ERROR) << version_error_prefix << " (version mismatch: version 0, server supports version " << current_persistent_format_version << ")";
throw std::runtime_error("logdir version mismatch");
}
std::string errmsg;
Expand Down
2 changes: 1 addition & 1 deletion src/limestone/dblogutil/dblogutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void log_and_exit(int error) {
namespace limestone {

void inspect(dblog_scan &ds, std::optional<epoch_id_type> epoch) {
std::cout << "persistent-format-version: 1" << std::endl;
std::cout << "persistent-format-version: " << internal::current_persistent_format_version << std::endl;
epoch_id_type ld_epoch{};
try {
ld_epoch = ds.last_durable_epoch_in_dir();
Expand Down
2 changes: 2 additions & 0 deletions src/limestone/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ std::optional<epoch_id_type> last_durable_epoch(const boost::filesystem::path& f

inline constexpr const std::string_view manifest_file_name = "limestone-manifest.json";

inline constexpr const int current_persistent_format_version = 2;

void setup_initial_logdir(const boost::filesystem::path& logdir);

/**
Expand Down
20 changes: 11 additions & 9 deletions test/limestone/log/log_dir_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace limestone::testing {
extern void create_file(const boost::filesystem::path& path, std::string_view content);
extern const std::string_view epoch_0_str;
extern const std::string_view epoch_0x100_str;
extern std::string data_manifest(int persistent_format_version = 1);
extern std::string data_manifest(int persistent_format_version = limestone::internal::current_persistent_format_version);
extern const std::string_view data_normal;
extern const std::string_view data_nondurable;

Expand Down Expand Up @@ -51,7 +51,7 @@ const boost::filesystem::path manifest_path = boost::filesystem::path(location)
static bool is_pwal(const boost::filesystem::path& p) { return starts_with(p.filename().string(), "pwal"); }
static void ignore_entry(limestone::api::log_entry&) {}

void create_mainfest_file(int persistent_format_version = 1) {
void create_mainfest_file(int persistent_format_version = limestone::internal::current_persistent_format_version) {
create_file(manifest_path, data_manifest(persistent_format_version));
}

Expand Down Expand Up @@ -112,20 +112,21 @@ TEST_F(log_dir_test, accept_directory_only_correct_manifest_file) {
}

TEST_F(log_dir_test, reject_directory_of_different_version) {
create_mainfest_file(222);
create_mainfest_file(limestone::internal::current_persistent_format_version + 222);

gen_datastore();
EXPECT_THROW({ limestone::internal::check_logdir_format(location); }, std::exception);
}

TEST_F(log_dir_test, rotate_old_ok_v1_dir) {
TEST_F(log_dir_test, rotate_old_ok_current_ver_dir) {
// setup backups
boost::filesystem::path bk_path = boost::filesystem::path(location) / "bk";
if (!boost::filesystem::create_directory(bk_path)) {
LOG(FATAL) << "cannot make directory";
}
create_file(bk_path / "epoch", epoch_0_str);
create_file(bk_path / std::string(limestone::internal::manifest_file_name), data_manifest(1));
create_file(bk_path / std::string(limestone::internal::manifest_file_name),
data_manifest(limestone::internal::current_persistent_format_version));

gen_datastore();

Expand All @@ -139,7 +140,8 @@ TEST_F(log_dir_test, rotate_old_rejects_unsupported_data) {
LOG(FATAL) << "cannot make directory";
}
create_file(bk_path / "epoch", epoch_0_str);
create_file(bk_path / std::string(limestone::internal::manifest_file_name), data_manifest(2));
create_file(bk_path / std::string(limestone::internal::manifest_file_name),
data_manifest(limestone::internal::current_persistent_format_version + 222));

gen_datastore();

Expand Down Expand Up @@ -174,14 +176,14 @@ TEST_F(log_dir_test, rotate_old_rejects_corrupted_dir) {
EXPECT_EQ(datastore_->restore(bk_path.string(), true), limestone::status::err_broken_data);
}

TEST_F(log_dir_test, rotate_prusik_ok_v1_dir) {
TEST_F(log_dir_test, rotate_prusik_ok_current_ver_dir) {
// setup backups
boost::filesystem::path bk_path = boost::filesystem::path(location) / "bk";
if (!boost::filesystem::create_directory(bk_path)) {
LOG(FATAL) << "cannot make directory";
}
create_file(bk_path / "epoch", epoch_0_str);
create_file(bk_path / std::string(limestone::internal::manifest_file_name), data_manifest(1));
create_file(bk_path / std::string(limestone::internal::manifest_file_name), data_manifest(limestone::internal::current_persistent_format_version));
// setup entries
std::vector<limestone::api::file_set_entry> entries;
entries.emplace_back("epoch", "epoch", false);
Expand All @@ -199,7 +201,7 @@ TEST_F(log_dir_test, rotate_prusik_rejects_unsupported_data) {
LOG(FATAL) << "cannot make directory";
}
create_file(bk_path / "epoch", epoch_0_str);
create_file(bk_path / std::string(limestone::internal::manifest_file_name), data_manifest(2));
create_file(bk_path / std::string(limestone::internal::manifest_file_name), data_manifest(limestone::internal::current_persistent_format_version + 222));
// setup entries
std::vector<limestone::api::file_set_entry> entries;
entries.emplace_back("epoch", "epoch", false);
Expand Down
6 changes: 3 additions & 3 deletions test/limestone/log/rotate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class rotate_test : public ::testing::Test {
};

extern void create_file(const boost::filesystem::path& path, std::string_view content);
extern std::string data_manifest(int persistent_format_version = 1);
extern std::string data_manifest(int persistent_format_version = limestone::internal::current_persistent_format_version);

TEST_F(rotate_test, log_is_rotated) { // NOLINT
using namespace limestone::api;
Expand Down Expand Up @@ -249,7 +249,7 @@ TEST_F(rotate_test, restore_prusik_all_abs) { // NOLINT
auto conffn = std::string(limestone::internal::manifest_file_name);
auto confd = location_path / "bk0";
boost::filesystem::create_directories(confd);
create_file(confd / conffn, data_manifest(1));
create_file(confd / conffn, data_manifest(limestone::internal::current_persistent_format_version));
data.emplace_back(confd / conffn, conffn, false);
#endif

Expand Down Expand Up @@ -299,7 +299,7 @@ TEST_F(rotate_test, restore_prusik_all_rel) { // NOLINT
std::string conffn(limestone::internal::manifest_file_name);
auto confd = location_path / "bk0";
boost::filesystem::create_directories(confd);
create_file(confd / conffn, data_manifest(1));
create_file(confd / conffn, data_manifest(limestone::internal::current_persistent_format_version));
data.emplace_back("bk0/" + conffn, conffn, false);
#endif

Expand Down
2 changes: 1 addition & 1 deletion test/limestone/log/testdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extern constexpr const std::string_view data_allzero =
"\x00\x00\x00\x00\x00\x00\x00\x00\x00" // UNKNOWN_TYPE_entry
""sv;

std::string data_manifest(int persistent_format_version = 1) {
std::string data_manifest(int persistent_format_version = limestone::internal::current_persistent_format_version) {
std::ostringstream ss;
ss << "{ \"format_version\": \"1.0\", \"persistent_format_version\": " << persistent_format_version << " }";
return ss.str();
Expand Down
2 changes: 1 addition & 1 deletion test/limestone/utils/dblogutil_compaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace limestone::internal;

extern void create_file(const boost::filesystem::path& path, std::string_view content);
extern std::string read_entire_file(const boost::filesystem::path& path);
extern std::string data_manifest(int persistent_format_version = 1);
extern std::string data_manifest(int persistent_format_version = limestone::internal::current_persistent_format_version);

extern const std::string_view epoch_0x100_str;

Expand Down
2 changes: 1 addition & 1 deletion test/limestone/utils/dblogutil_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace limestone::internal;

extern void create_file(const boost::filesystem::path& path, std::string_view content);
extern std::string read_entire_file(const boost::filesystem::path& path);
extern std::string data_manifest(int persistent_format_version = 1);
extern std::string data_manifest(int persistent_format_version = limestone::internal::current_persistent_format_version);

extern const std::string_view epoch_0x100_str;

Expand Down

0 comments on commit 313a23a

Please sign in to comment.