Add transaction IDs to Tantivy metadata
This commit is contained in:
parent
1334a631b3
commit
c2824e3dc0
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<mgcxx::text_search::Context *> &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<LabelId> &removed_labels) {
|
||||
void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage,
|
||||
const std::uint64_t transaction_start_timestamp,
|
||||
const std::vector<LabelId> &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<mgcxx::text_search::Context *> TextIndex::GetApplicableTextIndices(const std::vector<LabelId> &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;
|
||||
|
||||
|
@ -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<mgcxx::text_search::Context *> &applicable_text_indices);
|
||||
|
||||
std::vector<mgcxx::text_search::Context *> GetApplicableTextIndices(const std::vector<LabelId> &labels);
|
||||
@ -45,19 +45,23 @@ class TextIndex {
|
||||
std::map<std::string, mgcxx::text_search::Context> index_;
|
||||
std::map<LabelId, std::string> 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<LabelId> &removed_labels);
|
||||
void UpdateNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp,
|
||||
const std::vector<LabelId> &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<mgcxx::text_search::Context *> GetApplicableTextIndices(Vertex *vertex);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user