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:
commit
02ec6dd401
@ -48,11 +48,11 @@ ExperimentalAutoDetectBinPacking: false
|
|||||||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||||
IncludeCategories:
|
IncludeCategories:
|
||||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||||
Priority: 2
|
|
||||||
- Regex: '^(<|"(gtest|isl|json)/)'
|
|
||||||
Priority: 3
|
|
||||||
- Regex: '.*'
|
|
||||||
Priority: 1
|
Priority: 1
|
||||||
|
- Regex: '^(<|"(gtest|isl|json)/)'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 3
|
||||||
IndentCaseLabels: false
|
IndentCaseLabels: false
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
IndentWrappedFunctionNames: false
|
IndentWrappedFunctionNames: false
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ memgraph
|
|||||||
tags
|
tags
|
||||||
.gdb_history
|
.gdb_history
|
||||||
Testing/
|
Testing/
|
||||||
|
ve/
|
||||||
|
299
CMakeLists.txt
299
CMakeLists.txt
@ -116,19 +116,22 @@ FILE(MAKE_DIRECTORY ${cypher_build_include_dir})
|
|||||||
FILE(RENAME ${CMAKE_BINARY_DIR}/cypher.h ${cypher_build_include_dir}/cypher.h)
|
FILE(RENAME ${CMAKE_BINARY_DIR}/cypher.h ${cypher_build_include_dir}/cypher.h)
|
||||||
|
|
||||||
# prepare template and destination folders for query engine (tests)
|
# prepare template and destination folders for query engine (tests)
|
||||||
|
# and memgraph server binary
|
||||||
# copy query_engine's templates file
|
# 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}/tests)
|
||||||
|
FILE(COPY ${src_dir}/query_engine/template DESTINATION ${CMAKE_BINARY_DIR})
|
||||||
# create destination folder for compiled queries
|
# create destination folder for compiled queries
|
||||||
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/compiled/cpu)
|
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
|
# TODO: filter header files, all files don't need to be copied
|
||||||
# they are all copied because query engine needs header files during
|
# they are all copied because query engine needs header files during
|
||||||
# query compilation
|
# query compilation
|
||||||
# TODO: make a function (REMOVE copy pasted part)
|
# TODO: make a function (REMOVE copy pasted part)
|
||||||
SUBDIRLIST(source_folders ${src_dir})
|
# SUBDIRLIST(source_folders ${src_dir})
|
||||||
foreach(source_folder ${source_folders})
|
# foreach(source_folder ${source_folders})
|
||||||
file(COPY ${src_dir}/${source_folder} DESTINATION ${build_include_dir})
|
# file(COPY ${src_dir}/${source_folder} DESTINATION ${build_include_dir})
|
||||||
endforeach()
|
# endforeach()
|
||||||
SUBDIRLIST(source_folders ${src_dir})
|
SUBDIRLIST(source_folders ${src_dir})
|
||||||
foreach(source_folder ${source_folders})
|
foreach(source_folder ${source_folders})
|
||||||
file(COPY ${src_dir}/${source_folder} DESTINATION ${test_src_dir})
|
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})
|
file(COPY ${include_dir}/${source_folder} DESTINATION ${test_include_dir})
|
||||||
endforeach()
|
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
|
# add all cpp file recursive into sourceFiles varibale
|
||||||
# FILE(GLOB_RECURSE sourceFiles ${src_dir}/*.cpp)
|
# FILE(GLOB_RECURSE sourceFiles ${src_dir}/*.cpp)
|
||||||
# print list of source files
|
# print list of source files
|
||||||
# MESSAGE(STATUS "All source files are: ${sourceFiles}")
|
# MESSAGE(STATUS "All source files are: ${sourceFiles}")
|
||||||
|
|
||||||
# compiler options
|
# debug flags
|
||||||
# SET(COMPILE_OPTIONS "-O2 -Wall -Werror -fmessage-length=0")
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
|
# 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
|
# release flags
|
||||||
option(RUNTIME_ASSERT "Enable runtime assertions" OFF)
|
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)
|
if(RUNTIME_ASSERT)
|
||||||
add_definitions( -DRUNTIME_ASSERT_ON )
|
add_definitions(-DRUNTIME_ASSERT_ON)
|
||||||
endif()
|
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)
|
if(THROW_EXCEPTION_ON_ERROR)
|
||||||
add_definitions( -DTHROW_EXCEPTION_ON_ERROR )
|
add_definitions(-DTHROW_EXCEPTION_ON_ERROR)
|
||||||
endif()
|
endif()
|
||||||
|
# -- assert -------------------------------------------------------------------
|
||||||
|
# -- ndebug -------------------------------------------------------------------
|
||||||
option(NDEBUG "No debug" OFF)
|
option(NDEBUG "No debug" OFF)
|
||||||
|
message(STATUS "NDEBUG: ${NDEBUG} (be careful CMAKE_BUILD_TYPE can also append this flag)")
|
||||||
if(NDEBUG)
|
if(NDEBUG)
|
||||||
add_definitions( -DNDEBUG )
|
add_definitions( -DNDEBUG )
|
||||||
endif()
|
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(${CMAKE_SOURCE_DIR}/include)
|
||||||
include_directories(${src_dir})
|
include_directories(${src_dir})
|
||||||
include_directories(${build_include_dir})
|
include_directories(${build_include_dir})
|
||||||
@ -173,6 +362,7 @@ include_directories(${lexertl_dir})
|
|||||||
include_directories(${libuv_source_dir}/include)
|
include_directories(${libuv_source_dir}/include)
|
||||||
include_directories(${rapidjson_source_dir}/include)
|
include_directories(${rapidjson_source_dir}/include)
|
||||||
include_directories(${r3_source_dir}/include)
|
include_directories(${r3_source_dir}/include)
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
# creates build/libcypher_lib.a
|
# creates build/libcypher_lib.a
|
||||||
add_library(cypher_lib STATIC ${CMAKE_BINARY_DIR}/cypher.cpp)
|
add_library(cypher_lib STATIC ${CMAKE_BINARY_DIR}/cypher.cpp)
|
||||||
@ -183,30 +373,24 @@ EXECUTE_PROCESS(
|
|||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/api
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/api
|
||||||
)
|
)
|
||||||
|
|
||||||
# # memgraph executable
|
# TODO: create separate static library from bolt code
|
||||||
# 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})
|
|
||||||
|
|
||||||
set(memgraph_src_files
|
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}/mvcc/id.cpp
|
||||||
${src_dir}/storage/vertices.cpp
|
${src_dir}/storage/vertices.cpp
|
||||||
|
${src_dir}/storage/edges.cpp
|
||||||
${src_dir}/storage/label/label.cpp
|
${src_dir}/storage/label/label.cpp
|
||||||
${src_dir}/storage/label/label_collection.cpp
|
${src_dir}/storage/label/label_collection.cpp
|
||||||
${src_dir}/storage/label/label_store.cpp
|
${src_dir}/storage/label/label_store.cpp
|
||||||
@ -221,6 +405,13 @@ set(memgraph_src_files
|
|||||||
${src_dir}/storage/vertex_accessor.cpp
|
${src_dir}/storage/vertex_accessor.cpp
|
||||||
${src_dir}/transactions/transaction.cpp
|
${src_dir}/transactions/transaction.cpp
|
||||||
${src_dir}/template_engine/engine.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
|
# 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)
|
set_property(TARGET memgraph_pic PROPERTY POSITION_INDEPENDENT_CODE TRUE)
|
||||||
|
|
||||||
# tests
|
# tests
|
||||||
enable_testing()
|
if (TESTS)
|
||||||
add_subdirectory(tests)
|
enable_testing()
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif()
|
||||||
|
|
||||||
# proof of concept
|
# proof of concepts
|
||||||
add_subdirectory(poc)
|
if (POC)
|
||||||
|
add_subdirectory(poc)
|
||||||
|
endif()
|
||||||
|
|
||||||
# memgraph build name
|
# memgraph build name
|
||||||
execute_process(
|
execute_process(
|
||||||
@ -248,8 +443,28 @@ execute_process(
|
|||||||
)
|
)
|
||||||
string(STRIP ${COMMIT_HASH} COMMIT_HASH)
|
string(STRIP ${COMMIT_HASH} COMMIT_HASH)
|
||||||
string(STRIP ${COMMIT_NO} COMMIT_NO)
|
string(STRIP ${COMMIT_NO} COMMIT_NO)
|
||||||
set(MEMGRAPH_BUILD_NAME "memgraph_${COMMIT_HASH}_${COMMIT_NO}")
|
set(MEMGRAPH_BUILD_NAME
|
||||||
message(STATUS ${CMAKE_BUILD_TYPE})
|
"memgraph_${COMMIT_HASH}_${COMMIT_NO}_${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
# memgraph main executable
|
# 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})
|
||||||
|
@ -20,6 +20,10 @@ on a 64 bit linux kernel.
|
|||||||
* lemon (parser generator)
|
* lemon (parser generator)
|
||||||
* catch (for compiling tests)
|
* catch (for compiling tests)
|
||||||
|
|
||||||
|
### Bolt
|
||||||
|
|
||||||
|
sudo apt-get install libssl-dev
|
||||||
|
|
||||||
## build
|
## build
|
||||||
```
|
```
|
||||||
cd build
|
cd build
|
||||||
@ -30,8 +34,9 @@ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DRUNTIME_ASSERT=OFF
|
|||||||
# -DCMAKE_CXX_COMPILER=clang++
|
# -DCMAKE_CXX_COMPILER=clang++
|
||||||
# -DRUNTIME_ASSERT=OFF
|
# -DRUNTIME_ASSERT=OFF
|
||||||
# -DTHROW_EXCEPTION_ON_ERROR=OFF
|
# -DTHROW_EXCEPTION_ON_ERROR=OFF
|
||||||
# -DCMAKE_BUILD_TYPE:STRING=Debug
|
|
||||||
# -DNDEBUG=ON
|
# -DNDEBUG=ON
|
||||||
|
# -DCMAKE_BUILD_TYPE:STRING=debug
|
||||||
|
# -DCMAKE_BUILD_TYPE:STRING=release
|
||||||
|
|
||||||
make
|
make
|
||||||
ctest
|
ctest
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "states.hpp"
|
#include "communication/bolt/v1/states.hpp"
|
||||||
#include "io/network/socket.hpp"
|
#include "io/network/socket.hpp"
|
||||||
|
#include "dbms/dbms.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
||||||
@ -19,6 +20,7 @@ public:
|
|||||||
void close(Session* session);
|
void close(Session* session);
|
||||||
|
|
||||||
States states;
|
States states;
|
||||||
|
Dbms dbms;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
14
include/communication/bolt/v1/config.hpp
Normal file
14
include/communication/bolt/v1/config.hpp
Normal 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 */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "bolt/v1/transport/bolt_encoder.hpp"
|
#include "communication/bolt/v1/transport/bolt_encoder.hpp"
|
||||||
#include "bolt/v1/packing/codes.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/edge_accessor.hpp"
|
||||||
|
|
||||||
#include "storage/model/properties/properties.hpp"
|
#include "storage/model/properties/properties.hpp"
|
||||||
@ -17,8 +17,12 @@ class BoltSerializer
|
|||||||
{
|
{
|
||||||
friend class Property;
|
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:
|
public:
|
||||||
BoltSerializer() {}
|
BoltSerializer(Stream& stream) : encoder(stream) {}
|
||||||
|
|
||||||
/* Serializes the vertex accessor into the packstream format
|
/* Serializes the vertex accessor into the packstream format
|
||||||
*
|
*
|
||||||
@ -51,8 +55,10 @@ public:
|
|||||||
|
|
||||||
encoder.write_map_header(props.size());
|
encoder.write_map_header(props.size());
|
||||||
|
|
||||||
for(auto& prop : props)
|
for(auto& prop : props) {
|
||||||
write(prop);
|
write(prop.first);
|
||||||
|
write(*prop.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Serializes the vertex accessor into the packstream format
|
/* Serializes the vertex accessor into the packstream format
|
||||||
@ -87,8 +93,10 @@ public:
|
|||||||
|
|
||||||
encoder.write_map_header(props.size());
|
encoder.write_map_header(props.size());
|
||||||
|
|
||||||
for(auto& prop : props)
|
for(auto& prop : props) {
|
||||||
write(prop);
|
write(prop.first);
|
||||||
|
write(*prop.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const Property& prop)
|
void write(const Property& prop)
|
||||||
@ -126,19 +134,24 @@ public:
|
|||||||
encoder.write_integer(prop.value);
|
encoder.write_integer(prop.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write(const std::string& value)
|
||||||
|
{
|
||||||
|
encoder.write_string(value);
|
||||||
|
}
|
||||||
|
|
||||||
void write(const String& prop)
|
void write(const String& prop)
|
||||||
{
|
{
|
||||||
encoder.write_string(prop.value);
|
encoder.write_string(prop.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
BoltEncoder<Stream> encoder;
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void handle(const T& prop)
|
void handle(const T& prop)
|
||||||
{
|
{
|
||||||
write(prop);
|
write(prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Stream& encoder;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
130
include/communication/bolt/v1/serialization/record_stream.hpp
Normal file
130
include/communication/bolt/v1/serialization/record_stream.hpp
Normal 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};
|
||||||
|
};
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "io/network/server.hpp"
|
#include "io/network/server.hpp"
|
||||||
#include "bolt/v1/bolt.hpp"
|
#include "communication/bolt/v1/bolt.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
@ -1,19 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iomanip>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <sstream>
|
#include <cstdio>
|
||||||
|
#include <iomanip>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "io/network/stream_reader.hpp"
|
#include "communication/bolt/v1/bolt.hpp"
|
||||||
|
#include "communication/bolt/v1/session.hpp"
|
||||||
#include "bolt/v1/bolt.hpp"
|
|
||||||
#include "bolt/v1/session.hpp"
|
|
||||||
|
|
||||||
#include "logging/default.hpp"
|
#include "logging/default.hpp"
|
||||||
|
#include "io/network/stream_reader.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
||||||
@ -28,19 +25,19 @@ class Worker : public io::StreamReader<Worker, Session>
|
|||||||
public:
|
public:
|
||||||
using sptr = std::shared_ptr<Worker>;
|
using sptr = std::shared_ptr<Worker>;
|
||||||
|
|
||||||
Worker(Bolt& bolt) : bolt(bolt)
|
Worker(Bolt &bolt) : bolt(bolt)
|
||||||
{
|
{
|
||||||
logger = logging::log->logger("Network");
|
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());
|
logger.trace("Accepting connection on socket {}", socket.id());
|
||||||
|
|
||||||
return *bolt.get().create_session(std::forward<io::Socket>(socket));
|
return *bolt.get().create_session(std::forward<io::Socket>(socket));
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Session&)
|
void on_error(Session &)
|
||||||
{
|
{
|
||||||
logger.trace("[on_error] errno = {}", errno);
|
logger.trace("[on_error] errno = {}", errno);
|
||||||
|
|
||||||
@ -50,43 +47,39 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
logger.error("Error occured in this session");
|
logger.error("Error occured in this session");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_wait_timeout() {}
|
void on_wait_timeout() {}
|
||||||
|
|
||||||
Buffer on_alloc(Session&)
|
Buffer on_alloc(Session &)
|
||||||
{
|
{
|
||||||
/* logger.trace("[on_alloc] Allocating {}B", sizeof buf); */
|
/* 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);
|
logger.trace("[on_read] Received {}B", buf.len);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
std::stringstream stream;
|
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]));
|
stream << fmt::format("{:02X} ", static_cast<byte>(buf.ptr[i]));
|
||||||
|
|
||||||
logger.trace("[on_read] {}", stream.str());
|
logger.trace("[on_read] {}", stream.str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
session.execute(reinterpret_cast<const byte *>(buf.ptr), buf.len);
|
||||||
session.execute(reinterpret_cast<const byte*>(buf.ptr), buf.len);
|
} catch (const std::exception &e) {
|
||||||
}
|
|
||||||
catch(const std::exception& e)
|
|
||||||
{
|
|
||||||
logger.error("Error occured while executing statement.");
|
logger.error("Error occured while executing statement.");
|
||||||
logger.error("{}", e.what());
|
logger.error("{}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_close(Session& session)
|
void on_close(Session &session)
|
||||||
{
|
{
|
||||||
logger.trace("[on_close] Client closed the connection");
|
logger.trace("[on_close] Client closed the connection");
|
||||||
session.close();
|
session.close();
|
||||||
@ -100,13 +93,12 @@ protected:
|
|||||||
Logger logger;
|
Logger logger;
|
||||||
std::thread thread;
|
std::thread thread;
|
||||||
|
|
||||||
void start(std::atomic<bool>& alive)
|
void start(std::atomic<bool> &alive)
|
||||||
{
|
{
|
||||||
thread = std::thread([&, this]() {
|
thread = std::thread([&, this]() {
|
||||||
while(alive)
|
while (alive)
|
||||||
wait_and_process_events();
|
wait_and_process_events();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
43
include/communication/bolt/v1/session.hpp
Normal file
43
include/communication/bolt/v1/session.hpp
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "states/state.hpp"
|
#include "communication/bolt/v1/states/state.hpp"
|
||||||
#include "logging/log.hpp"
|
#include "logging/log.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
15
include/communication/bolt/v1/states/error.hpp
Normal file
15
include/communication/bolt/v1/states/error.hpp
Normal 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "bolt/v1/states/state.hpp"
|
#include "communication/bolt/v1/states/state.hpp"
|
||||||
#include "bolt/v1/session.hpp"
|
#include "communication/bolt/v1/session.hpp"
|
||||||
|
#include "query_engine/query_engine.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
||||||
@ -35,6 +36,10 @@ protected:
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void discard_all(Session& session);
|
void discard_all(Session& session);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QueryEngine query_engine;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "bolt/v1/states/state.hpp"
|
#include "communication/bolt/v1/states/state.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "bolt/v1/states/message_parser.hpp"
|
#include "communication/bolt/v1/states/message_parser.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "state.hpp"
|
#include "communication/bolt/v1/session.hpp"
|
||||||
|
#include "communication/bolt/v1/states/state.hpp"
|
||||||
#include "utils/crtp.hpp"
|
#include "utils/crtp.hpp"
|
||||||
|
|
||||||
#include "bolt/v1/session.hpp"
|
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -12,10 +11,9 @@ template <class Derived>
|
|||||||
class MessageParser : public State, public Crtp<Derived>
|
class MessageParser : public State, public Crtp<Derived>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MessageParser(Logger&& logger)
|
MessageParser(Logger &&logger) : logger(std::forward<Logger>(logger)) {}
|
||||||
: logger(std::forward<Logger>(logger)) {}
|
|
||||||
|
|
||||||
State* run(Session& session) override final
|
State *run(Session &session) override final
|
||||||
{
|
{
|
||||||
typename Derived::Message message;
|
typename Derived::Message message;
|
||||||
|
|
||||||
@ -23,8 +21,7 @@ public:
|
|||||||
auto next = this->derived().parse(session, message);
|
auto next = this->derived().parse(session, message);
|
||||||
|
|
||||||
// return next state if parsing was unsuccessful (i.e. error state)
|
// return next state if parsing was unsuccessful (i.e. error state)
|
||||||
if(next != &this->derived())
|
if (next != &this->derived()) return next;
|
||||||
return next;
|
|
||||||
|
|
||||||
logger.debug("Executing state");
|
logger.debug("Executing state");
|
||||||
return this->derived().execute(session, message);
|
return this->derived().execute(session, message);
|
||||||
@ -33,5 +30,4 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
Logger logger;
|
Logger logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "buffer.hpp"
|
#include "communication/bolt/v1/transport/buffer.hpp"
|
||||||
#include "chunked_decoder.hpp"
|
#include "communication/bolt/v1/transport/chunked_decoder.hpp"
|
||||||
|
|
||||||
#include "utils/types/byte.hpp"
|
#include "utils/types/byte.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
@ -11,15 +10,15 @@ namespace bolt
|
|||||||
class BoltDecoder
|
class BoltDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void handshake(const byte*& data, size_t len);
|
void handshake(const byte *&data, size_t len);
|
||||||
bool decode(const byte*& data, size_t len);
|
bool decode(const byte *&data, size_t len);
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
byte peek() const;
|
byte peek() const;
|
||||||
byte read_byte();
|
byte read_byte();
|
||||||
void read_bytes(void* dest, size_t n);
|
void read_bytes(void *dest, size_t n);
|
||||||
|
|
||||||
int16_t read_int16();
|
int16_t read_int16();
|
||||||
uint16_t read_uint16();
|
uint16_t read_uint16();
|
||||||
@ -36,10 +35,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
ChunkedDecoder<Buffer> decoder {buffer};
|
ChunkedDecoder<Buffer> decoder{buffer};
|
||||||
size_t pos {0};
|
size_t pos{0};
|
||||||
|
|
||||||
const byte* raw() const;
|
const byte *raw() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "bolt/v1/packing/codes.hpp"
|
#include "communication/bolt/v1/packing/codes.hpp"
|
||||||
#include "bolt/v1/messaging/codes.hpp"
|
#include "communication/bolt/v1/messaging/codes.hpp"
|
||||||
#include "utils/types/byte.hpp"
|
#include "utils/types/byte.hpp"
|
||||||
#include "utils/bswap.hpp"
|
#include "utils/bswap.hpp"
|
||||||
|
#include "logging/default.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
||||||
@ -22,7 +23,10 @@ class BoltEncoder
|
|||||||
static constexpr int64_t minus_2_to_the_31 = -2147483648L;
|
static constexpr int64_t minus_2_to_the_31 = -2147483648L;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BoltEncoder(Stream& stream) : stream(stream) {}
|
BoltEncoder(Stream& stream) : stream(stream)
|
||||||
|
{
|
||||||
|
logger = logging::log->logger("Bolt Encoder");
|
||||||
|
}
|
||||||
|
|
||||||
void flush()
|
void flush()
|
||||||
{
|
{
|
||||||
@ -36,6 +40,7 @@ public:
|
|||||||
|
|
||||||
void write_byte(byte value)
|
void write_byte(byte value)
|
||||||
{
|
{
|
||||||
|
logger.trace("write byte: {}", value);
|
||||||
stream.write(value);
|
stream.write(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,6 +264,9 @@ public:
|
|||||||
write_empty_map();
|
write_empty_map();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Logger logger;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
};
|
};
|
@ -4,14 +4,14 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "utils/types/byte.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
||||||
|
|
||||||
class Buffer
|
class Buffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using byte = uint8_t;
|
|
||||||
|
|
||||||
void write(const byte* data, size_t len);
|
void write(const byte* data, size_t len);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
74
include/communication/bolt/v1/transport/chunked_buffer.hpp
Normal file
74
include/communication/bolt/v1/transport/chunked_buffer.hpp
Normal 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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include "utils/exceptions/basic_exception.hpp"
|
|
||||||
#include "utils/likely.hpp"
|
|
||||||
|
|
||||||
#include "logging/default.hpp"
|
#include "logging/default.hpp"
|
||||||
|
#include "utils/exceptions/basic_exception.hpp"
|
||||||
|
#include "utils/likely.hpp"
|
||||||
|
#include "utils/types/byte.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
||||||
@ -22,8 +22,6 @@ public:
|
|||||||
using BasicException::BasicException;
|
using BasicException::BasicException;
|
||||||
};
|
};
|
||||||
|
|
||||||
using byte = unsigned char;
|
|
||||||
|
|
||||||
ChunkedDecoder(Stream& stream) : stream(stream) {}
|
ChunkedDecoder(Stream& stream) : stream(stream) {}
|
||||||
|
|
||||||
/* Decode chunked data
|
/* Decode chunked data
|
||||||
@ -33,14 +31,14 @@ public:
|
|||||||
* |Header| Data ||Header| Data || ... || End |
|
* |Header| Data ||Header| Data || ... || End |
|
||||||
* | 2B | size bytes || 2B | size bytes || ... ||00 00|
|
* | 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
|
// get size from first two bytes in the chunk
|
||||||
auto size = get_size(chunk);
|
auto size = get_size(chunk);
|
||||||
|
|
||||||
if(UNLIKELY(size + 2 > n))
|
if (UNLIKELY(size + 2 > n))
|
||||||
throw DecoderError("Chunk size larger than available data.");
|
throw DecoderError("Chunk size larger than available data.");
|
||||||
|
|
||||||
// advance chunk to pass those two bytes
|
// advance chunk to pass those two bytes
|
||||||
@ -48,8 +46,7 @@ public:
|
|||||||
n -= 2;
|
n -= 2;
|
||||||
|
|
||||||
// if chunk size is 0, we're done!
|
// if chunk size is 0, we're done!
|
||||||
if(size == 0)
|
if (size == 0) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
stream.get().write(chunk, size);
|
stream.get().write(chunk, size);
|
||||||
|
|
||||||
@ -60,18 +57,14 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator()(const byte*& chunk, size_t n)
|
bool operator()(const byte *&chunk, size_t n) { return decode(chunk, n); }
|
||||||
{
|
|
||||||
return decode(chunk, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::reference_wrapper<Stream> stream;
|
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];
|
return size_t(chunk[0]) << 8 | chunk[1];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -5,6 +5,8 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "utils/likely.hpp"
|
#include "utils/likely.hpp"
|
||||||
|
#include "communication/bolt/v1/config.hpp"
|
||||||
|
#include "logging/default.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
||||||
@ -12,13 +14,16 @@ namespace bolt
|
|||||||
template <class Stream>
|
template <class Stream>
|
||||||
class ChunkedEncoder
|
class ChunkedEncoder
|
||||||
{
|
{
|
||||||
static constexpr size_t N = 65535;
|
static constexpr size_t N = bolt::config::N;
|
||||||
static constexpr size_t C = N + 2 /* end mark */;
|
static constexpr size_t C = bolt::config::C;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using byte = unsigned char;
|
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;
|
static constexpr size_t chunk_size = N - 2;
|
||||||
|
|
||||||
@ -32,6 +37,8 @@ public:
|
|||||||
|
|
||||||
void write(const byte* values, size_t n)
|
void write(const byte* values, size_t n)
|
||||||
{
|
{
|
||||||
|
logger.trace("write {} bytes", n);
|
||||||
|
|
||||||
while(n > 0)
|
while(n > 0)
|
||||||
{
|
{
|
||||||
auto size = n < N - pos ? n : N - pos;
|
auto size = n < N - pos ? n : N - pos;
|
||||||
@ -58,6 +65,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Logger logger;
|
||||||
std::reference_wrapper<Stream> stream;
|
std::reference_wrapper<Stream> stream;
|
||||||
|
|
||||||
std::array<byte, C> chunk;
|
std::array<byte, C> chunk;
|
||||||
@ -65,7 +73,9 @@ private:
|
|||||||
|
|
||||||
void end_chunk()
|
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();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include "io/network/socket.hpp"
|
#include "io/network/socket.hpp"
|
||||||
#include "stream_error.hpp"
|
#include "communication/bolt/v1/transport/stream_error.hpp"
|
||||||
|
|
||||||
namespace bolt
|
namespace bolt
|
||||||
{
|
{
|
9
include/communication/communication.hpp
Normal file
9
include/communication/communication.hpp
Normal 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>;
|
||||||
|
}
|
4
include/communication/gate/init.hpp
Normal file
4
include/communication/gate/init.hpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* Memgraph Communication protocol
|
||||||
|
* gate is the first name proposal for the protocol */
|
3
include/communication/http/init.hpp
Normal file
3
include/communication/http/init.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* HTTP & HTTPS implementation */
|
@ -16,7 +16,6 @@ public:
|
|||||||
|
|
||||||
friend constexpr bool operator<(const Item &lhs, const Item &rhs)
|
friend constexpr bool operator<(const Item &lhs, const Item &rhs)
|
||||||
{
|
{
|
||||||
std::pair<const K, T> *a;
|
|
||||||
return lhs.first < rhs.first;
|
return lhs.first < rhs.first;
|
||||||
}
|
}
|
||||||
|
|
@ -6,11 +6,14 @@
|
|||||||
#include "memory/freelist.hpp"
|
#include "memory/freelist.hpp"
|
||||||
#include "memory/lazy_gc.hpp"
|
#include "memory/lazy_gc.hpp"
|
||||||
#include "threading/sync/spinlock.hpp"
|
#include "threading/sync/spinlock.hpp"
|
||||||
|
#include "logging/default.hpp"
|
||||||
|
|
||||||
template <class T, class lock_t = SpinLock>
|
template <class T, class lock_t = SpinLock>
|
||||||
class SkiplistGC : public LazyGC<SkiplistGC<T, lock_t>, lock_t>
|
class SkiplistGC : public LazyGC<SkiplistGC<T, lock_t>, lock_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
SkiplistGC() : logger(logging::log->logger("SkiplistGC")) {}
|
||||||
|
|
||||||
// release_ref method should be called by a thread
|
// release_ref method should be called by a thread
|
||||||
// when the thread finish it job over object
|
// when the thread finish it job over object
|
||||||
// which has to be lazy cleaned
|
// which has to be lazy cleaned
|
||||||
@ -33,9 +36,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (local_freelist.size() > 0) {
|
if (local_freelist.size() > 0) {
|
||||||
std::cout << "GC started" << std::endl;
|
logger.trace("GC started");
|
||||||
std::cout << "Local list size: " << local_freelist.size()
|
logger.trace("Local list size: {}", local_freelist.size());
|
||||||
<< std::endl;
|
|
||||||
long long counter = 0;
|
long long counter = 0;
|
||||||
// destroy all elements from local_freelist
|
// destroy all elements from local_freelist
|
||||||
for (auto element : local_freelist) {
|
for (auto element : local_freelist) {
|
||||||
@ -45,13 +47,15 @@ public:
|
|||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Number of destroyed elements " << counter
|
logger.trace("Number of destroyed elements: {}", counter);
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void collect(T *node) { freelist.add(node); }
|
void collect(T *node) { freelist.add(node); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Logger logger;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FreeList<T> freelist;
|
FreeList<T> freelist;
|
||||||
};
|
};
|
@ -9,12 +9,18 @@ class Db
|
|||||||
public:
|
public:
|
||||||
using sptr = std::shared_ptr<Db>;
|
using sptr = std::shared_ptr<Db>;
|
||||||
|
|
||||||
|
Db() = default;
|
||||||
|
Db(const std::string& name) : name_(name) {}
|
||||||
|
Db(const Db& db) = delete;
|
||||||
|
|
||||||
Graph graph;
|
Graph graph;
|
||||||
tx::Engine tx_engine;
|
tx::Engine tx_engine;
|
||||||
|
|
||||||
// only for test purposes
|
std::string& name()
|
||||||
std::string identifier()
|
|
||||||
{
|
{
|
||||||
return "memgraph";
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name_;
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#include "network_error.hpp"
|
#include "io/network/network_error.hpp"
|
||||||
#include "utils/underlying_cast.hpp"
|
#include "utils/underlying_cast.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "stream_reader.hpp"
|
#include "io/network/stream_reader.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
@ -3,7 +3,7 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
|
|
||||||
#include "socket.hpp"
|
#include "io/network/socket.hpp"
|
||||||
#include "utils/likely.hpp"
|
#include "utils/likely.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "epoll.hpp"
|
#include "io/network/epoll.hpp"
|
||||||
#include "utils/crtp.hpp"
|
#include "utils/crtp.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "socket.hpp"
|
#include "io/network/socket.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
#include "stream_reader.hpp"
|
#include "io/network/stream_reader.hpp"
|
||||||
#include "logging/default.hpp"
|
#include "logging/default.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "stream_reader.hpp"
|
#include "io/network/stream_reader.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
@ -13,7 +13,7 @@
|
|||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "addrinfo.hpp"
|
#include "io/network/addrinfo.hpp"
|
||||||
#include "utils/likely.hpp"
|
#include "utils/likely.hpp"
|
||||||
|
|
||||||
#include "logging/default.hpp"
|
#include "logging/default.hpp"
|
||||||
@ -48,8 +48,9 @@ public:
|
|||||||
if(socket == -1)
|
if(socket == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
std::cout << "DELETING SOCKET" << std::endl;
|
logging::debug("DELETING SOCKET");
|
||||||
|
#endif
|
||||||
|
|
||||||
::close(socket);
|
::close(socket);
|
||||||
}
|
}
|
||||||
@ -169,6 +170,7 @@ public:
|
|||||||
|
|
||||||
int write(const byte* data, size_t len)
|
int write(const byte* data, size_t len)
|
||||||
{
|
{
|
||||||
|
// TODO: use logger
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
||||||
@ -189,6 +191,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Logger logger;
|
||||||
int socket;
|
int socket;
|
||||||
};
|
};
|
||||||
|
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "
|
|
||||||
|
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "event_listener.hpp"
|
#include "io/network/event_listener.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "stream_listener.hpp"
|
#include "io/network/stream_listener.hpp"
|
||||||
#include "memory/literals.hpp"
|
#include "memory/literals.hpp"
|
||||||
|
|
||||||
namespace io
|
namespace io
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "log.hpp"
|
#include "logging/log.hpp"
|
||||||
#include "logger.hpp"
|
#include "logging/logger.hpp"
|
||||||
|
|
||||||
namespace logging
|
namespace logging
|
||||||
{
|
{
|
||||||
@ -16,6 +16,14 @@ void debug(Args&&... args)
|
|||||||
debug_logger.debug(std::forward<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_async();
|
||||||
void init_sync();
|
void init_sync();
|
||||||
|
|
@ -3,8 +3,8 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "log.hpp"
|
#include "logging/log.hpp"
|
||||||
#include "levels.hpp"
|
#include "logging/levels.hpp"
|
||||||
|
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
@ -8,9 +8,9 @@
|
|||||||
#include "transactions/engine.hpp"
|
#include "transactions/engine.hpp"
|
||||||
|
|
||||||
#include "mvcc/id.hpp"
|
#include "mvcc/id.hpp"
|
||||||
#include "cre_exp.hpp"
|
#include "mvcc/cre_exp.hpp"
|
||||||
#include "version.hpp"
|
#include "mvcc/version.hpp"
|
||||||
#include "hints.hpp"
|
#include "mvcc/hints.hpp"
|
||||||
#include "storage/locking/record_lock.hpp"
|
#include "storage/locking/record_lock.hpp"
|
||||||
|
|
||||||
// the mvcc implementation used here is very much like postgresql's
|
// the mvcc implementation used here is very much like postgresql's
|
49
include/query_engine/code_compiler.hpp
Normal file
49
include/query_engine/code_compiler.hpp
Normal 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;
|
||||||
|
};
|
@ -7,16 +7,15 @@
|
|||||||
#include "template_engine/engine.hpp"
|
#include "template_engine/engine.hpp"
|
||||||
#include "traverser/cpp_traverser.hpp"
|
#include "traverser/cpp_traverser.hpp"
|
||||||
#include "utils/string/file.hpp"
|
#include "utils/string/file.hpp"
|
||||||
|
#include "logging/default.hpp"
|
||||||
// TODO:
|
|
||||||
// * logger
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
class CodeGenerator
|
class CodeGenerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CodeGenerator() : logger(logging::log->logger("CodeGenerator")) {}
|
||||||
|
|
||||||
void generate_cpp(const std::string &query, const uint64_t stripped_hash,
|
void generate_cpp(const std::string &query, const uint64_t stripped_hash,
|
||||||
const std::string &path)
|
const std::string &path)
|
||||||
{
|
{
|
||||||
@ -33,6 +32,7 @@ public:
|
|||||||
try {
|
try {
|
||||||
tree = compiler.syntax_tree(query);
|
tree = compiler.syntax_tree(query);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
|
logger.error("Syntax error: {}", query);
|
||||||
throw QueryEngineException(std::string(e.what()));
|
throw QueryEngineException(std::string(e.what()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ public:
|
|||||||
} catch (const SemanticError &e) {
|
} catch (const SemanticError &e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
|
logger.error("AST traversal error: {}", std::string(e.what()));
|
||||||
throw QueryEngineException("Unknown code generation error");
|
throw QueryEngineException("Unknown code generation error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,12 +55,14 @@ public:
|
|||||||
{"query", query},
|
{"query", query},
|
||||||
{"code", cpp_traverser.code}});
|
{"code", cpp_traverser.code}});
|
||||||
|
|
||||||
// TODO: use logger, ifndef
|
logger.trace("generated code: {}", generated);
|
||||||
std::cout << generated << std::endl;
|
|
||||||
|
|
||||||
utils::write_file(generated, path);
|
utils::write_file(generated, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Logger logger;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template_engine::TemplateEngine template_engine;
|
template_engine::TemplateEngine template_engine;
|
||||||
ast::Ast tree;
|
ast::Ast tree;
|
@ -15,6 +15,9 @@
|
|||||||
using ParameterIndexKey::Type::InternalId;
|
using ParameterIndexKey::Type::InternalId;
|
||||||
using Direction = RelationshipData::Direction;
|
using Direction = RelationshipData::Direction;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
auto update_properties(const QueryActionData &action_data,
|
auto update_properties(const QueryActionData &action_data,
|
||||||
const std::string &name)
|
const std::string &name)
|
||||||
{
|
{
|
||||||
@ -29,3 +32,5 @@ auto update_properties(const QueryActionData &action_data,
|
|||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include "query_engine/code_generator/handlers/includes.hpp"
|
#include "query_engine/code_generator/handlers/includes.hpp"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
bool already_matched(CypherStateData &cypher_data, const std::string &name,
|
bool already_matched(CypherStateData &cypher_data, const std::string &name,
|
||||||
EntityType type)
|
EntityType type)
|
||||||
{
|
{
|
||||||
@ -18,6 +21,8 @@ auto fetch_internal_index(const QueryActionData &action_data,
|
|||||||
return action_data.parameter_index.at(ParameterIndexKey(InternalId, name));
|
return action_data.parameter_index.at(ParameterIndexKey(InternalId, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
auto match_query_action =
|
auto match_query_action =
|
||||||
[](CypherStateData &cypher_data,
|
[](CypherStateData &cypher_data,
|
||||||
const QueryActionData &action_data) -> std::string {
|
const QueryActionData &action_data) -> std::string {
|
@ -19,10 +19,11 @@ auto return_query_action =
|
|||||||
fmt::format("{} couldn't be found (RETURN clause).", entity));
|
fmt::format("{} couldn't be found (RETURN clause).", entity));
|
||||||
}
|
}
|
||||||
if (element.is_entity_only()) {
|
if (element.is_entity_only()) {
|
||||||
code += code_line(code::print_properties, entity);
|
code += code_line(code::write_entity, entity);
|
||||||
} else if (element.is_projection()) {
|
} else if (element.is_projection()) {
|
||||||
auto &property = element.property;
|
code += code_line("// TODO: implement projection");
|
||||||
code += code_line(code::print_property, entity, property);
|
// auto &property = element.property;
|
||||||
|
// code += code_line(code::print_property, entity, property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,5 +5,5 @@
|
|||||||
auto transaction_commit_action = [](CypherStateData &,
|
auto transaction_commit_action = [](CypherStateData &,
|
||||||
const QueryActionData &) -> std::string {
|
const QueryActionData &) -> std::string {
|
||||||
return code_line(code::transaction_commit) +
|
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
Loading…
Reference in New Issue
Block a user