diff --git a/src/storage/v3/shard.cpp b/src/storage/v3/shard.cpp index 803678c8a..d4191b4bb 100644 --- a/src/storage/v3/shard.cpp +++ b/src/storage/v3/shard.cpp @@ -1179,7 +1179,10 @@ std::map Shard::CollectTransactions(const std::set transactions; for (const auto commit_start : collected_transactions_start_id) { - transactions.insert({commit_start, start_logical_id_to_transaction_.at(commit_start)->Clone()}); + // If it does not contain then the transaction has commited, and we ignore it + if (start_logical_id_to_transaction_.contains(commit_start)) { + transactions.insert({commit_start, start_logical_id_to_transaction_[commit_start]->Clone()}); + } } // It is necessary to clone all the transactions first so we have new addresses // for deltas, before doing alignment of deltas and prev_ptr diff --git a/tests/unit/storage_v3_shard_split.cpp b/tests/unit/storage_v3_shard_split.cpp index ebfca2921..1cca21d62 100644 --- a/tests/unit/storage_v3_shard_split.cpp +++ b/tests/unit/storage_v3_shard_split.cpp @@ -87,7 +87,7 @@ TEST_F(ShardSplitTest, TestBasicSplitVerticesAndEdges) { EXPECT_EQ(splitted_data.transactions.size(), 0); } -TEST_F(ShardSplitTest, TestBasicSplit) { +TEST_F(ShardSplitTest, TestBasicSplitBeforeCommit) { auto acc = storage.Access(GetNextHlc()); EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(1)}, {}).HasError()); EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(2)}, {}).HasError()); @@ -112,4 +112,31 @@ TEST_F(ShardSplitTest, TestBasicSplit) { EXPECT_EQ(splitted_data.transactions.size(), 1); } +TEST_F(ShardSplitTest, TestBasicSplitAfterCommit) { + auto acc = storage.Access(GetNextHlc()); + EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(1)}, {}).HasError()); + EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(2)}, {}).HasError()); + EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(3)}, {}).HasError()); + EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(4)}, {}).HasError()); + EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(5)}, {}).HasError()); + EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(6)}, {}).HasError()); + + EXPECT_FALSE(acc.CreateEdge(VertexId{primary_label, PrimaryKey{PropertyValue(1)}}, + VertexId{primary_label, PrimaryKey{PropertyValue(2)}}, edge_type_id, Gid::FromUint(0)) + .HasError()); + EXPECT_FALSE(acc.CreateEdge(VertexId{primary_label, PrimaryKey{PropertyValue(1)}}, + VertexId{primary_label, PrimaryKey{PropertyValue(5)}}, edge_type_id, Gid::FromUint(1)) + .HasError()); + EXPECT_FALSE(acc.CreateEdge(VertexId{primary_label, PrimaryKey{PropertyValue(4)}}, + VertexId{primary_label, PrimaryKey{PropertyValue(6)}}, edge_type_id, Gid::FromUint(2)) + .HasError()); + + acc.Commit(GetNextHlc()); + + auto splitted_data = storage.PerformSplit({PropertyValue(4)}); + EXPECT_EQ(splitted_data.vertices.size(), 3); + EXPECT_EQ(splitted_data.edges->size(), 2); + EXPECT_EQ(splitted_data.transactions.size(), 0); +} + } // namespace memgraph::storage::v3::tests