Merge from reading deltas

This commit is contained in:
Josip Mrden
2023-05-05 15:40:09 +02:00
parent ea494d4381
commit 7d1b8100c7
4 changed files with 18 additions and 2 deletions

View File

@@ -170,7 +170,12 @@ bool CurrentVersionHasLabel(const Vertex &vertex, LabelId label, Transaction *tr
deleted = vertex.deleted;
has_label = utils::Contains(vertex.labels, label);
delta = vertex.delta;
if (!vertex.label_changed) {
return !deleted && has_label;
}
}
ApplyDeltasForRead(transaction, delta, view, [&deleted, &has_label, label](const Delta &delta) {
switch (delta.action) {
case Delta::Action::REMOVE_LABEL: {
@@ -223,7 +228,12 @@ bool CurrentVersionHasLabelProperty(const Vertex &vertex, LabelId label, Propert
has_label = utils::Contains(vertex.labels, label);
current_value_equal_to_value = vertex.properties.IsPropertyEqual(key, value);
delta = vertex.delta;
if (!vertex.label_changed && !vertex.property_changed) {
return !deleted && has_label && current_value_equal_to_value;
}
}
ApplyDeltasForRead(transaction, delta, view,
[&deleted, &has_label, &current_value_equal_to_value, key, label, &value](const Delta &delta) {
switch (delta.action) {

View File

@@ -1015,6 +1015,8 @@ void Storage::Accessor::Abort() {
auto vertex = prev.vertex;
std::lock_guard<utils::SpinLock> guard(vertex->lock);
Delta *current = vertex->delta;
vertex->label_changed = false;
vertex->property_changed = false;
while (current != nullptr && current->timestamp->load(std::memory_order_acquire) ==
transaction_.transaction_id.load(std::memory_order_acquire)) {
switch (current->action) {
@@ -1551,6 +1553,8 @@ void Storage::CollectGarbage() {
continue;
}
vertex->delta = nullptr;
vertex->label_changed = false;
vertex->property_changed = false;
if (vertex->deleted) {
current_deleted_vertices.push_back(vertex->gid);
}

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Memgraph Ltd.
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@@ -39,8 +39,9 @@ struct Vertex {
mutable utils::SpinLock lock;
bool deleted;
bool label_changed;
bool property_changed;
// uint8_t PAD;
// uint16_t PAD;
Delta *delta;
};

View File

@@ -85,6 +85,7 @@ Result<bool> VertexAccessor::AddLabel(LabelId label) {
if (std::find(vertex_->labels.begin(), vertex_->labels.end(), label) != vertex_->labels.end()) return false;
CreateAndLinkDelta(transaction_, vertex_, Delta::RemoveLabelTag(), label);
vertex_->label_changed = true;
vertex_->labels.push_back(label);