Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix save and load for shadowmap in index service #438

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "6.4.10"
version = "6.4.11"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
1 change: 0 additions & 1 deletion src/tests/btree_helpers/btree_test_kvs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ class TestVarLenKey : public BtreeKey {
std::stringstream ss;
ss << std::hex << data.substr(0, 8);
ss >> m_key;
assert(data == *idx_to_key(m_key));
}

// Add 8 bytes for preamble.
Expand Down
60 changes: 40 additions & 20 deletions src/tests/btree_helpers/shadow_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ class ShadowMap {
const int key_width = 20;

// Format the key-value pairs and insert them into the result string
ss << std::left << std::setw(key_width) << "KEY"
<< " "
<< "VaLUE" << '\n';
ss << std::left << std::setw(key_width) << "KEY" << " " << "VALUE" << '\n';
foreach ([&](const auto& key, const auto& value) {
ss << std::left << std::setw(key_width) << key.to_string() << " " << value.to_string() << '\n';
});
Expand Down Expand Up @@ -188,27 +186,49 @@ class ShadowMap {
m_range_scheduler.remove_keys(start_key, end_key);
}

void save(const std::string& filename) {
std::lock_guard lock{m_mutex};
std::ofstream file(filename);
void save(const std::filesystem::path& filename) {
std::scoped_lock lock{m_mutex};
std::ofstream file(filename, std::ios::binary);
if (!file) {
throw std::runtime_error("Error opening file for writing: " + filename.string());
}
for (const auto& [key, value] : m_map) {
file << key << " " << value << '\n';
auto s_Key = key.serialize();
auto s_value = value.serialize();
uint32_t k_size = s_Key.size();
uint32_t v_size = s_value.size();

file.write(reinterpret_cast< const char* >(&k_size), sizeof(k_size));
file.write(reinterpret_cast< const char* >(s_Key.cbytes()), k_size);
file.write(reinterpret_cast< const char* >(&v_size), sizeof(v_size));
file.write(reinterpret_cast< const char* >(s_value.cbytes()), v_size);
}
file.close();
}

void load(const std::string& filename) {
std::lock_guard lock{m_mutex};
std::ifstream file(filename);
if (file.is_open()) {
m_map.clear();
K key;
V value;
while (file >> key >> value) {
m_map.emplace(key, std::move(value));
m_range_scheduler.put_key(key.key());
}
file.close();
void load(const std::filesystem::path& filename) {
uint32_t k_size;
uint32_t v_size;
K key;
V value;
std::scoped_lock lock{m_mutex};
std::ifstream file(filename, std::ios::binary);
if (!file) {
throw std::runtime_error("Error opening file for writing: " + filename.string());
}

while (file.peek() != EOF) {
file.read(reinterpret_cast< char* >(&k_size), sizeof(k_size));
std::vector< uint8_t > k_buffer(k_size);
file.read(reinterpret_cast< char* >(k_buffer.data()), k_size);
file.read(reinterpret_cast< char* >(&v_size), sizeof(v_size));
std::vector< uint8_t > v_buffer(v_size);
file.read(reinterpret_cast< char* >(v_buffer.data()), v_size);

key.deserialize(sisl::blob(k_buffer.data(), k_size), true);
value.deserialize(sisl::blob(v_buffer.data(), v_size), true);

m_map.emplace(key, std::move(value));
m_range_scheduler.put_key(key.key());
}
}
};
1 change: 0 additions & 1 deletion src/tests/test_index_btree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*********************************************************************************/
#include <gtest/gtest.h>
#include <boost/uuid/random_generator.hpp>

#include <sisl/utility/enum.hpp>
#include "common/homestore_config.hpp"
#include "common/resource_mgr.hpp"
Expand Down
14 changes: 10 additions & 4 deletions src/tests/test_scripts/index_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def parse_arguments():
parser.add_argument('--dev_list', help='Device list', default='')
parser.add_argument('--cleanup_after_shutdown', help='Cleanup after shutdown', type=bool, default=False)
parser.add_argument('--init_device', help='Initialize device', type=bool, default=True)
parser.add_argument('--type', help='node type', type=int, default=0)

# Parse the known arguments and ignore any unknown arguments
args, unknown = parser.parse_known_args()
Expand Down Expand Up @@ -80,12 +81,13 @@ def long_running_clean_shutdown(options, type=0):
def main():
options = parse_arguments()
test_suite_name = options['test_suits']
tree_type = options['type']
try:
# Retrieve the function based on the name provided in options['test_suits']
test_suite_function = globals().get(test_suite_name)
if callable(test_suite_function):
print(f"Running {test_suite_name} with options: {options}")
test_suite_function(options)
test_suite_function(options, tree_type)
else:
print(f"Test suite '{test_suite_name}' is not a callable function.")
except KeyError:
Expand All @@ -94,9 +96,13 @@ def main():

def long_running(*args):
options = parse_arguments()
long_runnig_index(options)
long_running_clean_shutdown(options)

tree_type = options['type']
try:
long_runnig_index(options, tree_type)
long_running_clean_shutdown(options, tree_type)
except TestFailedError as e:
print(f"Test failed: {e}")
raise

if __name__ == "__main__":
main()
Loading