Make proof of concept for external storage

This commit is contained in:
Ante Pušić 2024-01-05 02:14:14 +01:00
parent f0a2b67f33
commit 6865616cae
4 changed files with 33 additions and 17 deletions

View File

@ -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<PropertyId, PropertyValue> 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> 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 <typename TContainer>
bool PropertyStore::DoInitProperties(const TContainer &properties) {
bool PropertyStore::DoInitProperties(const TContainer &properties, bool external, std::optional<Gid> 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<std::tuple<PropertyId, PropertyValue, PropertyValue>> PropertyStore::UpdateProperties(
std::map<PropertyId, PropertyValue> &properties) {
std::map<PropertyId, PropertyValue> &properties, bool external, std::optional<Gid> gid) {
auto old_properties = Properties();
ClearProperties();
@ -1362,17 +1368,19 @@ template bool PropertyStore::DoInitProperties<std::map<PropertyId, PropertyValue
template bool PropertyStore::DoInitProperties<std::vector<std::pair<PropertyId, PropertyValue>>>(
const std::vector<std::pair<PropertyId, PropertyValue>> &);
bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties) {
return DoInitProperties(properties);
bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties,
bool external, std::optional<Gid> gid) {
return DoInitProperties(properties, external, node_id);
}
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());
return DoInitProperties(properties);
return DoInitProperties(properties, external, node_id);
}
bool PropertyStore::ClearProperties() {
bool PropertyStore::ClearProperties(bool external, std::optional<Gid> gid) {
bool in_local_buffer = false;
uint64_t size;
uint8_t *data;

View File

@ -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> 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<storage::PropertyId, storage::PropertyValue> &properties);
bool InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties, bool external = false,
std::optional<Gid> 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<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
/// 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<std::tuple<PropertyId, PropertyValue, PropertyValue>> UpdateProperties(
std::map<storage::PropertyId, storage::PropertyValue> &properties);
std::map<storage::PropertyId, storage::PropertyValue> &properties, bool external = false,
std::optional<Gid> 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> gid = std::nullopt);
/// Return property buffer as a string
std::string StringBuffer() const;
@ -117,7 +120,7 @@ class PropertyStore {
private:
template <typename TContainer>
bool DoInitProperties(const TContainer &properties);
bool DoInitProperties(const TContainer &properties, bool external = false, std::optional<Gid> gid = std::nullopt);
uint8_t buffer_[sizeof(uint64_t) + sizeof(uint8_t *)];
};

View File

@ -301,7 +301,13 @@ Result<bool> VertexAccessor::InitProperties(const std::map<storage::PropertyId,
bool result{false};
utils::AtomicMemoryBlock atomic_memory_block{
[&result, &properties, storage = storage_, transaction = transaction_, vertex = vertex_]() {
if (!vertex->properties.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;
}

View File

@ -9,7 +9,6 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
#include <json/json.hpp>
#include <string>
#ifndef MEMCXX