From c2824e3dc04feac9def570834d8d577f7e7312b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Pu=C5=A1i=C4=87?= Date: Mon, 22 Jan 2024 09:04:21 +0100 Subject: [PATCH] Add transaction IDs to Tantivy metadata --- src/query/plan/operator.cpp | 15 ++++++++---- src/storage/v2/indices/indices.cpp | 6 ++--- src/storage/v2/indices/text_index.cpp | 34 ++++++++++++++++----------- src/storage/v2/indices/text_index.hpp | 18 ++++++++------ 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 574e9dc90..fbd507937 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -252,7 +252,8 @@ VertexAccessor &CreateLocalVertex(const NodeCreationInfo &node_info, Frame *fram MultiPropsInitChecked(&new_node, properties); if (flags::run_time::GetTextSearchEnabled()) { - new_node.impl_.storage_->indices_.text_index_->AddNode(new_node.impl_.vertex_, new_node.impl_.storage_); + new_node.impl_.storage_->indices_.text_index_->AddNode(new_node.impl_.vertex_, new_node.impl_.storage_, + new_node.impl_.transaction_->start_timestamp); } (*frame)[node_info.symbol] = new_node; @@ -2825,7 +2826,8 @@ bool SetProperty::SetPropertyCursor::Pull(Frame &frame, ExecutionContext &contex } if (flags::run_time::GetTextSearchEnabled()) { auto new_node = lhs.ValueVertex(); - new_node.impl_.storage_->indices_.text_index_->UpdateNode(new_node.impl_.vertex_, new_node.impl_.storage_); + new_node.impl_.storage_->indices_.text_index_->UpdateNode(new_node.impl_.vertex_, new_node.impl_.storage_, + new_node.impl_.transaction_->start_timestamp); } break; } @@ -2985,7 +2987,8 @@ void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetPr update_props(new_properties); if (flags::run_time::GetTextSearchEnabled()) { auto new_node = rhs.ValueVertex(); - new_node.impl_.storage_->indices_.text_index_->UpdateNode(new_node.impl_.vertex_, new_node.impl_.storage_); + new_node.impl_.storage_->indices_.text_index_->UpdateNode(new_node.impl_.vertex_, new_node.impl_.storage_, + new_node.impl_.transaction_->start_timestamp); } break; } @@ -3134,7 +3137,8 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, ExecutionContext &context) { } if (flags::run_time::GetTextSearchEnabled()) { - vertex.impl_.storage_->indices_.text_index_->UpdateNode(vertex.impl_.vertex_, vertex.impl_.storage_); + vertex.impl_.storage_->indices_.text_index_->UpdateNode(vertex.impl_.vertex_, vertex.impl_.storage_, + vertex.impl_.transaction_->start_timestamp); } return true; @@ -3299,7 +3303,8 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame, ExecutionContext &cont } if (flags::run_time::GetTextSearchEnabled()) { - vertex.impl_.storage_->indices_.text_index_->UpdateNode(vertex.impl_.vertex_, vertex.impl_.storage_, self_.labels_); + vertex.impl_.storage_->indices_.text_index_->UpdateNode(vertex.impl_.vertex_, vertex.impl_.storage_, + vertex.impl_.transaction_->start_timestamp, self_.labels_); } return true; diff --git a/src/storage/v2/indices/indices.cpp b/src/storage/v2/indices/indices.cpp index 929ef0200..b902aee91 100644 --- a/src/storage/v2/indices/indices.cpp +++ b/src/storage/v2/indices/indices.cpp @@ -43,7 +43,7 @@ void Indices::UpdateOnAddLabel(LabelId label, Vertex *vertex, const Transaction label_index_->UpdateOnAddLabel(label, vertex, tx); label_property_index_->UpdateOnAddLabel(label, vertex, tx); if (update_text_index) { - text_index_->UpdateOnAddLabel(label, vertex, storage, tx); + text_index_->UpdateOnAddLabel(label, vertex, storage, tx.start_timestamp); } } @@ -51,7 +51,7 @@ void Indices::UpdateOnRemoveLabel(LabelId label, Vertex *vertex, const Transacti label_index_->UpdateOnRemoveLabel(label, vertex, tx); label_property_index_->UpdateOnRemoveLabel(label, vertex, tx); if (update_text_index) { - text_index_->UpdateOnRemoveLabel(label, vertex, tx); + text_index_->UpdateOnRemoveLabel(label, vertex, tx.start_timestamp); } } @@ -59,7 +59,7 @@ void Indices::UpdateOnSetProperty(PropertyId property, const PropertyValue &valu const Transaction &tx, Storage *storage, bool update_text_index) const { label_property_index_->UpdateOnSetProperty(property, value, vertex, tx); if (update_text_index) { - text_index_->UpdateOnSetProperty(vertex, storage, tx); + text_index_->UpdateOnSetProperty(vertex, storage, tx.start_timestamp); } } diff --git a/src/storage/v2/indices/text_index.cpp b/src/storage/v2/indices/text_index.cpp index 8fccfcc18..161845dfb 100644 --- a/src/storage/v2/indices/text_index.cpp +++ b/src/storage/v2/indices/text_index.cpp @@ -16,7 +16,7 @@ namespace memgraph::storage { -void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage, +void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage, const std::uint64_t transaction_start_timestamp, const std::vector &applicable_text_indices) { // NOTE: Text indexes are presently all-property indices. If we allow text indexes restricted to specific properties, // an indexable document should be created for each applicable index. @@ -30,7 +30,7 @@ void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage, document["data"] = properties; document["metadata"] = {}; document["metadata"]["gid"] = vertex_after_update->gid.AsInt(); - // TODO add txid + document["metadata"]["txid"] = transaction_start_timestamp; document["metadata"]["deleted"] = false; document["metadata"]["is_node"] = true; @@ -44,27 +44,31 @@ void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage, } } -void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage) { +void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage, + const std::uint64_t transaction_start_timestamp) { auto applicable_text_indices = GetApplicableTextIndices(vertex_after_update); if (applicable_text_indices.empty()) return; - AddNode(vertex_after_update, storage, applicable_text_indices); + AddNode(vertex_after_update, storage, transaction_start_timestamp, applicable_text_indices); } -void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage) { +void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage, + const std::uint64_t transaction_start_timestamp) { auto applicable_text_indices = GetApplicableTextIndices(vertex_after_update); if (applicable_text_indices.empty()) return; RemoveNode(vertex_after_update, applicable_text_indices); - AddNode(vertex_after_update, storage, applicable_text_indices); + AddNode(vertex_after_update, storage, transaction_start_timestamp, applicable_text_indices); } -void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage, const std::vector &removed_labels) { +void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage, + const std::uint64_t transaction_start_timestamp, + const std::vector &removed_labels) { auto indexes_to_remove_node_from = GetApplicableTextIndices(removed_labels); RemoveNode(vertex_after_update, indexes_to_remove_node_from); auto indexes_to_update_node = GetApplicableTextIndices(vertex_after_update); if (indexes_to_update_node.empty()) return; RemoveNode(vertex_after_update, indexes_to_update_node); - AddNode(vertex_after_update, storage, indexes_to_update_node); + AddNode(vertex_after_update, storage, transaction_start_timestamp, indexes_to_update_node); } void TextIndex::RemoveNode(Vertex *vertex_after_update, @@ -88,22 +92,24 @@ void TextIndex::RemoveNode(Vertex *vertex_after_update) { } void TextIndex::UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, Storage *storage, - const Transaction &tx) { + const std::uint64_t transaction_start_timestamp) { if (!label_to_index_.contains(added_label)) { return; } - AddNode(vertex_after_update, storage, {&index_.at(label_to_index_.at(added_label))}); + AddNode(vertex_after_update, storage, transaction_start_timestamp, {&index_.at(label_to_index_.at(added_label))}); } -void TextIndex::UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update, const Transaction &tx) { +void TextIndex::UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update, + const std::uint64_t transaction_start_timestamp) { if (!label_to_index_.contains(removed_label)) { return; } RemoveNode(vertex_after_update, {&index_.at(label_to_index_.at(removed_label))}); } -void TextIndex::UpdateOnSetProperty(Vertex *vertex_after_update, Storage *storage, const Transaction &tx) { - UpdateNode(vertex_after_update, storage); +void TextIndex::UpdateOnSetProperty(Vertex *vertex_after_update, Storage *storage, + std::uint64_t transaction_start_timestamp) { + UpdateNode(vertex_after_update, storage, transaction_start_timestamp); } std::vector TextIndex::GetApplicableTextIndices(const std::vector &labels) { @@ -165,7 +171,7 @@ bool TextIndex::CreateIndex(std::string index_name, LabelId label, memgraph::que document["data"] = properties; document["metadata"] = {}; document["metadata"]["gid"] = v.Gid().AsInt(); - // TODO add txid + document["metadata"]["txid"] = v.impl_.transaction_->start_timestamp; document["metadata"]["deleted"] = false; document["metadata"]["is_node"] = true; diff --git a/src/storage/v2/indices/text_index.hpp b/src/storage/v2/indices/text_index.hpp index 4bfaede7c..e1d07faed 100644 --- a/src/storage/v2/indices/text_index.hpp +++ b/src/storage/v2/indices/text_index.hpp @@ -25,7 +25,7 @@ class Storage; class TextIndex { private: - void AddNode(Vertex *vertex, Storage *storage, + void AddNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp, const std::vector &applicable_text_indices); std::vector GetApplicableTextIndices(const std::vector &labels); @@ -45,19 +45,23 @@ class TextIndex { std::map index_; std::map label_to_index_; - void AddNode(Vertex *vertex, Storage *storage); + void AddNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp); - void UpdateNode(Vertex *vertex, Storage *storage); + void UpdateNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp); - void UpdateNode(Vertex *vertex, Storage *storage, const std::vector &removed_labels); + void UpdateNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp, + const std::vector &removed_labels); void RemoveNode(Vertex *vertex); - void UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, Storage *storage, const Transaction &tx); + void UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, Storage *storage, + const std::uint64_t transaction_start_timestamp); - void UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update, const Transaction &tx); + void UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update, + const std::uint64_t transaction_start_timestamp); - void UpdateOnSetProperty(Vertex *vertex_after_update, Storage *storage, const Transaction &tx); + void UpdateOnSetProperty(Vertex *vertex_after_update, Storage *storage, + const std::uint64_t transaction_start_timestamp); std::vector GetApplicableTextIndices(Vertex *vertex);