merge with edges, from and to are moved to the EdgeRecord, they are not copied along with properties inside the MVCC, TODO: graph interface, Accessor and Stores

This commit is contained in:
Kruno Tomola Fabro 2016-08-11 15:13:19 +01:00
commit 02ec6dd401
280 changed files with 1457 additions and 967 deletions

View File

@ -48,11 +48,11 @@ ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ memgraph
tags
.gdb_history
Testing/
ve/

View File

@ -116,19 +116,22 @@ FILE(MAKE_DIRECTORY ${cypher_build_include_dir})
FILE(RENAME ${CMAKE_BINARY_DIR}/cypher.h ${cypher_build_include_dir}/cypher.h)
# prepare template and destination folders for query engine (tests)
# and memgraph server binary
# copy query_engine's templates file
FILE(COPY ${src_dir}/query_engine/template DESTINATION ${CMAKE_BINARY_DIR}/tests)
FILE(COPY ${src_dir}/query_engine/template DESTINATION ${CMAKE_BINARY_DIR})
# create destination folder for compiled queries
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/compiled/cpu)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/compiled/cpu)
# TODO: filter header files, all files don't need to be copied
# they are all copied because query engine needs header files during
# query compilation
# TODO: make a function (REMOVE copy pasted part)
SUBDIRLIST(source_folders ${src_dir})
foreach(source_folder ${source_folders})
file(COPY ${src_dir}/${source_folder} DESTINATION ${build_include_dir})
endforeach()
# SUBDIRLIST(source_folders ${src_dir})
# foreach(source_folder ${source_folders})
# file(COPY ${src_dir}/${source_folder} DESTINATION ${build_include_dir})
# endforeach()
SUBDIRLIST(source_folders ${src_dir})
foreach(source_folder ${source_folders})
file(COPY ${src_dir}/${source_folder} DESTINATION ${test_src_dir})
@ -138,32 +141,218 @@ foreach(source_foler ${source_folders})
file(COPY ${include_dir}/${source_folder} DESTINATION ${test_include_dir})
endforeach()
# -----------------------------------------------------------------------------
# COPY header files required by query engine (query compiler)
# TODO: somehow automate (in destination dir should be only required include files)
FILE(COPY ${include_dir}/database/db.hpp DESTINATION ${build_include_dir}/database)
FILE(COPY ${include_dir}/storage/common.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/graph.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/edge.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/edge_accessor.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/edges.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/vertices.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/vertex.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/vertex_accessor.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/record_accessor.hpp DESTINATION ${build_include_dir}/storage)
FILE(COPY ${include_dir}/storage/locking/record_lock.hpp DESTINATION ${build_include_dir}/storage/locking)
FILE(COPY ${include_dir}/storage/locking/lock_status.hpp DESTINATION ${build_include_dir}/storage/locking)
FILE(COPY ${include_dir}/storage/edge_type/edge_type_store.hpp DESTINATION ${build_include_dir}/storage/edge_type)
FILE(COPY ${include_dir}/storage/edge_type/edge_type.hpp DESTINATION ${build_include_dir}/storage/edge_type)
FILE(COPY ${include_dir}/storage/label/label_store.hpp DESTINATION ${build_include_dir}/storage/label)
FILE(COPY ${include_dir}/query_engine/util.hpp DESTINATION ${build_include_dir}/query_engine)
FILE(COPY ${include_dir}/query_engine/i_code_cpu.hpp DESTINATION ${build_include_dir}/query_engine)
FILE(COPY ${include_dir}/query_engine/query_result.hpp DESTINATION ${build_include_dir}/query_engine)
FILE(COPY ${include_dir}/query_engine/query_stripped.hpp DESTINATION ${build_include_dir}/query_engine)
FILE(COPY ${include_dir}/data_structures/concurrent/concurrent_map.hpp DESTINATION ${build_include_dir}/data_structures/concurrent)
FILE(COPY ${include_dir}/data_structures/concurrent/concurrent_set.hpp DESTINATION ${build_include_dir}/data_structures/concurrent)
FILE(COPY ${include_dir}/data_structures/concurrent/common.hpp DESTINATION ${build_include_dir}/data_structures/concurrent)
FILE(COPY ${include_dir}/data_structures/concurrent/skiplist.hpp DESTINATION ${build_include_dir}/data_structures/concurrent)
FILE(COPY ${include_dir}/data_structures/concurrent/skiplist_gc.hpp DESTINATION ${build_include_dir}/data_structures/concurrent)
FILE(COPY ${include_dir}/data_structures/bitset/dynamic_bitset.hpp DESTINATION ${build_include_dir}/data_structures/bitset)
FILE(COPY ${include_dir}/threading/sync/lockable.hpp DESTINATION ${build_include_dir}/threading/sync)
FILE(COPY ${include_dir}/threading/sync/spinlock.hpp DESTINATION ${build_include_dir}/threading/sync)
FILE(COPY ${include_dir}/threading/sync/futex.hpp DESTINATION ${build_include_dir}/threading/sync)
FILE(COPY ${include_dir}/threading/sync/lock_timeout_error.hpp DESTINATION ${build_include_dir}/threading/sync)
FILE(COPY ${include_dir}/memory/freelist.hpp DESTINATION ${build_include_dir}/memory)
FILE(COPY ${include_dir}/memory/lazy_gc.hpp DESTINATION ${build_include_dir}/memory)
FILE(COPY ${include_dir}/mvcc/cre_exp.hpp DESTINATION ${build_include_dir}/mvcc)
FILE(COPY ${include_dir}/mvcc/hints.hpp DESTINATION ${build_include_dir}/mvcc)
FILE(COPY ${include_dir}/mvcc/id.hpp DESTINATION ${build_include_dir}/mvcc)
FILE(COPY ${include_dir}/mvcc/mvcc_error.hpp DESTINATION ${build_include_dir}/mvcc)
FILE(COPY ${include_dir}/mvcc/record.hpp DESTINATION ${build_include_dir}/mvcc)
FILE(COPY ${include_dir}/mvcc/serialization_error.hpp DESTINATION ${build_include_dir}/mvcc)
FILE(COPY ${include_dir}/mvcc/version.hpp DESTINATION ${build_include_dir}/mvcc)
FILE(COPY ${include_dir}/mvcc/version_list.hpp DESTINATION ${build_include_dir}/mvcc)
FILE(COPY ${include_dir}/transactions/transaction.hpp DESTINATION ${build_include_dir}/transactions)
FILE(COPY ${include_dir}/transactions/lock_store.hpp DESTINATION ${build_include_dir}/transactions)
FILE(COPY ${include_dir}/transactions/snapshot.hpp DESTINATION ${build_include_dir}/transactions)
FILE(COPY ${include_dir}/transactions/commit_log.hpp DESTINATION ${build_include_dir}/transactions)
FILE(COPY ${include_dir}/transactions/engine.hpp DESTINATION ${build_include_dir}/transactions)
FILE(COPY ${include_dir}/transactions/transaction_store.hpp DESTINATION ${build_include_dir}/transactions)
FILE(COPY ${include_dir}/storage/model/properties/properties.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/property.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/traversers/consolewriter.hpp DESTINATION ${build_include_dir}/storage/model/properties/traversers)
FILE(COPY ${include_dir}/storage/model/properties/traversers/jsonwriter.hpp DESTINATION ${build_include_dir}/storage/model/properties/traversers)
FILE(COPY ${include_dir}/storage/model/properties/handler.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/all.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/bool.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/float.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/double.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/int32.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/int64.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/string.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/floating.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/number.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/integral.hpp DESTINATION ${build_include_dir}/storage/model/properties)
FILE(COPY ${include_dir}/storage/model/properties/utils/math_operations.hpp DESTINATION ${build_include_dir}/storage/model/properties/utils)
FILE(COPY ${include_dir}/storage/model/properties/utils/unary_negation.hpp DESTINATION ${build_include_dir}/storage/model/properties/utils)
FILE(COPY ${include_dir}/storage/model/properties/utils/modulo.hpp DESTINATION ${build_include_dir}/storage/model/properties/utils)
FILE(COPY ${include_dir}/storage/model/edge_model.hpp DESTINATION ${build_include_dir}/storage/model)
FILE(COPY ${include_dir}/storage/model/property_model.hpp DESTINATION ${build_include_dir}/storage/model)
FILE(COPY ${include_dir}/storage/model/vertex_model.hpp DESTINATION ${build_include_dir}/storage/model)
FILE(COPY ${include_dir}/storage/model/edge_list.hpp DESTINATION ${build_include_dir}/storage/model)
FILE(COPY ${include_dir}/storage/label/label.hpp DESTINATION ${build_include_dir}/storage/label)
FILE(COPY ${include_dir}/storage/label/label_collection.hpp DESTINATION ${build_include_dir}/storage/label)
FILE(COPY ${include_dir}/storage/label/label_store.hpp DESTINATION ${build_include_dir}/storage/label)
FILE(COPY ${include_dir}/storage/indexes/index.hpp DESTINATION ${build_include_dir}/storage/indexes)
FILE(COPY ${include_dir}/storage/indexes/index_record.hpp DESTINATION ${build_include_dir}/storage/indexes)
FILE(COPY ${include_dir}/storage/indexes/index_record_collection.hpp DESTINATION ${build_include_dir}/storage/indexes)
FILE(COPY ${include_dir}/utils/sys.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/bswap.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/stacktrace.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/auto_scope.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/assert.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/reference_wrapper.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/underlying_cast.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/total_ordering.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/crtp.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/placeholder.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/likely.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/cpu_relax.hpp DESTINATION ${build_include_dir}/utils)
FILE(COPY ${include_dir}/utils/counters/atomic_counter.hpp DESTINATION ${build_include_dir}/utils/counters)
FILE(COPY ${include_dir}/utils/counters/simple_counter.hpp DESTINATION ${build_include_dir}/utils/counters)
FILE(COPY ${include_dir}/utils/random/fast_binomial.hpp DESTINATION ${build_include_dir}/utils/random)
FILE(COPY ${include_dir}/utils/random/xorshift128plus.hpp DESTINATION ${build_include_dir}/utils/random)
FILE(COPY ${include_dir}/utils/exceptions/basic_exception.hpp DESTINATION ${build_include_dir}/utils/exceptions)
FILE(COPY ${include_dir}/utils/datetime/timestamp.hpp DESTINATION ${build_include_dir}/utils/datetime)
FILE(COPY ${include_dir}/utils/datetime/datetime_error.hpp DESTINATION ${build_include_dir}/utils/datetime)
FILE(COPY ${include_dir}/utils/types/byte.hpp DESTINATION ${build_include_dir}/utils/types)
FILE(COPY ${include_dir}/communication/communication.hpp DESTINATION ${build_include_dir}/communication)
FILE(COPY ${include_dir}/communication/bolt/v1/config.hpp DESTINATION ${build_include_dir}/communication/bolt/v1)
FILE(COPY ${include_dir}/communication/bolt/v1/serialization/record_stream.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/serialization)
FILE(COPY ${include_dir}/communication/bolt/v1/serialization/bolt_serializer.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/serialization)
FILE(COPY ${include_dir}/communication/bolt/v1/transport/bolt_encoder.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport)
FILE(COPY ${include_dir}/communication/bolt/v1/transport/chunked_buffer.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport)
FILE(COPY ${include_dir}/communication/bolt/v1/transport/chunked_encoder.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport)
FILE(COPY ${include_dir}/communication/bolt/v1/transport/socket_stream.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport)
FILE(COPY ${include_dir}/communication/bolt/v1/transport/stream_error.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport)
FILE(COPY ${include_dir}/communication/bolt/v1/packing/codes.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/packing)
FILE(COPY ${include_dir}/communication/bolt/v1/messaging/codes.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/messaging)
FILE(COPY ${include_dir}/io/network/socket.hpp DESTINATION ${build_include_dir}/io/network)
FILE(COPY ${include_dir}/io/network/addrinfo.hpp DESTINATION ${build_include_dir}/io/network)
FILE(COPY ${include_dir}/io/network/network_error.hpp DESTINATION ${build_include_dir}/io/network)
FILE(COPY ${include_dir}/io/network/socket.hpp DESTINATION ${build_include_dir}/io/network)
FILE(COPY ${include_dir}/logging/default.hpp DESTINATION ${build_include_dir}/logging)
FILE(COPY ${include_dir}/logging/log.hpp DESTINATION ${build_include_dir}/logging)
FILE(COPY ${include_dir}/logging/logger.hpp DESTINATION ${build_include_dir}/logging)
FILE(COPY ${include_dir}/logging/levels.hpp DESTINATION ${build_include_dir}/logging)
# -----------------------------------------------------------------------------
# add all cpp file recursive into sourceFiles varibale
# FILE(GLOB_RECURSE sourceFiles ${src_dir}/*.cpp)
# print list of source files
# MESSAGE(STATUS "All source files are: ${sourceFiles}")
# compiler options
# SET(COMPILE_OPTIONS "-O2 -Wall -Werror -fmessage-length=0")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
# debug flags
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# set(CMAKE_CXX_FLAGS_DEBUG "-Wl,--export-dynamic ${CMAKE_CXX_FLAGS_DEBUG}")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# set(CMAKE_CXX_FLAGS_DEBUG "-rdynamic ${CMAKE_CXX_FLAGS_DEBUG}")
endif()
# manual defines at configure time
option(RUNTIME_ASSERT "Enable runtime assertions" OFF)
# release flags
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} -march=native -Wall -Werror")
# -- configure defines -- default is ON | true | enabled ----------------------
# -- logging ------------------------------------------------------------------
option(LOG_NO_TRACE "Disable trace logging" OFF)
message(STATUS "LOG_NO_TRACE: ${LOG_NO_TRACE}")
if (LOG_NO_TRACE)
add_definitions(-DLOG_NO_TRACE)
endif()
option(LOG_NO_DEBUG "Disable debug logging" OFF)
message(STATUS "LOG_NO_DEBUG: ${LOG_NO_DEBUG}")
if (LOG_NO_DEBUG)
add_definitions(-DLOG_NO_DEBUG)
endif()
option(LOG_NO_INFO "Disable info logging" OFF)
message(STATUS "LOG_NO_INFO: ${LOG_NO_INFO}")
if (LOG_NO_INFO)
add_definitions(-DLOG_NO_INFO)
endif()
option(LOG_NO_WARN "Disable warn logging" OFF)
message(STATUS "LOG_NO_WARN: ${LOG_NO_WARN}")
if (LOG_NO_WARN)
add_definitions(-DLOG_NO_WARN)
endif()
option(LOG_NO_ERROR "Disable error logging" OFF)
message(STATUS "LOG_NO_ERROR: ${LOG_NO_ERROR}")
if (LOG_NO_ERROR)
add_definitions(-DLOG_NO_ERROR)
endif()
# -- logging ------------------------------------------------------------------
# -- assert -------------------------------------------------------------------
option(RUNTIME_ASSERT "Enable runtime assertions" ON)
message(STATUS "RUNTIME_ASSERT: ${RUNTIME_ASSERT}")
if(RUNTIME_ASSERT)
add_definitions( -DRUNTIME_ASSERT_ON )
add_definitions(-DRUNTIME_ASSERT_ON)
endif()
option(THROW_EXCEPTION_ON_ERROR "Throw exception on error" OFF)
option(THROW_EXCEPTION_ON_ERROR "Throw exception on error" ON)
message(STATUS "THROW_EXCEPTION_ON_ERROR: ${THROW_EXCEPTION_ON_ERROR}")
if(THROW_EXCEPTION_ON_ERROR)
add_definitions( -DTHROW_EXCEPTION_ON_ERROR )
add_definitions(-DTHROW_EXCEPTION_ON_ERROR)
endif()
# -- assert -------------------------------------------------------------------
# -- ndebug -------------------------------------------------------------------
option(NDEBUG "No debug" OFF)
message(STATUS "NDEBUG: ${NDEBUG} (be careful CMAKE_BUILD_TYPE can also append this flag)")
if(NDEBUG)
add_definitions( -DNDEBUG )
endif()
# -- ndebug -------------------------------------------------------------------
# -- binaries -----------------------------------------------------------------
option(MEMGRAPH "Build memgraph binary" ON)
message(STATUS "MEMGRAPH binary: ${MEMGRAPH}")
option(POC "Build proof of concept binaries" ON)
message(STATUS "POC binaries: ${POC}")
option(TESTS "Build test binaries" ON)
message(STATUS "TESTS binaries: ${TESTS}")
# -- binaries -----------------------------------------------------------------
# -- configure defines --------------------------------------------------------
# includes
# -- includes -----------------------------------------------------------------
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${src_dir})
include_directories(${build_include_dir})
@ -173,6 +362,7 @@ include_directories(${lexertl_dir})
include_directories(${libuv_source_dir}/include)
include_directories(${rapidjson_source_dir}/include)
include_directories(${r3_source_dir}/include)
# -----------------------------------------------------------------------------
# creates build/libcypher_lib.a
add_library(cypher_lib STATIC ${CMAKE_BINARY_DIR}/cypher.cpp)
@ -183,30 +373,24 @@ EXECUTE_PROCESS(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/api
)
# # memgraph executable
# add_executable(memgraph_http src/memgraph.cpp)
# add_dependencies(memgraph_http cypher_lib)
# target_link_libraries(memgraph_http Threads::Threads)
# target_link_libraries(memgraph_http pcre)
# target_link_libraries(memgraph_http ${libuv_static_lib})
# target_link_libraries(memgraph_http ${r3_static_lib})
# target_link_libraries(memgraph_http ${http_parser_static_lib})
# # query_engine executable
# add_executable(query_engine src/query_engine/main_query_engine.cpp)
# # query_engine link libraries
# target_link_libraries(query_engine Threads::Threads)
# target_link_libraries(query_engine dl)
# target_link_libraries(query_engine cypher_lib)
# target_link_libraries(query_engine ${fmt_static_lib})
# # query hasher executable
# add_executable(query_hasher src/query_engine/main_query_hasher.cpp)
# target_link_libraries(query_hasher ${fmt_static_lib})
# TODO: create separate static library from bolt code
set(memgraph_src_files
${src_dir}/utils/string/transform.cpp
${src_dir}/utils/string/join.cpp
${src_dir}/utils/string/file.cpp
${src_dir}/query_engine/util.cpp
${src_dir}/communication/bolt/v1/bolt.cpp
${src_dir}/communication/bolt/v1/states.cpp
${src_dir}/communication/bolt/v1/session.cpp
${src_dir}/communication/bolt/v1/states/error.cpp
${src_dir}/communication/bolt/v1/states/executor.cpp
${src_dir}/communication/bolt/v1/states/init.cpp
${src_dir}/communication/bolt/v1/states/handshake.cpp
${src_dir}/communication/bolt/v1/transport/bolt_decoder.cpp
${src_dir}/communication/bolt/v1/transport/buffer.cpp
${src_dir}/mvcc/id.cpp
${src_dir}/storage/vertices.cpp
${src_dir}/storage/edges.cpp
${src_dir}/storage/label/label.cpp
${src_dir}/storage/label/label_collection.cpp
${src_dir}/storage/label/label_store.cpp
@ -221,6 +405,13 @@ set(memgraph_src_files
${src_dir}/storage/vertex_accessor.cpp
${src_dir}/transactions/transaction.cpp
${src_dir}/template_engine/engine.cpp
${src_dir}/logging/streams/stdout.cpp
${src_dir}/logging/levels.cpp
${src_dir}/logging/logs/sync_log.cpp
${src_dir}/logging/logs/async_log.cpp
${src_dir}/logging/default.cpp
${src_dir}/logging/log.cpp
${src_dir}/io/network/tls.cpp
)
# STATIC library used by memgraph executables
@ -231,11 +422,15 @@ add_library(memgraph_pic STATIC ${memgraph_src_files})
set_property(TARGET memgraph_pic PROPERTY POSITION_INDEPENDENT_CODE TRUE)
# tests
enable_testing()
add_subdirectory(tests)
if (TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# proof of concept
add_subdirectory(poc)
# proof of concepts
if (POC)
add_subdirectory(poc)
endif()
# memgraph build name
execute_process(
@ -248,8 +443,28 @@ execute_process(
)
string(STRIP ${COMMIT_HASH} COMMIT_HASH)
string(STRIP ${COMMIT_NO} COMMIT_NO)
set(MEMGRAPH_BUILD_NAME "memgraph_${COMMIT_HASH}_${COMMIT_NO}")
message(STATUS ${CMAKE_BUILD_TYPE})
set(MEMGRAPH_BUILD_NAME
"memgraph_${COMMIT_HASH}_${COMMIT_NO}_${CMAKE_BUILD_TYPE}")
# memgraph main executable
add_executable(${MEMGRAPH_BUILD_NAME}_${CMAKE_BUILD_TYPE} ${src_dir}/memgraph_bolt.cpp)
if (MEMGRAPH)
add_executable(${MEMGRAPH_BUILD_NAME} ${src_dir}/memgraph_bolt.cpp)
target_link_libraries(${MEMGRAPH_BUILD_NAME} memgraph)
target_link_libraries(${MEMGRAPH_BUILD_NAME} Threads::Threads)
target_link_libraries(${MEMGRAPH_BUILD_NAME} cypher_lib)
if (UNIX)
target_link_libraries(${MEMGRAPH_BUILD_NAME} crypto)
# target_link_libraries(${MEMGRAPH_BUILD_NAME} ssl)
target_link_libraries(${MEMGRAPH_BUILD_NAME} ${fmt_static_lib})
target_link_libraries(${MEMGRAPH_BUILD_NAME} dl)
endif (UNIX)
endif()
# # memgraph executable HTTP TODO: DEPRICATED
# add_executable(memgraph_http src/memgraph.cpp)
# add_dependencies(memgraph_http cypher_lib)
# target_link_libraries(memgraph_http Threads::Threads)
# target_link_libraries(memgraph_http pcre)
# target_link_libraries(memgraph_http ${libuv_static_lib})
# target_link_libraries(memgraph_http ${r3_static_lib})
# target_link_libraries(memgraph_http ${http_parser_static_lib})

View File

@ -20,6 +20,10 @@ on a 64 bit linux kernel.
* lemon (parser generator)
* catch (for compiling tests)
### Bolt
sudo apt-get install libssl-dev
## build
```
cd build
@ -30,8 +34,9 @@ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DRUNTIME_ASSERT=OFF
# -DCMAKE_CXX_COMPILER=clang++
# -DRUNTIME_ASSERT=OFF
# -DTHROW_EXCEPTION_ON_ERROR=OFF
# -DCMAKE_BUILD_TYPE:STRING=Debug
# -DNDEBUG=ON
# -DCMAKE_BUILD_TYPE:STRING=debug
# -DCMAKE_BUILD_TYPE:STRING=release
make
ctest

View File

@ -1,7 +1,8 @@
#pragma once
#include "states.hpp"
#include "communication/bolt/v1/states.hpp"
#include "io/network/socket.hpp"
#include "dbms/dbms.hpp"
namespace bolt
{
@ -19,6 +20,7 @@ public:
void close(Session* session);
States states;
Dbms dbms;
};
}

View File

@ -0,0 +1,14 @@
#pragma once
#include <cstddef>
namespace bolt
{
namespace config
{
static constexpr size_t N = 65535; /* chunk size */
static constexpr size_t C = N + 2; /* end mark */
}
}

View File

@ -1,9 +1,9 @@
#pragma once
#include "bolt/v1/transport/bolt_encoder.hpp"
#include "bolt/v1/packing/codes.hpp"
#include "communication/bolt/v1/transport/bolt_encoder.hpp"
#include "communication/bolt/v1/packing/codes.hpp"
#include "include/storage/vertex_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/model/properties/properties.hpp"
@ -17,8 +17,12 @@ class BoltSerializer
{
friend class Property;
// TODO: here shoud be friend but it doesn't work
// template <class Handler>
// friend void accept(const Property &property, Handler &h);
public:
BoltSerializer() {}
BoltSerializer(Stream& stream) : encoder(stream) {}
/* Serializes the vertex accessor into the packstream format
*
@ -51,8 +55,10 @@ public:
encoder.write_map_header(props.size());
for(auto& prop : props)
write(prop);
for(auto& prop : props) {
write(prop.first);
write(*prop.second);
}
}
/* Serializes the vertex accessor into the packstream format
@ -87,8 +93,10 @@ public:
encoder.write_map_header(props.size());
for(auto& prop : props)
write(prop);
for(auto& prop : props) {
write(prop.first);
write(*prop.second);
}
}
void write(const Property& prop)
@ -126,19 +134,24 @@ public:
encoder.write_integer(prop.value);
}
void write(const std::string& value)
{
encoder.write_string(value);
}
void write(const String& prop)
{
encoder.write_string(prop.value);
}
protected:
BoltEncoder<Stream> encoder;
template <class T>
void handle(const T& prop)
{
write(prop);
}
protected:
Stream& encoder;
};
}

View File

@ -0,0 +1,130 @@
#pragma once
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"
#include "communication/bolt/v1/transport/chunked_buffer.hpp"
#include "communication/bolt/v1/transport/chunked_encoder.hpp"
#include "communication/bolt/v1/transport/socket_stream.hpp"
#include "logging/default.hpp"
namespace bolt
{
// compiled queries have to use this class in order to return results
// query code should not know about bolt protocol
template <class Socket>
class RecordStream
{
public:
RecordStream(Socket &socket) : socket(socket)
{
logger = logging::log->logger("Record Stream");
}
// TODO: create apstract methods that are not bolt specific ---------------
void write_success()
{
logger.trace("write_success");
bolt_encoder.message_success();
}
void write_success_empty()
{
logger.trace("write_success_empty");
bolt_encoder.message_success_empty();
}
void write_ignored()
{
logger.trace("write_ignored");
bolt_encoder.message_ignored();
}
void write_fields(const std::vector<std::string> &fields)
{
// TODO: that should be one level below?
bolt_encoder.message_success();
bolt_encoder.write_map_header(1);
bolt_encoder.write_string("fields");
write_list_header(fields.size());
for (auto &name : fields) {
bolt_encoder.write_string(name);
}
flush();
}
void write_field(const std::string& field)
{
bolt_encoder.message_success();
bolt_encoder.write_map_header(1);
bolt_encoder.write_string("fields");
write_list_header(1);
bolt_encoder.write_string(field);
flush();
}
void write_list_header(size_t size)
{
bolt_encoder.write_list_header(size);
}
void write_record()
{
bolt_encoder.message_record();
}
// -- BOLT SPECIFIC METHODS -----------------------------------------------
void write(const Vertex::Accessor &vertex) { serializer.write(vertex); }
void write(const Edge::Accessor &edge) { serializer.write(edge); }
void write(const Property &prop) { serializer.write(prop); }
void write(const Bool& prop) { serializer.write(prop); }
void write(const Float& prop) { serializer.write(prop); }
void write(const Int32& prop) { serializer.write(prop); }
void write(const Int64& prop) { serializer.write(prop); }
void write(const Double& prop) { serializer.write(prop); }
void write(const String& prop) { serializer.write(prop); }
void flush()
{
chunked_encoder.flush();
chunked_buffer.flush();
}
void _write_test()
{
logger.trace("write_test");
write_fields({{"name"}});
write_record();
write_list_header(1);
write(String("max"));
write_record();
write_list_header(1);
write(String("paul"));
write_success_empty();
}
protected:
Logger logger;
private:
using buffer_t = ChunkedBuffer<SocketStream>;
using chunked_encoder_t = ChunkedEncoder<buffer_t>;
using bolt_encoder_t = BoltEncoder<chunked_encoder_t>;
using bolt_serializer_t = BoltSerializer<bolt_encoder_t>;
SocketStream socket;
buffer_t chunked_buffer{socket};
chunked_encoder_t chunked_encoder{chunked_buffer};
bolt_encoder_t bolt_encoder{chunked_encoder};
bolt_serializer_t serializer{bolt_encoder};
};
}

View File

@ -7,7 +7,7 @@
#include <cassert>
#include "io/network/server.hpp"
#include "bolt/v1/bolt.hpp"
#include "communication/bolt/v1/bolt.hpp"
namespace bolt
{

View File

@ -1,19 +1,16 @@
#pragma once
#include <iomanip>
#include <cstdio>
#include <atomic>
#include <sstream>
#include <cstdio>
#include <iomanip>
#include <memory>
#include <sstream>
#include <thread>
#include "io/network/stream_reader.hpp"
#include "bolt/v1/bolt.hpp"
#include "bolt/v1/session.hpp"
#include "communication/bolt/v1/bolt.hpp"
#include "communication/bolt/v1/session.hpp"
#include "logging/default.hpp"
#include "io/network/stream_reader.hpp"
namespace bolt
{
@ -28,19 +25,19 @@ class Worker : public io::StreamReader<Worker, Session>
public:
using sptr = std::shared_ptr<Worker>;
Worker(Bolt& bolt) : bolt(bolt)
Worker(Bolt &bolt) : bolt(bolt)
{
logger = logging::log->logger("Network");
}
Session& on_connect(io::Socket&& socket)
Session &on_connect(io::Socket &&socket)
{
logger.trace("Accepting connection on socket {}", socket.id());
return *bolt.get().create_session(std::forward<io::Socket>(socket));
}
void on_error(Session&)
void on_error(Session &)
{
logger.trace("[on_error] errno = {}", errno);
@ -50,43 +47,39 @@ public:
#endif
logger.error("Error occured in this session");
}
void on_wait_timeout() {}
Buffer on_alloc(Session&)
Buffer on_alloc(Session &)
{
/* logger.trace("[on_alloc] Allocating {}B", sizeof buf); */
return Buffer { buf, sizeof buf };
return Buffer{buf, sizeof buf};
}
void on_read(Session& session, Buffer& buf)
void on_read(Session &session, Buffer &buf)
{
logger.trace("[on_read] Received {}B", buf.len);
#ifndef NDEBUG
std::stringstream stream;
for(size_t i = 0; i < buf.len; ++i)
for (size_t i = 0; i < buf.len; ++i)
stream << fmt::format("{:02X} ", static_cast<byte>(buf.ptr[i]));
logger.trace("[on_read] {}", stream.str());
#endif
try
{
session.execute(reinterpret_cast<const byte*>(buf.ptr), buf.len);
}
catch(const std::exception& e)
{
try {
session.execute(reinterpret_cast<const byte *>(buf.ptr), buf.len);
} catch (const std::exception &e) {
logger.error("Error occured while executing statement.");
logger.error("{}", e.what());
}
}
void on_close(Session& session)
void on_close(Session &session)
{
logger.trace("[on_close] Client closed the connection");
session.close();
@ -100,13 +93,12 @@ protected:
Logger logger;
std::thread thread;
void start(std::atomic<bool>& alive)
void start(std::atomic<bool> &alive)
{
thread = std::thread([&, this]() {
while(alive)
while (alive)
wait_and_process_events();
});
}
};
}

View File

@ -0,0 +1,43 @@
#pragma once
#include "io/network/socket.hpp"
#include "io/network/tcp/stream.hpp"
#include "communication/bolt/v1/bolt.hpp"
#include "communication/bolt/v1/serialization/record_stream.hpp"
#include "communication/bolt/v1/states/state.hpp"
#include "communication/bolt/v1/transport/bolt_decoder.hpp"
#include "communication/bolt/v1/transport/bolt_encoder.hpp"
#include "communication/communication.hpp"
#include "logging/default.hpp"
namespace bolt
{
class Session : public io::tcp::Stream<io::Socket>
{
public:
using Decoder = BoltDecoder;
using OutputStream = communication::OutputStream;
Session(io::Socket &&socket, Bolt &bolt);
bool alive() const;
void execute(const byte *data, size_t len);
void close();
Bolt &bolt;
Db &active_db();
Decoder decoder;
OutputStream output_stream{socket};
bool connected{false};
State *state;
protected:
Logger logger;
};
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "states/state.hpp"
#include "communication/bolt/v1/states/state.hpp"
#include "logging/log.hpp"
namespace bolt

View File

@ -0,0 +1,15 @@
#pragma once
#include "communication/bolt/v1/session.hpp"
#include "communication/bolt/v1/states/state.hpp"
namespace bolt
{
class Error : public State
{
public:
State *run(Session &session) override;
};
}

View File

@ -1,7 +1,8 @@
#pragma once
#include "bolt/v1/states/state.hpp"
#include "bolt/v1/session.hpp"
#include "communication/bolt/v1/states/state.hpp"
#include "communication/bolt/v1/session.hpp"
#include "query_engine/query_engine.hpp"
namespace bolt
{
@ -35,6 +36,10 @@ protected:
*
*/
void discard_all(Session& session);
private:
QueryEngine query_engine;
};
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "bolt/v1/states/state.hpp"
#include "communication/bolt/v1/states/state.hpp"
namespace bolt
{

View File

@ -1,6 +1,6 @@
#pragma once
#include "bolt/v1/states/message_parser.hpp"
#include "communication/bolt/v1/states/message_parser.hpp"
namespace bolt
{

View File

@ -1,10 +1,9 @@
#pragma once
#include "state.hpp"
#include "communication/bolt/v1/session.hpp"
#include "communication/bolt/v1/states/state.hpp"
#include "utils/crtp.hpp"
#include "bolt/v1/session.hpp"
namespace bolt
{
@ -12,10 +11,9 @@ template <class Derived>
class MessageParser : public State, public Crtp<Derived>
{
public:
MessageParser(Logger&& logger)
: logger(std::forward<Logger>(logger)) {}
MessageParser(Logger &&logger) : logger(std::forward<Logger>(logger)) {}
State* run(Session& session) override final
State *run(Session &session) override final
{
typename Derived::Message message;
@ -23,8 +21,7 @@ public:
auto next = this->derived().parse(session, message);
// return next state if parsing was unsuccessful (i.e. error state)
if(next != &this->derived())
return next;
if (next != &this->derived()) return next;
logger.debug("Executing state");
return this->derived().execute(session, message);
@ -33,5 +30,4 @@ public:
protected:
Logger logger;
};
}

View File

@ -1,8 +1,7 @@
#pragma once
#include "buffer.hpp"
#include "chunked_decoder.hpp"
#include "communication/bolt/v1/transport/buffer.hpp"
#include "communication/bolt/v1/transport/chunked_decoder.hpp"
#include "utils/types/byte.hpp"
namespace bolt
@ -11,15 +10,15 @@ namespace bolt
class BoltDecoder
{
public:
void handshake(const byte*& data, size_t len);
bool decode(const byte*& data, size_t len);
void handshake(const byte *&data, size_t len);
bool decode(const byte *&data, size_t len);
bool empty() const;
void reset();
byte peek() const;
byte read_byte();
void read_bytes(void* dest, size_t n);
void read_bytes(void *dest, size_t n);
int16_t read_int16();
uint16_t read_uint16();
@ -36,10 +35,9 @@ public:
private:
Buffer buffer;
ChunkedDecoder<Buffer> decoder {buffer};
size_t pos {0};
ChunkedDecoder<Buffer> decoder{buffer};
size_t pos{0};
const byte* raw() const;
const byte *raw() const;
};
}

View File

@ -2,10 +2,11 @@
#include <string>
#include "bolt/v1/packing/codes.hpp"
#include "bolt/v1/messaging/codes.hpp"
#include "communication/bolt/v1/packing/codes.hpp"
#include "communication/bolt/v1/messaging/codes.hpp"
#include "utils/types/byte.hpp"
#include "utils/bswap.hpp"
#include "logging/default.hpp"
namespace bolt
{
@ -22,7 +23,10 @@ class BoltEncoder
static constexpr int64_t minus_2_to_the_31 = -2147483648L;
public:
BoltEncoder(Stream& stream) : stream(stream) {}
BoltEncoder(Stream& stream) : stream(stream)
{
logger = logging::log->logger("Bolt Encoder");
}
void flush()
{
@ -36,6 +40,7 @@ public:
void write_byte(byte value)
{
logger.trace("write byte: {}", value);
stream.write(value);
}
@ -259,6 +264,9 @@ public:
write_empty_map();
}
protected:
Logger logger;
private:
Stream& stream;
};

View File

@ -4,14 +4,14 @@
#include <cstdlib>
#include <vector>
#include "utils/types/byte.hpp"
namespace bolt
{
class Buffer
{
public:
using byte = uint8_t;
void write(const byte* data, size_t len);
void clear();

View File

@ -0,0 +1,74 @@
#pragma once
#include <memory>
#include <vector>
#include <cstring>
#include "communication/bolt/v1/config.hpp"
#include "utils/types/byte.hpp"
#include "logging/default.hpp"
namespace bolt
{
template <class Stream>
class ChunkedBuffer
{
static constexpr size_t C = bolt::config::C; /* chunk size */
public:
ChunkedBuffer(Stream &stream) : stream(stream)
{
logger = logging::log->logger("Chunked Buffer");
}
void write(const byte *values, size_t n)
{
// TODO: think about shared pointer
// TODO: this is naive implementation, it can be implemented much better
logger.trace("write {} bytes", n);
byte *chunk = chunk = (byte *)std::malloc(n * sizeof(byte));
last_size = n;
std::memcpy(chunk, values, n);
buffer.push_back(chunk);
}
void flush()
{
logger.trace("Flush");
for (size_t i = 0; i < buffer.size(); ++i) {
if (i == buffer.size() - 1)
stream.get().write(buffer[i], last_size);
else
stream.get().write(buffer[i], C);
}
destroy();
}
~ChunkedBuffer()
{
destroy();
}
private:
Logger logger;
std::reference_wrapper<Stream> stream;
std::vector<byte *> buffer;
size_t last_size {0}; // last chunk size (it is going to be less than C)
void destroy()
{
for (size_t i = 0; i < buffer.size(); ++i) {
std::free(buffer[i]);
}
buffer.clear();
}
};
}

View File

@ -1,13 +1,13 @@
#pragma once
#include <cassert>
#include <cstring>
#include <functional>
#include <cassert>
#include "utils/exceptions/basic_exception.hpp"
#include "utils/likely.hpp"
#include "logging/default.hpp"
#include "utils/exceptions/basic_exception.hpp"
#include "utils/likely.hpp"
#include "utils/types/byte.hpp"
namespace bolt
{
@ -22,8 +22,6 @@ public:
using BasicException::BasicException;
};
using byte = unsigned char;
ChunkedDecoder(Stream& stream) : stream(stream) {}
/* Decode chunked data
@ -33,14 +31,14 @@ public:
* |Header| Data ||Header| Data || ... || End |
* | 2B | size bytes || 2B | size bytes || ... ||00 00|
*/
bool decode(const byte*& chunk, size_t n)
bool decode(const byte *&chunk, size_t n)
{
while(n > 0)
while (n > 0)
{
// get size from first two bytes in the chunk
auto size = get_size(chunk);
if(UNLIKELY(size + 2 > n))
if (UNLIKELY(size + 2 > n))
throw DecoderError("Chunk size larger than available data.");
// advance chunk to pass those two bytes
@ -48,8 +46,7 @@ public:
n -= 2;
// if chunk size is 0, we're done!
if(size == 0)
return true;
if (size == 0) return true;
stream.get().write(chunk, size);
@ -60,18 +57,14 @@ public:
return false;
}
bool operator()(const byte*& chunk, size_t n)
{
return decode(chunk, n);
}
bool operator()(const byte *&chunk, size_t n) { return decode(chunk, n); }
private:
std::reference_wrapper<Stream> stream;
size_t get_size(const byte* chunk)
size_t get_size(const byte *chunk)
{
return size_t(chunk[0]) << 8 | chunk[1];
}
};
}

View File

@ -5,6 +5,8 @@
#include <functional>
#include "utils/likely.hpp"
#include "communication/bolt/v1/config.hpp"
#include "logging/default.hpp"
namespace bolt
{
@ -12,13 +14,16 @@ namespace bolt
template <class Stream>
class ChunkedEncoder
{
static constexpr size_t N = 65535;
static constexpr size_t C = N + 2 /* end mark */;
static constexpr size_t N = bolt::config::N;
static constexpr size_t C = bolt::config::C;
public:
using byte = unsigned char;
ChunkedEncoder(Stream& stream) : stream(stream) {}
ChunkedEncoder(Stream& stream) : stream(stream)
{
logger = logging::log->logger("Chunked Encoder");
}
static constexpr size_t chunk_size = N - 2;
@ -32,6 +37,8 @@ public:
void write(const byte* values, size_t n)
{
logger.trace("write {} bytes", n);
while(n > 0)
{
auto size = n < N - pos ? n : N - pos;
@ -58,6 +65,7 @@ public:
}
private:
Logger logger;
std::reference_wrapper<Stream> stream;
std::array<byte, C> chunk;
@ -65,7 +73,9 @@ private:
void end_chunk()
{
write_chunk_header();
// TODO: this call is unnecessary bacause the same method is called
// inside the flush method
// write_chunk_header();
flush();
}

View File

@ -5,7 +5,7 @@
#include <cstdio>
#include "io/network/socket.hpp"
#include "stream_error.hpp"
#include "communication/bolt/v1/transport/stream_error.hpp"
namespace bolt
{

View File

@ -0,0 +1,9 @@
#pragma once
#include "io/network/socket.hpp"
#include "communication/bolt/v1/serialization/record_stream.hpp"
namespace communication
{
using OutputStream = bolt::RecordStream<io::Socket>;
}

View File

@ -0,0 +1,4 @@
#pragma once
/* Memgraph Communication protocol
* gate is the first name proposal for the protocol */

View File

@ -0,0 +1,3 @@
#pragma once
/* HTTP & HTTPS implementation */

View File

@ -16,7 +16,6 @@ public:
friend constexpr bool operator<(const Item &lhs, const Item &rhs)
{
std::pair<const K, T> *a;
return lhs.first < rhs.first;
}

View File

@ -6,11 +6,14 @@
#include "memory/freelist.hpp"
#include "memory/lazy_gc.hpp"
#include "threading/sync/spinlock.hpp"
#include "logging/default.hpp"
template <class T, class lock_t = SpinLock>
class SkiplistGC : public LazyGC<SkiplistGC<T, lock_t>, lock_t>
{
public:
SkiplistGC() : logger(logging::log->logger("SkiplistGC")) {}
// release_ref method should be called by a thread
// when the thread finish it job over object
// which has to be lazy cleaned
@ -33,9 +36,8 @@ public:
}
if (local_freelist.size() > 0) {
std::cout << "GC started" << std::endl;
std::cout << "Local list size: " << local_freelist.size()
<< std::endl;
logger.trace("GC started");
logger.trace("Local list size: {}", local_freelist.size());
long long counter = 0;
// destroy all elements from local_freelist
for (auto element : local_freelist) {
@ -45,13 +47,15 @@ public:
counter++;
}
}
std::cout << "Number of destroyed elements " << counter
<< std::endl;
logger.trace("Number of destroyed elements: {}", counter);
}
}
void collect(T *node) { freelist.add(node); }
protected:
Logger logger;
private:
FreeList<T> freelist;
};

View File

@ -9,12 +9,18 @@ class Db
public:
using sptr = std::shared_ptr<Db>;
Db() = default;
Db(const std::string& name) : name_(name) {}
Db(const Db& db) = delete;
Graph graph;
tx::Engine tx_engine;
// only for test purposes
std::string identifier()
std::string& name()
{
return "memgraph";
return name_;
}
private:
std::string name_;
};

View File

@ -3,7 +3,7 @@
#include <cstring>
#include <netdb.h>
#include "network_error.hpp"
#include "io/network/network_error.hpp"
#include "utils/underlying_cast.hpp"
namespace io

View File

@ -1,6 +1,6 @@
#pragma once
#include "stream_reader.hpp"
#include "io/network/stream_reader.hpp"
namespace io
{

View File

@ -3,7 +3,7 @@
#include <malloc.h>
#include <sys/epoll.h>
#include "socket.hpp"
#include "io/network/socket.hpp"
#include "utils/likely.hpp"
namespace io

View File

@ -1,6 +1,6 @@
#pragma once
#include "epoll.hpp"
#include "io/network/epoll.hpp"
#include "utils/crtp.hpp"
namespace io

View File

@ -1,6 +1,6 @@
#pragma once
#include "socket.hpp"
#include "io/network/socket.hpp"
namespace io
{

View File

@ -2,7 +2,7 @@
#include <openssl/ssl.h>
#include "stream_reader.hpp"
#include "io/network/stream_reader.hpp"
#include "logging/default.hpp"
namespace io

View File

@ -1,6 +1,6 @@
#pragma once
#include "stream_reader.hpp"
#include "io/network/stream_reader.hpp"
namespace io
{

View File

@ -13,7 +13,7 @@
#include <sys/epoll.h>
#include <errno.h>
#include "addrinfo.hpp"
#include "io/network/addrinfo.hpp"
#include "utils/likely.hpp"
#include "logging/default.hpp"
@ -48,8 +48,9 @@ public:
if(socket == -1)
return;
std::cout << "DELETING SOCKET" << std::endl;
#ifndef NDEBUG
logging::debug("DELETING SOCKET");
#endif
::close(socket);
}
@ -169,6 +170,7 @@ public:
int write(const byte* data, size_t len)
{
// TODO: use logger
#ifndef NDEBUG
std::stringstream stream;
@ -189,6 +191,7 @@ public:
}
protected:
Logger logger;
int socket;
};

View File

@ -1,6 +1,5 @@
#pragma once
#include "
namespace io
{

View File

@ -1,6 +1,6 @@
#pragma once
#include "event_listener.hpp"
#include "io/network/event_listener.hpp"
namespace io
{

View File

@ -1,6 +1,6 @@
#pragma once
#include "stream_listener.hpp"
#include "io/network/stream_listener.hpp"
#include "memory/literals.hpp"
namespace io

View File

@ -1,7 +1,7 @@
#pragma once
#include "log.hpp"
#include "logger.hpp"
#include "logging/log.hpp"
#include "logging/logger.hpp"
namespace logging
{
@ -16,6 +16,14 @@ void debug(Args&&... args)
debug_logger.debug(std::forward<Args>(args)...);
}
extern Logger info_logger;
template <class... Args>
void info(Args&&... args)
{
info_logger.info(std::forward<Args>(args)...);
}
void init_async();
void init_sync();

View File

@ -3,8 +3,8 @@
#include <cassert>
#include <fmt/format.h>
#include "log.hpp"
#include "levels.hpp"
#include "logging/log.hpp"
#include "logging/levels.hpp"
class Logger
{

View File

@ -8,9 +8,9 @@
#include "transactions/engine.hpp"
#include "mvcc/id.hpp"
#include "cre_exp.hpp"
#include "version.hpp"
#include "hints.hpp"
#include "mvcc/cre_exp.hpp"
#include "mvcc/version.hpp"
#include "mvcc/hints.hpp"
#include "storage/locking/record_lock.hpp"
// the mvcc implementation used here is very much like postgresql's

View File

@ -0,0 +1,49 @@
#pragma once
#include <string>
#include "exceptions/exceptions.hpp"
#include "logging/default.hpp"
#include "utils/string/join.hpp"
// TODO:
// * all libraries have to be compiled in the server compile time
// * compile command has to be generated
class CodeCompiler
{
public:
CodeCompiler() : logger(logging::log->logger("CodeCompiler")) {}
void compile(const std::string &in_file, const std::string &out_file)
{
// generate compile command
auto compile_command = utils::prints(
"clang++",
// "-std=c++1y -O2 -DNDEBUG", // compile flags
"-std=c++1y", // compile flags // TODO: load from config file
in_file, // input file
"-o", out_file, // ouput file
"-I./include", // include paths (TODO: parameter)
"-I../libs/fmt", // TODO: load from config
"-L./ -lmemgraph_pic",
"-shared -fPIC" // shared library flags
);
// synchronous call
auto compile_status = system(compile_command.c_str());
// if compilation has failed throw exception
if (compile_status == -1) {
throw QueryEngineException("Code compilation error. Generated code "
"is not compilable or compilation "
"settings are wrong");
}
logger.debug("SUCCESS: Query Code Compilation: {} -> {}", in_file,
out_file);
}
protected:
Logger logger;
};

View File

@ -7,16 +7,15 @@
#include "template_engine/engine.hpp"
#include "traverser/cpp_traverser.hpp"
#include "utils/string/file.hpp"
// TODO:
// * logger
#include <iostream>
#include "logging/default.hpp"
using std::string;
class CodeGenerator
{
public:
CodeGenerator() : logger(logging::log->logger("CodeGenerator")) {}
void generate_cpp(const std::string &query, const uint64_t stripped_hash,
const std::string &path)
{
@ -33,6 +32,7 @@ public:
try {
tree = compiler.syntax_tree(query);
} catch (const std::runtime_error &e) {
logger.error("Syntax error: {}", query);
throw QueryEngineException(std::string(e.what()));
}
@ -44,6 +44,7 @@ public:
} catch (const SemanticError &e) {
throw e;
} catch (const std::exception &e) {
logger.error("AST traversal error: {}", std::string(e.what()));
throw QueryEngineException("Unknown code generation error");
}
@ -54,12 +55,14 @@ public:
{"query", query},
{"code", cpp_traverser.code}});
// TODO: use logger, ifndef
std::cout << generated << std::endl;
logger.trace("generated code: {}", generated);
utils::write_file(generated, path);
}
protected:
Logger logger;
private:
template_engine::TemplateEngine template_engine;
ast::Ast tree;

View File

@ -15,6 +15,9 @@
using ParameterIndexKey::Type::InternalId;
using Direction = RelationshipData::Direction;
namespace
{
auto update_properties(const QueryActionData &action_data,
const std::string &name)
{
@ -29,3 +32,5 @@ auto update_properties(const QueryActionData &action_data,
return code;
}
}

View File

@ -2,6 +2,9 @@
#include "query_engine/code_generator/handlers/includes.hpp"
namespace
{
bool already_matched(CypherStateData &cypher_data, const std::string &name,
EntityType type)
{
@ -18,6 +21,8 @@ auto fetch_internal_index(const QueryActionData &action_data,
return action_data.parameter_index.at(ParameterIndexKey(InternalId, name));
}
}
auto match_query_action =
[](CypherStateData &cypher_data,
const QueryActionData &action_data) -> std::string {

View File

@ -19,10 +19,11 @@ auto return_query_action =
fmt::format("{} couldn't be found (RETURN clause).", entity));
}
if (element.is_entity_only()) {
code += code_line(code::print_properties, entity);
code += code_line(code::write_entity, entity);
} else if (element.is_projection()) {
auto &property = element.property;
code += code_line(code::print_property, entity, property);
code += code_line("// TODO: implement projection");
// auto &property = element.property;
// code += code_line(code::print_property, entity, property);
}
}

View File

@ -5,5 +5,5 @@
auto transaction_commit_action = [](CypherStateData &,
const QueryActionData &) -> std::string {
return code_line(code::transaction_commit) +
code_line(code::return_empty_result);
code_line(code::return_true);
};

Some files were not shown because too many files have changed in this diff Show More