From 5ee40bbc5f620f987fbb8a7bb1609b07b2450141 Mon Sep 17 00:00:00 2001 From: Yao Xiao <87789492+yao-xiao-github@users.noreply.github.com> Date: Thu, 4 Aug 2022 02:12:04 -0700 Subject: [PATCH] Clean up empty physical shards in KVS. (#7674) --- fdbserver/storageserver.actor.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fdbserver/storageserver.actor.cpp b/fdbserver/storageserver.actor.cpp index 54546a0304..68137c8d6a 100644 --- a/fdbserver/storageserver.actor.cpp +++ b/fdbserver/storageserver.actor.cpp @@ -8607,10 +8607,19 @@ ACTOR Future updateStorage(StorageServer* data) { .detail("OldestRemoveKVSRangesVersion", data->pendingRemoveRanges.begin()->first); ASSERT(newOldestVersion <= data->pendingRemoveRanges.begin()->first); if (newOldestVersion == data->pendingRemoveRanges.begin()->first) { + state std::vector emptyShardIds; for (const auto& range : data->pendingRemoveRanges.begin()->second) { - data->storage.removeRange(range); + auto ids = data->storage.removeRange(range); + emptyShardIds.insert(emptyShardIds.end(), ids.begin(), ids.end()); TraceEvent(SevVerbose, "RemoveKVSRange", data->thisServerID).detail("Range", range); } + if (emptyShardIds.size() > 0) { + state double start = now(); + wait(data->storage.cleanUpShardsIfNeeded(emptyShardIds)); + TraceEvent(SevInfo, "RemoveEmptyPhysicalShards", data->thisServerID) + .detail("NumShards", emptyShardIds.size()) + .detail("TimeSpent", now() - start); + } data->pendingRemoveRanges.erase(data->pendingRemoveRanges.begin()); } removeKVSRanges = false;