From 6865616cae4b1d0e18becbef8a145fb83a2ec928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Pu=C5=A1i=C4=87?= Date: Fri, 5 Jan 2024 02:14:14 +0100 Subject: [PATCH] Make proof of concept for external storage --- src/storage/v2/property_store.cpp | 24 ++++++++++++++++-------- src/storage/v2/property_store.hpp | 17 ++++++++++------- src/storage/v2/vertex_accessor.cpp | 8 +++++++- src/utils/memcxx.hpp | 1 - 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/storage/v2/property_store.cpp b/src/storage/v2/property_store.cpp index 26cc74dc2..e0196892c 100644 --- a/src/storage/v2/property_store.cpp +++ b/src/storage/v2/property_store.cpp @@ -24,6 +24,7 @@ #include "storage/v2/temporal.hpp" #include "utils/cast.hpp" #include "utils/logging.hpp" +#include "utils/memcxx.hpp" namespace memgraph::storage { @@ -1133,7 +1134,8 @@ std::map PropertyStore::Properties() const { } /// 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 PropertyStore::SetProperty(PropertyId property, const PropertyValue &value, bool external, + std::optional gid) { // if (external) { // // TODO @antepusic: assignment pending delete() in the mgcxx API @@ -1274,7 +1276,11 @@ bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value) } template -bool PropertyStore::DoInitProperties(const TContainer &properties) { +bool PropertyStore::DoInitProperties(const TContainer &properties, bool external, std::optional gid) { + if (external) { + // memcxx_mock::text_search::Mock::add() + } + uint64_t size = 0; uint8_t *data = nullptr; std::tie(size, data) = GetSizeData(buffer_); @@ -1333,7 +1339,7 @@ bool PropertyStore::DoInitProperties(const TContainer &properties) { } std::vector> PropertyStore::UpdateProperties( - std::map &properties) { + std::map &properties, bool external, std::optional gid) { auto old_properties = Properties(); ClearProperties(); @@ -1362,17 +1368,19 @@ template bool PropertyStore::DoInitProperties>>( const std::vector> &); -bool PropertyStore::InitProperties(const std::map &properties) { - return DoInitProperties(properties); +bool PropertyStore::InitProperties(const std::map &properties, + bool external, std::optional gid) { + return DoInitProperties(properties, external, node_id); } -bool PropertyStore::InitProperties(std::vector> properties) { +bool PropertyStore::InitProperties(std::vector> properties, + bool external, std::optional gid) { std::sort(properties.begin(), properties.end()); - return DoInitProperties(properties); + return DoInitProperties(properties, external, node_id); } -bool PropertyStore::ClearProperties() { +bool PropertyStore::ClearProperties(bool external, std::optional gid) { bool in_local_buffer = false; uint64_t size; uint8_t *data; diff --git a/src/storage/v2/property_store.hpp b/src/storage/v2/property_store.hpp index ba6f9423b..85a122f7c 100644 --- a/src/storage/v2/property_store.hpp +++ b/src/storage/v2/property_store.hpp @@ -78,8 +78,8 @@ class PropertyStore { /// returned if assignment took place. The time complexity of this function is /// O(n). /// @throw std::bad_alloc - /// NOTE: The external_store_mock argument will be removed after replacing the mock with the mgcxx Tantivy API - bool SetProperty(PropertyId property, const PropertyValue &value); + bool SetProperty(PropertyId property, const PropertyValue &value, bool external = false, + std::optional gid = std::nullopt); // , const bool external = false, // SearchableExternalStoreMock *external_store_mock = nullptr); @@ -87,13 +87,15 @@ class PropertyStore { /// 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). /// @throw std::bad_alloc - bool InitProperties(const std::map &properties); + bool InitProperties(const std::map &properties, bool external = false, + std::optional gid = std::nullopt); /// 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 /// complexity of this function is O(n*log(n)): /// @throw std::bad_alloc - bool InitProperties(std::vector> properties); + bool InitProperties(std::vector> properties, + bool external = false, std::optional gid = std::nullopt); /// 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 @@ -101,13 +103,14 @@ class PropertyStore { /// The time complexity of this function is O(n*log(n)): /// @throw std::bad_alloc std::vector> UpdateProperties( - std::map &properties); + std::map &properties, bool external = false, + std::optional gid = std::nullopt); /// Remove all properties and return `true` if any removal took place. /// `false` is returned if there were no properties to remove. The time /// complexity of this function is O(1). /// @throw std::bad_alloc - bool ClearProperties(); + bool ClearProperties(bool external = false, std::optional gid = std::nullopt); /// Return property buffer as a string std::string StringBuffer() const; @@ -117,7 +120,7 @@ class PropertyStore { private: template - bool DoInitProperties(const TContainer &properties); + bool DoInitProperties(const TContainer &properties, bool external = false, std::optional gid = std::nullopt); uint8_t buffer_[sizeof(uint64_t) + sizeof(uint8_t *)]; }; diff --git a/src/storage/v2/vertex_accessor.cpp b/src/storage/v2/vertex_accessor.cpp index a7ac3e528..fdf774e75 100644 --- a/src/storage/v2/vertex_accessor.cpp +++ b/src/storage/v2/vertex_accessor.cpp @@ -301,7 +301,13 @@ Result VertexAccessor::InitProperties(const std::mapproperties.InitProperties(properties)) { + if (std::ranges::any_of(vertex->labels, + [storage](auto &label) { return storage->indices_.text_index_->IndexExists(label); })) { + if (!vertex->properties.InitProperties(properties, true, vertex->gid)) { + result = false; + return; + } + } else if (!vertex->properties.InitProperties(properties)) { result = false; return; } diff --git a/src/utils/memcxx.hpp b/src/utils/memcxx.hpp index eeb74b3a7..e7e5b8ee5 100644 --- a/src/utils/memcxx.hpp +++ b/src/utils/memcxx.hpp @@ -9,7 +9,6 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -#include #include #ifndef MEMCXX