From b12097dc610cb1a73201d13bed9bbbca06fb9cc8 Mon Sep 17 00:00:00 2001 From: Jie Yao Date: Wed, 14 Aug 2024 09:10:17 +0800 Subject: [PATCH] fix create chunk (#495) --- conanfile.py | 2 +- src/lib/blkalloc/fixed_blk_allocator.cpp | 1 - src/lib/device/device_manager.cpp | 8 +++++++- src/lib/device/physical_dev.cpp | 9 ++++++--- src/tests/test_common/homestore_test_common.hpp | 3 ++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/conanfile.py b/conanfile.py index edaa61d41..d417c3fc7 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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") diff --git a/src/lib/blkalloc/fixed_blk_allocator.cpp b/src/lib/blkalloc/fixed_blk_allocator.cpp index 9df3a07ca..9a44a80f3 100644 --- a/src/lib/blkalloc/fixed_blk_allocator.cpp +++ b/src/lib/blkalloc/fixed_blk_allocator.cpp @@ -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(); } } diff --git a/src/lib/device/device_manager.cpp b/src/lib/device/device_manager.cpp index ea8461c67..7fe73a5f1 100644 --- a/src/lib/device/device_manager.cpp +++ b/src/lib/device/device_manager.cpp @@ -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; diff --git a/src/lib/device/physical_dev.cpp b/src/lib/device/physical_dev.cpp index 5ebb1963d..cfcf9985f 100644 --- a/src/lib/device/physical_dev.cpp +++ b/src/lib/device/physical_dev.cpp @@ -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(); @@ -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; } @@ -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); } diff --git a/src/tests/test_common/homestore_test_common.hpp b/src/tests/test_common/homestore_test_common.hpp index 7aa90b94a..3b5484966 100644 --- a/src/tests/test_common/homestore_test_common.hpp +++ b/src/tests/test_common/homestore_test_common.hpp @@ -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,