Skip deleted vertices when building index

Summary:
There's a possible race condition where we add a deleted vertex into
index and garbage collection removes it from main storage before indices are
cleaned-up.

Reviewers: mferencevic, teon.banek

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2314
This commit is contained in:
Marin Tomic 2019-08-21 17:22:50 +02:00
parent 4f93632fb8
commit 21d461e77d
2 changed files with 6 additions and 6 deletions

View File

@ -449,7 +449,7 @@ bool LabelPropertyIndex::CreateIndex(
} }
auto acc = it->second.access(); auto acc = it->second.access();
for (Vertex &vertex : vertices) { for (Vertex &vertex : vertices) {
if (!utils::Contains(vertex.labels, label)) { if (vertex.deleted || !utils::Contains(vertex.labels, label)) {
continue; continue;
} }
auto it = vertex.properties.find(property); auto it = vertex.properties.find(property);

View File

@ -149,7 +149,7 @@ TEST_F(IndexTest, LabelIndexDuplicateVersions) {
EXPECT_THAT(GetIds(acc.Vertices(label1, View::NEW), View::NEW), EXPECT_THAT(GetIds(acc.Vertices(label1, View::NEW), View::NEW),
UnorderedElementsAre(0, 1, 2, 3, 4)); UnorderedElementsAre(0, 1, 2, 3, 4));
acc.Commit(); ASSERT_EQ(acc.Commit(), std::nullopt);
} }
{ {
@ -194,7 +194,7 @@ TEST_F(IndexTest, LabelIndexTransactionalIsolation) {
EXPECT_THAT(GetIds(acc_after.Vertices(label1, View::NEW), View::NEW), EXPECT_THAT(GetIds(acc_after.Vertices(label1, View::NEW), View::NEW),
IsEmpty()); IsEmpty());
acc.Commit(); ASSERT_EQ(acc.Commit(), std::nullopt);
auto acc_after_commit = storage.Access(); auto acc_after_commit = storage.Access();
@ -324,7 +324,7 @@ TEST_F(IndexTest, LabelPropertyIndexDuplicateVersions) {
EXPECT_THAT(GetIds(acc.Vertices(label1, prop_val, View::NEW), View::NEW), EXPECT_THAT(GetIds(acc.Vertices(label1, prop_val, View::NEW), View::NEW),
UnorderedElementsAre(0, 1, 2, 3, 4)); UnorderedElementsAre(0, 1, 2, 3, 4));
acc.Commit(); ASSERT_EQ(acc.Commit(), std::nullopt);
} }
{ {
@ -374,7 +374,7 @@ TEST_F(IndexTest, LabelPropertyIndexTransactionalIsolation) {
GetIds(acc_after.Vertices(label1, prop_val, View::NEW), View::NEW), GetIds(acc_after.Vertices(label1, prop_val, View::NEW), View::NEW),
IsEmpty()); IsEmpty());
acc.Commit(); ASSERT_EQ(acc.Commit(), std::nullopt);
auto acc_after_commit = storage.Access(); auto acc_after_commit = storage.Access();
@ -408,7 +408,7 @@ TEST_F(IndexTest, LabelPropertyIndexFiltering) {
ASSERT_NO_ERROR(vertex.SetProperty( ASSERT_NO_ERROR(vertex.SetProperty(
prop_val, i % 2 ? PropertyValue(i / 2) : PropertyValue(i / 2.0))); prop_val, i % 2 ? PropertyValue(i / 2) : PropertyValue(i / 2.0)));
} }
acc.Commit(); ASSERT_EQ(acc.Commit(), std::nullopt);
} }
{ {
auto acc = storage.Access(); auto acc = storage.Access();