Skip to content

Commit

Permalink
Support flexible virtual device creation in HomeStore with num_chunks…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Hooper9973 committed Nov 26, 2024
1 parent 1a87f71 commit aff7a0a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 16 additions & 1 deletion src/include/homestore/blkdata_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
20 changes: 19 additions & 1 deletion src/lib/blkdata_svc/blkdata_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
32 changes: 26 additions & 6 deletions src/lib/homestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

Expand Down

0 comments on commit aff7a0a

Please sign in to comment.