diff --git a/src/limestone/datastore_snapshot.cpp b/src/limestone/datastore_snapshot.cpp index 4f6e97cc..00492680 100644 --- a/src/limestone/datastore_snapshot.cpp +++ b/src/limestone/datastore_snapshot.cpp @@ -53,7 +53,7 @@ static int comp_twisted_key(const std::string_view& a, const std::string_view& b } [[maybe_unused]] -static void insert_entry_or_update_to_max(sortdb_wrapper* sortdb, log_entry& e) { +static void insert_entry_or_update_to_max(sortdb_wrapper* sortdb, const log_entry& e) { bool need_write = true; // skip older entry than already inserted std::string value; @@ -73,7 +73,7 @@ static void insert_entry_or_update_to_max(sortdb_wrapper* sortdb, log_entry& e) } [[maybe_unused]] -static void insert_twisted_entry(sortdb_wrapper* sortdb, log_entry& e) { +static void insert_twisted_entry(sortdb_wrapper* sortdb, const log_entry& e) { // key_sid: storage_id[8] key[*], value_etc: epoch[8]LE minor_version[8]LE value[*], type: type[1] // db_key: epoch[8]BE minor_version[8]BE storage_id[8] key[*], db_value: type[1] value[*] std::string db_key(write_version_size + e.key_sid().size(), '\0'); @@ -105,7 +105,7 @@ static std::pair> create_sortdb_f const auto add_entry_to_point = insert_entry_or_update_to_max; bool works_with_multi_thread = false; #endif - auto add_entry = [&sortdb, &add_entry_to_point](log_entry& e){ + auto add_entry = [&sortdb, &add_entry_to_point](const log_entry& e){ switch (e.type()) { case log_entry::entry_type::normal_entry: case log_entry::entry_type::remove_entry: diff --git a/src/limestone/log_entry.h b/src/limestone/log_entry.h index dce7871e..a01e5416 100644 --- a/src/limestone/log_entry.h +++ b/src/limestone/log_entry.h @@ -325,18 +325,19 @@ class log_entry { return true; } - void write_version(write_version_type& buf) { - memcpy(static_cast(&buf), value_etc_.data(), sizeof(epoch_id_type) + sizeof(std::uint64_t)); + void write_version(write_version_type& buf) const { + buf.epoch_number_ = write_version_epoch_number(value_etc_); + buf.minor_write_version_ = write_version_minor_write_version(value_etc_); } [[nodiscard]] storage_id_type storage() const { storage_id_type storage_id{}; memcpy(static_cast(&storage_id), key_sid_.data(), sizeof(storage_id_type)); - return storage_id; + return le64toh(storage_id); } - void value(std::string& buf) { + void value(std::string& buf) const { buf = value_etc_.substr(sizeof(epoch_id_type) + sizeof(std::uint64_t)); } - void key(std::string& buf) { + void key(std::string& buf) const { buf = key_sid_.substr(sizeof(storage_id_type)); } [[nodiscard]] entry_type type() const { @@ -350,18 +351,24 @@ class log_entry { std::string& value_etc() { return value_etc_; } + [[nodiscard]] const std::string& value_etc() const { + return value_etc_; + } std::string& key_sid() { return key_sid_; } + [[nodiscard]] const std::string& key_sid() const { + return key_sid_; + } static epoch_id_type write_version_epoch_number(std::string_view value_etc) { epoch_id_type epoch_id{}; memcpy(static_cast(&epoch_id), value_etc.data(), sizeof(epoch_id_type)); - return epoch_id; + return le64toh(epoch_id); } static std::uint64_t write_version_minor_write_version(std::string_view value_etc) { std::uint64_t minor_write_version{}; memcpy(static_cast(&minor_write_version), value_etc.data() + sizeof(epoch_id_type), sizeof(std::uint64_t)); - return minor_write_version; + return le64toh(minor_write_version); } private: