From 313a23a988b5a56e26b6c3425083be360ded3ef2 Mon Sep 17 00:00:00 2001 From: Nobuhiro Ban Date: Thu, 22 Aug 2024 21:32:14 +0900 Subject: [PATCH] increment current persisitent format version --- src/limestone/datastore_format.cpp | 17 +++++++++------- src/limestone/dblogutil/dblogutil.cpp | 2 +- src/limestone/internal.h | 2 ++ test/limestone/log/log_dir_test.cpp | 20 ++++++++++--------- test/limestone/log/rotate_test.cpp | 6 +++--- test/limestone/log/testdata.cpp | 2 +- .../utils/dblogutil_compaction_test.cpp | 2 +- test/limestone/utils/dblogutil_test.cpp | 2 +- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/limestone/datastore_format.cpp b/src/limestone/datastore_format.cpp index 59c857e6..45239913 100644 --- a/src/limestone/datastore_format.cpp +++ b/src/limestone/datastore_format.cpp @@ -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. @@ -31,9 +31,9 @@ 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) @@ -41,7 +41,7 @@ void setup_initial_logdir(const boost::filesystem::path& logdir) { 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; @@ -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(); @@ -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; diff --git a/src/limestone/dblogutil/dblogutil.cpp b/src/limestone/dblogutil/dblogutil.cpp index dab72eb6..cc11a83e 100644 --- a/src/limestone/dblogutil/dblogutil.cpp +++ b/src/limestone/dblogutil/dblogutil.cpp @@ -59,7 +59,7 @@ void log_and_exit(int error) { namespace limestone { void inspect(dblog_scan &ds, std::optional 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(); diff --git a/src/limestone/internal.h b/src/limestone/internal.h index a83df066..e639a1c8 100644 --- a/src/limestone/internal.h +++ b/src/limestone/internal.h @@ -46,6 +46,8 @@ std::optional 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); /** diff --git a/test/limestone/log/log_dir_test.cpp b/test/limestone/log/log_dir_test.cpp index 0eead184..27d88db8 100644 --- a/test/limestone/log/log_dir_test.cpp +++ b/test/limestone/log/log_dir_test.cpp @@ -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; @@ -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)); } @@ -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(); @@ -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(); @@ -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 entries; entries.emplace_back("epoch", "epoch", false); @@ -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 entries; entries.emplace_back("epoch", "epoch", false); diff --git a/test/limestone/log/rotate_test.cpp b/test/limestone/log/rotate_test.cpp index 460c5b26..e864c17c 100644 --- a/test/limestone/log/rotate_test.cpp +++ b/test/limestone/log/rotate_test.cpp @@ -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; @@ -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 @@ -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 diff --git a/test/limestone/log/testdata.cpp b/test/limestone/log/testdata.cpp index 5fd24620..d35f9e07 100644 --- a/test/limestone/log/testdata.cpp +++ b/test/limestone/log/testdata.cpp @@ -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(); diff --git a/test/limestone/utils/dblogutil_compaction_test.cpp b/test/limestone/utils/dblogutil_compaction_test.cpp index dbde5593..fc08b95d 100644 --- a/test/limestone/utils/dblogutil_compaction_test.cpp +++ b/test/limestone/utils/dblogutil_compaction_test.cpp @@ -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; diff --git a/test/limestone/utils/dblogutil_test.cpp b/test/limestone/utils/dblogutil_test.cpp index 6088db64..9288a310 100644 --- a/test/limestone/utils/dblogutil_test.cpp +++ b/test/limestone/utils/dblogutil_test.cpp @@ -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;