diff --git a/src/query/plan/operator_type_info.cpp b/src/query/plan/operator_type_info.cpp index ac75581d1..fea7d015e 100644 --- a/src/query/plan/operator_type_info.cpp +++ b/src/query/plan/operator_type_info.cpp @@ -50,7 +50,6 @@ constexpr utils::TypeInfo query::plan::ScanAllByLabelProperty::kType{ constexpr utils::TypeInfo query::plan::ScanAllById::kType{utils::TypeId::SCAN_ALL_BY_ID, "ScanAllById", &query::plan::ScanAll::kType}; -// TODO check if the kType is correct here. constexpr utils::TypeInfo query::plan::ScanAllByEdgeType::kType{utils::TypeId::SCAN_ALL_BY_EDGE_TYPE, "ScanAllByEdgeType", &query::plan::ScanAll::kType}; diff --git a/src/storage/v2/edge_accessor.cpp b/src/storage/v2/edge_accessor.cpp index 95b6f4624..9ee223c80 100644 --- a/src/storage/v2/edge_accessor.cpp +++ b/src/storage/v2/edge_accessor.cpp @@ -16,6 +16,7 @@ #include #include "storage/v2/delta.hpp" +#include "storage/v2/edge_info_helpers.hpp" #include "storage/v2/mvcc.hpp" #include "storage/v2/property_store.hpp" #include "storage/v2/property_value.hpp" @@ -28,9 +29,11 @@ namespace memgraph::storage { std::optional EdgeAccessor::Create(EdgeRef edge, EdgeTypeId edge_type, Vertex *from_vertex, Vertex *to_vertex, Storage *storage, Transaction *transaction, - bool for_deleted) { - // TODO Take the view as well and determine if the - // constructs are visible or not. Checkout VertexAccessor. + View view, bool for_deleted) { + if (!IsEdgeVisible(edge.ptr, transaction, view)) { + return std::nullopt; + } + return EdgeAccessor(edge, edge_type, from_vertex, to_vertex, storage, transaction, for_deleted); } diff --git a/src/storage/v2/edge_accessor.hpp b/src/storage/v2/edge_accessor.hpp index 92451b084..8fa61a588 100644 --- a/src/storage/v2/edge_accessor.hpp +++ b/src/storage/v2/edge_accessor.hpp @@ -45,7 +45,8 @@ class EdgeAccessor final { for_deleted_(for_deleted) {} static std::optional Create(EdgeRef edge, EdgeTypeId edge_type, Vertex *from_vertex, Vertex *to_vertex, - Storage *storage, Transaction *transaction, bool for_deleted = false); + Storage *storage, Transaction *transaction, View view, + bool for_deleted = false); bool IsDeleted() const; diff --git a/src/storage/v2/edge_info_helpers.hpp b/src/storage/v2/edge_info_helpers.hpp new file mode 100644 index 000000000..b8de186f1 --- /dev/null +++ b/src/storage/v2/edge_info_helpers.hpp @@ -0,0 +1,56 @@ +// Copyright 2024 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 +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. +#pragma once + +#include "storage/v2/delta.hpp" +#include "storage/v2/edge.hpp" +#include "storage/v2/mvcc.hpp" +#include "storage/v2/transaction.hpp" +#include "storage/v2/view.hpp" + +#include + +namespace memgraph::storage { + +inline bool IsEdgeVisible(Edge *edge, const Transaction *transaction, View view) { + bool exists = true; + bool deleted = true; + Delta *delta = nullptr; + { + auto guard = std::shared_lock{edge->lock}; + deleted = edge->deleted; + delta = edge->delta; + } + ApplyDeltasForRead(transaction, delta, view, [&](const Delta &delta) { + switch (delta.action) { + case Delta::Action::ADD_LABEL: + case Delta::Action::REMOVE_LABEL: + case Delta::Action::SET_PROPERTY: + case Delta::Action::ADD_IN_EDGE: + case Delta::Action::ADD_OUT_EDGE: + case Delta::Action::REMOVE_IN_EDGE: + case Delta::Action::REMOVE_OUT_EDGE: + break; + case Delta::Action::RECREATE_OBJECT: { + deleted = false; + break; + } + case Delta::Action::DELETE_DESERIALIZED_OBJECT: + case Delta::Action::DELETE_OBJECT: { + exists = false; + break; + } + } + }); + return exists && !deleted; +} + +} // namespace memgraph::storage diff --git a/src/storage/v2/inmemory/edge_type_index.cpp b/src/storage/v2/inmemory/edge_type_index.cpp index e439628b4..495a2f37b 100644 --- a/src/storage/v2/inmemory/edge_type_index.cpp +++ b/src/storage/v2/inmemory/edge_type_index.cpp @@ -12,6 +12,7 @@ #include "storage/v2/inmemory/edge_type_index.hpp" #include "storage/v2/constraints/constraints.hpp" +#include "storage/v2/edge_info_helpers.hpp" #include "storage/v2/indices/indices_utils.hpp" #include "utils/counter.hpp" @@ -25,39 +26,6 @@ using EdgeTypeId = memgraph::storage::EdgeTypeId; using Transaction = memgraph::storage::Transaction; using View = memgraph::storage::View; -bool IsIndexEntryVisible(Edge *edge, const Transaction *transaction, View view) { - bool exists = true; - bool deleted = true; - Delta *delta = nullptr; - { - auto guard = std::shared_lock{edge->lock}; - deleted = edge->deleted; - delta = edge->delta; - } - ApplyDeltasForRead(transaction, delta, view, [&](const Delta &delta) { - switch (delta.action) { - case Delta::Action::ADD_LABEL: - case Delta::Action::REMOVE_LABEL: - case Delta::Action::SET_PROPERTY: - case Delta::Action::ADD_IN_EDGE: - case Delta::Action::ADD_OUT_EDGE: - case Delta::Action::REMOVE_IN_EDGE: - case Delta::Action::REMOVE_OUT_EDGE: - break; - case Delta::Action::RECREATE_OBJECT: { - deleted = false; - break; - } - case Delta::Action::DELETE_DESERIALIZED_OBJECT: - case Delta::Action::DELETE_OBJECT: { - exists = false; - break; - } - } - }); - return exists && !deleted; -} - using ReturnType = std::optional>; ReturnType VertexDeletedConnectedEdges(Vertex *vertex, Edge *edge, const Transaction *transaction, View view) { ReturnType link; @@ -242,7 +210,7 @@ void InMemoryEdgeTypeIndex::Iterable::Iterator::AdvanceUntilValid() { auto *from_vertex = index_iterator_->from_vertex; auto *to_vertex = index_iterator_->to_vertex; - if (!IsIndexEntryVisible(index_iterator_->edge, self_->transaction_, self_->view_) || from_vertex->deleted || + if (!IsEdgeVisible(index_iterator_->edge, self_->transaction_, self_->view_) || from_vertex->deleted || to_vertex->deleted) { continue; } diff --git a/src/storage/v2/inmemory/storage.cpp b/src/storage/v2/inmemory/storage.cpp index df9deafbc..131a4deb7 100644 --- a/src/storage/v2/inmemory/storage.cpp +++ b/src/storage/v2/inmemory/storage.cpp @@ -1475,7 +1475,7 @@ std::optional InMemoryStorage::InMemoryAccessor::FindEdge(Gid gid, auto &edge_info = *maybe_edge_info; return EdgeAccessor::Create(std::get<0>(edge_info), std::get<1>(edge_info), std::get<2>(edge_info), - std::get<3>(edge_info), storage_, &transaction_); + std::get<3>(edge_info), storage_, &transaction_, view); } // If metadata on edges is not enables we will have to do @@ -1495,7 +1495,7 @@ std::optional InMemoryStorage::InMemoryAccessor::FindEdge(Gid gid, auto &edge_info = *maybe_edge_info; return EdgeAccessor::Create(std::get<0>(edge_info), std::get<1>(edge_info), std::get<2>(edge_info), - std::get<3>(edge_info), storage_, &transaction_); + std::get<3>(edge_info), storage_, &transaction_, view); } Transaction InMemoryStorage::CreateTransaction(