diff --git a/src/Coordination/SnapshotableHashTable.h b/src/Coordination/SnapshotableHashTable.h index d1ed7d822aa..42d1c297efb 100644 --- a/src/Coordination/SnapshotableHashTable.h +++ b/src/Coordination/SnapshotableHashTable.h @@ -192,6 +192,7 @@ public: return false; auto list_itr = it->second; + UInt64 old_data_size = sizeOf(&list_itr->value); if (snapshot_mode) { list_itr->active_in_map = false; @@ -203,7 +204,7 @@ public: list.erase(list_itr); } - updateDataSize(ERASE, sizeOf(&key), 0, sizeOf(&list_itr->value)); + updateDataSize(ERASE, sizeOf(&key), 0, old_data_size); return true; } diff --git a/src/Coordination/tests/gtest_coordination.cpp b/src/Coordination/tests/gtest_coordination.cpp index 22a0dfcdbaa..0b8c9809085 100644 --- a/src/Coordination/tests/gtest_coordination.cpp +++ b/src/Coordination/tests/gtest_coordination.cpp @@ -963,6 +963,7 @@ TEST_P(CoordinationTest, SnapshotableHashMapDataSize) n1.data = "1234"; Node n2; n2.data = "123456"; + n2.children.insert(""); world.disableSnapshotMode(); world.insert("world", n1); @@ -974,7 +975,7 @@ TEST_P(CoordinationTest, SnapshotableHashMapDataSize) world.updateValue("world", [&](Node & value) { value = n2; }); EXPECT_EQ(world.getApproximateSataSize(), 171); - world.clear(); + world.erase("world"); EXPECT_EQ(world.getApproximateSataSize(), 0); world.enableSnapshotMode(); @@ -985,6 +986,12 @@ TEST_P(CoordinationTest, SnapshotableHashMapDataSize) world.clearOutdatedNodes(); EXPECT_EQ(world.getApproximateSataSize(), 171); + + world.erase("world"); + EXPECT_EQ(world.getApproximateSataSize(), 171); + + world.clear(); + EXPECT_EQ(world.getApproximateSataSize(), 0); } void addNode(DB::KeeperStorage & storage, const std::string & path, const std::string & data, int64_t ephemeral_owner=0)