Tidy up code
This commit is contained in:
parent
ff69a891d8
commit
59b83d003f
@ -660,19 +660,11 @@ uint64_t InMemoryReplicationHandlers::ReadAndApplyDelta(storage::InMemoryStorage
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WalDeltaData::Type::TEXT_INDEX_CREATE: {
|
case WalDeltaData::Type::TEXT_INDEX_CREATE: {
|
||||||
const auto &info = delta.operation_text;
|
// NOTE: Phase 1 of the text search feature doesn't have replication in scope
|
||||||
spdlog::trace(" Create text index {} on :{}", info.index_name, info.label);
|
|
||||||
auto *transaction = get_transaction(timestamp, kUniqueAccess);
|
|
||||||
if (transaction->CreateTextIndex(info.index_name, storage->NameToLabel(info.label), this).HasError())
|
|
||||||
throw utils::BasicException("Invalid transaction! Please raise an issue, {}:{}", __FILE__, __LINE__);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WalDeltaData::Type::TEXT_INDEX_DROP: {
|
case WalDeltaData::Type::TEXT_INDEX_DROP: {
|
||||||
const auto &info = delta.operation_text;
|
// NOTE: Phase 1 of the text search feature doesn't have replication in scope
|
||||||
spdlog::trace(" Drop text index {} on :{}", info.index_name, info.label);
|
|
||||||
auto *transaction = get_transaction(timestamp, kUniqueAccess);
|
|
||||||
if (transaction->DropTextIndex(info.index_name).HasError())
|
|
||||||
throw utils::BasicException("Invalid transaction! Please raise an issue, {}:{}", __FILE__, __LINE__);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WalDeltaData::Type::EXISTENCE_CONSTRAINT_CREATE: {
|
case WalDeltaData::Type::EXISTENCE_CONSTRAINT_CREATE: {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// 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
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -26,6 +26,7 @@ constexpr const char *kVertexCountDescr = "vertex_count";
|
|||||||
constexpr const char *kEdgeDountDescr = "edge_count";
|
constexpr const char *kEdgeDountDescr = "edge_count";
|
||||||
constexpr const char *kLabelIndexStr = "label_index";
|
constexpr const char *kLabelIndexStr = "label_index";
|
||||||
constexpr const char *kLabelPropertyIndexStr = "label_property_index";
|
constexpr const char *kLabelPropertyIndexStr = "label_property_index";
|
||||||
|
constexpr const char *kTextIndexStr = "label_property_index";
|
||||||
constexpr const char *kExistenceConstraintsStr = "existence_constraints";
|
constexpr const char *kExistenceConstraintsStr = "existence_constraints";
|
||||||
constexpr const char *kUniqueConstraintsStr = "unique_constraints";
|
constexpr const char *kUniqueConstraintsStr = "unique_constraints";
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -144,6 +145,29 @@ bool DurableMetadata::PersistLabelPropertyIndexAndExistenceConstraintDeletion(La
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DurableMetadata::PersistTextIndexCreation(std::string index_name) {
|
||||||
|
if (auto text_index_store = durability_kvstore_.Get(kTextIndexStr); text_index_store.has_value()) {
|
||||||
|
std::string &value = text_index_store.value();
|
||||||
|
value += "|";
|
||||||
|
value += index_name;
|
||||||
|
return durability_kvstore_.Put(kTextIndexStr, value);
|
||||||
|
}
|
||||||
|
return durability_kvstore_.Put(kTextIndexStr, index_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DurableMetadata::PersistTextIndexDeletion(std::string index_name) {
|
||||||
|
if (auto text_index_store = durability_kvstore_.Get(kTextIndexStr); text_index_store.has_value()) {
|
||||||
|
const std::string &value = text_index_store.value();
|
||||||
|
std::vector<std::string> text_indices = utils::Split(value, "|");
|
||||||
|
std::erase(text_indices, index_name);
|
||||||
|
if (text_indices.empty()) {
|
||||||
|
return durability_kvstore_.Delete(kTextIndexStr);
|
||||||
|
}
|
||||||
|
return durability_kvstore_.Put(kTextIndexStr, utils::Join(text_indices, "|"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool DurableMetadata::PersistUniqueConstraintCreation(LabelId label, const std::set<PropertyId> &properties) {
|
bool DurableMetadata::PersistUniqueConstraintCreation(LabelId label, const std::set<PropertyId> &properties) {
|
||||||
const std::string entry = utils::GetKeyForUniqueConstraintsDurability(label, properties);
|
const std::string entry = utils::GetKeyForUniqueConstraintsDurability(label, properties);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// 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
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -53,6 +53,10 @@ class DurableMetadata {
|
|||||||
bool PersistLabelPropertyIndexAndExistenceConstraintDeletion(LabelId label, PropertyId property,
|
bool PersistLabelPropertyIndexAndExistenceConstraintDeletion(LabelId label, PropertyId property,
|
||||||
const std::string &key);
|
const std::string &key);
|
||||||
|
|
||||||
|
bool PersistTextIndexCreation(std::string index_name);
|
||||||
|
|
||||||
|
bool PersistTextIndexDeletion(std::string index_name);
|
||||||
|
|
||||||
bool PersistUniqueConstraintCreation(LabelId label, const std::set<PropertyId> &properties);
|
bool PersistUniqueConstraintCreation(LabelId label, const std::set<PropertyId> &properties);
|
||||||
|
|
||||||
bool PersistUniqueConstraintDeletion(LabelId label, const std::set<PropertyId> &properties);
|
bool PersistUniqueConstraintDeletion(LabelId label, const std::set<PropertyId> &properties);
|
||||||
|
@ -1652,10 +1652,14 @@ utils::BasicResult<StorageManipulationError, void> DiskStorage::DiskAccessor::Co
|
|||||||
throw utils::NotYetImplemented("ClearIndexStats(stats) is not implemented for DiskStorage.");
|
throw utils::NotYetImplemented("ClearIndexStats(stats) is not implemented for DiskStorage.");
|
||||||
} break;
|
} break;
|
||||||
case MetadataDelta::Action::TEXT_INDEX_CREATE: {
|
case MetadataDelta::Action::TEXT_INDEX_CREATE: {
|
||||||
// TODO antepusic
|
if (!disk_storage->durable_metadata_.PersistTextIndexCreation(md_delta.text.index_name)) {
|
||||||
|
return StorageManipulationError{PersistenceError{}};
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case MetadataDelta::Action::TEXT_INDEX_DROP: {
|
case MetadataDelta::Action::TEXT_INDEX_DROP: {
|
||||||
// TODO antepusic
|
if (!disk_storage->durable_metadata_.PersistTextIndexDeletion(md_delta.text.index_name)) {
|
||||||
|
return StorageManipulationError{PersistenceError{}};
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case MetadataDelta::Action::EXISTENCE_CONSTRAINT_CREATE: {
|
case MetadataDelta::Action::EXISTENCE_CONSTRAINT_CREATE: {
|
||||||
const auto &info = md_delta.label_property;
|
const auto &info = md_delta.label_property;
|
||||||
@ -1905,8 +1909,6 @@ utils::BasicResult<StorageIndexDefinitionError, void> DiskStorage::DiskAccessor:
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO antepusic move text index creation here
|
|
||||||
|
|
||||||
utils::BasicResult<StorageIndexDefinitionError, void> DiskStorage::DiskAccessor::CreateIndex(LabelId label,
|
utils::BasicResult<StorageIndexDefinitionError, void> DiskStorage::DiskAccessor::CreateIndex(LabelId label,
|
||||||
PropertyId property) {
|
PropertyId property) {
|
||||||
MG_ASSERT(unique_guard_.owns_lock(), "Create index requires a unique access to the storage!");
|
MG_ASSERT(unique_guard_.owns_lock(), "Create index requires a unique access to the storage!");
|
||||||
@ -1951,8 +1953,6 @@ utils::BasicResult<StorageIndexDefinitionError, void> DiskStorage::DiskAccessor:
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO antepusic move text index deletion here
|
|
||||||
|
|
||||||
utils::BasicResult<StorageExistenceConstraintDefinitionError, void>
|
utils::BasicResult<StorageExistenceConstraintDefinitionError, void>
|
||||||
DiskStorage::DiskAccessor::CreateExistenceConstraint(LabelId label, PropertyId property) {
|
DiskStorage::DiskAccessor::CreateExistenceConstraint(LabelId label, PropertyId property) {
|
||||||
MG_ASSERT(unique_guard_.owns_lock(), "Create existence constraint requires a unique access to the storage!");
|
MG_ASSERT(unique_guard_.owns_lock(), "Create existence constraint requires a unique access to the storage!");
|
||||||
|
@ -1184,8 +1184,6 @@ utils::BasicResult<StorageIndexDefinitionError, void> InMemoryStorage::InMemoryA
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO antepusic move text index creation here
|
|
||||||
|
|
||||||
utils::BasicResult<StorageIndexDefinitionError, void> InMemoryStorage::InMemoryAccessor::DropIndex(LabelId label) {
|
utils::BasicResult<StorageIndexDefinitionError, void> InMemoryStorage::InMemoryAccessor::DropIndex(LabelId label) {
|
||||||
MG_ASSERT(unique_guard_.owns_lock(), "Dropping label index requires a unique access to the storage!");
|
MG_ASSERT(unique_guard_.owns_lock(), "Dropping label index requires a unique access to the storage!");
|
||||||
auto *in_memory = static_cast<InMemoryStorage *>(storage_);
|
auto *in_memory = static_cast<InMemoryStorage *>(storage_);
|
||||||
@ -1214,8 +1212,6 @@ utils::BasicResult<StorageIndexDefinitionError, void> InMemoryStorage::InMemoryA
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO antepusic move text index deletion here
|
|
||||||
|
|
||||||
utils::BasicResult<StorageExistenceConstraintDefinitionError, void>
|
utils::BasicResult<StorageExistenceConstraintDefinitionError, void>
|
||||||
InMemoryStorage::InMemoryAccessor::CreateExistenceConstraint(LabelId label, PropertyId property) {
|
InMemoryStorage::InMemoryAccessor::CreateExistenceConstraint(LabelId label, PropertyId property) {
|
||||||
MG_ASSERT(unique_guard_.owns_lock(), "Creating existence requires a unique access to the storage!");
|
MG_ASSERT(unique_guard_.owns_lock(), "Creating existence requires a unique access to the storage!");
|
||||||
|
@ -316,7 +316,6 @@ void ReplicaStream::AppendOperation(durability::StorageMetadataOperation operati
|
|||||||
const std::set<PropertyId> &properties, const LabelIndexStats &stats,
|
const std::set<PropertyId> &properties, const LabelIndexStats &stats,
|
||||||
const LabelPropertyIndexStats &property_stats, uint64_t timestamp) {
|
const LabelPropertyIndexStats &property_stats, uint64_t timestamp) {
|
||||||
replication::Encoder encoder(stream_.GetBuilder());
|
replication::Encoder encoder(stream_.GetBuilder());
|
||||||
// TODO antepusic
|
|
||||||
EncodeOperation(&encoder, storage_->name_id_mapper_.get(), operation, label, properties, stats, property_stats,
|
EncodeOperation(&encoder, storage_->name_id_mapper_.get(), operation, label, properties, stats, property_stats,
|
||||||
timestamp);
|
timestamp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user