Skip to content

Commit

Permalink
Add cp flush during shutdown in index btree (eBay#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
shosseinimotlagh authored Oct 5, 2023
1 parent cd4d671 commit bf8e6fd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
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

0 comments on commit bf8e6fd

Please sign in to comment.