From a7fabe6109c8f5824f0ea70d0ed795d55995fdb0 Mon Sep 17 00:00:00 2001 From: Marin Tomic Date: Mon, 1 Jul 2019 10:52:11 +0200 Subject: [PATCH] Fix PrepareForWrite function in storage V2 Summary: We forgot to update `modified_vertices` in the case when the vertex has an empty version chain. It didn't manifest before because it was impossible for a vertex to have an empty version chain without garbage collection. Reviewers: mferencevic, teon.banek Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2154 --- src/storage/v2/mvcc.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/storage/v2/mvcc.hpp b/src/storage/v2/mvcc.hpp index be2cd80d5..375e1ddc2 100644 --- a/src/storage/v2/mvcc.hpp +++ b/src/storage/v2/mvcc.hpp @@ -52,12 +52,18 @@ inline void ApplyDeltasForRead(Transaction *transaction, Delta *delta, /// transaction) and returns a `bool` value indicating whether the caller can /// proceed with a write operation. inline bool PrepareForWrite(Transaction *transaction, Vertex *vertex) { - if (vertex->delta == nullptr) return true; + if (vertex->delta == nullptr) { + if (transaction->modified_vertices.empty() || + transaction->modified_vertices.back() != vertex) { + transaction->modified_vertices.push_back(vertex); + } + return true; + } auto ts = vertex->delta->timestamp->load(std::memory_order_acquire); if (ts == transaction->transaction_id || ts < transaction->start_timestamp) { - auto it = transaction->modified_vertices.rbegin(); - if (it == transaction->modified_vertices.rend() || *it != vertex) { + if (transaction->modified_vertices.empty() || + transaction->modified_vertices.back() != vertex) { transaction->modified_vertices.push_back(vertex); } return true;