Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
aa3e137
Add custom once cursor
gitbuda Mar 9, 2024
96c6d65
Add produce and dummy custom_storage
gitbuda Mar 10, 2024
664b8d0
Move custom_storage to memgraph.cpp
gitbuda Mar 10, 2024
b8be5e0
Add graphar, not working yet
gitbuda Mar 10, 2024
e16b202
Fix the basic code in the manual test
gitbuda Mar 10, 2024
75cac2d
Add meaningful code for storing vertices
gitbuda Mar 11, 2024
8256a20
Add edge storage example
gitbuda Mar 11, 2024
ed6fe4b
Add storage high-level ideas, part 1
gitbuda Mar 12, 2024
308bb0d
Add prep for CreateNodeCursor implementation
gitbuda Mar 13, 2024
157c012
Add custom vertex
gitbuda Mar 17, 2024
5f0bbc0
Upgrade graphar and merge latest memgraph upstream
gitbuda Apr 1, 2024
44d5f23
Merge branch 'master' into alternative-storage
gitbuda Apr 2, 2024
cdd841f
Sort the graphar schema a bit
gitbuda Apr 2, 2024
5ea313a
Put config under custom storage
gitbuda Apr 2, 2024
b2a3fee
Merge branch 'master' into alternative-storage
gitbuda Apr 4, 2024
9c87180
Merge master and update clang tidy
gitbuda Apr 4, 2024
f79e131
Wire GARDatabase and custom storage part 1
gitbuda Apr 8, 2024
6553de1
Merge master
gitbuda Apr 23, 2024
5a0da20
Merge master
gitbuda Apr 23, 2024
ebce4fa
Switch to the incubator URL
gitbuda Apr 23, 2024
5bff383
Add more comments
gitbuda Apr 26, 2024
baef016
Merge master
gitbuda May 3, 2024
eb905f4
Patch GraphAR because it doesn't compile under the latest toolchain
gitbuda May 3, 2024
f9c9a1f
Merge branch 'master' into alternative-storage
gitbuda May 19, 2024
cf8a691
Merge branch 'master' into alternative-storage
gitbuda May 31, 2024
1ac84d1
Merge master and a few new comments
gitbuda May 31, 2024
4780d1a
Upgrade to GraphAr v0.12
gitbuda Sep 1, 2024
30d027f
Merge master
gitbuda Sep 7, 2024
10bf29d
Add example GAR graph metadata and reading
gitbuda Sep 14, 2024
ab7e434
Play with the PMR (WIP)
gitbuda Sep 22, 2024
3e8fb3d
Add a bit more complex PMR example
gitbuda Sep 22, 2024
574c70f
Change Vertex and Edge types
gitbuda Sep 22, 2024
aac9b79
Add print_alloc memory resource + create_container func
gitbuda Oct 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ mark_as_advanced(MGCXX_INCLUDE_DIR TANTIVY_TEXT_SEARCH_LIBRARY MGCXX_TEXT_SEARCH
import_library(tantivy_text_search STATIC ${TANTIVY_TEXT_SEARCH_LIBRARY} ${MGCXX_INCLUDE_DIR} mgcxx-proj)
import_library(mgcxx_text_search STATIC ${MGCXX_TEXT_SEARCH_LIBRARY} ${MGCXX_INCLUDE_DIR} mgcxx-proj)


# setup strong_type (cmake sub_directory tolerant)
add_subdirectory(strong_type EXCLUDE_FROM_ALL)

# Setup GraphAr
import_external_library(graphar SHARED
${CMAKE_CURRENT_SOURCE_DIR}/graphar/cpp/lib/libgraphar.so
${CMAKE_CURRENT_SOURCE_DIR}/graphar/cpp/include
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/graphar/cpp)
6 changes: 6 additions & 0 deletions libs/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ declare -A primary_urls=(
["nuraft"]="http://$local_cache_host/git/NuRaft.git"
["asio"]="http://$local_cache_host/git/asio.git"
["mgcxx"]="http://$local_cache_host/git/mgcxx.git"
["graphar"]="http://$local_cache_host/git/GraphAr.git"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to apache incubator link

["strong_type"]="http://$local_cache_host/git/strong_type.git"
)

Expand Down Expand Up @@ -191,6 +192,7 @@ declare -A secondary_urls=(
["asio"]="https://github.com/chriskohlhoff/asio.git"
["mgcxx"]="https://github.com/memgraph/mgcxx.git"
["strong_type"]="https://github.com/rollbear/strong_type.git"
["graphar"]="https://github.com/apache/incubator-graphar.git"
)

# antlr
Expand Down Expand Up @@ -337,3 +339,7 @@ repo_clone_try_double "${primary_urls[mgcxx]}" "${secondary_urls[mgcxx]}" "mgcxx
# strong_type v14
strong_type_ref="v14"
repo_clone_try_double "${primary_urls[strong_type]}" "${secondary_urls[strong_type]}" "strong_type" "$strong_type_ref"

# GraphAr 2024-07-02
graphar_tag="v0.12.0"
repo_clone_try_double "${primary_urls[graphar]}" "${secondary_urls[graphar]}" "graphar" "$graphar_tag" true
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_subdirectory(kvstore)
add_subdirectory(telemetry)
add_subdirectory(communication)
add_subdirectory(memory)
add_subdirectory(storage/v2)
add_subdirectory(storage)
add_subdirectory(integrations)
add_subdirectory(query)
add_subdirectory(glue)
Expand Down
1 change: 1 addition & 0 deletions src/flags/experimental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ auto const canonicalize_string = [](auto &&rng) {
namespace memgraph::flags {

auto const mapping = std::map{std::pair{"text-search"sv, Experiments::TEXT_SEARCH},
std::pair{"alternative-storage"sv, Experiments::ALTERNATIVE_STORAGE},
std::pair{"high-availability"sv, Experiments::HIGH_AVAILABILITY}};

auto ExperimentsInstance() -> Experiments & {
Expand Down
1 change: 1 addition & 0 deletions src/flags/experimental.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace memgraph::flags {
enum class Experiments : uint8_t {
TEXT_SEARCH = 1 << 0,
HIGH_AVAILABILITY = 1 << 1,
ALTERNATIVE_STORAGE = 1 << 2,
};

bool AreExperimentsEnabled(Experiments experiments);
Expand Down
3 changes: 3 additions & 0 deletions src/memgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ int main(int argc, char **argv) {
*auth_, FLAGS_data_recovery_on_startup
#endif
);
auto custom_storage = std::make_unique<memgraph::storage::custom_storage::Storage>();

// Note: Now that all system's subsystems are initialised (dbms & auth)
// We can now initialise the recovery of replication (which will include those subsystems)
Expand Down Expand Up @@ -590,6 +591,8 @@ int main(int argc, char **argv) {

auto &interpreter_context_ = memgraph::query::InterpreterContextHolder::GetInstance();
MG_ASSERT(db_acc, "Failed to access the main database");
// TODO(gitbuda): Init moved here because tests are constructing the interpreter context.
interpreter_context_.custom_storage = custom_storage.get();

memgraph::query::procedure::gModuleRegistry.SetModulesDirectory(memgraph::flags::ParseQueryModulesDirectory(),
FLAGS_data_directory);
Expand Down
2 changes: 2 additions & 0 deletions src/query/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ target_sources(mg-query
string_helpers.hpp
)

add_subdirectory(custom_cursors)

target_link_libraries(mg-query
PUBLIC
Expand All @@ -96,6 +97,7 @@ target_link_libraries(mg-query
mg::system
mg-flags
mg-dbms
mg_custom_cursors
mg-events
PRIVATE
mg-module-support
Expand Down
2 changes: 2 additions & 0 deletions src/query/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "query/trigger.hpp"
#include "utils/async_timer.hpp"

#include "storage/custom_storage/storage.hpp"
#include "query/frame_change.hpp"
#include "query/hops_limit.hpp"

Expand Down Expand Up @@ -79,6 +80,7 @@ inline std::vector<storage::LabelId> NamesToLabels(const std::vector<std::string
}

struct ExecutionContext {
memgraph::storage::custom_storage::Storage *custom_storage{nullptr};
DbAccessor *db_accessor{nullptr};
SymbolTable symbol_table;
EvaluationContext evaluation_context;
Expand Down
9 changes: 9 additions & 0 deletions src/query/custom_cursors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(mg_custom_cursors_sources
create_node.cpp
once.cpp
scanall.cpp
produce.cpp
)
add_library(mg_custom_cursors STATIC ${mg_custom_cursors_sources})
# TODO(gitbuda): Having mg-storage-v2 here is broken.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken because
Screenshot 2024-03-09 at 10 18 41 AM

target_link_libraries(mg_custom_cursors mg-utils mg-storage-v2 mg_custom_storage mg-query)
17 changes: 17 additions & 0 deletions src/query/custom_cursors/all.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024 Memgraph Ltd.
//
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

#pragma once

#include "query/custom_cursors/create_node.hpp"
#include "query/custom_cursors/once.hpp"
#include "query/custom_cursors/produce.hpp"
#include "query/custom_cursors/scanall.hpp"
14 changes: 14 additions & 0 deletions src/query/custom_cursors/bfs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2024 Memgraph Ltd.
//
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

#pragma once

// TODO(gitbuda): To make BFS fast -> global cache required.
15 changes: 15 additions & 0 deletions src/query/custom_cursors/create_edge.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2024 Memgraph Ltd.
//
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

#pragma once

// TODO(gitbuda): To make this Cypher CREATE edge fast -> add global cache.
// TODO(gitbuda): To make create edge fast -> introduce a new semantic.
83 changes: 83 additions & 0 deletions src/query/custom_cursors/create_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2024 Memgraph Ltd.
//
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

#include "query/custom_cursors/create_node.hpp"
#include "query/context.hpp"
#include "query/custom_cursors/utils.hpp"
#include "query/interpret/eval.hpp"
#include "query/interpret/frame.hpp"
#include "query/plan/operator.hpp"
#include "query/plan/scoped_profile.hpp"
#include "storage/custom_storage/types.hpp"
#include "utils/logging.hpp"

namespace memgraph::query::custom_cursors {

struct QueryVertex {};

// Creates a vertex on this GraphDb. Returns a reference to vertex placed on the
// frame.
QueryVertex CreateVertex(const plan::NodeCreationInfo &node_info, Frame *frame, ExecutionContext &context) {
auto &dba = *context.db_accessor;
if (node_info.labels.size() != 1) {
throw QueryRuntimeException(
"0 or multiple labels not yet supported under CreateNode. You have to provide exactly 1 lable for any given "
"vertex/node.");
}
// NOTE: Evaluator should use the latest accessors, as modified in this query, when
// setting properties on new nodes.
// NOTE: Evaluator is using query::DBAccessor of default storage mode (IN_MEM_TX), for props mapping & storage mode.
ExpressionEvaluator evaluator(frame, context.symbol_table, context.evaluation_context, context.db_accessor,
storage::View::NEW);
// TODO: PropsSetChecked allocates a PropertyValue, make it use context.memory
// when we update PropertyValue with custom allocator.
std::map<storage::PropertyId, storage::PropertyValue> properties;
if (const auto *node_info_properties = std::get_if<plan::PropertiesMapList>(&node_info.properties)) {
for (const auto &[key, value_expression] : *node_info_properties) {
properties.emplace(key, value_expression->Accept(evaluator));
}
} else {
auto property_map = evaluator.Visit(*std::get<ParameterLookup *>(node_info.properties));
for (const auto &[key, value] : property_map.ValueMap()) {
properties.emplace(dba.NameToProperty(key), value);
}
}
// TODO(gitbuda): Put vertex on the frame. (*frame)[node_info.symbol] = new_node;
// (*frame)[node_info.symbol] = new_node;
// return (*frame)[node_info.symbol].ValueVertex();

// TODO(gitbuda): node_info.labels change type -> add the transformation.
// auto new_node = memgraph::storage::custom_storage::Vertex{.labels = node_info.labels, .properties = properties};
auto new_node = memgraph::storage::custom_storage::Vertex{.labels = {}, .properties = properties};
auto *vertex_ptr = context.custom_storage->AddVertex(std::move(new_node));
SPDLOG_WARN("{}", context.custom_storage->VerticesNo());
return QueryVertex{};
}

CreateNodeCursor::CreateNodeCursor(const plan::CreateNode &logical_operator, plan::UniqueCursorPtr input_cursor)
: logical_operator_(logical_operator), input_cursor_(std::move(input_cursor)) {}

bool CreateNodeCursor::Pull(Frame &frame, ExecutionContext &context) {
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
memgraph::query::plan::ScopedProfile profile{ComputeProfilingKey(this), "CreateNode", &context};
SPDLOG_WARN("CreateNodeCursor::Pull");
if (input_cursor_->Pull(frame, context)) {
CreateVertex(logical_operator_.node_info_, &frame, context);
return true;
}
return false;
}

void CreateNodeCursor::Shutdown() { input_cursor_->Shutdown(); }

void CreateNodeCursor::Reset() { input_cursor_->Reset(); }

} // namespace memgraph::query::custom_cursors
39 changes: 39 additions & 0 deletions src/query/custom_cursors/create_node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 Memgraph Ltd.
//
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

#pragma once

#include "query/plan/cursor.hpp"

// TASKS:
// 1. check label creation access rule
// 2. create vertex
// 3. inform the trigger

namespace memgraph::query::plan {
class CreateNode;
} // namespace memgraph::query::plan

namespace memgraph::query::custom_cursors {

class CreateNodeCursor : public memgraph::query::plan::Cursor {
public:
explicit CreateNodeCursor(const plan::CreateNode &logical_operator, plan::UniqueCursorPtr input_cursor);
bool Pull(Frame &frame, ExecutionContext &context) override;
void Shutdown() override;
void Reset() override;

private:
const plan::CreateNode &logical_operator_;
const plan::UniqueCursorPtr input_cursor_;
};

} // namespace memgraph::query::custom_cursors
36 changes: 36 additions & 0 deletions src/query/custom_cursors/once.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2024 Memgraph Ltd.
//
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

#include "query/custom_cursors/once.hpp"
#include "query/context.hpp"
#include "query/custom_cursors/utils.hpp"
#include "query/interpret/frame.hpp"
#include "query/plan/scoped_profile.hpp"
#include "utils/logging.hpp"

namespace memgraph::query::custom_cursors {

bool OnceCursor::Pull(Frame & /*unused*/, ExecutionContext &context) {
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
memgraph::query::plan::ScopedProfile profile{ComputeProfilingKey(this), "Once", &context};
SPDLOG_WARN("OnceCursor::Pull");
if (!did_pull_) {
did_pull_ = true;
return true;
}
return false;
}

void OnceCursor::Shutdown() {}

void OnceCursor::Reset() { did_pull_ = false; }

} // namespace memgraph::query::custom_cursors
29 changes: 29 additions & 0 deletions src/query/custom_cursors/once.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 Memgraph Ltd.
//
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

#pragma once

#include "query/plan/cursor.hpp"

namespace memgraph::query::custom_cursors {

class OnceCursor : public memgraph::query::plan::Cursor {
public:
OnceCursor() = default;
bool Pull(Frame & /*unused*/, ExecutionContext &context) override;
void Shutdown() override;
void Reset() override;

private:
bool did_pull_{false};
};

} // namespace memgraph::query::custom_cursors
34 changes: 34 additions & 0 deletions src/query/custom_cursors/produce.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 Memgraph Ltd.
//
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

#include "query/custom_cursors/produce.hpp"
#include "query/context.hpp"
#include "query/custom_cursors/utils.hpp"
#include "query/interpret/frame.hpp"
#include "spdlog/spdlog.h"
#include "utils/logging.hpp"

namespace memgraph::query::custom_cursors {

ProduceCursor::ProduceCursor(plan::UniqueCursorPtr input_cursor) : input_cursor_(std::move(input_cursor)) {}

bool ProduceCursor::Pull(Frame &frame, ExecutionContext &context) {
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
memgraph::query::plan::ScopedProfile profile{ComputeProfilingKey(this), "Produce", &context};
SPDLOG_WARN("Produce");
return input_cursor_->Pull(frame, context);
}

void ProduceCursor::Shutdown() { input_cursor_->Shutdown(); }

void ProduceCursor::Reset() { input_cursor_->Reset(); }

} // namespace memgraph::query::custom_cursors
Loading