From f8a9e229deb434b493887ac3c6c387fe599a24c0 Mon Sep 17 00:00:00 2001 From: Jaya Prakash Date: Wed, 12 Mar 2025 19:01:52 +0000 Subject: [PATCH] os/bluestore: Refactor ExtentMap::reshard() into separate decision and action phases Refactored ExtentMap::reshard() by splitting it into two distinct functions: - reshard_decision(): Determines the resharding plan by analyzing shard distribution, extent sizes, and spanning blob ranges - reshard_action(): Applies the resharding plan, handling faulting, key removals, and shard updates Signed-off-by: Jaya Prakash (cherry picked from commit 44f93a610222338f7e763b08fc6c52ac3e82473e) --- src/os/bluestore/BlueStore.cc | 69 ++++++++++++++++++++++++++--------- src/os/bluestore/BlueStore.h | 17 +++++++++ 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 8533d676119..a2f33c26b9f 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -3573,11 +3573,9 @@ bid_t BlueStore::ExtentMap::allocate_spanning_blob_id() ceph_abort_msg("no available blob id"); } -void BlueStore::ExtentMap::reshard( - KeyValueDB *db, - KeyValueDB::Transaction t, - uint32_t segment_size) -{ +BlueStore::ExtentMap::ReshardPlan +BlueStore::ExtentMap::reshard_decision(uint32_t segment_size) { + ReshardPlan plan; auto cct = onode->c->store->cct; // used by dout dout(10) << __func__ << " 0x[" << std::hex << needs_reshard_begin << "," @@ -3616,7 +3614,6 @@ void BlueStore::ExtentMap::reshard( needs_reshard_end = OBJECT_MAX_SIZE; } - fault_range(db, needs_reshard_begin, (needs_reshard_end - needs_reshard_begin)); uint64_t data_reshard_end = needs_reshard_end; if (needs_reshard_end == OBJECT_MAX_SIZE && !extent_map.empty()) { data_reshard_end = extent_map.rbegin()->blob_end(); @@ -3628,17 +3625,6 @@ void BlueStore::ExtentMap::reshard( uint32_t spanning_scan_begin = needs_reshard_begin; uint32_t spanning_scan_end = needs_reshard_end; - // remove old keys - string key; - for (unsigned i = shard_index_begin; i < shard_index_end; ++i) { - generate_extent_shard_key_and_apply( - onode->key, shards[i].shard_info->offset, &key, - [&](const string& final_key) { - t->rmkey(PREFIX_OBJ, final_key); - } - ); - } - // calculate average extent size unsigned bytes = 0; unsigned extents = 0; @@ -3745,6 +3731,47 @@ void BlueStore::ExtentMap::reshard( auto& extent_map_shards = onode->onode.extent_map_shards; dout(20) << __func__ << " new " << new_shard_info << dendl; dout(20) << __func__ << " old " << extent_map_shards << dendl; + + plan.shard_index_begin = shard_index_begin; + plan.shard_index_end = shard_index_end; + plan.spanning_scan_begin = spanning_scan_begin; + plan.spanning_scan_end = spanning_scan_end; + plan.new_shard_info = std::move(new_shard_info); + return plan; +} + + +void BlueStore::ExtentMap::reshard_action( + ReshardPlan& plan, + KeyValueDB *db, + KeyValueDB::Transaction t) { + auto cct = onode->c->store->cct; // For configuration and logging + + std::vector new_shard_info = plan.new_shard_info; + unsigned shard_index_begin = plan.shard_index_begin; + unsigned shard_index_end = plan.shard_index_end; + uint32_t spanning_scan_begin = plan.spanning_scan_begin; + uint32_t spanning_scan_end = plan.spanning_scan_end; + + dout(20) << __func__ << " applying plan with shards [" << shard_index_begin << "," + << shard_index_end << ")" << dendl; + + // Fault the range + fault_range(db, needs_reshard_begin, (needs_reshard_end - needs_reshard_begin)); + + // Remove old shard keys + string key; + for (unsigned i = shard_index_begin; i < shard_index_end; ++i) { + generate_extent_shard_key_and_apply( + onode->key, shards[i].shard_info->offset, &key, + [&](const string& final_key) { + t->rmkey(PREFIX_OBJ, final_key); + } + ); + } + + // Update extent_map_shards and shards + auto& extent_map_shards = onode->onode.extent_map_shards; if (extent_map_shards.empty()) { // no old shards to keep extent_map_shards.swap(new_shard_info); @@ -3920,6 +3947,14 @@ void BlueStore::ExtentMap::reshard( clear_needs_reshard(); } +void BlueStore::ExtentMap::reshard( + KeyValueDB *db, + KeyValueDB::Transaction t, + uint32_t segment_size) { + auto plan = reshard_decision(segment_size); + reshard_action(plan, db, t); +} + bool BlueStore::ExtentMap::encode_some( uint32_t offset, uint32_t length, diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 693d4499a30..b82e119c406 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1059,6 +1059,23 @@ public: bool just_after_reshard //true to indicate that update should now respect shard boundaries ); //as no further resharding will be done decltype(BlueStore::Blob::id) allocate_spanning_blob_id(); + + struct ReshardPlan { + std::vector new_shard_info; + unsigned shard_index_begin; + unsigned shard_index_end; + uint32_t spanning_scan_begin; + uint32_t spanning_scan_end; + }; + + ReshardPlan reshard_decision(uint32_t segment_size); + + void reshard_action( + ReshardPlan& plan, + KeyValueDB *db, + KeyValueDB::Transaction t); + + void reshard( KeyValueDB *db, KeyValueDB::Transaction t, -- 2.39.5