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

Add cp flush during shutdown in index btree #194

Merged
merged 2 commits into from
Oct 5, 2023
Merged
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 = "4.5.2"
version = "4.5.3"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
1 change: 1 addition & 0 deletions src/include/homestore/index/index_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class IndexTableBase {
virtual ~IndexTableBase() = default;
virtual uuid_t uuid() const = 0;
virtual uint64_t used_size() const = 0;
virtual void destroy() = 0;
};

enum class index_buf_state_t : uint8_t {
Expand Down
6 changes: 6 additions & 0 deletions src/include/homestore/index/index_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class IndexTable : public IndexTableBase, public Btree< K, V > {
Btree< K, V >::set_root_node_info(BtreeLinkInfo{m_sb->root_node, m_sb->link_version});
}

void destroy() override {
auto cpg = hs()->cp_mgr().cp_guard();
auto op_context = (void*)cpg.context(cp_consumer_t::INDEX_SVC);
Btree< K, V >::destroy_btree(op_context);
}

btree_status_t init() {
auto cp = hs()->cp_mgr().cp_guard();
auto ret = Btree< K, V >::init((void*)cp.context(cp_consumer_t::INDEX_SVC));
Expand Down
3 changes: 3 additions & 0 deletions src/include/homestore/index_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class IndexService {
// Start the Index Service
void start();

// Stop the Index Service
void stop();

// Add/Remove Index Table to/from the index service
void add_index_table(const std::shared_ptr< IndexTableBase >& tbl);
void remove_index_table(const std::shared_ptr< IndexTableBase >& tbl);
Expand Down
6 changes: 6 additions & 0 deletions src/lib/homestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ void HomeStore::do_start() {

void HomeStore::shutdown() {
LOGINFO("Homestore shutdown is started");

if (has_index_service()) {
m_index_service->stop();
// m_index_service.reset();
}

if (has_log_service()) {
m_log_service->stop();
m_log_service.reset();
Expand Down
16 changes: 16 additions & 0 deletions src/lib/index/index_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,27 @@ void IndexService::start() {
std::move(std::make_unique< IndexCPCallbacks >(m_wb_cache.get())));
}

void IndexService::stop() {
std::unique_lock lg(m_index_map_mtx);
auto fut = homestore::hs()->cp_mgr().trigger_cp_flush(true /* force */);
auto success = std::move(fut).get();
HS_REL_ASSERT_EQ(success, true, "CP Flush failed");
LOGINFO("CP Flush completed");

for (auto [id, tbl] : m_index_map) { tbl->destroy(); }
}
void IndexService::add_index_table(const std::shared_ptr< IndexTableBase >& tbl) {
std::unique_lock lg(m_index_map_mtx);
m_index_map.insert(std::make_pair(tbl->uuid(), tbl));
}

void IndexService::remove_index_table(const std::shared_ptr< IndexTableBase >& tbl) {
std::unique_lock lg(m_index_map_mtx);
auto cpg = hs()->cp_mgr().cp_guard();
auto op_context = (void*)cpg.context(cp_consumer_t::INDEX_SVC);
m_index_map.erase(tbl->uuid());
}

uint32_t IndexService::node_size() const { return hs()->device_mgr()->atomic_page_size(HSDevType::Fast); }

uint64_t IndexService::used_size() const {
Expand Down
1 change: 0 additions & 1 deletion src/tests/test_index_btree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ struct BtreeTest : public testing::Test {
}

void TearDown() override {
this->destroy_btree();
test_common::HSTestHelper::shutdown_homestore();
}

Expand Down