Remove boolean update_text_index from method signatures

This commit is contained in:
Ante Pušić 2024-02-09 21:22:53 +01:00
parent fc0a71f3d5
commit 34c7a8b098
8 changed files with 83 additions and 101 deletions

View File

@ -535,7 +535,7 @@ uint64_t InMemoryReplicationHandlers::ReadAndApplyDelta(storage::InMemoryStorage
if (!vertex)
throw utils::BasicException("Invalid transaction! Please raise an issue, {}:{}", __FILE__, __LINE__);
// NOTE: Phase 1 of the text search feature doesn't have replication in scope
auto ret = vertex->AddLabel(transaction->NameToLabel(delta.vertex_add_remove_label.label), false);
auto ret = vertex->AddLabel(transaction->NameToLabel(delta.vertex_add_remove_label.label));
if (ret.HasError() || !ret.GetValue())
throw utils::BasicException("Invalid transaction! Please raise an issue, {}:{}", __FILE__, __LINE__);
break;
@ -548,7 +548,7 @@ uint64_t InMemoryReplicationHandlers::ReadAndApplyDelta(storage::InMemoryStorage
if (!vertex)
throw utils::BasicException("Invalid transaction! Please raise an issue, {}:{}", __FILE__, __LINE__);
// NOTE: Phase 1 of the text search feature doesn't have replication in scope
auto ret = vertex->RemoveLabel(transaction->NameToLabel(delta.vertex_add_remove_label.label), false);
auto ret = vertex->RemoveLabel(transaction->NameToLabel(delta.vertex_add_remove_label.label));
if (ret.HasError() || !ret.GetValue())
throw utils::BasicException("Invalid transaction! Please raise an issue, {}:{}", __FILE__, __LINE__);
break;
@ -562,7 +562,7 @@ uint64_t InMemoryReplicationHandlers::ReadAndApplyDelta(storage::InMemoryStorage
throw utils::BasicException("Invalid transaction! Please raise an issue, {}:{}", __FILE__, __LINE__);
// NOTE: Phase 1 of the text search feature doesn't have replication in scope
auto ret = vertex->SetProperty(transaction->NameToProperty(delta.vertex_edge_set_property.property),
delta.vertex_edge_set_property.value, false);
delta.vertex_edge_set_property.value);
if (ret.HasError())
throw utils::BasicException("Invalid transaction! Please raise an issue, {}:{}", __FILE__, __LINE__);
break;

View File

@ -115,13 +115,9 @@ class VertexAccessor final {
auto Labels(storage::View view) const { return impl_.Labels(view); }
storage::Result<bool> AddLabel(storage::LabelId label, bool update_text_index = false) {
return impl_.AddLabel(label, update_text_index);
}
storage::Result<bool> AddLabel(storage::LabelId label) { return impl_.AddLabel(label); }
storage::Result<bool> RemoveLabel(storage::LabelId label, bool update_text_index = false) {
return impl_.RemoveLabel(label, update_text_index);
}
storage::Result<bool> RemoveLabel(storage::LabelId label) { return impl_.RemoveLabel(label); }
storage::Result<bool> HasLabel(storage::View view, storage::LabelId label) const {
return impl_.HasLabel(label, view);
@ -133,29 +129,25 @@ class VertexAccessor final {
return impl_.GetProperty(key, view);
}
storage::Result<storage::PropertyValue> SetProperty(storage::PropertyId key, const storage::PropertyValue &value,
bool update_text_index = false) {
return impl_.SetProperty(key, value, update_text_index);
storage::Result<storage::PropertyValue> SetProperty(storage::PropertyId key, const storage::PropertyValue &value) {
return impl_.SetProperty(key, value);
}
storage::Result<bool> InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties,
bool update_text_index = false) {
return impl_.InitProperties(properties, update_text_index);
storage::Result<bool> InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties) {
return impl_.InitProperties(properties);
}
storage::Result<std::vector<std::tuple<storage::PropertyId, storage::PropertyValue, storage::PropertyValue>>>
UpdateProperties(std::map<storage::PropertyId, storage::PropertyValue> &properties,
bool update_text_index = false) const {
return impl_.UpdateProperties(properties, update_text_index);
UpdateProperties(std::map<storage::PropertyId, storage::PropertyValue> &properties) const {
return impl_.UpdateProperties(properties);
}
storage::Result<storage::PropertyValue> RemoveProperty(storage::PropertyId key, bool update_text_index = false) {
return SetProperty(key, storage::PropertyValue(), update_text_index);
storage::Result<storage::PropertyValue> RemoveProperty(storage::PropertyId key) {
return SetProperty(key, storage::PropertyValue());
}
storage::Result<std::map<storage::PropertyId, storage::PropertyValue>> ClearProperties(
bool update_text_index = false) {
return impl_.ClearProperties(update_text_index);
storage::Result<std::map<storage::PropertyId, storage::PropertyValue>> ClearProperties() {
return impl_.ClearProperties();
}
storage::Result<EdgeVertexAccessorResult> InEdges(storage::View view,
@ -262,13 +254,9 @@ class SubgraphVertexAccessor final {
auto Labels(storage::View view) const { return impl_.Labels(view); }
storage::Result<bool> AddLabel(storage::LabelId label, bool update_text_index = false) {
return impl_.AddLabel(label, update_text_index);
}
storage::Result<bool> AddLabel(storage::LabelId label) { return impl_.AddLabel(label); }
storage::Result<bool> RemoveLabel(storage::LabelId label, bool update_text_index = false) {
return impl_.RemoveLabel(label, update_text_index);
}
storage::Result<bool> RemoveLabel(storage::LabelId label) { return impl_.RemoveLabel(label); }
storage::Result<bool> HasLabel(storage::View view, storage::LabelId label) const {
return impl_.HasLabel(view, label);
@ -286,15 +274,13 @@ class SubgraphVertexAccessor final {
storage::Result<size_t> OutDegree(storage::View view) const { return impl_.OutDegree(view); }
storage::Result<storage::PropertyValue> SetProperty(storage::PropertyId key, const storage::PropertyValue &value,
bool update_text_index = false) {
return impl_.SetProperty(key, value, update_text_index);
storage::Result<storage::PropertyValue> SetProperty(storage::PropertyId key, const storage::PropertyValue &value) {
return impl_.SetProperty(key, value);
}
storage::Result<std::vector<std::tuple<storage::PropertyId, storage::PropertyValue, storage::PropertyValue>>>
UpdateProperties(std::map<storage::PropertyId, storage::PropertyValue> &properties,
bool update_text_index = false) const {
return impl_.UpdateProperties(properties, update_text_index);
UpdateProperties(std::map<storage::PropertyId, storage::PropertyValue> &properties) const {
return impl_.UpdateProperties(properties);
}
VertexAccessor GetVertexAccessor() const;

View File

@ -217,7 +217,7 @@ VertexAccessor &CreateLocalVertex(const NodeCreationInfo &node_info, Frame *fram
auto new_node = dba.InsertVertex();
context.execution_stats[ExecutionStats::Key::CREATED_NODES] += 1;
for (auto label : node_info.labels) {
auto maybe_error = new_node.AddLabel(label, false); // skip updating text indices until all labels are added
auto maybe_error = new_node.AddLabel(label); // skip updating text indices until all labels are added
if (maybe_error.HasError()) {
switch (maybe_error.GetError()) {
case storage::Error::SERIALIZATION_ERROR:
@ -3177,7 +3177,7 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, ExecutionContext &context) {
#endif
for (auto label : self_.labels_) {
auto maybe_value = vertex.AddLabel(label, false); // skip updating text indices until all labels are added
auto maybe_value = vertex.AddLabel(label);
if (maybe_value.HasError()) {
switch (maybe_value.GetError()) {
case storage::Error::SERIALIZATION_ERROR:
@ -3345,7 +3345,7 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame, ExecutionContext &cont
#endif
for (auto label : self_.labels_) {
auto maybe_value = vertex.RemoveLabel(label, false);
auto maybe_value = vertex.RemoveLabel(label);
if (maybe_value.HasError()) {
switch (maybe_value.GetError()) {
case storage::Error::SERIALIZATION_ERROR:

View File

@ -1841,8 +1841,8 @@ mgp_error mgp_vertex_set_property(struct mgp_vertex *v, const char *property_nam
const auto result = std::visit(
[prop_key, property_value](auto &impl) {
return impl.SetProperty(prop_key, ToPropertyValue(*property_value),
memgraph::flags::run_time::GetExperimentalTextSearchEnabled());
// TODO antepusic also update text index
return impl.SetProperty(prop_key, ToPropertyValue(*property_value));
},
v->impl);
if (result.HasError()) {
@ -1900,8 +1900,8 @@ mgp_error mgp_vertex_set_properties(struct mgp_vertex *v, struct mgp_map *proper
v->graph->impl));
}
const auto result =
v->getImpl().UpdateProperties(props, memgraph::flags::run_time::GetExperimentalTextSearchEnabled());
const auto result = v->getImpl().UpdateProperties(props);
// TODO antepusic also update text index
if (result.HasError()) {
switch (result.GetError()) {
case memgraph::storage::Error::DELETED_OBJECT:
@ -1960,7 +1960,8 @@ mgp_error mgp_vertex_add_label(struct mgp_vertex *v, mgp_label label) {
const auto result = std::visit(
[label_id](auto &impl) {
return impl.AddLabel(label_id, memgraph::flags::run_time::GetExperimentalTextSearchEnabled());
// TODO antepusic also update text index
return impl.AddLabel(label_id);
},
v->impl);
@ -2006,7 +2007,8 @@ mgp_error mgp_vertex_remove_label(struct mgp_vertex *v, mgp_label label) {
}
const auto result = std::visit(
[label_id](auto &impl) {
return impl.RemoveLabel(label_id, memgraph::flags::run_time::GetExperimentalTextSearchEnabled());
// todo also remove from text index
return impl.RemoveLabel(label_id);
},
v->impl);

View File

@ -39,29 +39,28 @@ void Indices::RemoveObsoleteEntries(uint64_t oldest_active_start_timestamp, std:
->RemoveObsoleteEntries(oldest_active_start_timestamp, std::move(token));
}
void Indices::UpdateOnAddLabel(LabelId label, Vertex *vertex, const Transaction &tx, Storage *storage,
bool update_text_index) const {
void Indices::UpdateOnAddLabel(LabelId label, Vertex *vertex, const Transaction &tx, Storage *storage) const {
label_index_->UpdateOnAddLabel(label, vertex, tx);
label_property_index_->UpdateOnAddLabel(label, vertex, tx);
if (update_text_index) {
text_index_.UpdateOnAddLabel(label, vertex, storage->name_id_mapper_.get(), tx.start_timestamp);
}
// if (update_text_index) {
// text_index_.UpdateOnAddLabel(label, vertex, storage->name_id_mapper_.get(), tx.start_timestamp);
// }
}
void Indices::UpdateOnRemoveLabel(LabelId label, Vertex *vertex, const Transaction &tx, bool update_text_index) const {
void Indices::UpdateOnRemoveLabel(LabelId label, Vertex *vertex, const Transaction &tx) const {
label_index_->UpdateOnRemoveLabel(label, vertex, tx);
label_property_index_->UpdateOnRemoveLabel(label, vertex, tx);
if (update_text_index) {
text_index_.UpdateOnRemoveLabel(label, vertex, tx.start_timestamp);
}
// if (update_text_index) {
// text_index_.UpdateOnRemoveLabel(label, vertex, tx.start_timestamp);
// }
}
void Indices::UpdateOnSetProperty(PropertyId property, const PropertyValue &value, Vertex *vertex,
const Transaction &tx, Storage *storage, bool update_text_index) const {
const Transaction &tx, Storage *storage) const {
label_property_index_->UpdateOnSetProperty(property, value, vertex, tx);
if (update_text_index) {
text_index_.UpdateOnSetProperty(vertex, storage->name_id_mapper_.get(), tx.start_timestamp);
}
// if (update_text_index) {
// text_index_.UpdateOnSetProperty(vertex, storage->name_id_mapper_.get(), tx.start_timestamp);
// }
}
Indices::Indices(const Config &config, StorageMode storage_mode) {

View File

@ -56,15 +56,14 @@ struct Indices {
/// This function should be called whenever a label is added to a vertex.
/// @throw std::bad_alloc
void UpdateOnAddLabel(LabelId label, Vertex *vertex, const Transaction &tx, Storage *storage,
bool update_text_index = false) const;
void UpdateOnAddLabel(LabelId label, Vertex *vertex, const Transaction &tx, Storage *storage) const;
void UpdateOnRemoveLabel(LabelId label, Vertex *vertex, const Transaction &tx, bool update_text_index = false) const;
void UpdateOnRemoveLabel(LabelId label, Vertex *vertex, const Transaction &tx) const;
/// This function should be called whenever a property is modified on a vertex.
/// @throw std::bad_alloc
void UpdateOnSetProperty(PropertyId property, const PropertyValue &value, Vertex *vertex, const Transaction &tx,
Storage *storage, bool update_text_index = false) const;
Storage *storage) const;
std::unique_ptr<LabelIndex> label_index_;
std::unique_ptr<LabelPropertyIndex> label_property_index_;

View File

@ -100,7 +100,7 @@ bool VertexAccessor::IsVisible(View view) const {
return exists && (for_deleted_ || !deleted);
}
Result<bool> VertexAccessor::AddLabel(LabelId label, bool update_text_index) {
Result<bool> VertexAccessor::AddLabel(LabelId label) {
if (transaction_->edge_import_mode_active) {
throw query::WriteVertexOperationInEdgeImportModeException();
}
@ -124,14 +124,14 @@ Result<bool> VertexAccessor::AddLabel(LabelId label, bool update_text_index) {
/// TODO: some by pointers, some by reference => not good, make it better
storage_->constraints_.unique_constraints_->UpdateOnAddLabel(label, *vertex_, transaction_->start_timestamp);
transaction_->constraint_verification_info.AddedLabel(vertex_);
storage_->indices_.UpdateOnAddLabel(label, vertex_, *transaction_, storage_, update_text_index);
storage_->indices_.UpdateOnAddLabel(label, vertex_, *transaction_, storage_);
transaction_->manyDeltasCache.Invalidate(vertex_, label);
return true;
}
/// TODO: move to after update and change naming to vertex after update
Result<bool> VertexAccessor::RemoveLabel(LabelId label, bool update_text_index) {
Result<bool> VertexAccessor::RemoveLabel(LabelId label) {
if (transaction_->edge_import_mode_active) {
throw query::WriteVertexOperationInEdgeImportModeException();
}
@ -152,7 +152,7 @@ Result<bool> VertexAccessor::RemoveLabel(LabelId label, bool update_text_index)
/// TODO: some by pointers, some by reference => not good, make it better
storage_->constraints_.unique_constraints_->UpdateOnRemoveLabel(label, *vertex_, transaction_->start_timestamp);
storage_->indices_.UpdateOnRemoveLabel(label, vertex_, *transaction_, update_text_index);
storage_->indices_.UpdateOnRemoveLabel(label, vertex_, *transaction_);
transaction_->manyDeltasCache.Invalidate(vertex_, label);
return true;
@ -252,8 +252,7 @@ Result<std::vector<LabelId>> VertexAccessor::Labels(View view) const {
return std::move(labels);
}
Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const PropertyValue &value,
bool update_text_index) {
Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const PropertyValue &value) {
if (transaction_->edge_import_mode_active) {
throw query::WriteVertexOperationInEdgeImportModeException();
}
@ -285,14 +284,13 @@ Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const Pro
} else {
transaction_->constraint_verification_info.RemovedProperty(vertex_);
}
storage_->indices_.UpdateOnSetProperty(property, value, vertex_, *transaction_, storage_, update_text_index);
storage_->indices_.UpdateOnSetProperty(property, value, vertex_, *transaction_, storage_);
transaction_->manyDeltasCache.Invalidate(vertex_, property);
return std::move(current_value);
}
Result<bool> VertexAccessor::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties,
bool update_text_index) {
Result<bool> VertexAccessor::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties) {
if (transaction_->edge_import_mode_active) {
throw query::WriteVertexOperationInEdgeImportModeException();
}
@ -305,14 +303,14 @@ Result<bool> VertexAccessor::InitProperties(const std::map<storage::PropertyId,
if (vertex_->deleted) return Error::DELETED_OBJECT;
bool result{false};
utils::AtomicMemoryBlock atomic_memory_block{
[&result, &properties, storage = storage_, transaction = transaction_, vertex = vertex_, update_text_index]() {
[&result, &properties, storage = storage_, transaction = transaction_, vertex = vertex_]() {
if (!vertex->properties.InitProperties(properties)) {
result = false;
return;
}
for (const auto &[property, value] : properties) {
CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), property, PropertyValue());
storage->indices_.UpdateOnSetProperty(property, value, vertex, *transaction, storage, update_text_index);
storage->indices_.UpdateOnSetProperty(property, value, vertex, *transaction, storage);
transaction->manyDeltasCache.Invalidate(vertex, property);
if (!value.IsNull()) {
transaction->constraint_verification_info.AddedProperty(vertex);
@ -328,7 +326,7 @@ Result<bool> VertexAccessor::InitProperties(const std::map<storage::PropertyId,
}
Result<std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>>> VertexAccessor::UpdateProperties(
std::map<storage::PropertyId, storage::PropertyValue> &properties, bool update_text_index) const {
std::map<storage::PropertyId, storage::PropertyValue> &properties) const {
if (transaction_->edge_import_mode_active) {
throw query::WriteVertexOperationInEdgeImportModeException();
}
@ -342,30 +340,30 @@ Result<std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>>> Vertex
using ReturnType = decltype(vertex_->properties.UpdateProperties(properties));
std::optional<ReturnType> id_old_new_change;
utils::AtomicMemoryBlock atomic_memory_block{[storage = storage_, transaction = transaction_, vertex = vertex_,
&properties, &id_old_new_change, update_text_index]() {
id_old_new_change.emplace(vertex->properties.UpdateProperties(properties));
utils::AtomicMemoryBlock atomic_memory_block{
[storage = storage_, transaction = transaction_, vertex = vertex_, &properties, &id_old_new_change]() {
id_old_new_change.emplace(vertex->properties.UpdateProperties(properties));
if (!id_old_new_change.has_value()) {
return;
}
for (auto &[id, old_value, new_value] : *id_old_new_change) {
storage->indices_.UpdateOnSetProperty(id, new_value, vertex, *transaction, storage, update_text_index);
CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), id, std::move(old_value));
transaction->manyDeltasCache.Invalidate(vertex, id);
if (!new_value.IsNull()) {
transaction->constraint_verification_info.AddedProperty(vertex);
} else {
transaction->constraint_verification_info.RemovedProperty(vertex);
}
}
}};
if (!id_old_new_change.has_value()) {
return;
}
for (auto &[id, old_value, new_value] : *id_old_new_change) {
storage->indices_.UpdateOnSetProperty(id, new_value, vertex, *transaction, storage);
CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), id, std::move(old_value));
transaction->manyDeltasCache.Invalidate(vertex, id);
if (!new_value.IsNull()) {
transaction->constraint_verification_info.AddedProperty(vertex);
} else {
transaction->constraint_verification_info.RemovedProperty(vertex);
}
}
}};
std::invoke(atomic_memory_block);
return id_old_new_change.has_value() ? std::move(id_old_new_change.value()) : ReturnType{};
}
Result<std::map<PropertyId, PropertyValue>> VertexAccessor::ClearProperties(bool update_text_index) {
Result<std::map<PropertyId, PropertyValue>> VertexAccessor::ClearProperties() {
if (transaction_->edge_import_mode_active) {
throw query::WriteVertexOperationInEdgeImportModeException();
}
@ -378,15 +376,14 @@ Result<std::map<PropertyId, PropertyValue>> VertexAccessor::ClearProperties(bool
using ReturnType = decltype(vertex_->properties.Properties());
std::optional<ReturnType> properties;
utils::AtomicMemoryBlock atomic_memory_block{
[storage = storage_, transaction = transaction_, vertex = vertex_, &properties, update_text_index]() {
[storage = storage_, transaction = transaction_, vertex = vertex_, &properties]() {
properties.emplace(vertex->properties.Properties());
if (!properties.has_value()) {
return;
}
for (const auto &[property, value] : *properties) {
CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), property, value);
storage->indices_.UpdateOnSetProperty(property, PropertyValue(), vertex, *transaction, storage,
update_text_index);
storage->indices_.UpdateOnSetProperty(property, PropertyValue(), vertex, *transaction, storage);
transaction->constraint_verification_info.RemovedProperty(vertex);
transaction->manyDeltasCache.Invalidate(vertex, property);
}

View File

@ -47,12 +47,12 @@ class VertexAccessor final {
/// Add a label and return `true` if insertion took place.
/// `false` is returned if the label already existed.
/// @throw std::bad_alloc
Result<bool> AddLabel(LabelId label, bool update_text_index = false);
Result<bool> AddLabel(LabelId label);
/// Remove a label and return `true` if deletion took place.
/// `false` is returned if the vertex did not have a label already.
/// @throw std::bad_alloc
Result<bool> RemoveLabel(LabelId label, bool update_text_index = false);
Result<bool> RemoveLabel(LabelId label);
Result<bool> HasLabel(LabelId label, View view) const;
@ -63,20 +63,19 @@ class VertexAccessor final {
/// Set a property value and return the old value.
/// @throw std::bad_alloc
Result<PropertyValue> SetProperty(PropertyId property, const PropertyValue &value, bool update_text_index = false);
Result<PropertyValue> SetProperty(PropertyId property, const PropertyValue &value);
/// Set property values only if property store is empty. Returns `true` if successully set all values,
/// `false` otherwise.
/// @throw std::bad_alloc
Result<bool> InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties,
bool update_text_index = false);
Result<bool> InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties);
Result<std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>>> UpdateProperties(
std::map<storage::PropertyId, storage::PropertyValue> &properties, bool update_text_index = false) const;
std::map<storage::PropertyId, storage::PropertyValue> &properties) const;
/// Remove all properties and return the values of the removed properties.
/// @throw std::bad_alloc
Result<std::map<PropertyId, PropertyValue>> ClearProperties(bool update_text_index = false);
Result<std::map<PropertyId, PropertyValue>> ClearProperties();
/// @throw std::bad_alloc
Result<PropertyValue> GetProperty(PropertyId property, View view) const;