From aff7a0afb1ffc858e7d476c2667f3af0b74a58f1 Mon Sep 17 00:00:00 2001 From: Hooper Date: Tue, 26 Nov 2024 10:54:41 +0800 Subject: [PATCH] Support flexible virtual device creation in HomeStore with num_chunks or chunk_size Refactored the BlkDataService and updated HomeStore::format_and_start to support virtual device creation by specifying either the number of chunks or the size of each chunk. - Renamed the original `create_vdev` method to `create_vdev_with_num_chunks` to explicitly indicate the use of num_chunks. - Added a new method `create_vdev_with_chunk_size` to allow specifying chunk size instead of the number of chunks. - Updated format_and_start to conditionally call create_vdev_with_num_chunks or create_vdev_with_chunk_size based on non-zero values, ensuring at least one is specified. --- conanfile.py | 2 +- src/include/homestore/blkdata_service.hpp | 17 +++++++++++- src/lib/blkdata_svc/blkdata_service.cpp | 20 +++++++++++++- src/lib/homestore.cpp | 32 ++++++++++++++++++----- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/conanfile.py b/conanfile.py index d6fd6f6f1..606d1a6ea 100644 --- a/conanfile.py +++ b/conanfile.py @@ -9,7 +9,7 @@ class HomestoreConan(ConanFile): name = "homestore" - version = "6.5.16" + version = "6.5.17" homepage = "https://github.com/eBay/Homestore" description = "HomeStore Storage Engine" diff --git a/src/include/homestore/blkdata_service.hpp b/src/include/homestore/blkdata_service.hpp index b82ec886b..e0df5ef9b 100644 --- a/src/include/homestore/blkdata_service.hpp +++ b/src/include/homestore/blkdata_service.hpp @@ -65,9 +65,24 @@ class BlkDataService { * @param chunk_sel_type The type of chunk selector to use for the virtual device. * @param num_chunks The number of chunks to use for the virtual device. */ - void create_vdev(uint64_t size, HSDevType devType, uint32_t blk_size, blk_allocator_type_t alloc_type, + void create_vdev_with_num_chunks(uint64_t size, HSDevType devType, uint32_t blk_size, blk_allocator_type_t alloc_type, chunk_selector_type_t chunk_sel_type, uint32_t num_chunks); + /** + * @brief Creates a new virtual device with the specified size and block size, using the specified + * block allocator and chunk selector types. The virtual device will be composed of the specified + * size of chunks. + * + * @param size The size of the virtual device, in bytes. + * @param blk_size The size of each block in the virtual device, in bytes. + * @param alloc_type The type of block allocator to use for the virtual device. + * @param chunk_sel_type The type of chunk selector to use for the virtual device. + * @param chunk_size The size of chunks to use for the virtual device, in bytes. + */ + void create_vdev_with_chunk_size(uint64_t size, HSDevType devType, uint32_t blk_size, blk_allocator_type_t alloc_type, + chunk_selector_type_t chunk_sel_type, uint32_t chunk_size); + + /** * @brief Opens a virtual device with the specified virtual device information. * diff --git a/src/lib/blkdata_svc/blkdata_service.cpp b/src/lib/blkdata_svc/blkdata_service.cpp index 4acd3d846..4558cceae 100644 --- a/src/lib/blkdata_svc/blkdata_service.cpp +++ b/src/lib/blkdata_svc/blkdata_service.cpp @@ -37,7 +37,7 @@ BlkDataService::BlkDataService(shared< ChunkSelector > chunk_selector) : BlkDataService::~BlkDataService() = default; // first-time boot path -void BlkDataService::create_vdev(uint64_t size, HSDevType devType, uint32_t blk_size, blk_allocator_type_t alloc_type, +void BlkDataService::create_vdev_with_num_chunks(uint64_t size, HSDevType devType, uint32_t blk_size, blk_allocator_type_t alloc_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; @@ -55,6 +55,24 @@ void BlkDataService::create_vdev(uint64_t size, HSDevType devType, uint32_t blk_ .context_data = vdev_ctx.to_blob()}); } +void BlkDataService::create_vdev_with_chunk_size(uint64_t size, HSDevType devType, uint32_t blk_size, blk_allocator_type_t alloc_type, + chunk_selector_type_t chunk_sel_type, uint32_t chunk_size) { + 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(devType); } + m_vdev = + hs()->device_mgr()->create_vdev(vdev_parameters{.vdev_name = "blkdata", + .vdev_size = size, + .chunk_size = chunk_size, + .blk_size = blk_size, + .dev_type = devType, + .alloc_type = alloc_type, + .chunk_sel_type = chunk_sel_type, + .multi_pdev_opts = vdev_multi_pdev_opts_t::ALL_PDEV_STRIPED, + .context_data = vdev_ctx.to_blob()}); +} + // both first_time_boot and recovery path will come here shared< VirtualDev > BlkDataService::open_vdev(const vdev_info& vinfo, bool load_existing) { if (m_vdev) return m_vdev; diff --git a/src/lib/homestore.cpp b/src/lib/homestore.cpp index feec506c5..17f6059e0 100644 --- a/src/lib/homestore.cpp +++ b/src/lib/homestore.cpp @@ -224,13 +224,33 @@ void HomeStore::format_and_start(std::map< uint32_t, hs_format_params >&& format m_index_service->create_vdev(pct_to_size(fparams.size_pct, fparams.dev_type), fparams.dev_type, fparams.num_chunks); } else if ((svc_type & HS_SERVICE::DATA) && has_data_service()) { - m_data_service->create_vdev(pct_to_size(fparams.size_pct, fparams.dev_type), fparams.dev_type, - fparams.block_size, fparams.alloc_type, fparams.chunk_sel_type, - fparams.num_chunks); + if (fparams.num_chunks != 0) { + m_data_service->create_vdev_with_num_chunks(pct_to_size(fparams.size_pct, fparams.dev_type), + fparams.dev_type, fparams.block_size, fparams.alloc_type, + fparams.chunk_sel_type, + fparams.num_chunks); + } else if (fparams.chunk_size != 0) { + m_data_service->create_vdev_with_chunk_size(pct_to_size(fparams.size_pct, fparams.dev_type), + fparams.dev_type, fparams.block_size, fparams.alloc_type, + fparams.chunk_sel_type, + fparams.chunk_size); + } else { + RELEASE_ASSERT(false, "Both num_chunks and chunk_size cant be zero for vdev"); + } } else if ((svc_type & HS_SERVICE::REPLICATION) && has_repl_data_service()) { - m_data_service->create_vdev(pct_to_size(fparams.size_pct, fparams.dev_type), fparams.dev_type, - fparams.block_size, fparams.alloc_type, fparams.chunk_sel_type, - fparams.num_chunks); + if (fparams.num_chunks != 0) { + m_data_service->create_vdev_with_num_chunks(pct_to_size(fparams.size_pct, fparams.dev_type), + fparams.dev_type, fparams.block_size, fparams.alloc_type, + fparams.chunk_sel_type, + fparams.num_chunks); + } else if (fparams.chunk_size != 0) { + m_data_service->create_vdev_with_chunk_size(pct_to_size(fparams.size_pct, fparams.dev_type), + fparams.dev_type, fparams.block_size, fparams.alloc_type, + fparams.chunk_sel_type, + fparams.chunk_size); + } else { + RELEASE_ASSERT(false, "Both num_chunks and chunk_size cant be zero for vdev"); + } } }