Move text index data CRUD to VertexAccessor

This commit is contained in:
Ante Pušić 2024-01-09 21:09:38 +01:00
parent 5fb9324239
commit 3595a9c3b5
3 changed files with 36 additions and 69 deletions

View File

@ -1134,25 +1134,7 @@ std::map<PropertyId, PropertyValue> PropertyStore::Properties() const {
} }
/// NOTE: The external_store_mock argument will be removed after replacing the mock with the mgcxx Tantivy API /// NOTE: The external_store_mock argument will be removed after replacing the mock with the mgcxx Tantivy API
bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value, bool external, bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value) {
std::optional<Gid> gid) {
// if (external) {
// // TODO @antepusic: assignment pending delete() in the mgcxx API
// int DUMMY_GRAPH_ELEMENT_ID = 1;
// nlohmann::json document;
// nlohmann::json property_map;
// if (!value.IsNull()) {
// property_map[property.ToString()] = value.ValueInt();
// }
// document["id"] = DUMMY_GRAPH_ELEMENT_ID;
// document["properties"] = property_map;
// external_store_mock->AddDocument(DUMMY_GRAPH_ELEMENT_ID, document);
// return true;
// }
uint64_t property_size = 0; uint64_t property_size = 0;
if (!value.IsNull()) { if (!value.IsNull()) {
Writer writer; Writer writer;
@ -1276,11 +1258,7 @@ bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value,
} }
template <typename TContainer> template <typename TContainer>
bool PropertyStore::DoInitProperties(const TContainer &properties, bool external, std::optional<Gid> gid) { bool PropertyStore::DoInitProperties(const TContainer &properties) {
if (external) {
// mgcxx_mock::text_search::Mock::add()
}
uint64_t size = 0; uint64_t size = 0;
uint8_t *data = nullptr; uint8_t *data = nullptr;
std::tie(size, data) = GetSizeData(buffer_); std::tie(size, data) = GetSizeData(buffer_);
@ -1339,7 +1317,7 @@ bool PropertyStore::DoInitProperties(const TContainer &properties, bool external
} }
std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>> PropertyStore::UpdateProperties( std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>> PropertyStore::UpdateProperties(
std::map<PropertyId, PropertyValue> &properties, bool external, std::optional<Gid> gid) { std::map<PropertyId, PropertyValue> &properties) {
auto old_properties = Properties(); auto old_properties = Properties();
ClearProperties(); ClearProperties();
@ -1364,24 +1342,21 @@ std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>> PropertyStore:
} }
template bool PropertyStore::DoInitProperties<std::map<PropertyId, PropertyValue>>( template bool PropertyStore::DoInitProperties<std::map<PropertyId, PropertyValue>>(
const std::map<PropertyId, PropertyValue> &, bool external = false, std::optional<Gid> gid = std::nullopt); const std::map<PropertyId, PropertyValue> &);
template bool PropertyStore::DoInitProperties<std::vector<std::pair<PropertyId, PropertyValue>>>( template bool PropertyStore::DoInitProperties<std::vector<std::pair<PropertyId, PropertyValue>>>(
const std::vector<std::pair<PropertyId, PropertyValue>> &, bool external = false, const std::vector<std::pair<PropertyId, PropertyValue>> &);
std::optional<Gid> gid = std::nullopt);
bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties, bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties) {
bool external, std::optional<Gid> gid) { return DoInitProperties(properties);
return DoInitProperties(properties, external, gid);
} }
bool PropertyStore::InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> properties, bool PropertyStore::InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> properties) {
bool external, std::optional<Gid> gid) {
std::sort(properties.begin(), properties.end()); std::sort(properties.begin(), properties.end());
return DoInitProperties(properties, external, gid); return DoInitProperties(properties);
} }
bool PropertyStore::ClearProperties(bool external, std::optional<Gid> gid) { bool PropertyStore::ClearProperties() {
bool in_local_buffer = false; bool in_local_buffer = false;
uint64_t size; uint64_t size;
uint8_t *data; uint8_t *data;

View File

@ -78,24 +78,19 @@ class PropertyStore {
/// returned if assignment took place. The time complexity of this function is /// returned if assignment took place. The time complexity of this function is
/// O(n). /// O(n).
/// @throw std::bad_alloc /// @throw std::bad_alloc
bool SetProperty(PropertyId property, const PropertyValue &value, bool external = false, bool SetProperty(PropertyId property, const PropertyValue &value);
std::optional<Gid> gid = std::nullopt);
// , const bool external = false,
// SearchableExternalStoreMock *external_store_mock = nullptr);
/// Init property values and return `true` if insertion took place. `false` is /// Init property values and return `true` if insertion took place. `false` is
/// returned if there is any existing property in property store and insertion couldn't take place. The time /// returned if there is any existing property in property store and insertion couldn't take place. The time
/// complexity of this function is O(n). /// complexity of this function is O(n).
/// @throw std::bad_alloc /// @throw std::bad_alloc
bool InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties, bool external = false, bool InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties);
std::optional<Gid> gid = std::nullopt);
/// Init property values and return `true` if insertion took place. `false` is /// Init property values and return `true` if insertion took place. `false` is
/// returned if there is any existing property in property store and insertion couldn't take place. The time /// returned if there is any existing property in property store and insertion couldn't take place. The time
/// complexity of this function is O(n*log(n)): /// complexity of this function is O(n*log(n)):
/// @throw std::bad_alloc /// @throw std::bad_alloc
bool InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> properties, bool InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> properties);
bool external = false, std::optional<Gid> gid = std::nullopt);
/// Update property values in property store with sent properties. Returns vector of changed /// Update property values in property store with sent properties. Returns vector of changed
/// properties. Each tuple inside vector consists of PropertyId of inserted property, together with old /// properties. Each tuple inside vector consists of PropertyId of inserted property, together with old
@ -103,14 +98,13 @@ class PropertyStore {
/// The time complexity of this function is O(n*log(n)): /// The time complexity of this function is O(n*log(n)):
/// @throw std::bad_alloc /// @throw std::bad_alloc
std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>> UpdateProperties( std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>> UpdateProperties(
std::map<storage::PropertyId, storage::PropertyValue> &properties, bool external = false, std::map<storage::PropertyId, storage::PropertyValue> &properties);
std::optional<Gid> gid = std::nullopt);
/// Remove all properties and return `true` if any removal took place. /// Remove all properties and return `true` if any removal took place.
/// `false` is returned if there were no properties to remove. The time /// `false` is returned if there were no properties to remove. The time
/// complexity of this function is O(1). /// complexity of this function is O(1).
/// @throw std::bad_alloc /// @throw std::bad_alloc
bool ClearProperties(bool external = false, std::optional<Gid> gid = std::nullopt); bool ClearProperties();
/// Return property buffer as a string /// Return property buffer as a string
std::string StringBuffer() const; std::string StringBuffer() const;
@ -120,7 +114,7 @@ class PropertyStore {
private: private:
template <typename TContainer> template <typename TContainer>
bool DoInitProperties(const TContainer &properties, bool external = false, std::optional<Gid> gid = std::nullopt); bool DoInitProperties(const TContainer &properties);
uint8_t buffer_[sizeof(uint64_t) + sizeof(uint8_t *)]; uint8_t buffer_[sizeof(uint64_t) + sizeof(uint8_t *)];
}; };

View File

@ -274,31 +274,29 @@ Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const Pro
utils::AtomicMemoryBlock atomic_memory_block{ utils::AtomicMemoryBlock atomic_memory_block{
[transaction = transaction_, storage = storage_, vertex = vertex_, &value, &property, &current_value]() { [transaction = transaction_, storage = storage_, vertex = vertex_, &value, &property, &current_value]() {
CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), property, current_value); CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), property, current_value);
// // Option 1 (current) if (flags::run_time::GetTextSearchEnabled()) {
// if (std::ranges::any_of(vertex->labels, // if (!storage->indices_.text_index_->IndexExists(storage->NameToLabel(name))) continue;
// [storage](auto &label) { return storage->indices_.text_index_->IndexExists(label); // TODO antepusic: check which text indices apply
// })) { // for (const auto index : GetApplicableTextIndices(vertex)) {
// vertex->properties.SetProperty(property, value, true, vertex->gid); //
// } else {
// vertex->properties.SetProperty(property, value);
// } // }
for (auto label : vertex->labels) {
auto &context = storage->indices_.text_index_->index_.at("myIndex");
// // Option 2 (proposed) // Calling the text search tool is done here and not inside a PropertyStore method
// if (flags::run_time::GetTextSearchEnabled()) { // make SearchInput
// for (auto label : vertex->labels) {
// if (!storage->indices_.text_index_->IndexExists(label)) continue;
// auto &context = storage->indices_.text_index_->index_.at(label); auto search_input = mgcxx_mock::text_search::SearchInput{};
// // Calling the text search tool is done here and not inside a PropertyStore method auto search_result = mgcxx_mock::text_search::Mock::search(context, search_input);
// // make SearchInput mgcxx_mock::text_search::Mock::delete_document(context, search_input, true);
// auto search_result = mgcxx_mock::text_search::Mock::search(context, search_this_node_document); // parse result to JSON, set property in JSON and convert to string
// mgcxx_mock::text_search::Mock::delete_document(context, search_this_node_document); auto new_properties = search_result.docs[0].data;
// // parse result to JSON, set property in JSON and convert to string auto new_properties_document = mgcxx_mock::text_search::DocumentInput{.data = new_properties};
// mgcxx_mock::text_search::Mock::add(context, DocumentInput{result_with_property_set.asString()}); mgcxx_mock::text_search::Mock::add(context, new_properties_document, true);
// } }
// } }
// vertex->properties.SetProperty(property, value); vertex->properties.SetProperty(property, value);
}}; }};
std::invoke(atomic_memory_block); std::invoke(atomic_memory_block);