Fix indices locking in storage v2

Summary:
The functions that previously had locks in them are always called while the
vertex lock is already being held. Also, the lock guards were implemented
incorrectly.

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2580
This commit is contained in:
Matej Ferencevic 2019-12-03 19:09:51 +01:00
parent 10cc831ed2
commit 83c368c82b

View File

@ -268,7 +268,8 @@ void LabelIndex::UpdateOnAddLabel(LabelId label, Vertex *vertex,
const Transaction &tx) { const Transaction &tx) {
auto it = index_.find(label); auto it = index_.find(label);
if (it == index_.end()) return; if (it == index_.end()) return;
it->second.access().insert(Entry{vertex, tx.start_timestamp}); auto acc = it->second.access();
acc.insert(Entry{vertex, tx.start_timestamp});
} }
bool LabelIndex::CreateIndex(LabelId label, bool LabelIndex::CreateIndex(LabelId label,
@ -394,16 +395,10 @@ void LabelPropertyIndex::UpdateOnAddLabel(LabelId label, Vertex *vertex,
if (label_prop.first != label) { if (label_prop.first != label) {
continue; continue;
} }
PropertyValue value; auto it = vertex->properties.find(label_prop.second);
{ if (it != vertex->properties.end() && !it->second.IsNull()) {
utils::SpinLock guard(vertex->lock); auto acc = storage.access();
auto it = vertex->properties.find(label_prop.second); acc.insert(Entry{it->second, vertex, tx.start_timestamp});
if (it != vertex->properties.end()) {
value = it->second;
}
}
if (!value.IsNull()) {
storage.access().insert(Entry{value, vertex, tx.start_timestamp});
} }
} }
} }
@ -419,13 +414,9 @@ void LabelPropertyIndex::UpdateOnSetProperty(PropertyId property,
if (label_prop.second != property) { if (label_prop.second != property) {
continue; continue;
} }
bool has_label; if (utils::Contains(vertex->labels, label_prop.first)) {
{ auto acc = storage.access();
utils::SpinLock guard(vertex->lock); acc.insert(Entry{value, vertex, tx.start_timestamp});
has_label = utils::Contains(vertex->labels, label_prop.first);
}
if (has_label) {
storage.access().insert(Entry{value, vertex, tx.start_timestamp});
} }
} }
} }