Skip to content

Commit

Permalink
Add cp flush during shutdown in index btree
Browse files Browse the repository at this point in the history
  • Loading branch information
shosseinimotlagh committed Oct 5, 2023
2 parents fb6ddf4 + 119e67e commit f4e486e
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 27 deletions.
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
2 changes: 1 addition & 1 deletion src/include/homestore/blkdata_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BlkDataService {
* @param size : size of this vdev
*/
void create_vdev(uint64_t size, uint32_t blk_size, blk_allocator_type_t alloc_type,
chunk_selector_type_t chunk_sel_type);
chunk_selector_type_t chunk_sel_type, uint32_t num_chunks);

/**
* @brief : called during recovery to open existing vdev for data service
Expand Down
2 changes: 1 addition & 1 deletion src/include/homestore/index_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class IndexService {
IndexService(std::unique_ptr< IndexServiceCallbacks > cbs);

// Creates the vdev that is needed to initialize the device
void create_vdev(uint64_t size);
void create_vdev(uint64_t size, uint32_t num_chunks);

// Open the existing vdev which is represnted by the vdev_info_block
shared< VirtualDev > open_vdev(const vdev_info& vb, bool load_existing);
Expand Down
2 changes: 1 addition & 1 deletion src/include/homestore/logstore_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class LogStoreService {
void device_truncate(const device_truncate_cb_t& cb = nullptr, const bool wait_till_done = false,
const bool dry_run = false);

folly::Future< std::error_code > create_vdev(uint64_t size, logstore_family_id_t family);
folly::Future< std::error_code > create_vdev(uint64_t size, logstore_family_id_t family, uint32_t num_chunks);
shared< VirtualDev > open_vdev(const vdev_info& vinfo, logstore_family_id_t family, bool load_existing);
shared< JournalVirtualDev > get_vdev(logstore_family_id_t family) const {
return (family == DATA_LOG_FAMILY_IDX) ? m_data_logdev_vdev : m_ctrl_logdev_vdev;
Expand Down
2 changes: 1 addition & 1 deletion src/include/homestore/meta_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class MetaBlkService {
~MetaBlkService() = default;

// Creates the vdev that is needed to initialize the device
void create_vdev(uint64_t size);
void create_vdev(uint64_t size, uint32_t num_chunks);

// Open the existing vdev which is represented by the vdev_info
shared< VirtualDev > open_vdev(const vdev_info& vinfo, bool load_existing);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/blkdata_svc/blkdata_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ BlkDataService::~BlkDataService() = default;

// first-time boot path
void BlkDataService::create_vdev(uint64_t size, uint32_t blk_size, blk_allocator_type_t alloc_type,
chunk_selector_type_t chunk_sel_type) {
chunk_selector_type_t chunk_sel_type, uint32_t num_chunks) {
hs_vdev_context vdev_ctx;
vdev_ctx.type = hs_vdev_type_t::DATA_VDEV;

if (blk_size == 0) { blk_size = hs()->device_mgr()->optimal_page_size(HSDevType::Data); }
m_vdev =
hs()->device_mgr()->create_vdev(vdev_parameters{.vdev_name = "blkdata",
.vdev_size = size,
.num_chunks = 1,
.num_chunks = num_chunks,
.blk_size = blk_size,
.dev_type = HSDevType::Data,
.alloc_type = alloc_type,
Expand Down
7 changes: 4 additions & 3 deletions src/lib/checkpoint/cp_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ void CPManager::create_first_cp() {
}

void CPManager::shutdown() {
LOGINFO("Stopping cp timer");
iomanager.cancel_timer(m_cp_timer_hdl, true);
m_cp_timer_hdl = iomgr::null_timer_handle;

auto cp = get_cur_cp();
delete (cp);
rcu_xchg_pointer(&m_cur_cp, nullptr);
Expand All @@ -79,9 +83,6 @@ void CPManager::shutdown() {
m_wd_cp->stop();
m_wd_cp.reset();
}

iomanager.cancel_timer(m_cp_timer_hdl, true);
m_cp_timer_hdl = iomgr::null_timer_handle;
}

void CPManager::register_consumer(cp_consumer_t consumer_id, std::unique_ptr< CPCallbacks > callbacks) {
Expand Down
13 changes: 13 additions & 0 deletions src/lib/device/device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ shared< VirtualDev > DeviceManager::create_vdev(vdev_parameters&& vparam) {
LOGINFO("{} Virtual device is attempted to be created with size={}, it needs to be rounded to new_size={}",
vparam.vdev_name, in_bytes(input_vdev_size), in_bytes(vparam.vdev_size));
}

// Adjust the maximum number chunks requested.
uint32_t max_num_chunks = 0;
for (const auto& d : m_dev_infos) {
max_num_chunks += hs_super_blk::max_chunks_in_pdev(d);
}
auto input_num_chunks = vparam.num_chunks;
vparam.num_chunks = std::min(vparam.num_chunks, max_num_chunks);
if (input_num_chunks != vparam.num_chunks) {
LOGINFO("{} Virtual device is attempted to be created with num_chunks={}, it needs to be adjust to "
"new_num_chunks={}",
vparam.vdev_name, in_bytes(input_num_chunks), in_bytes(vparam.num_chunks));
}
uint32_t chunk_size = vparam.vdev_size / vparam.num_chunks;

LOGINFO(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/device/physical_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void PhysicalDev::free_chunk_info(chunk_info* cinfo) {
}

ChunkInterval PhysicalDev::find_next_chunk_area(uint64_t size) const {
auto ins_ival = ChunkInterval::right_open(data_start_offset(), size);
auto ins_ival = ChunkInterval::right_open(data_start_offset(), data_start_offset() + size);
for (auto& exist_ival : m_chunk_data_area) {
if (ins_ival.upper() <= exist_ival.lower()) { break; }
ins_ival = ChunkInterval::right_open(exist_ival.upper(), exist_ival.upper() + size);
Expand Down
14 changes: 7 additions & 7 deletions src/lib/homestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,21 @@ void HomeStore::format_and_start(std::map< uint32_t, hs_format_params >&& format
if (fparams.size_pct == 0) { continue; }

if ((svc_type & HS_SERVICE::META) && has_meta_service()) {
m_meta_service->create_vdev(pct_to_size(fparams.size_pct, HSDevType::Fast));
m_meta_service->create_vdev(pct_to_size(fparams.size_pct, HSDevType::Fast), fparams.num_chunks);
} else if ((svc_type & HS_SERVICE::LOG_REPLICATED) && has_log_service()) {
futs.emplace_back(m_log_service->create_vdev(pct_to_size(fparams.size_pct, HSDevType::Fast),
LogStoreService::DATA_LOG_FAMILY_IDX));
LogStoreService::DATA_LOG_FAMILY_IDX, fparams.num_chunks));
} else if ((svc_type & HS_SERVICE::LOG_LOCAL) && has_log_service()) {
futs.emplace_back(m_log_service->create_vdev(pct_to_size(fparams.size_pct, HSDevType::Fast),
LogStoreService::CTRL_LOG_FAMILY_IDX));
LogStoreService::CTRL_LOG_FAMILY_IDX, fparams.num_chunks));
} else if ((svc_type & HS_SERVICE::DATA) && has_data_service()) {
m_data_service->create_vdev(pct_to_size(fparams.size_pct, HSDevType::Data), fparams.block_size,
fparams.alloc_type, fparams.chunk_sel_type);
fparams.alloc_type, fparams.chunk_sel_type, fparams.num_chunks);
} else if ((svc_type & HS_SERVICE::INDEX) && has_index_service()) {
m_index_service->create_vdev(pct_to_size(fparams.size_pct, HSDevType::Fast));
m_index_service->create_vdev(pct_to_size(fparams.size_pct, HSDevType::Fast), fparams.num_chunks);
} else if ((svc_type & HS_SERVICE::REPLICATION) && has_repl_data_service()) {
m_data_service->create_vdev(pct_to_size(fparams.size_pct, HSDevType::Data), fparams.block_size,
fparams.alloc_type, fparams.chunk_sel_type);
fparams.alloc_type, fparams.chunk_sel_type, fparams.num_chunks);
}
}

Expand Down Expand Up @@ -216,7 +216,7 @@ void HomeStore::shutdown() {

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

if (has_log_service()) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/index/index_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ IndexService::IndexService(std::unique_ptr< IndexServiceCallbacks > cbs) : m_svc
nullptr);
}

void IndexService::create_vdev(uint64_t size) {
void IndexService::create_vdev(uint64_t size, uint32_t num_chunks) {
auto const atomic_page_size = hs()->device_mgr()->atomic_page_size(HSDevType::Fast);
hs_vdev_context vdev_ctx;
vdev_ctx.type = hs_vdev_type_t::INDEX_VDEV;

hs()->device_mgr()->create_vdev(vdev_parameters{.vdev_name = "index",
.vdev_size = size,
.num_chunks = 1,
.num_chunks = num_chunks,
.blk_size = atomic_page_size,
.dev_type = HSDevType::Fast,
.alloc_type = blk_allocator_type_t::fixed,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/logstore/log_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void LogDev::stop() {
m_block_flush_q_cv.wait(lk, [&] { return m_stopped; });
}

// cancel the timer
iomanager.cancel_timer(m_flush_timer_hdl, true);

m_log_records = nullptr;
m_logdev_meta.reset();
m_log_idx.store(0);
Expand All @@ -137,8 +140,6 @@ void LogDev::stop() {
}

THIS_LOGDEV_LOG(INFO, "LogDev stopped successfully");
// cancel the timer
iomanager.cancel_timer(m_flush_timer_hdl, true);
m_hs.reset();
}

Expand Down
5 changes: 3 additions & 2 deletions src/lib/logstore/log_store_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ LogStoreService::LogStoreService() :
m_logstore_families{std::make_unique< LogStoreFamily >(DATA_LOG_FAMILY_IDX),
std::make_unique< LogStoreFamily >(CTRL_LOG_FAMILY_IDX)} {}

folly::Future< std::error_code > LogStoreService::create_vdev(uint64_t size, logstore_family_id_t family) {
folly::Future< std::error_code > LogStoreService::create_vdev(uint64_t size, logstore_family_id_t family,
uint32_t num_chunks) {
const auto atomic_page_size = hs()->device_mgr()->atomic_page_size(HSDevType::Fast);

hs_vdev_context hs_ctx;
Expand All @@ -62,7 +63,7 @@ folly::Future< std::error_code > LogStoreService::create_vdev(uint64_t size, log
auto vdev =
hs()->device_mgr()->create_vdev(vdev_parameters{.vdev_name = name,
.vdev_size = size,
.num_chunks = 1,
.num_chunks = num_chunks,
.blk_size = atomic_page_size,
.dev_type = HSDevType::Fast,
.alloc_type = blk_allocator_type_t::none,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/meta/meta_blk_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ MetaBlkService& meta_service() { return hs()->meta_service(); }

MetaBlkService::MetaBlkService(const char* name) : m_metrics{name} { m_last_mblk_id = std::make_unique< BlkId >(); }

void MetaBlkService::create_vdev(uint64_t size) {
void MetaBlkService::create_vdev(uint64_t size, uint32_t num_chunks) {
const auto phys_page_size = hs()->device_mgr()->optimal_page_size(HSDevType::Fast);

meta_vdev_context meta_ctx;
meta_ctx.type = hs_vdev_type_t::META_VDEV;

hs()->device_mgr()->create_vdev(vdev_parameters{.vdev_name = "meta",
.vdev_size = size,
.num_chunks = 1,
.num_chunks = num_chunks,
.blk_size = phys_page_size,
.dev_type = HSDevType::Fast,
.alloc_type = blk_allocator_type_t::varsize,
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ TEST_F(DeviceMgrTest, StripedVDevCreation) {
avail_size += pdev->data_size();
}

uint32_t size_pct = 4;
uint32_t size_pct = 2;
uint64_t remain_size = avail_size;

LOGINFO("Step 1: Creating {} vdevs with combined size as {}", in_bytes(avail_size));
Expand Down

0 comments on commit f4e486e

Please sign in to comment.