Implement edge-visibility checking
This commit is contained in:
parent
9825bdb41b
commit
db6b1fc265
@ -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};
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <tuple>
|
||||
|
||||
#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> 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);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,8 @@ class EdgeAccessor final {
|
||||
for_deleted_(for_deleted) {}
|
||||
|
||||
static std::optional<EdgeAccessor> 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;
|
||||
|
||||
|
56
src/storage/v2/edge_info_helpers.hpp
Normal file
56
src/storage/v2/edge_info_helpers.hpp
Normal file
@ -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 <shared_mutex>
|
||||
|
||||
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
|
@ -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<std::tuple<EdgeTypeId, Vertex *, EdgeRef>>;
|
||||
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;
|
||||
}
|
||||
|
@ -1475,7 +1475,7 @@ std::optional<EdgeAccessor> 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<EdgeAccessor> 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(
|
||||
|
Loading…
Reference in New Issue
Block a user