Switch to experimental flags

This commit is contained in:
Ante Pušić 2024-02-18 19:35:10 +01:00
parent d00a18172f
commit 30522ccaf1
16 changed files with 50 additions and 58 deletions

View File

@ -19,13 +19,14 @@
// Bolt server flags.
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
DEFINE_string(experimental_enabled, "",
"Experimental features to be used, comma seperated. Options [system-replication]");
"Experimental features to be used, comma-separated. Options [system-replication, text-search]");
using namespace std::string_view_literals;
namespace memgraph::flags {
auto const mapping = std::map{std::pair{"system-replication"sv, Experiments::SYSTEM_REPLICATION}};
auto const mapping = std::map{std::pair{"system-replication"sv, Experiments::SYSTEM_REPLICATION},
std::pair{"text-search"sv, Experiments::TEXT_SEARCH}};
auto ExperimentsInstance() -> Experiments & {
static auto instance = Experiments{};
@ -44,7 +45,7 @@ bool AreExperimentsEnabled(Experiments experiments) {
void InitializeExperimental() {
namespace rv = ranges::views;
auto const connonicalize_string = [](auto &&rng) {
auto const canonicalize_string = [](auto &&rng) {
auto const is_space = [](auto c) { return c == ' '; };
auto const to_lower = [](unsigned char c) { return std::tolower(c); };
@ -55,7 +56,7 @@ void InitializeExperimental() {
auto const mapping_end = mapping.cend();
using underlying_type = std::underlying_type_t<Experiments>;
auto to_set = underlying_type{};
for (auto &&experiment : FLAGS_experimental_enabled | rv::split(',') | rv::transform(connonicalize_string)) {
for (auto &&experiment : FLAGS_experimental_enabled | rv::split(',') | rv::transform(canonicalize_string)) {
if (auto it = mapping.find(experiment); it != mapping_end) {
to_set |= static_cast<underlying_type>(it->second);
}

View File

@ -23,6 +23,7 @@ namespace memgraph::flags {
// old experiments can be reused once code cleanup has happened
enum class Experiments : uint8_t {
SYSTEM_REPLICATION = 1 << 0,
TEXT_SEARCH = 1 << 1,
};
bool AreExperimentsEnabled(Experiments experiments);

View File

@ -54,9 +54,6 @@ DEFINE_double(query_execution_timeout_sec, 600,
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
DEFINE_bool(cartesian_product_enabled, true, "Enable cartesian product expansion.");
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
DEFINE_bool(experimental_text_search_enabled, false, "Enable experimental text search.");
namespace {
// Bolt server name
constexpr auto kServerNameSettingKey = "server.name";
@ -76,14 +73,10 @@ constexpr auto kLogToStderrGFlagsKey = "also_log_to_stderr";
constexpr auto kCartesianProductEnabledSettingKey = "cartesian-product-enabled";
constexpr auto kCartesianProductEnabledGFlagsKey = "cartesian-product-enabled";
constexpr auto kExperimentalTextSearchEnabledSettingKey = "experimental-text-search-enabled";
constexpr auto kExperimentalTextSearchEnabledGFlagsKey = "experimental-text-search-enabled";
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
// Local cache-like thing
std::atomic<double> execution_timeout_sec_;
std::atomic<bool> cartesian_product_enabled_{true};
std::atomic<bool> experimental_text_search_enabled_{true};
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
auto ToLLEnum(std::string_view val) {
@ -193,10 +186,6 @@ void Initialize() {
register_flag(
kCartesianProductEnabledGFlagsKey, kCartesianProductEnabledSettingKey, !kRestore,
[](const std::string &val) { cartesian_product_enabled_ = val == "true"; }, ValidBoolStr);
register_flag(
kExperimentalTextSearchEnabledGFlagsKey, kExperimentalTextSearchEnabledSettingKey, !kRestore,
[](const std::string &val) { experimental_text_search_enabled_ = val == "true"; }, ValidBoolStr);
}
std::string GetServerName() {
@ -210,6 +199,4 @@ double GetExecutionTimeout() { return execution_timeout_sec_; }
bool GetCartesianProductEnabled() { return cartesian_product_enabled_; }
bool GetExperimentalTextSearchEnabled() { return experimental_text_search_enabled_; }
} // namespace memgraph::flags::run_time

View File

@ -42,11 +42,4 @@ double GetExecutionTimeout();
*/
bool GetCartesianProductEnabled();
/**
* @brief Get whether text search is enabled
*
* @return bool
*/
bool GetExperimentalTextSearchEnabled();
} // namespace memgraph::flags::run_time

View File

@ -440,7 +440,9 @@ class TextSearchException : public QueryException {
class TextSearchDisabledException : public TextSearchException {
public:
TextSearchDisabledException() : TextSearchException("To use text indices, enable the text search feature.") {}
TextSearchDisabledException()
: TextSearchException(
"To use text indices and text search, start Memgraph with the experimental text search feature enabled.") {}
SPECIALIZE_GET_EXCEPTION_NAME(TextSearchDisabledException)
};

View File

@ -39,6 +39,7 @@
#include "dbms/dbms_handler.hpp"
#include "dbms/global.hpp"
#include "dbms/inmemory/storage_helper.hpp"
#include "flags/experimental.hpp"
#include "flags/replication.hpp"
#include "flags/run_time_configurable.hpp"
#include "glue/communication.hpp"
@ -2716,7 +2717,7 @@ PreparedQuery PrepareTextIndexQuery(ParsedQuery parsed_query, bool in_explicit_t
// TODO: not just storage + invalidate_plan_cache. Need a DB transaction (for replication)
handler = [dba, label, index_name,
invalidate_plan_cache = std::move(invalidate_plan_cache)](Notification &index_notification) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw TextSearchDisabledException();
}
dba->CreateTextIndex(index_name, label);
@ -2730,7 +2731,7 @@ PreparedQuery PrepareTextIndexQuery(ParsedQuery parsed_query, bool in_explicit_t
// TODO: not just storage + invalidate_plan_cache. Need a DB transaction (for replication)
handler = [dba, index_name,
invalidate_plan_cache = std::move(invalidate_plan_cache)](Notification &index_notification) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw TextSearchDisabledException();
}
dba->DropTextIndex(index_name);

View File

@ -32,6 +32,7 @@
#include "spdlog/spdlog.h"
#include "csv/parsing.hpp"
#include "flags/experimental.hpp"
#include "license/license.hpp"
#include "query/auth_checker.hpp"
#include "query/context.hpp"
@ -251,7 +252,7 @@ VertexAccessor &CreateLocalVertex(const NodeCreationInfo &node_info, Frame *fram
}
MultiPropsInitChecked(&new_node, properties);
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
context.db_accessor->TextIndexAddVertex(&new_node);
}
@ -2885,7 +2886,7 @@ bool SetProperty::SetPropertyCursor::Pull(Frame &frame, ExecutionContext &contex
context.trigger_context_collector->RegisterSetObjectProperty(lhs.ValueVertex(), self_.property_,
TypedValue{std::move(old_value)}, TypedValue{rhs});
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
auto new_node = lhs.ValueVertex();
context.db_accessor->TextIndexUpdateVertex(&new_node);
}
@ -3045,7 +3046,7 @@ void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetPr
case TypedValue::Type::Vertex: {
PropertiesMap new_properties = get_props(rhs.ValueVertex());
update_props(new_properties);
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
auto new_node = rhs.ValueVertex();
context->db_accessor->TextIndexUpdateVertex(&new_node);
}
@ -3106,7 +3107,7 @@ bool SetProperties::SetPropertiesCursor::Pull(Frame &frame, ExecutionContext &co
}
#endif
SetPropertiesOnRecord(&lhs.ValueVertex(), rhs, self_.op_, &context, cached_name_id_);
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
context.db_accessor->TextIndexUpdateVertex(&lhs.ValueVertex());
}
break;
@ -3198,7 +3199,7 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, ExecutionContext &context) {
}
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
context.db_accessor->TextIndexUpdateVertex(&vertex);
}
@ -3273,7 +3274,7 @@ bool RemoveProperty::RemovePropertyCursor::Pull(Frame &frame, ExecutionContext &
}
#endif
remove_prop(&lhs.ValueVertex());
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
auto &updated_vertex = lhs.ValueVertex();
context.db_accessor->TextIndexUpdateVertex(&updated_vertex);
}
@ -3367,7 +3368,7 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame, ExecutionContext &cont
}
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
context.db_accessor->TextIndexUpdateVertex(&vertex, self_.labels_);
}

View File

@ -23,6 +23,7 @@
#include <utility>
#include <variant>
#include "flags/experimental.hpp"
#include "flags/run_time_configurable.hpp"
#include "license/license.hpp"
#include "mg_procedure.h"
@ -1843,7 +1844,7 @@ 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)); },
v->impl);
if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled() && !result.HasError()) {
if (memgraph::flags::AreExperimentsEnabled(memgraph::flags::Experiments::TEXT_SEARCH) && !result.HasError()) {
auto v_impl = v->getImpl();
v->graph->getImpl()->TextIndexUpdateVertex(&v_impl);
}
@ -1904,7 +1905,7 @@ mgp_error mgp_vertex_set_properties(struct mgp_vertex *v, struct mgp_map *proper
}
const auto result = v->getImpl().UpdateProperties(props);
if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled() && !result.HasError()) {
if (memgraph::flags::AreExperimentsEnabled(memgraph::flags::Experiments::TEXT_SEARCH) && !result.HasError()) {
auto v_impl = v->getImpl();
v->graph->getImpl()->TextIndexUpdateVertex(&v_impl);
}
@ -1966,7 +1967,7 @@ 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); }, v->impl);
if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled() && !result.HasError()) {
if (memgraph::flags::AreExperimentsEnabled(memgraph::flags::Experiments::TEXT_SEARCH) && !result.HasError()) {
auto v_impl = v->getImpl();
v->graph->getImpl()->TextIndexUpdateVertex(&v_impl);
}
@ -2012,7 +2013,7 @@ mgp_error mgp_vertex_remove_label(struct mgp_vertex *v, mgp_label label) {
throw ImmutableObjectException{"Cannot remove a label from an immutable vertex!"};
}
const auto result = std::visit([label_id](auto &impl) { return impl.RemoveLabel(label_id); }, v->impl);
if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled() && !result.HasError()) {
if (memgraph::flags::AreExperimentsEnabled(memgraph::flags::Experiments::TEXT_SEARCH) && !result.HasError()) {
auto v_impl = v->getImpl();
v->graph->getImpl()->TextIndexUpdateVertex(&v_impl, {label_id});
}
@ -2986,7 +2987,7 @@ mgp_error mgp_graph_create_vertex(struct mgp_graph *graph, mgp_memory *memory, m
auto *vertex = std::visit(
[=](auto *impl) { return NewRawMgpObject<mgp_vertex>(memory, impl->InsertVertex(), graph); }, graph->impl);
// TODO antepusic update text index
if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled()) {
if (memgraph::flags::AreExperimentsEnabled(memgraph::flags::Experiments::TEXT_SEARCH)) {
auto v_impl = vertex->getImpl();
vertex->graph->getImpl()->TextIndexAddVertex(&v_impl);
}

View File

@ -29,6 +29,7 @@
#include <rocksdb/utilities/transaction.h>
#include <rocksdb/utilities/transaction_db.h>
#include "flags/experimental.hpp"
#include "flags/run_time_configurable.hpp"
#include "kvstore/kvstore.hpp"
#include "spdlog/spdlog.h"
@ -1766,7 +1767,7 @@ utils::BasicResult<StorageManipulationError, void> DiskStorage::DiskAccessor::Co
return StorageManipulationError{SerializationError{}};
}
spdlog::trace("rocksdb: Commit successful");
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
disk_storage->indices_.text_index_.Commit();
}
@ -1887,7 +1888,7 @@ void DiskStorage::DiskAccessor::Abort() {
// query_plan_accumulate_aggregate.cpp
transaction_.disk_transaction_->Rollback();
transaction_.disk_transaction_->ClearSnapshot();
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
storage_->indices_.text_index_.Rollback();
}
delete transaction_.disk_transaction_;

View File

@ -197,7 +197,7 @@ void RecoverIndicesAndStats(const RecoveredIndicesAndConstraints::IndicesMetadat
}
spdlog::info("Label+property indices statistics are recreated.");
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
// Recover text indices.
spdlog::info("Recreating {} text indices from metadata.", indices_metadata.text_indices.size());
auto &mem_text_index = indices->text_index_;

View File

@ -13,6 +13,7 @@
#include <thread>
#include "flags/experimental.hpp"
#include "flags/run_time_configurable.hpp"
#include "spdlog/spdlog.h"
#include "storage/v2/durability/exceptions.hpp"
@ -1631,7 +1632,7 @@ RecoveredSnapshot LoadSnapshot(const std::filesystem::path &path, utils::SkipLis
}
// Recover text indices.
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
auto size = snapshot.ReadUint();
if (!size) throw RecoveryFailure("Couldn't recover the number of text indices!");
spdlog::info("Recovering metadata of {} text indices.", *size);
@ -2126,7 +2127,7 @@ void CreateSnapshot(Storage *storage, Transaction *transaction, const std::files
}
// Write text indices.
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
auto text_indices = storage->indices_.text_index_.ListIndices();
snapshot.WriteUint(text_indices.size());
for (const auto &item : text_indices) {

View File

@ -10,6 +10,7 @@
// licenses/APL.txt.
#include "storage/v2/indices/text_index.hpp"
#include "flags/experimental.hpp"
#include "flags/run_time_configurable.hpp"
#include "query/db_accessor.hpp"
#include "storage/v2/view.hpp"
@ -24,7 +25,7 @@ std::string GetPropertyName(PropertyId prop_id, NameIdMapper *name_id_mapper) {
}
void TextIndex::CreateEmptyIndex(const std::string &index_name, LabelId label) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}
@ -78,7 +79,7 @@ nlohmann::json TextIndex::SerializeProperties(const std::map<PropertyId, Propert
}
std::vector<mgcxx::text_search::Context *> TextIndex::GetApplicableTextIndices(const std::vector<LabelId> &labels) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}
@ -132,7 +133,7 @@ void TextIndex::CommitLoadedNodes(mgcxx::text_search::Context &index_context) {
void TextIndex::AddNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}
@ -142,7 +143,7 @@ void TextIndex::AddNode(Vertex *vertex_after_update, NameIdMapper *name_id_mappe
}
void TextIndex::AddNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}
@ -153,7 +154,7 @@ void TextIndex::AddNode(Vertex *vertex_after_update, NameIdMapper *name_id_mappe
void TextIndex::UpdateNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::vector<LabelId> &removed_labels) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}
@ -170,7 +171,7 @@ void TextIndex::UpdateNode(Vertex *vertex_after_update, NameIdMapper *name_id_ma
void TextIndex::RemoveNode(Vertex *vertex_after_update,
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}
@ -187,7 +188,7 @@ void TextIndex::RemoveNode(Vertex *vertex_after_update,
}
void TextIndex::RemoveNode(Vertex *vertex_after_update) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}
@ -231,7 +232,7 @@ void TextIndex::RecoverIndex(const std::string &index_name, LabelId label,
}
LabelId TextIndex::DropIndex(const std::string &index_name) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}
@ -255,7 +256,7 @@ LabelId TextIndex::DropIndex(const std::string &index_name) {
bool TextIndex::IndexExists(const std::string &index_name) const { return index_.contains(index_name); }
std::vector<Gid> TextIndex::Search(const std::string &index_name, const std::string &search_query) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
throw query::TextSearchDisabledException();
}

View File

@ -14,6 +14,7 @@
#include <functional>
#include <optional>
#include "dbms/constants.hpp"
#include "flags/experimental.hpp"
#include "flags/run_time_configurable.hpp"
#include "memory/global_memory_control.hpp"
#include "storage/v2/durability/durability.hpp"
@ -876,7 +877,7 @@ utils::BasicResult<StorageManipulationError, void> InMemoryStorage::InMemoryAcce
return StorageManipulationError{*unique_constraint_violation};
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
mem_storage->indices_.text_index_.Commit();
}
}
@ -1201,7 +1202,7 @@ void InMemoryStorage::InMemoryAccessor::Abort() {
for (auto const &[property, prop_vertices] : property_cleanup) {
storage_->indices_.AbortEntries(property, prop_vertices, transaction_.start_timestamp);
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
storage_->indices_.text_index_.Rollback();
}

View File

@ -13,6 +13,7 @@
#include "absl/container/flat_hash_set.h"
#include "spdlog/spdlog.h"
#include "flags/experimental.hpp"
#include "flags/run_time_configurable.hpp"
#include "storage/v2/disk/name_id_mapper.hpp"
#include "storage/v2/storage.hpp"
@ -274,7 +275,7 @@ Storage::Accessor::DetachDelete(std::vector<VertexAccessor *> nodes, std::vector
return maybe_deleted_vertices.GetError();
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
for (auto *node : nodes_to_delete) {
storage_->indices_.text_index_.RemoveNode(node);
}

View File

@ -228,6 +228,6 @@ startup_config_dict = {
"experimental_enabled": (
"",
"",
"Experimental features to be used, comma seperated. Options [system-replication]",
"Experimental features to be used, comma-separated. Options [system-replication, text-search]",
),
}

View File

@ -1,7 +1,7 @@
text_search_cluster: &text_search_cluster
cluster:
main:
args: ["--bolt-port", "7687", "--log-level=TRACE", "--experimental-text-search-enabled=true"]
args: ["--bolt-port", "7687", "--log-level=TRACE", "--experimental-enabled=text-search"]
log_file: "text_search.log"
setup_queries: []
validation_queries: []