Skip to content

Commit

Permalink
fix create chunk (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonYao287 authored Aug 14, 2024
1 parent 2080ad4 commit b12097d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 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.4.41"
version = "6.4.42"
homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
topics = ("ebay", "nublox")
Expand Down
1 change: 0 additions & 1 deletion src/lib/blkalloc/fixed_blk_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace homestore {
FixedBlkAllocator::FixedBlkAllocator(BlkAllocConfig const& cfg, bool is_fresh, chunk_num_t chunk_id) :
BitmapBlkAllocator(cfg, is_fresh, chunk_id), m_free_blk_q{get_total_blks()} {
LOGINFO("FixedBlkAllocator total blks: {}", get_total_blks());
if (is_fresh || !is_persistent()) { load(); }
}

Expand Down
8 changes: 7 additions & 1 deletion src/lib/device/device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,13 @@ shared< Chunk > DeviceManager::create_chunk(HSDevType dev_type, uint32_t vdev_id
// Create a chunk on any pdev of device type.
for (const auto& dev : pdevs) {
// Ordinal added in add_chunk.
chunk = dev->create_chunk(chunk_id, vdev_id, chunk_size, 0 /* ordinal */, data);
try {
chunk = dev->create_chunk(chunk_id, vdev_id, chunk_size, 0 /* ordinal */, data);
} catch (std::out_of_range const& e) {
HS_LOG(DEBUG, device, "can not create new chunk on dev {}, try next one!", dev->get_devname());
continue;
}

if (chunk != nullptr) {
pdev = dev;
break;
Expand Down
9 changes: 6 additions & 3 deletions src/lib/device/physical_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,15 @@ std::vector< shared< Chunk > > PhysicalDev::create_chunks(const std::vector< uin
std::unique_lock lg{m_chunk_op_mtx};
auto chunks_remaining = chunk_ids.size();
uint32_t cit{0};
uint8_t* buf{nullptr};

try {
while (chunks_remaining > 0) {
auto b = m_chunk_info_slots->get_next_contiguous_n_reset_bits(0u, chunks_remaining);
if (b.nbits == 0) { throw std::out_of_range("System has no room for additional chunk"); }

auto buf = hs_utils::iobuf_alloc(chunk_info::size * b.nbits, sisl::buftag::superblk,
m_pdev_info.dev_attr.align_size);
buf = hs_utils::iobuf_alloc(chunk_info::size * b.nbits, sisl::buftag::superblk,
m_pdev_info.dev_attr.align_size);
auto ptr = buf;
for (auto cslot = b.start_bit; cslot < b.start_bit + b.nbits; ++cslot, ++cit, ptr += chunk_info::size) {
chunk_info* cinfo = new (ptr) chunk_info();
Expand All @@ -255,7 +256,7 @@ std::vector< shared< Chunk > > PhysicalDev::create_chunks(const std::vector< uin
write_super_block(buf, chunk_info::size * b.nbits, chunk_info_offset_nth(b.start_bit));

hs_utils::iobuf_free(buf, sisl::buftag::superblk);

buf = nullptr;
chunks_remaining -= b.nbits;
}

Expand All @@ -264,6 +265,8 @@ std::vector< shared< Chunk > > PhysicalDev::create_chunks(const std::vector< uin
write_super_block(bitmap_mem->cbytes(), bitmap_mem->size(), hs_super_blk::chunk_sb_offset());
} catch (const std::out_of_range& e) {
LOGERROR("Creation of chunks failed because of space, removing {} partially created chunks", ret_chunks.size());
// exception is thrown out by populate_chunk_info
if (buf) hs_utils::iobuf_free(buf, sisl::buftag::superblk);
for (auto& chunk : ret_chunks) {
do_remove_chunk(chunk);
}
Expand Down
3 changes: 2 additions & 1 deletion src/tests/test_common/homestore_test_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ class HSTestHelper {
.chunk_sel_type = svc_params[HS_SERVICE::DATA].custom_chunk_selector
? chunk_selector_type_t::CUSTOM
: chunk_selector_type_t::ROUND_ROBIN}},
{HS_SERVICE::INDEX, {.size_pct = svc_params[HS_SERVICE::INDEX].size_pct}},
{HS_SERVICE::INDEX,
{.dev_type = homestore::HSDevType::Fast, .size_pct = svc_params[HS_SERVICE::INDEX].size_pct}},
{HS_SERVICE::REPLICATION,
{.size_pct = svc_params[HS_SERVICE::REPLICATION].size_pct,
.alloc_type = svc_params[HS_SERVICE::REPLICATION].blkalloc_type,
Expand Down

0 comments on commit b12097d

Please sign in to comment.