fix seg fault and add test

This commit is contained in:
JackyWoo 2021-11-02 17:13:35 +08:00
parent 89f7c7eef6
commit ec1ad60e9d
2 changed files with 10 additions and 2 deletions

View File

@ -192,6 +192,7 @@ public:
return false;
auto list_itr = it->second;
UInt64 old_data_size = sizeOf<V>(&list_itr->value);
if (snapshot_mode)
{
list_itr->active_in_map = false;
@ -203,7 +204,7 @@ public:
list.erase(list_itr);
}
updateDataSize(ERASE, sizeOf<std::string>(&key), 0, sizeOf<V>(&list_itr->value));
updateDataSize(ERASE, sizeOf<std::string>(&key), 0, old_data_size);
return true;
}

View File

@ -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)