From 5f7837d6134b33d96a6cca5e2bd702b724ac3e7d Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Wed, 20 Dec 2017 11:24:48 +0100 Subject: [PATCH] Serialize Ast classes Summary: Although the first solution used cereal, the final implementation uses boost. Since the cereal is still used in the codebase, compilation has been modified to support multithreaded cereal. In addition to serializing Ast classes, the following also needed to be serialized: * GraphDbTypes * Symbol * TypedValue TypedValue is treated specially, by inlining the serialization code in the Ast class, concretely PrimitiveLiteral. Another special case was the Function Ast class, which now stores a function name which is resolved to a concrete std::function on construction. Tests have been added for serialized Ast in tests/unit/cypher_main_visitor Reviewers: mferencevic, mislav.bradac, florijan Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1067 --- CMakeLists.txt | 3 + init | 4 + libs/CMakeLists.txt | 3 + src/CMakeLists.txt | 2 +- src/database/graph_db_datatypes.hpp | 52 + src/query/frontend/ast/ast.cpp | 138 ++ src/query/frontend/ast/ast.hpp | 1358 ++++++++++++++++- .../frontend/ast/cypher_main_visitor.cpp | 17 +- src/query/frontend/semantic/symbol.hpp | 11 + src/query/interpret/eval.hpp | 2 +- tests/unit/cypher_main_visitor.cpp | 35 +- tests/unit/query_common.hpp | 6 +- tests/unit/query_expression_evaluator.cpp | 3 +- 13 files changed, 1591 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a12a61721..1fddb3cb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,9 @@ if (USE_READLINE) endif() endif() +set(Boost_USE_STATIC_LIBS ON) +find_package(Boost REQUIRED COMPONENTS serialization) + set(libs_dir ${CMAKE_SOURCE_DIR}/libs) add_subdirectory(libs EXCLUDE_FROM_ALL) diff --git a/init b/init index d65133386..23a31a1f0 100755 --- a/init +++ b/init @@ -1,10 +1,14 @@ #!/bin/bash -e +# TODO: Consider putting boost library in libs/setup.sh, since the license +# allows source modification and static compilation. Unfortunately, it is quite +# a pain to set up the boost build process. required_pkgs=(git arcanist # source code control cmake clang-3.8 llvm-3.8 pkg-config # build system curl wget # for downloading libs uuid-dev default-jre-headless # required by antlr libreadline-dev # for memgraph console + libboost-serialization-dev python3 python-virtualenv python3-pip # for qa, macro_benchmark and stress tests ) diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 0d4dca5d3..59ac57995 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -167,3 +167,6 @@ import_header_library(json ${CMAKE_CURRENT_SOURCE_DIR}) # Setup cereal import_header_library(cereal "${CMAKE_CURRENT_SOURCE_DIR}/cereal/include") +# Make cereal multithreaded by passing -DCEREAL_THREAD_SAFE=1 (note that -D is omitted below). +set_property(TARGET cereal PROPERTY + INTERFACE_COMPILE_DEFINITIONS CEREAL_THREAD_SAFE=1) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f5b7859d8..4028355d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,7 +54,7 @@ set(memgraph_src_files # memgraph_lib depend on these libraries set(MEMGRAPH_ALL_LIBS stdc++fs Threads::Threads fmt cppitertools cereal - antlr_opencypher_parser_lib dl glog gflags) + antlr_opencypher_parser_lib dl glog gflags Boost::serialization) if (USE_LTALLOC) list(APPEND MEMGRAPH_ALL_LIBS ltalloc) diff --git a/src/database/graph_db_datatypes.hpp b/src/database/graph_db_datatypes.hpp index aadbf6d6d..b53deb3cf 100644 --- a/src/database/graph_db_datatypes.hpp +++ b/src/database/graph_db_datatypes.hpp @@ -2,6 +2,9 @@ #include +#include "boost/serialization/base_object.hpp" +#include "cereal/types/base_class.hpp" + #include "utils/total_ordering.hpp" namespace GraphDbTypes { @@ -33,18 +36,67 @@ class Common : TotalOrdering { private: StorageT storage_{0}; + + friend class boost::serialization::access; + + template + void serialize(TArchive &ar, const unsigned int) { + ar & storage_; + } }; class Label : public Common