Fix text index metadata in disk storage

This commit is contained in:
Ante Pušić 2024-02-18 16:15:43 +01:00
parent c40bf89f63
commit e1e025f0ed
3 changed files with 13 additions and 9 deletions

View File

@ -145,21 +145,23 @@ bool DurableMetadata::PersistLabelPropertyIndexAndExistenceConstraintDeletion(La
return true; return true;
} }
bool DurableMetadata::PersistTextIndexCreation(const std::string &index_name) { bool DurableMetadata::PersistTextIndexCreation(const std::string &index_name, LabelId label) {
const std::string index_name_label_pair = index_name + "," + label.ToString();
if (auto text_index_store = durability_kvstore_.Get(kTextIndexStr); text_index_store.has_value()) { if (auto text_index_store = durability_kvstore_.Get(kTextIndexStr); text_index_store.has_value()) {
std::string &value = text_index_store.value(); std::string &value = text_index_store.value();
value += "|"; value += "|";
value += index_name; value += index_name_label_pair;
return durability_kvstore_.Put(kTextIndexStr, value); return durability_kvstore_.Put(kTextIndexStr, value);
} }
return durability_kvstore_.Put(kTextIndexStr, index_name); return durability_kvstore_.Put(kTextIndexStr, index_name_label_pair);
} }
bool DurableMetadata::PersistTextIndexDeletion(const std::string &index_name) { bool DurableMetadata::PersistTextIndexDeletion(const std::string &index_name, LabelId label) {
const std::string index_name_label_pair = index_name + "," + label.ToString();
if (auto text_index_store = durability_kvstore_.Get(kTextIndexStr); text_index_store.has_value()) { if (auto text_index_store = durability_kvstore_.Get(kTextIndexStr); text_index_store.has_value()) {
const std::string &value = text_index_store.value(); const std::string &value = text_index_store.value();
std::vector<std::string> text_indices = utils::Split(value, "|"); std::vector<std::string> text_indices = utils::Split(value, "|");
std::erase(text_indices, index_name); std::erase(text_indices, index_name_label_pair);
if (text_indices.empty()) { if (text_indices.empty()) {
return durability_kvstore_.Delete(kTextIndexStr); return durability_kvstore_.Delete(kTextIndexStr);
} }

View File

@ -53,9 +53,9 @@ class DurableMetadata {
bool PersistLabelPropertyIndexAndExistenceConstraintDeletion(LabelId label, PropertyId property, bool PersistLabelPropertyIndexAndExistenceConstraintDeletion(LabelId label, PropertyId property,
const std::string &key); const std::string &key);
bool PersistTextIndexCreation(const std::string &index_name); bool PersistTextIndexCreation(const std::string &index_name, LabelId label);
bool PersistTextIndexDeletion(const std::string &index_name); bool PersistTextIndexDeletion(const std::string &index_name, LabelId label);
bool PersistUniqueConstraintCreation(LabelId label, const std::set<PropertyId> &properties); bool PersistUniqueConstraintCreation(LabelId label, const std::set<PropertyId> &properties);

View File

@ -1657,12 +1657,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: {
if (!disk_storage->durable_metadata_.PersistTextIndexCreation(md_delta.text_indices.index_name)) { const auto &info = md_delta.text_index;
if (!disk_storage->durable_metadata_.PersistTextIndexCreation(info.index_name, info.label)) {
return StorageManipulationError{PersistenceError{}}; return StorageManipulationError{PersistenceError{}};
} }
} break; } break;
case MetadataDelta::Action::TEXT_INDEX_DROP: { case MetadataDelta::Action::TEXT_INDEX_DROP: {
if (!disk_storage->durable_metadata_.PersistTextIndexDeletion(md_delta.text_indices.index_name)) { const auto &info = md_delta.text_index;
if (!disk_storage->durable_metadata_.PersistTextIndexDeletion(info.index_name, info.label)) {
return StorageManipulationError{PersistenceError{}}; return StorageManipulationError{PersistenceError{}};
} }
} break; } break;