diff --git a/.clang-format b/.clang-format index a96c05f11..d34cbdb68 100644 --- a/.clang-format +++ b/.clang-format @@ -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 diff --git a/.gitignore b/.gitignore index 320fbc5c7..73bd3a458 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ memgraph tags .gdb_history Testing/ +ve/ diff --git a/CMakeLists.txt b/CMakeLists.txt index f62acbd98..74df3c068 100644 --- a/CMakeLists.txt +++ b/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) # 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}) diff --git a/README.md b/README.md index dedb5b959..8b7325980 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/bolt/v1/bolt.hpp b/include/communication/bolt/v1/bolt.hpp similarity index 75% rename from src/bolt/v1/bolt.hpp rename to include/communication/bolt/v1/bolt.hpp index 3b42a200e..850aa5195 100644 --- a/src/bolt/v1/bolt.hpp +++ b/include/communication/bolt/v1/bolt.hpp @@ -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; }; } diff --git a/include/communication/bolt/v1/config.hpp b/include/communication/bolt/v1/config.hpp new file mode 100644 index 000000000..afd953f91 --- /dev/null +++ b/include/communication/bolt/v1/config.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace bolt +{ + +namespace config +{ + static constexpr size_t N = 65535; /* chunk size */ + static constexpr size_t C = N + 2; /* end mark */ +} + +} diff --git a/src/bolt/v1/messaging/codes.hpp b/include/communication/bolt/v1/messaging/codes.hpp similarity index 100% rename from src/bolt/v1/messaging/codes.hpp rename to include/communication/bolt/v1/messaging/codes.hpp diff --git a/src/bolt/v1/packing/codes.hpp b/include/communication/bolt/v1/packing/codes.hpp similarity index 100% rename from src/bolt/v1/packing/codes.hpp rename to include/communication/bolt/v1/packing/codes.hpp diff --git a/src/bolt/v1/packing/types.hpp b/include/communication/bolt/v1/packing/types.hpp similarity index 100% rename from src/bolt/v1/packing/types.hpp rename to include/communication/bolt/v1/packing/types.hpp diff --git a/src/bolt/v1/serialization/bolt_serializer.hpp b/include/communication/bolt/v1/serialization/bolt_serializer.hpp similarity index 81% rename from src/bolt/v1/serialization/bolt_serializer.hpp rename to include/communication/bolt/v1/serialization/bolt_serializer.hpp index be791817b..6d7248b6f 100644 --- a/src/bolt/v1/serialization/bolt_serializer.hpp +++ b/include/communication/bolt/v1/serialization/bolt_serializer.hpp @@ -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 + // 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 encoder; - template void handle(const T& prop) { write(prop); } + +protected: + Stream& encoder; }; } diff --git a/include/communication/bolt/v1/serialization/record_stream.hpp b/include/communication/bolt/v1/serialization/record_stream.hpp new file mode 100644 index 000000000..aa4ab438f --- /dev/null +++ b/include/communication/bolt/v1/serialization/record_stream.hpp @@ -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 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 &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; + using chunked_encoder_t = ChunkedEncoder; + using bolt_encoder_t = BoltEncoder; + using bolt_serializer_t = BoltSerializer; + + 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}; +}; +} diff --git a/src/bolt/v1/server/server.hpp b/include/communication/bolt/v1/server/server.hpp similarity index 96% rename from src/bolt/v1/server/server.hpp rename to include/communication/bolt/v1/server/server.hpp index ea61154aa..a6493ea2d 100644 --- a/src/bolt/v1/server/server.hpp +++ b/include/communication/bolt/v1/server/server.hpp @@ -7,7 +7,7 @@ #include #include "io/network/server.hpp" -#include "bolt/v1/bolt.hpp" +#include "communication/bolt/v1/bolt.hpp" namespace bolt { diff --git a/src/bolt/v1/server/worker.hpp b/include/communication/bolt/v1/server/worker.hpp similarity index 73% rename from src/bolt/v1/server/worker.hpp rename to include/communication/bolt/v1/server/worker.hpp index eb475e135..7a6ac0183 100644 --- a/src/bolt/v1/server/worker.hpp +++ b/include/communication/bolt/v1/server/worker.hpp @@ -1,19 +1,16 @@ #pragma once -#include -#include #include -#include - +#include +#include #include +#include #include -#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 public: using sptr = std::shared_ptr; - 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(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(buf.ptr[i])); logger.trace("[on_read] {}", stream.str()); #endif - try - { - session.execute(reinterpret_cast(buf.ptr), buf.len); - } - catch(const std::exception& e) - { + try { + session.execute(reinterpret_cast(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& alive) + void start(std::atomic &alive) { thread = std::thread([&, this]() { - while(alive) + while (alive) wait_and_process_events(); }); } }; - } diff --git a/include/communication/bolt/v1/session.hpp b/include/communication/bolt/v1/session.hpp new file mode 100644 index 000000000..b0c5a147f --- /dev/null +++ b/include/communication/bolt/v1/session.hpp @@ -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 +{ +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; +}; +} diff --git a/src/bolt/v1/states.hpp b/include/communication/bolt/v1/states.hpp similarity index 80% rename from src/bolt/v1/states.hpp rename to include/communication/bolt/v1/states.hpp index be4cbc344..d15a1b747 100644 --- a/src/bolt/v1/states.hpp +++ b/include/communication/bolt/v1/states.hpp @@ -1,6 +1,6 @@ #pragma once -#include "states/state.hpp" +#include "communication/bolt/v1/states/state.hpp" #include "logging/log.hpp" namespace bolt diff --git a/include/communication/bolt/v1/states/error.hpp b/include/communication/bolt/v1/states/error.hpp new file mode 100644 index 000000000..0748fc5e5 --- /dev/null +++ b/include/communication/bolt/v1/states/error.hpp @@ -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; +}; + +} diff --git a/src/bolt/v1/states/executor.hpp b/include/communication/bolt/v1/states/executor.hpp similarity index 74% rename from src/bolt/v1/states/executor.hpp rename to include/communication/bolt/v1/states/executor.hpp index 5b1127a3a..649655fbb 100644 --- a/src/bolt/v1/states/executor.hpp +++ b/include/communication/bolt/v1/states/executor.hpp @@ -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; + }; } diff --git a/src/bolt/v1/states/handshake.hpp b/include/communication/bolt/v1/states/handshake.hpp similarity index 71% rename from src/bolt/v1/states/handshake.hpp rename to include/communication/bolt/v1/states/handshake.hpp index fe6d7052a..8ca4c2e10 100644 --- a/src/bolt/v1/states/handshake.hpp +++ b/include/communication/bolt/v1/states/handshake.hpp @@ -1,6 +1,6 @@ #pragma once -#include "bolt/v1/states/state.hpp" +#include "communication/bolt/v1/states/state.hpp" namespace bolt { diff --git a/src/bolt/v1/states/init.hpp b/include/communication/bolt/v1/states/init.hpp similarity index 82% rename from src/bolt/v1/states/init.hpp rename to include/communication/bolt/v1/states/init.hpp index dce0c2b83..b471e078d 100644 --- a/src/bolt/v1/states/init.hpp +++ b/include/communication/bolt/v1/states/init.hpp @@ -1,6 +1,6 @@ #pragma once -#include "bolt/v1/states/message_parser.hpp" +#include "communication/bolt/v1/states/message_parser.hpp" namespace bolt { diff --git a/src/bolt/v1/states/message_parser.hpp b/include/communication/bolt/v1/states/message_parser.hpp similarity index 65% rename from src/bolt/v1/states/message_parser.hpp rename to include/communication/bolt/v1/states/message_parser.hpp index ff8b6952c..0c86753b1 100644 --- a/src/bolt/v1/states/message_parser.hpp +++ b/include/communication/bolt/v1/states/message_parser.hpp @@ -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 MessageParser : public State, public Crtp { public: - MessageParser(Logger&& logger) - : logger(std::forward(logger)) {} + MessageParser(Logger &&logger) : logger(std::forward(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; }; - } diff --git a/src/bolt/v1/states/state.hpp b/include/communication/bolt/v1/states/state.hpp similarity index 100% rename from src/bolt/v1/states/state.hpp rename to include/communication/bolt/v1/states/state.hpp diff --git a/src/bolt/v1/transport/bolt_decoder.hpp b/include/communication/bolt/v1/transport/bolt_decoder.hpp similarity index 55% rename from src/bolt/v1/transport/bolt_decoder.hpp rename to include/communication/bolt/v1/transport/bolt_decoder.hpp index c326f0548..d80f3dc31 100644 --- a/src/bolt/v1/transport/bolt_decoder.hpp +++ b/include/communication/bolt/v1/transport/bolt_decoder.hpp @@ -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 decoder {buffer}; - size_t pos {0}; + ChunkedDecoder decoder{buffer}; + size_t pos{0}; - const byte* raw() const; + const byte *raw() const; }; - } diff --git a/src/bolt/v1/transport/bolt_encoder.hpp b/include/communication/bolt/v1/transport/bolt_encoder.hpp similarity index 94% rename from src/bolt/v1/transport/bolt_encoder.hpp rename to include/communication/bolt/v1/transport/bolt_encoder.hpp index fe26349b2..cdeb8ab9a 100644 --- a/src/bolt/v1/transport/bolt_encoder.hpp +++ b/include/communication/bolt/v1/transport/bolt_encoder.hpp @@ -2,10 +2,11 @@ #include -#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; }; diff --git a/src/bolt/v1/transport/buffer.hpp b/include/communication/bolt/v1/transport/buffer.hpp similarity index 93% rename from src/bolt/v1/transport/buffer.hpp rename to include/communication/bolt/v1/transport/buffer.hpp index ae44c7f19..51dc89ce6 100644 --- a/src/bolt/v1/transport/buffer.hpp +++ b/include/communication/bolt/v1/transport/buffer.hpp @@ -4,14 +4,14 @@ #include #include +#include "utils/types/byte.hpp" + namespace bolt { class Buffer { public: - using byte = uint8_t; - void write(const byte* data, size_t len); void clear(); diff --git a/include/communication/bolt/v1/transport/chunked_buffer.hpp b/include/communication/bolt/v1/transport/chunked_buffer.hpp new file mode 100644 index 000000000..eb368431e --- /dev/null +++ b/include/communication/bolt/v1/transport/chunked_buffer.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include +#include +#include + +#include "communication/bolt/v1/config.hpp" +#include "utils/types/byte.hpp" +#include "logging/default.hpp" + +namespace bolt +{ + +template +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; + std::vector 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(); + } +}; + +} diff --git a/src/bolt/v1/transport/chunked_decoder.hpp b/include/communication/bolt/v1/transport/chunked_decoder.hpp similarity index 79% rename from src/bolt/v1/transport/chunked_decoder.hpp rename to include/communication/bolt/v1/transport/chunked_decoder.hpp index 6f1feb166..b7252b59f 100644 --- a/src/bolt/v1/transport/chunked_decoder.hpp +++ b/include/communication/bolt/v1/transport/chunked_decoder.hpp @@ -1,13 +1,13 @@ #pragma once +#include #include #include -#include - -#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; - size_t get_size(const byte* chunk) + size_t get_size(const byte *chunk) { return size_t(chunk[0]) << 8 | chunk[1]; } }; - } diff --git a/src/bolt/v1/transport/chunked_encoder.hpp b/include/communication/bolt/v1/transport/chunked_encoder.hpp similarity index 74% rename from src/bolt/v1/transport/chunked_encoder.hpp rename to include/communication/bolt/v1/transport/chunked_encoder.hpp index 9ded82c9a..e3fbcebbd 100644 --- a/src/bolt/v1/transport/chunked_encoder.hpp +++ b/include/communication/bolt/v1/transport/chunked_encoder.hpp @@ -5,6 +5,8 @@ #include #include "utils/likely.hpp" +#include "communication/bolt/v1/config.hpp" +#include "logging/default.hpp" namespace bolt { @@ -12,13 +14,16 @@ namespace bolt template 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; std::array 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(); } diff --git a/src/bolt/v1/transport/socket_stream.hpp b/include/communication/bolt/v1/transport/socket_stream.hpp similarity index 91% rename from src/bolt/v1/transport/socket_stream.hpp rename to include/communication/bolt/v1/transport/socket_stream.hpp index de41815bc..ca0688dc7 100644 --- a/src/bolt/v1/transport/socket_stream.hpp +++ b/include/communication/bolt/v1/transport/socket_stream.hpp @@ -5,7 +5,7 @@ #include #include "io/network/socket.hpp" -#include "stream_error.hpp" +#include "communication/bolt/v1/transport/stream_error.hpp" namespace bolt { diff --git a/src/bolt/v1/transport/stream_error.hpp b/include/communication/bolt/v1/transport/stream_error.hpp similarity index 100% rename from src/bolt/v1/transport/stream_error.hpp rename to include/communication/bolt/v1/transport/stream_error.hpp diff --git a/include/communication/communication.hpp b/include/communication/communication.hpp new file mode 100644 index 000000000..c52945361 --- /dev/null +++ b/include/communication/communication.hpp @@ -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; +} diff --git a/include/communication/gate/init.hpp b/include/communication/gate/init.hpp new file mode 100644 index 000000000..a5c4e8129 --- /dev/null +++ b/include/communication/gate/init.hpp @@ -0,0 +1,4 @@ +#pragma once + +/* Memgraph Communication protocol + * gate is the first name proposal for the protocol */ diff --git a/include/communication/http/init.hpp b/include/communication/http/init.hpp new file mode 100644 index 000000000..628d42bba --- /dev/null +++ b/include/communication/http/init.hpp @@ -0,0 +1,3 @@ +#pragma once + +/* HTTP & HTTPS implementation */ diff --git a/src/data_structures/bitset/dynamic_bitset.hpp b/include/data_structures/bitset/dynamic_bitset.hpp similarity index 100% rename from src/data_structures/bitset/dynamic_bitset.hpp rename to include/data_structures/bitset/dynamic_bitset.hpp diff --git a/src/data_structures/concurrent/common.hpp b/include/data_structures/concurrent/common.hpp similarity index 98% rename from src/data_structures/concurrent/common.hpp rename to include/data_structures/concurrent/common.hpp index bab056330..4ec9e7c16 100644 --- a/src/data_structures/concurrent/common.hpp +++ b/include/data_structures/concurrent/common.hpp @@ -16,7 +16,6 @@ public: friend constexpr bool operator<(const Item &lhs, const Item &rhs) { - std::pair *a; return lhs.first < rhs.first; } diff --git a/src/data_structures/concurrent/concurrent_map.hpp b/include/data_structures/concurrent/concurrent_map.hpp similarity index 100% rename from src/data_structures/concurrent/concurrent_map.hpp rename to include/data_structures/concurrent/concurrent_map.hpp diff --git a/src/data_structures/concurrent/concurrent_multimap.hpp b/include/data_structures/concurrent/concurrent_multimap.hpp similarity index 100% rename from src/data_structures/concurrent/concurrent_multimap.hpp rename to include/data_structures/concurrent/concurrent_multimap.hpp diff --git a/src/data_structures/concurrent/concurrent_multiset.hpp b/include/data_structures/concurrent/concurrent_multiset.hpp similarity index 100% rename from src/data_structures/concurrent/concurrent_multiset.hpp rename to include/data_structures/concurrent/concurrent_multiset.hpp diff --git a/src/data_structures/concurrent/concurrent_set.hpp b/include/data_structures/concurrent/concurrent_set.hpp similarity index 100% rename from src/data_structures/concurrent/concurrent_set.hpp rename to include/data_structures/concurrent/concurrent_set.hpp diff --git a/src/data_structures/concurrent/skiplist.hpp b/include/data_structures/concurrent/skiplist.hpp similarity index 100% rename from src/data_structures/concurrent/skiplist.hpp rename to include/data_structures/concurrent/skiplist.hpp diff --git a/src/data_structures/concurrent/skiplist_gc.hpp b/include/data_structures/concurrent/skiplist_gc.hpp similarity index 82% rename from src/data_structures/concurrent/skiplist_gc.hpp rename to include/data_structures/concurrent/skiplist_gc.hpp index 196b4c5d6..61777b7bf 100644 --- a/src/data_structures/concurrent/skiplist_gc.hpp +++ b/include/data_structures/concurrent/skiplist_gc.hpp @@ -6,11 +6,14 @@ #include "memory/freelist.hpp" #include "memory/lazy_gc.hpp" #include "threading/sync/spinlock.hpp" +#include "logging/default.hpp" template class SkiplistGC : public LazyGC, 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 freelist; }; diff --git a/include/database/db.hpp b/include/database/db.hpp index 77210b6da..8cee20063 100644 --- a/include/database/db.hpp +++ b/include/database/db.hpp @@ -9,12 +9,18 @@ class Db public: using sptr = std::shared_ptr; + 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_; }; diff --git a/src/io/network/.gitignore b/include/io/network/.gitignore similarity index 100% rename from src/io/network/.gitignore rename to include/io/network/.gitignore diff --git a/src/io/network/addrinfo.hpp b/include/io/network/addrinfo.hpp similarity index 95% rename from src/io/network/addrinfo.hpp rename to include/io/network/addrinfo.hpp index 9aba76629..e85b289c5 100644 --- a/src/io/network/addrinfo.hpp +++ b/include/io/network/addrinfo.hpp @@ -3,7 +3,7 @@ #include #include -#include "network_error.hpp" +#include "io/network/network_error.hpp" #include "utils/underlying_cast.hpp" namespace io diff --git a/src/io/network/client.hpp b/include/io/network/client.hpp similarity index 94% rename from src/io/network/client.hpp rename to include/io/network/client.hpp index ec2ea102d..6df50e520 100644 --- a/src/io/network/client.hpp +++ b/include/io/network/client.hpp @@ -1,6 +1,6 @@ #pragma once -#include "stream_reader.hpp" +#include "io/network/stream_reader.hpp" namespace io { diff --git a/src/io/network/epoll.hpp b/include/io/network/epoll.hpp similarity index 96% rename from src/io/network/epoll.hpp rename to include/io/network/epoll.hpp index 6ce725280..61a501c6f 100644 --- a/src/io/network/epoll.hpp +++ b/include/io/network/epoll.hpp @@ -3,7 +3,7 @@ #include #include -#include "socket.hpp" +#include "io/network/socket.hpp" #include "utils/likely.hpp" namespace io diff --git a/src/io/network/event_listener.hpp b/include/io/network/event_listener.hpp similarity index 98% rename from src/io/network/event_listener.hpp rename to include/io/network/event_listener.hpp index 1600b835a..8ce0c5fe8 100644 --- a/src/io/network/event_listener.hpp +++ b/include/io/network/event_listener.hpp @@ -1,6 +1,6 @@ #pragma once -#include "epoll.hpp" +#include "io/network/epoll.hpp" #include "utils/crtp.hpp" namespace io diff --git a/src/io/network/event_loop.hpp b/include/io/network/event_loop.hpp similarity index 80% rename from src/io/network/event_loop.hpp rename to include/io/network/event_loop.hpp index b8dc5759f..aa382d210 100644 --- a/src/io/network/event_loop.hpp +++ b/include/io/network/event_loop.hpp @@ -1,6 +1,6 @@ #pragma once -#include "socket.hpp" +#include "io/network/socket.hpp" namespace io { diff --git a/src/io/network/network_error.hpp b/include/io/network/network_error.hpp similarity index 100% rename from src/io/network/network_error.hpp rename to include/io/network/network_error.hpp diff --git a/src/io/network/secure_socket.hpp b/include/io/network/secure_socket.hpp similarity index 100% rename from src/io/network/secure_socket.hpp rename to include/io/network/secure_socket.hpp diff --git a/src/io/network/secure_stream_reader.hpp b/include/io/network/secure_stream_reader.hpp similarity index 97% rename from src/io/network/secure_stream_reader.hpp rename to include/io/network/secure_stream_reader.hpp index 889bdb60f..6a2c26b2a 100644 --- a/src/io/network/secure_stream_reader.hpp +++ b/include/io/network/secure_stream_reader.hpp @@ -2,7 +2,7 @@ #include -#include "stream_reader.hpp" +#include "io/network/stream_reader.hpp" #include "logging/default.hpp" namespace io diff --git a/src/io/network/server.hpp b/include/io/network/server.hpp similarity index 94% rename from src/io/network/server.hpp rename to include/io/network/server.hpp index 47d5bf792..c71f57470 100644 --- a/src/io/network/server.hpp +++ b/include/io/network/server.hpp @@ -1,6 +1,6 @@ #pragma once -#include "stream_reader.hpp" +#include "io/network/stream_reader.hpp" namespace io { diff --git a/src/io/network/socket.hpp b/include/io/network/socket.hpp similarity index 96% rename from src/io/network/socket.hpp rename to include/io/network/socket.hpp index e93ec02ee..c5e49d8d8 100644 --- a/src/io/network/socket.hpp +++ b/include/io/network/socket.hpp @@ -13,7 +13,7 @@ #include #include -#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; }; diff --git a/src/io/network/stream_dispatcher.hpp b/include/io/network/stream_dispatcher.hpp similarity index 85% rename from src/io/network/stream_dispatcher.hpp rename to include/io/network/stream_dispatcher.hpp index 3db4c00b4..382514e94 100644 --- a/src/io/network/stream_dispatcher.hpp +++ b/include/io/network/stream_dispatcher.hpp @@ -1,6 +1,5 @@ #pragma once -#include " namespace io { diff --git a/src/io/network/stream_listener.hpp b/include/io/network/stream_listener.hpp similarity index 95% rename from src/io/network/stream_listener.hpp rename to include/io/network/stream_listener.hpp index 8048be7f9..28adfd4f4 100644 --- a/src/io/network/stream_listener.hpp +++ b/include/io/network/stream_listener.hpp @@ -1,6 +1,6 @@ #pragma once -#include "event_listener.hpp" +#include "io/network/event_listener.hpp" namespace io { diff --git a/src/io/network/stream_reader.hpp b/include/io/network/stream_reader.hpp similarity index 98% rename from src/io/network/stream_reader.hpp rename to include/io/network/stream_reader.hpp index 48e8d70d1..7f7406312 100644 --- a/src/io/network/stream_reader.hpp +++ b/include/io/network/stream_reader.hpp @@ -1,6 +1,6 @@ #pragma once -#include "stream_listener.hpp" +#include "io/network/stream_listener.hpp" #include "memory/literals.hpp" namespace io diff --git a/src/io/network/tcp/stream.hpp b/include/io/network/tcp/stream.hpp similarity index 100% rename from src/io/network/tcp/stream.hpp rename to include/io/network/tcp/stream.hpp diff --git a/src/io/network/tls.hpp b/include/io/network/tls.hpp similarity index 100% rename from src/io/network/tls.hpp rename to include/io/network/tls.hpp diff --git a/src/io/network/tls_error.hpp b/include/io/network/tls_error.hpp similarity index 100% rename from src/io/network/tls_error.hpp rename to include/io/network/tls_error.hpp diff --git a/src/io/uv/blockbuffer.hpp b/include/io/uv/blockbuffer.hpp similarity index 100% rename from src/io/uv/blockbuffer.hpp rename to include/io/uv/blockbuffer.hpp diff --git a/src/io/uv/core.hpp b/include/io/uv/core.hpp similarity index 100% rename from src/io/uv/core.hpp rename to include/io/uv/core.hpp diff --git a/src/io/uv/tcpstream.hpp b/include/io/uv/tcpstream.hpp similarity index 100% rename from src/io/uv/tcpstream.hpp rename to include/io/uv/tcpstream.hpp diff --git a/src/io/uv/uv.hpp b/include/io/uv/uv.hpp similarity index 100% rename from src/io/uv/uv.hpp rename to include/io/uv/uv.hpp diff --git a/src/io/uv/uv_error.hpp b/include/io/uv/uv_error.hpp similarity index 100% rename from src/io/uv/uv_error.hpp rename to include/io/uv/uv_error.hpp diff --git a/src/io/uv/uvbuffer.hpp b/include/io/uv/uvbuffer.hpp similarity index 100% rename from src/io/uv/uvbuffer.hpp rename to include/io/uv/uvbuffer.hpp diff --git a/src/io/uv/uvloop.hpp b/include/io/uv/uvloop.hpp similarity index 100% rename from src/io/uv/uvloop.hpp rename to include/io/uv/uvloop.hpp diff --git a/src/logging/default.hpp b/include/logging/default.hpp similarity index 56% rename from src/logging/default.hpp rename to include/logging/default.hpp index dd8357426..31344446b 100644 --- a/src/logging/default.hpp +++ b/include/logging/default.hpp @@ -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)...); } +extern Logger info_logger; + +template +void info(Args&&... args) +{ + info_logger.info(std::forward(args)...); +} + void init_async(); void init_sync(); diff --git a/src/logging/levels.hpp b/include/logging/levels.hpp similarity index 100% rename from src/logging/levels.hpp rename to include/logging/levels.hpp diff --git a/src/logging/log.hpp b/include/logging/log.hpp similarity index 100% rename from src/logging/log.hpp rename to include/logging/log.hpp diff --git a/src/logging/logger.hpp b/include/logging/logger.hpp similarity index 97% rename from src/logging/logger.hpp rename to include/logging/logger.hpp index d85c2e23d..dc3d72df1 100644 --- a/src/logging/logger.hpp +++ b/include/logging/logger.hpp @@ -3,8 +3,8 @@ #include #include -#include "log.hpp" -#include "levels.hpp" +#include "logging/log.hpp" +#include "logging/levels.hpp" class Logger { diff --git a/src/logging/logs/async_log.hpp b/include/logging/logs/async_log.hpp similarity index 100% rename from src/logging/logs/async_log.hpp rename to include/logging/logs/async_log.hpp diff --git a/src/logging/logs/sync_log.hpp b/include/logging/logs/sync_log.hpp similarity index 100% rename from src/logging/logs/sync_log.hpp rename to include/logging/logs/sync_log.hpp diff --git a/src/logging/streams/stdout.hpp b/include/logging/streams/stdout.hpp similarity index 100% rename from src/logging/streams/stdout.hpp rename to include/logging/streams/stdout.hpp diff --git a/src/memory/freelist.hpp b/include/memory/freelist.hpp similarity index 100% rename from src/memory/freelist.hpp rename to include/memory/freelist.hpp diff --git a/src/memory/lazy_gc.hpp b/include/memory/lazy_gc.hpp similarity index 100% rename from src/memory/lazy_gc.hpp rename to include/memory/lazy_gc.hpp diff --git a/src/mvcc/cre_exp.hpp b/include/mvcc/cre_exp.hpp similarity index 100% rename from src/mvcc/cre_exp.hpp rename to include/mvcc/cre_exp.hpp diff --git a/src/mvcc/hints.hpp b/include/mvcc/hints.hpp similarity index 100% rename from src/mvcc/hints.hpp rename to include/mvcc/hints.hpp diff --git a/src/mvcc/mvcc_error.hpp b/include/mvcc/mvcc_error.hpp similarity index 100% rename from src/mvcc/mvcc_error.hpp rename to include/mvcc/mvcc_error.hpp diff --git a/src/mvcc/record.hpp b/include/mvcc/record.hpp similarity index 98% rename from src/mvcc/record.hpp rename to include/mvcc/record.hpp index 8d74b61bc..2731c2b56 100644 --- a/src/mvcc/record.hpp +++ b/include/mvcc/record.hpp @@ -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 diff --git a/src/mvcc/serialization_error.hpp b/include/mvcc/serialization_error.hpp similarity index 100% rename from src/mvcc/serialization_error.hpp rename to include/mvcc/serialization_error.hpp diff --git a/src/mvcc/version.hpp b/include/mvcc/version.hpp similarity index 100% rename from src/mvcc/version.hpp rename to include/mvcc/version.hpp diff --git a/src/mvcc/version_list.hpp b/include/mvcc/version_list.hpp similarity index 100% rename from src/mvcc/version_list.hpp rename to include/mvcc/version_list.hpp diff --git a/include/query_engine/code_compiler.hpp b/include/query_engine/code_compiler.hpp new file mode 100644 index 000000000..21125d9c2 --- /dev/null +++ b/include/query_engine/code_compiler.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include + +#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; +}; diff --git a/src/query_engine/code_generator.hpp b/include/query_engine/code_generator.hpp similarity index 84% rename from src/query_engine/code_generator.hpp rename to include/query_engine/code_generator.hpp index 1115b511b..e010c7a3c 100644 --- a/src/query_engine/code_generator.hpp +++ b/include/query_engine/code_generator.hpp @@ -7,16 +7,15 @@ #include "template_engine/engine.hpp" #include "traverser/cpp_traverser.hpp" #include "utils/string/file.hpp" - -// TODO: -// * logger -#include +#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; diff --git a/src/query_engine/code_generator/clause_action.hpp b/include/query_engine/code_generator/clause_action.hpp similarity index 100% rename from src/query_engine/code_generator/clause_action.hpp rename to include/query_engine/code_generator/clause_action.hpp diff --git a/src/query_engine/code_generator/cpp_generator.hpp b/include/query_engine/code_generator/cpp_generator.hpp similarity index 100% rename from src/query_engine/code_generator/cpp_generator.hpp rename to include/query_engine/code_generator/cpp_generator.hpp diff --git a/src/query_engine/code_generator/cypher_state.hpp b/include/query_engine/code_generator/cypher_state.hpp similarity index 100% rename from src/query_engine/code_generator/cypher_state.hpp rename to include/query_engine/code_generator/cypher_state.hpp diff --git a/src/query_engine/code_generator/entity_search.hpp b/include/query_engine/code_generator/entity_search.hpp similarity index 100% rename from src/query_engine/code_generator/entity_search.hpp rename to include/query_engine/code_generator/entity_search.hpp diff --git a/src/query_engine/code_generator/handlers/all.hpp b/include/query_engine/code_generator/handlers/all.hpp similarity index 100% rename from src/query_engine/code_generator/handlers/all.hpp rename to include/query_engine/code_generator/handlers/all.hpp diff --git a/src/query_engine/code_generator/handlers/create.hpp b/include/query_engine/code_generator/handlers/create.hpp similarity index 100% rename from src/query_engine/code_generator/handlers/create.hpp rename to include/query_engine/code_generator/handlers/create.hpp diff --git a/src/query_engine/code_generator/handlers/delete.hpp b/include/query_engine/code_generator/handlers/delete.hpp similarity index 100% rename from src/query_engine/code_generator/handlers/delete.hpp rename to include/query_engine/code_generator/handlers/delete.hpp diff --git a/src/query_engine/code_generator/handlers/includes.hpp b/include/query_engine/code_generator/handlers/includes.hpp similarity index 98% rename from src/query_engine/code_generator/handlers/includes.hpp rename to include/query_engine/code_generator/handlers/includes.hpp index 960398ca9..eb546ce73 100644 --- a/src/query_engine/code_generator/handlers/includes.hpp +++ b/include/query_engine/code_generator/handlers/includes.hpp @@ -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; } + +} diff --git a/src/query_engine/code_generator/handlers/match.hpp b/include/query_engine/code_generator/handlers/match.hpp similarity index 99% rename from src/query_engine/code_generator/handlers/match.hpp rename to include/query_engine/code_generator/handlers/match.hpp index 73dd51238..39463cdf2 100644 --- a/src/query_engine/code_generator/handlers/match.hpp +++ b/include/query_engine/code_generator/handlers/match.hpp @@ -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 { diff --git a/src/query_engine/code_generator/handlers/return.hpp b/include/query_engine/code_generator/handlers/return.hpp similarity index 75% rename from src/query_engine/code_generator/handlers/return.hpp rename to include/query_engine/code_generator/handlers/return.hpp index 43592e2b3..eb64d8b4e 100644 --- a/src/query_engine/code_generator/handlers/return.hpp +++ b/include/query_engine/code_generator/handlers/return.hpp @@ -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); } } diff --git a/src/query_engine/code_generator/handlers/set.hpp b/include/query_engine/code_generator/handlers/set.hpp similarity index 100% rename from src/query_engine/code_generator/handlers/set.hpp rename to include/query_engine/code_generator/handlers/set.hpp diff --git a/src/query_engine/code_generator/handlers/transaction_begin.hpp b/include/query_engine/code_generator/handlers/transaction_begin.hpp similarity index 100% rename from src/query_engine/code_generator/handlers/transaction_begin.hpp rename to include/query_engine/code_generator/handlers/transaction_begin.hpp diff --git a/src/query_engine/code_generator/handlers/transaction_commit.hpp b/include/query_engine/code_generator/handlers/transaction_commit.hpp similarity index 84% rename from src/query_engine/code_generator/handlers/transaction_commit.hpp rename to include/query_engine/code_generator/handlers/transaction_commit.hpp index 41777fd3b..a19749dea 100644 --- a/src/query_engine/code_generator/handlers/transaction_commit.hpp +++ b/include/query_engine/code_generator/handlers/transaction_commit.hpp @@ -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); }; diff --git a/src/query_engine/code_generator/query_action.hpp b/include/query_engine/code_generator/query_action.hpp similarity index 100% rename from src/query_engine/code_generator/query_action.hpp rename to include/query_engine/code_generator/query_action.hpp diff --git a/src/query_engine/code_generator/query_action_data.hpp b/include/query_engine/code_generator/query_action_data.hpp similarity index 100% rename from src/query_engine/code_generator/query_action_data.hpp rename to include/query_engine/code_generator/query_action_data.hpp diff --git a/src/query_engine/code_generator/structures.hpp b/include/query_engine/code_generator/structures.hpp similarity index 100% rename from src/query_engine/code_generator/structures.hpp rename to include/query_engine/code_generator/structures.hpp diff --git a/src/query_engine/exceptions/errors.hpp b/include/query_engine/exceptions/errors.hpp similarity index 100% rename from src/query_engine/exceptions/errors.hpp rename to include/query_engine/exceptions/errors.hpp diff --git a/src/query_engine/exceptions/exceptions.hpp b/include/query_engine/exceptions/exceptions.hpp similarity index 100% rename from src/query_engine/exceptions/exceptions.hpp rename to include/query_engine/exceptions/exceptions.hpp diff --git a/src/query_engine/hardcode/queries.hpp b/include/query_engine/hardcode/queries.hpp similarity index 100% rename from src/query_engine/hardcode/queries.hpp rename to include/query_engine/hardcode/queries.hpp diff --git a/include/query_engine/i_code_cpu.hpp b/include/query_engine/i_code_cpu.hpp new file mode 100644 index 000000000..1735b067e --- /dev/null +++ b/include/query_engine/i_code_cpu.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "communication/communication.hpp" +#include "database/db.hpp" +#include "query_engine/query_stripped.hpp" + +class ICodeCPU +{ +public: + virtual bool run(Db &db, code_args_t &args, + communication::OutputStream &stream) = 0; + virtual ~ICodeCPU() {} +}; + +using produce_t = ICodeCPU *(*)(); +using destruct_t = void (*)(ICodeCPU *); diff --git a/src/query_engine/memgraph_dynamic_lib.hpp b/include/query_engine/memgraph_dynamic_lib.hpp similarity index 89% rename from src/query_engine/memgraph_dynamic_lib.hpp rename to include/query_engine/memgraph_dynamic_lib.hpp index 7dbc07ed2..f4a8b3039 100644 --- a/src/query_engine/memgraph_dynamic_lib.hpp +++ b/include/query_engine/memgraph_dynamic_lib.hpp @@ -1,8 +1,11 @@ #pragma once -#include "i_code_cpu.hpp" +#include "query_engine/i_code_cpu.hpp" #include "dc/dynamic_lib.hpp" +namespace +{ + class MemgraphDynamicLib { public: @@ -16,3 +19,5 @@ const std::string MemgraphDynamicLib::produce_name = "produce"; const std::string MemgraphDynamicLib::destruct_name = "destruct"; using CodeLib = DynamicLib; + +} diff --git a/src/query_engine/program_executor.hpp b/include/query_engine/program_executor.hpp similarity index 76% rename from src/query_engine/program_executor.hpp rename to include/query_engine/program_executor.hpp index a12f4b667..b0aa6df75 100644 --- a/src/query_engine/program_executor.hpp +++ b/include/query_engine/program_executor.hpp @@ -3,10 +3,9 @@ #include #include "database/db.hpp" +#include "query_engine/exceptions/exceptions.hpp" #include "query_engine/util.hpp" #include "query_program.hpp" -#include "utils/log/logger.hpp" -#include "query_engine/exceptions/exceptions.hpp" // preparations before execution // execution @@ -15,19 +14,15 @@ class ProgramExecutor { public: - auto execute(QueryProgram &program) + auto execute(QueryProgram &program, Db &db, + communication::OutputStream &stream) { try { // TODO: return result of query/code exection - return program.code->run(db, program.stripped.arguments); + return program.code->run(db, program.stripped.arguments, stream); } catch (...) { // TODO: return more information about the error throw QueryEngineException("code execution error"); } } - -public: - // TODO: here shoud be one database from DBMS, not local instance of - // DB - Db db; }; diff --git a/src/query_engine/program_loader.hpp b/include/query_engine/program_loader.hpp similarity index 79% rename from src/query_engine/program_loader.hpp rename to include/query_engine/program_loader.hpp index b8d4ef18e..c5e178466 100644 --- a/src/query_engine/program_loader.hpp +++ b/include/query_engine/program_loader.hpp @@ -4,38 +4,35 @@ #include #include -#define NOT_LOG_INFO - -#include "code_compiler.hpp" -#include "code_generator.hpp" #include "config/config.hpp" -#include "memgraph_dynamic_lib.hpp" -#include "query_program.hpp" -#include "query_stripper.hpp" +#include "query_engine/code_compiler.hpp" +#include "query_engine/code_generator.hpp" +#include "query_engine/memgraph_dynamic_lib.hpp" +#include "query_engine/query_program.hpp" +#include "query_engine/query_stripper.hpp" #include "utils/hashing/fnv.hpp" -#include "utils/log/logger.hpp" +#include "logging/default.hpp" using std::string; -using std::cout; -using std::endl; class ProgramLoader { public: using sptr_code_lib = std::shared_ptr; - ProgramLoader() - : stripper(make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL)) + ProgramLoader() : + stripper(make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL)), + logger(logging::log->logger("ProgramLoader")) { } auto load(const string &query) { auto stripped = stripper.strip(query); - LOG_INFO("stripped_query = " + stripped.query); + logger.debug("stripped_query = {}", stripped.query); auto hash_string = std::to_string(stripped.hash); - LOG_INFO("query_hash = " + hash_string); + logger.debug("query_hash = {}", hash_string); auto code_lib_iter = code_libs.find(stripped.hash); @@ -65,6 +62,9 @@ public: return QueryProgram(code_lib->instance(), std::move(stripped)); } +protected: + Logger logger; + private: // TODO somehow remove int.. from here QueryStripper stripper; diff --git a/include/query_engine/query_engine.hpp b/include/query_engine/query_engine.hpp new file mode 100644 index 000000000..940ef1c95 --- /dev/null +++ b/include/query_engine/query_engine.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include "database/db.hpp" +#include "logging/default.hpp" +#include "program_executor.hpp" +#include "program_loader.hpp" +#include "query_result.hpp" + +/* + * Current arhitecture: + * query -> code_loader -> query_stripper -> [code_generator] + * -> [code_compiler] -> code_executor + */ + +class QueryEngine +{ +public: + QueryEngine() : logger(logging::log->logger("QueryEngine")) {} + + auto execute(const std::string &query, Db &db, + communication::OutputStream &stream) + { + try { + auto program = program_loader.load(query); + auto result = program_executor.execute(program, db, stream); + if (UNLIKELY(!result)) { + // info because it might be something like deadlock in which + // case one thread is stopped and user has try again + logger.info( + "Unable to execute query (executor returned false)"); + } + return result; + } catch (QueryEngineException &e) { + // in this case something fatal went wrong + logger.error("QueryEngineException: {}", std::string(e.what())); + return false; + } + } + +protected: + Logger logger; + +private: + ProgramExecutor program_executor; + ProgramLoader program_loader; +}; diff --git a/src/query_engine/query_hasher.hpp b/include/query_engine/query_hasher.hpp similarity index 100% rename from src/query_engine/query_hasher.hpp rename to include/query_engine/query_hasher.hpp diff --git a/src/query_engine/query_program.hpp b/include/query_engine/query_program.hpp similarity index 80% rename from src/query_engine/query_program.hpp rename to include/query_engine/query_program.hpp index 8a35b5376..35d1fd7bc 100644 --- a/src/query_engine/query_program.hpp +++ b/include/query_engine/query_program.hpp @@ -1,7 +1,7 @@ #pragma once -#include "i_code_cpu.hpp" -#include "query_stripped.hpp" +#include "query_engine/i_code_cpu.hpp" +#include "query_engine/query_stripped.hpp" struct QueryProgram { diff --git a/src/query_engine/query_result.hpp b/include/query_engine/query_result.hpp similarity index 96% rename from src/query_engine/query_result.hpp rename to include/query_engine/query_result.hpp index f59e3578b..992df23c0 100644 --- a/src/query_engine/query_result.hpp +++ b/include/query_engine/query_result.hpp @@ -1,5 +1,8 @@ #pragma once +// !! DEPRICATED !! +// TODO: DELETE + #include #include #include diff --git a/src/query_engine/query_stripped.hpp b/include/query_engine/query_stripped.hpp similarity index 100% rename from src/query_engine/query_stripped.hpp rename to include/query_engine/query_stripped.hpp diff --git a/src/query_engine/query_stripper.hpp b/include/query_engine/query_stripper.hpp similarity index 100% rename from src/query_engine/query_stripper.hpp rename to include/query_engine/query_stripper.hpp diff --git a/src/query_engine/traverser/code.hpp b/include/query_engine/traverser/code.hpp similarity index 82% rename from src/query_engine/traverser/code.hpp rename to include/query_engine/traverser/code.hpp index cb5740f4d..412716167 100644 --- a/src/query_engine/traverser/code.hpp +++ b/include/query_engine/traverser/code.hpp @@ -50,8 +50,13 @@ const std::string match_edge_by_id = "auto {0} = db.graph.edges.find(t, args[{1}]->as().value);\n" " if (!{0}) return t.commit(), std::make_shared();"; -const std::string return_empty_result = - "return std::make_shared();"; +const std::string write_entity = + "stream.write_field(\"{0}\");\n" + " stream.write_record();\n" + " stream.write({0});\n" + " stream.write_success_empty();\n"; + +const std::string return_true = "return true;"; const std::string update_property = "{}.property(\"{}\", args[{}]);"; @@ -62,15 +67,4 @@ const std::string print_properties = const std::string print_property = "cout_property(\"{0}\", {0}.property(\"{1}\"));"; -std::string debug_print_vertex_labels() -{ -#ifdef DEBUG - return code_line("PRINT_PROPS(vertex_accessor.properties());") + - code_line("cout << \"LABELS:\" << endl;") + - code_line("for (auto label_ref : vertex_accessor.labels()) {") + - code_line("cout << label_ref.get() << endl;") + code_line("}"); -#else - return ""; -#endif -} } diff --git a/src/query_engine/traverser/cpp_traverser.hpp b/include/query_engine/traverser/cpp_traverser.hpp similarity index 97% rename from src/query_engine/traverser/cpp_traverser.hpp rename to include/query_engine/traverser/cpp_traverser.hpp index 7c14bb278..0431340f6 100644 --- a/src/query_engine/traverser/cpp_traverser.hpp +++ b/include/query_engine/traverser/cpp_traverser.hpp @@ -92,6 +92,13 @@ private: // TODO: remove this constraint bool has_return; + void finish_query_execution() + { + generator.add_action(QueryAction::TransactionCommit); + code += generator.generate(); + generator.clear(); + } + public: void semantic_check() const { @@ -108,6 +115,9 @@ public: generator.add_action(QueryAction::TransactionBegin); Traverser::visit(write_query); + + // TODO: put this inside the top level mentioned above + finish_query_execution(); } void visit(ast::ReadQuery &read_query) override @@ -115,6 +125,8 @@ public: generator.add_action(QueryAction::TransactionBegin); Traverser::visit(read_query); + + finish_query_execution(); } void visit(ast::UpdateQuery &update_query) override @@ -122,6 +134,8 @@ public: generator.add_action(QueryAction::TransactionBegin); Traverser::visit(update_query); + + finish_query_execution(); } void visit(ast::DeleteQuery &delete_query) override @@ -129,6 +143,8 @@ public: generator.add_action(QueryAction::TransactionBegin); Traverser::visit(delete_query); + + finish_query_execution(); } void visit(ast::ReadWriteQuery &read_write_query) override @@ -136,6 +152,8 @@ public: generator.add_action(QueryAction::TransactionBegin); Traverser::visit(read_write_query); + + finish_query_execution(); } void visit(ast::Match &ast_match) override @@ -188,12 +206,6 @@ public: Traverser::visit(ast_return); - // TODO: move commit somewhare that is more appropriate - generator.add_action(QueryAction::TransactionCommit); - - code += generator.generate(); - - generator.clear(); } void visit(ast::ReturnList &ast_return_list) override diff --git a/src/query_engine/util.hpp b/include/query_engine/util.hpp similarity index 60% rename from src/query_engine/util.hpp rename to include/query_engine/util.hpp index 03f676897..76bf1e5a6 100644 --- a/src/query_engine/util.hpp +++ b/include/query_engine/util.hpp @@ -11,46 +11,34 @@ using std::cout; using std::endl; -void print_props(const Properties &properties) -{ - StringBuffer buffer; - JsonWriter writer(buffer); - properties.accept(writer); - cout << buffer.str() << endl; -} +void print_props(const Properties &properties); -#ifdef DEBUG -#define PRINT_PROPS(_PROPS_) print_props(_PROPS_); -#else +#ifdef NDEBUG #define PRINT_PROPS(_) +#else +#define PRINT_PROPS(_PROPS_) print_props(_PROPS_); #endif -void cout_properties(const Properties &properties) -{ - ConsoleWriter writer; - properties.accept(writer); - cout << "----" << endl; -} +void cout_properties(const Properties &properties); -void cout_property(const std::string &key, const Property &property) -{ - ConsoleWriter writer; - writer.handle(key, property); - cout << "----" << endl; -} +void cout_property(const std::string &key, const Property &property); + +// this is a nice way how to avoid multiple definition problem with +// headers because it will create a unique namespace for each compilation unit +// http://stackoverflow.com/questions/2727582/multiple-definition-in-header-file +namespace +{ -// wrapper for fmt format template std::string format(const std::string &format_str, const Args &... args) { return fmt::format(format_str, args...); } -// wrapper for single code line template std::string code_line(const std::string &format_str, const Args &... args) { return "\t" + format(format_str, args...) + "\n"; } - +} diff --git a/src/storage/common.hpp b/include/storage/common.hpp similarity index 100% rename from src/storage/common.hpp rename to include/storage/common.hpp diff --git a/src/storage/edge.hpp b/include/storage/edge.hpp similarity index 79% rename from src/storage/edge.hpp rename to include/storage/edge.hpp index 507af2925..55a3ea182 100644 --- a/src/storage/edge.hpp +++ b/include/storage/edge.hpp @@ -1,8 +1,8 @@ #pragma once #include "mvcc/record.hpp" -#include "model/edge_model.hpp" -#include "model/properties/traversers/jsonwriter.hpp" +#include "storage/model/edge_model.hpp" +#include "storage/model/properties/traversers/jsonwriter.hpp" class Edge : public mvcc::Record { diff --git a/src/storage/edge_accessor.hpp b/include/storage/edge_accessor.hpp similarity index 100% rename from src/storage/edge_accessor.hpp rename to include/storage/edge_accessor.hpp diff --git a/include/storage/edges.hpp b/include/storage/edges.hpp new file mode 100644 index 000000000..67a51adda --- /dev/null +++ b/include/storage/edges.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "data_structures/concurrent/concurrent_map.hpp" +#include "storage/common.hpp" +#include "storage/edge_accessor.hpp" + +class Edges +{ +public: + Edge::Accessor find(tx::Transaction &t, const Id &id); + Edge::Accessor insert(tx::Transaction &t); + +private: + ConcurrentMap edges; + AtomicCounter counter; +}; diff --git a/src/storage/graph.hpp b/include/storage/graph.hpp similarity index 100% rename from src/storage/graph.hpp rename to include/storage/graph.hpp index 6637e51af..c14728658 100644 --- a/src/storage/graph.hpp +++ b/include/storage/graph.hpp @@ -10,8 +10,8 @@ class Graph public: Graph() {} - Edges edges; Vertices vertices; + Edges edges; LabelStore label_store; EdgeTypeStore edge_type_store; diff --git a/src/storage/indexes/index.hpp b/include/storage/indexes/index.hpp similarity index 100% rename from src/storage/indexes/index.hpp rename to include/storage/indexes/index.hpp diff --git a/src/storage/indexes/index_record.hpp b/include/storage/indexes/index_record.hpp similarity index 100% rename from src/storage/indexes/index_record.hpp rename to include/storage/indexes/index_record.hpp diff --git a/src/storage/indexes/index_record_collection.hpp b/include/storage/indexes/index_record_collection.hpp similarity index 100% rename from src/storage/indexes/index_record_collection.hpp rename to include/storage/indexes/index_record_collection.hpp diff --git a/src/storage/indexes/keys/index_key.hpp b/include/storage/indexes/keys/index_key.hpp similarity index 100% rename from src/storage/indexes/keys/index_key.hpp rename to include/storage/indexes/keys/index_key.hpp diff --git a/src/storage/indexes/keys/non_unique_key.hpp b/include/storage/indexes/keys/non_unique_key.hpp similarity index 100% rename from src/storage/indexes/keys/non_unique_key.hpp rename to include/storage/indexes/keys/non_unique_key.hpp diff --git a/src/storage/indexes/keys/unique_key.hpp b/include/storage/indexes/keys/unique_key.hpp similarity index 100% rename from src/storage/indexes/keys/unique_key.hpp rename to include/storage/indexes/keys/unique_key.hpp diff --git a/src/storage/indexes/sort_order.hpp b/include/storage/indexes/sort_order.hpp similarity index 100% rename from src/storage/indexes/sort_order.hpp rename to include/storage/indexes/sort_order.hpp diff --git a/src/storage/locking/lock_status.hpp b/include/storage/locking/lock_status.hpp similarity index 100% rename from src/storage/locking/lock_status.hpp rename to include/storage/locking/lock_status.hpp diff --git a/src/storage/model/edge_list.hpp b/include/storage/model/edge_list.hpp similarity index 95% rename from src/storage/model/edge_list.hpp rename to include/storage/model/edge_list.hpp index 49af91f68..87c1e0f12 100644 --- a/src/storage/model/edge_list.hpp +++ b/include/storage/model/edge_list.hpp @@ -1,9 +1,9 @@ #pragma once -#include "mvcc/edge_record.hpp" -#include "mvcc/version_list.hpp" #include +#include "mvcc/version_list.hpp" + class EdgeList { public: diff --git a/src/storage/model/edge_model.hpp b/include/storage/model/edge_model.hpp similarity index 88% rename from src/storage/model/edge_model.hpp rename to include/storage/model/edge_model.hpp index 907e54ac0..a00754934 100644 --- a/src/storage/model/edge_model.hpp +++ b/include/storage/model/edge_model.hpp @@ -1,7 +1,7 @@ #pragma once #include "mvcc/version_list.hpp" -#include "property_model.hpp" +#include "storage/model/property_model.hpp" #include "storage/edge_type/edge_type.hpp" class EdgeModel : public PropertyModel diff --git a/src/storage/model/properties/double.hpp b/include/storage/model/properties/double.hpp similarity index 80% rename from src/storage/model/properties/double.hpp rename to include/storage/model/properties/double.hpp index 780c2cba0..6c4e8e9e7 100644 --- a/src/storage/model/properties/double.hpp +++ b/include/storage/model/properties/double.hpp @@ -1,6 +1,6 @@ #pragma once -#include "floating.hpp" +#include "storage/model/properties/floating.hpp" struct Double : public Floating { diff --git a/src/storage/model/properties/float.hpp b/include/storage/model/properties/float.hpp similarity index 73% rename from src/storage/model/properties/float.hpp rename to include/storage/model/properties/float.hpp index 64496ba0d..25d812c42 100644 --- a/src/storage/model/properties/float.hpp +++ b/include/storage/model/properties/float.hpp @@ -1,7 +1,7 @@ #pragma once -#include "floating.hpp" -#include "double.hpp" +#include "storage/model/properties/floating.hpp" +#include "storage/model/properties/double.hpp" class Float : public Floating { diff --git a/src/storage/model/properties/floating.hpp b/include/storage/model/properties/floating.hpp similarity index 72% rename from src/storage/model/properties/floating.hpp rename to include/storage/model/properties/floating.hpp index 04afd23a8..8b1f8174b 100644 --- a/src/storage/model/properties/floating.hpp +++ b/include/storage/model/properties/floating.hpp @@ -1,6 +1,6 @@ #pragma once -#include "number.hpp" +#include "storage/model/properties/number.hpp" template struct Floating : public Number diff --git a/src/storage/model/properties/int32.hpp b/include/storage/model/properties/int32.hpp similarity index 74% rename from src/storage/model/properties/int32.hpp rename to include/storage/model/properties/int32.hpp index ed588b4fd..644bd8c98 100644 --- a/src/storage/model/properties/int32.hpp +++ b/include/storage/model/properties/int32.hpp @@ -1,7 +1,7 @@ #pragma once -#include "integral.hpp" -#include "int64.hpp" +#include "storage/model/properties/integral.hpp" +#include "storage/model/properties/int64.hpp" class Int32 : public Integral { diff --git a/src/storage/model/properties/int64.hpp b/include/storage/model/properties/int64.hpp similarity index 80% rename from src/storage/model/properties/int64.hpp rename to include/storage/model/properties/int64.hpp index eb699ce06..333a0f8aa 100644 --- a/src/storage/model/properties/int64.hpp +++ b/include/storage/model/properties/int64.hpp @@ -1,6 +1,6 @@ #pragma once -#include "integral.hpp" +#include "storage/model/properties/integral.hpp" class Int64 : public Integral { diff --git a/src/storage/model/properties/integral.hpp b/include/storage/model/properties/integral.hpp similarity index 55% rename from src/storage/model/properties/integral.hpp rename to include/storage/model/properties/integral.hpp index e94bed313..4042c1a58 100644 --- a/src/storage/model/properties/integral.hpp +++ b/include/storage/model/properties/integral.hpp @@ -1,8 +1,8 @@ #pragma once -#include "number.hpp" -#include "floating.hpp" -#include "utils/modulo.hpp" +#include "storage/model/properties/floating.hpp" +#include "storage/model/properties/number.hpp" +#include "storage/model/properties/utils/modulo.hpp" template struct Integral : public Number, public Modulo @@ -10,7 +10,7 @@ struct Integral : public Number, public Modulo using Number::Number; template , T>::value>> + std::is_base_of, T>::value>> operator T() const { return T(this->derived().value); diff --git a/src/storage/model/properties/number.hpp b/include/storage/model/properties/number.hpp similarity index 88% rename from src/storage/model/properties/number.hpp rename to include/storage/model/properties/number.hpp index 1cc988818..396b2fa87 100644 --- a/src/storage/model/properties/number.hpp +++ b/include/storage/model/properties/number.hpp @@ -1,9 +1,9 @@ #pragma once #include "storage/model/properties/property.hpp" -#include "utils/math_operations.hpp" +#include "storage/model/properties/utils/math_operations.hpp" +#include "storage/model/properties/utils/unary_negation.hpp" #include "utils/total_ordering.hpp" -#include "utils/unary_negation.hpp" template class Number : public Property, diff --git a/src/storage/model/properties/traversers/consolewriter.hpp b/include/storage/model/properties/traversers/consolewriter.hpp similarity index 100% rename from src/storage/model/properties/traversers/consolewriter.hpp rename to include/storage/model/properties/traversers/consolewriter.hpp diff --git a/src/storage/model/properties/traversers/jsonwriter.hpp b/include/storage/model/properties/traversers/jsonwriter.hpp similarity index 100% rename from src/storage/model/properties/traversers/jsonwriter.hpp rename to include/storage/model/properties/traversers/jsonwriter.hpp diff --git a/src/storage/model/properties/utils/math_operations.hpp b/include/storage/model/properties/utils/math_operations.hpp similarity index 100% rename from src/storage/model/properties/utils/math_operations.hpp rename to include/storage/model/properties/utils/math_operations.hpp diff --git a/src/storage/model/properties/utils/modulo.hpp b/include/storage/model/properties/utils/modulo.hpp similarity index 100% rename from src/storage/model/properties/utils/modulo.hpp rename to include/storage/model/properties/utils/modulo.hpp diff --git a/src/storage/model/properties/utils/unary_negation.hpp b/include/storage/model/properties/utils/unary_negation.hpp similarity index 100% rename from src/storage/model/properties/utils/unary_negation.hpp rename to include/storage/model/properties/utils/unary_negation.hpp diff --git a/src/storage/model/property_model.hpp b/include/storage/model/property_model.hpp similarity index 100% rename from src/storage/model/property_model.hpp rename to include/storage/model/property_model.hpp diff --git a/include/storage/model/vertex_model.hpp b/include/storage/model/vertex_model.hpp new file mode 100644 index 000000000..a5e794466 --- /dev/null +++ b/include/storage/model/vertex_model.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "storage/model/edge_list.hpp" +#include "storage/model/property_model.hpp" + +class VertexModel : public PropertyModel +{ +public: + EdgeList out; + EdgeMap in; + LabelCollection labels; +}; diff --git a/src/storage/record_accessor.hpp b/include/storage/record_accessor.hpp similarity index 100% rename from src/storage/record_accessor.hpp rename to include/storage/record_accessor.hpp diff --git a/src/storage/vertex.hpp b/include/storage/vertex.hpp similarity index 89% rename from src/storage/vertex.hpp rename to include/storage/vertex.hpp index da4d571f8..9d8f8e294 100644 --- a/src/storage/vertex.hpp +++ b/include/storage/vertex.hpp @@ -1,8 +1,8 @@ #pragma once #include "mvcc/record.hpp" -#include "model/vertex_model.hpp" -#include "model/properties/traversers/jsonwriter.hpp" +#include "storage/model/vertex_model.hpp" +#include "storage/model/properties/traversers/jsonwriter.hpp" class Vertex : public mvcc::Record { diff --git a/src/threading/.gitignore b/include/threading/.gitignore similarity index 100% rename from src/threading/.gitignore rename to include/threading/.gitignore diff --git a/src/threading/hazard_ptr.hpp b/include/threading/hazard_ptr.hpp similarity index 100% rename from src/threading/hazard_ptr.hpp rename to include/threading/hazard_ptr.hpp diff --git a/src/threading/hazard_store.hpp b/include/threading/hazard_store.hpp similarity index 100% rename from src/threading/hazard_store.hpp rename to include/threading/hazard_store.hpp diff --git a/src/threading/id.hpp b/include/threading/id.hpp similarity index 100% rename from src/threading/id.hpp rename to include/threading/id.hpp diff --git a/src/threading/pool.hpp b/include/threading/pool.hpp similarity index 100% rename from src/threading/pool.hpp rename to include/threading/pool.hpp diff --git a/src/threading/sync/caslock.hpp b/include/threading/sync/caslock.hpp similarity index 100% rename from src/threading/sync/caslock.hpp rename to include/threading/sync/caslock.hpp diff --git a/src/threading/sync/futex.hpp b/include/threading/sync/futex.hpp similarity index 98% rename from src/threading/sync/futex.hpp rename to include/threading/sync/futex.hpp index d4739a94f..e11dab3d5 100644 --- a/src/threading/sync/futex.hpp +++ b/include/threading/sync/futex.hpp @@ -4,7 +4,7 @@ #include #include -#include "lock_timeout_error.hpp" +#include "threading/sync/lock_timeout_error.hpp" #include "utils/cpu_relax.hpp" #include "utils/sys.hpp" diff --git a/src/threading/sync/lock_timeout_error.hpp b/include/threading/sync/lock_timeout_error.hpp similarity index 100% rename from src/threading/sync/lock_timeout_error.hpp rename to include/threading/sync/lock_timeout_error.hpp diff --git a/src/threading/sync/lockable.hpp b/include/threading/sync/lockable.hpp similarity index 90% rename from src/threading/sync/lockable.hpp rename to include/threading/sync/lockable.hpp index ce7141912..495634363 100644 --- a/src/threading/sync/lockable.hpp +++ b/include/threading/sync/lockable.hpp @@ -2,7 +2,7 @@ #include -#include "spinlock.hpp" +#include "threading/sync/spinlock.hpp" template class Lockable diff --git a/src/threading/sync/spinlock.hpp b/include/threading/sync/spinlock.hpp similarity index 100% rename from src/threading/sync/spinlock.hpp rename to include/threading/sync/spinlock.hpp diff --git a/src/threading/sync/timed_spinlock.hpp b/include/threading/sync/timed_spinlock.hpp similarity index 100% rename from src/threading/sync/timed_spinlock.hpp rename to include/threading/sync/timed_spinlock.hpp diff --git a/src/threading/task.hpp b/include/threading/task.hpp similarity index 100% rename from src/threading/task.hpp rename to include/threading/task.hpp diff --git a/src/threading/test.cpp b/include/threading/test.cpp similarity index 100% rename from src/threading/test.cpp rename to include/threading/test.cpp diff --git a/src/threading/thread.hpp b/include/threading/thread.hpp similarity index 100% rename from src/threading/thread.hpp rename to include/threading/thread.hpp diff --git a/src/transactions/commit_log.hpp b/include/transactions/commit_log.hpp similarity index 100% rename from src/transactions/commit_log.hpp rename to include/transactions/commit_log.hpp diff --git a/src/transactions/engine.hpp b/include/transactions/engine.hpp similarity index 84% rename from src/transactions/engine.hpp rename to include/transactions/engine.hpp index e18927cf5..2fb9d95d7 100644 --- a/src/transactions/engine.hpp +++ b/include/transactions/engine.hpp @@ -3,13 +3,12 @@ #include #include +#include "threading/sync/lockable.hpp" +#include "threading/sync/spinlock.hpp" +#include "transactions/commit_log.hpp" #include "transactions/transaction.hpp" #include "transactions/transaction_store.hpp" -#include "commit_log.hpp" - #include "utils/counters/simple_counter.hpp" -#include "threading/sync/spinlock.hpp" -#include "threading/sync/lockable.hpp" namespace tx { @@ -27,7 +26,7 @@ public: Engine() : counter(1) {} - Transaction& begin() + Transaction &begin() { auto guard = this->acquire_unique(); @@ -40,14 +39,13 @@ public: return *t; } - Transaction& advance(const Id& id) + Transaction &advance(const Id &id) { auto guard = this->acquire_unique(); - auto* t = store.get(id); + auto *t = store.get(id); - if(t == nullptr) - throw TransactionError("transaction does not exist"); + if (t == nullptr) throw TransactionError("transaction does not exist"); // this is a new command t->cid++; @@ -55,7 +53,7 @@ public: return *t; } - void commit(const Transaction& t) + void commit(const Transaction &t) { auto guard = this->acquire_unique(); clog.set_committed(t.id); @@ -63,7 +61,7 @@ public: finalize(t); } - void abort(const Transaction& t) + void abort(const Transaction &t) { auto guard = this->acquire_unique(); clog.set_aborted(t.id); @@ -94,7 +92,7 @@ public: CommitLog clog; private: - void finalize(const Transaction& t) + void finalize(const Transaction &t) { active.remove(t.id); @@ -106,5 +104,4 @@ private: Snapshot active; TransactionStore store; }; - } diff --git a/src/transactions/lock_store.hpp b/include/transactions/lock_store.hpp similarity index 100% rename from src/transactions/lock_store.hpp rename to include/transactions/lock_store.hpp diff --git a/src/transactions/snapshot.hpp b/include/transactions/snapshot.hpp similarity index 100% rename from src/transactions/snapshot.hpp rename to include/transactions/snapshot.hpp diff --git a/src/transactions/transaction_store.hpp b/include/transactions/transaction_store.hpp similarity index 100% rename from src/transactions/transaction_store.hpp rename to include/transactions/transaction_store.hpp diff --git a/src/utils/assert.hpp b/include/utils/assert.hpp similarity index 52% rename from src/utils/assert.hpp rename to include/utils/assert.hpp index f2ae72049..52c4ee49c 100644 --- a/src/utils/assert.hpp +++ b/include/utils/assert.hpp @@ -3,33 +3,33 @@ #include #include -#include "exceptions/basic_exception.hpp" +#include "utils/exceptions/basic_exception.hpp" // #define THROW_EXCEPTION_ON_ERROR // #define RUNTIME_ASSERT_ON -// handle assertion error -void assert_error_handler(const char *file_name, unsigned line_number, - const char *message) -{ -// this is a good place to put your debug breakpoint -// and add some other destination for error message -#ifdef THROW_EXCEPTION_ON_ERROR - throw BasicException(message); -#else - std::cerr << message << " in file " << file_name << " #" << line_number - << std::endl; - exit(1); -#endif -} +// // handle assertion error +// void assert_error_handler_(const char *file_name, unsigned line_number, +// const char *message) +// { +// // this is a good place to put your debug breakpoint +// // and add some other destination for error message +// #ifdef THROW_EXCEPTION_ON_ERROR +// throw BasicException(message); +// #else +// std::cerr << message << " in file " << file_name << " #" << line_number +// << std::endl; +// exit(1); +// #endif +// } // parmanant exception will always be executed #define permanent_assert(condition, message) \ if (!(condition)) { \ std::ostringstream s; \ s << message; \ - assert_error_handler(__FILE__, __LINE__, s.str().c_str()); \ } +// assert_error_handler_(__FILE__, __LINE__, s.str().c_str()); // runtime exception #ifdef RUNTIME_ASSERT_ON diff --git a/src/utils/auto_scope.hpp b/include/utils/auto_scope.hpp similarity index 100% rename from src/utils/auto_scope.hpp rename to include/utils/auto_scope.hpp diff --git a/src/utils/bash_colors.hpp b/include/utils/bash_colors.hpp similarity index 100% rename from src/utils/bash_colors.hpp rename to include/utils/bash_colors.hpp diff --git a/src/utils/bswap.hpp b/include/utils/bswap.hpp similarity index 100% rename from src/utils/bswap.hpp rename to include/utils/bswap.hpp diff --git a/src/utils/buffer.hpp b/include/utils/buffer.hpp similarity index 100% rename from src/utils/buffer.hpp rename to include/utils/buffer.hpp diff --git a/src/utils/command_line/arguments.hpp b/include/utils/command_line/arguments.hpp similarity index 100% rename from src/utils/command_line/arguments.hpp rename to include/utils/command_line/arguments.hpp diff --git a/src/utils/config/config.hpp b/include/utils/config/config.hpp similarity index 100% rename from src/utils/config/config.hpp rename to include/utils/config/config.hpp diff --git a/src/utils/counters/atomic_counter.hpp b/include/utils/counters/atomic_counter.hpp similarity index 100% rename from src/utils/counters/atomic_counter.hpp rename to include/utils/counters/atomic_counter.hpp diff --git a/src/utils/counters/ring_counter.hpp b/include/utils/counters/ring_counter.hpp similarity index 100% rename from src/utils/counters/ring_counter.hpp rename to include/utils/counters/ring_counter.hpp diff --git a/src/utils/counters/simple_counter.hpp b/include/utils/counters/simple_counter.hpp similarity index 100% rename from src/utils/counters/simple_counter.hpp rename to include/utils/counters/simple_counter.hpp diff --git a/src/utils/cpu_relax.hpp b/include/utils/cpu_relax.hpp similarity index 56% rename from src/utils/cpu_relax.hpp rename to include/utils/cpu_relax.hpp index 40cb4497a..eaf06be34 100644 --- a/src/utils/cpu_relax.hpp +++ b/include/utils/cpu_relax.hpp @@ -5,5 +5,8 @@ */ inline void cpu_relax() { + // if IBMPower + // HMT_very_low() + // http://stackoverflow.com/questions/5425506/equivalent-of-x86-pause-instruction-for-ppc asm("PAUSE"); } diff --git a/src/utils/crtp.hpp b/include/utils/crtp.hpp similarity index 100% rename from src/utils/crtp.hpp rename to include/utils/crtp.hpp diff --git a/src/utils/datetime/datetime.hpp b/include/utils/datetime/datetime.hpp similarity index 100% rename from src/utils/datetime/datetime.hpp rename to include/utils/datetime/datetime.hpp diff --git a/src/utils/datetime/datetime_error.hpp b/include/utils/datetime/datetime_error.hpp similarity index 100% rename from src/utils/datetime/datetime_error.hpp rename to include/utils/datetime/datetime_error.hpp diff --git a/src/utils/datetime/timestamp.hpp b/include/utils/datetime/timestamp.hpp similarity index 100% rename from src/utils/datetime/timestamp.hpp rename to include/utils/datetime/timestamp.hpp diff --git a/src/utils/exceptions/basic_exception.hpp b/include/utils/exceptions/basic_exception.hpp similarity index 100% rename from src/utils/exceptions/basic_exception.hpp rename to include/utils/exceptions/basic_exception.hpp diff --git a/src/utils/hashing/fnv.hpp b/include/utils/hashing/fnv.hpp similarity index 96% rename from src/utils/hashing/fnv.hpp rename to include/utils/hashing/fnv.hpp index 5259f5dc9..265f483c1 100644 --- a/src/utils/hashing/fnv.hpp +++ b/include/utils/hashing/fnv.hpp @@ -11,6 +11,9 @@ // fnv1a is recommended so use it as a default implementation. also use the // platform specific version of the function +namespace +{ + #ifdef MEMGRAPH64 template @@ -28,4 +31,5 @@ uint32_t fnv(const T& data) } #endif - + +} diff --git a/src/utils/hashing/fnv32.hpp b/include/utils/hashing/fnv32.hpp similarity index 98% rename from src/utils/hashing/fnv32.hpp rename to include/utils/hashing/fnv32.hpp index 7b02e6495..784861a16 100644 --- a/src/utils/hashing/fnv32.hpp +++ b/include/utils/hashing/fnv32.hpp @@ -3,6 +3,9 @@ #include #include +namespace +{ + #define OFFSET_BASIS32 2166136261u #define FNV_PRIME32 16777619u @@ -47,3 +50,5 @@ template<> uint32_t fnv1a32(const std::string& data) { return fnv1a32((const unsigned char*)data.c_str(), data.size()); } + +} diff --git a/src/utils/hashing/fnv64.hpp b/include/utils/hashing/fnv64.hpp similarity index 98% rename from src/utils/hashing/fnv64.hpp rename to include/utils/hashing/fnv64.hpp index 891163a76..ea741b956 100644 --- a/src/utils/hashing/fnv64.hpp +++ b/include/utils/hashing/fnv64.hpp @@ -3,6 +3,9 @@ #include #include +namespace +{ + #define OFFSET_BASIS64 14695981039346656037u #define FNV_PRIME64 1099511628211u @@ -47,3 +50,5 @@ template<> uint64_t fnv1a64(const std::string& data) { return fnv1a64((const unsigned char*)data.c_str(), data.size()); } + +} diff --git a/src/utils/ioc/container.hpp b/include/utils/ioc/container.hpp similarity index 100% rename from src/utils/ioc/container.hpp rename to include/utils/ioc/container.hpp diff --git a/src/utils/likely.hpp b/include/utils/likely.hpp similarity index 100% rename from src/utils/likely.hpp rename to include/utils/likely.hpp diff --git a/src/utils/mark_ref.hpp b/include/utils/mark_ref.hpp similarity index 100% rename from src/utils/mark_ref.hpp rename to include/utils/mark_ref.hpp diff --git a/src/utils/memory/allocator.hpp b/include/utils/memory/allocator.hpp similarity index 100% rename from src/utils/memory/allocator.hpp rename to include/utils/memory/allocator.hpp diff --git a/src/utils/memory/atomic_shared_ptr.hpp b/include/utils/memory/atomic_shared_ptr.hpp similarity index 100% rename from src/utils/memory/atomic_shared_ptr.hpp rename to include/utils/memory/atomic_shared_ptr.hpp diff --git a/src/utils/memory/block_allocator.hpp b/include/utils/memory/block_allocator.hpp similarity index 100% rename from src/utils/memory/block_allocator.hpp rename to include/utils/memory/block_allocator.hpp diff --git a/src/utils/memory/maker.hpp b/include/utils/memory/maker.hpp similarity index 100% rename from src/utils/memory/maker.hpp rename to include/utils/memory/maker.hpp diff --git a/src/utils/numerics/ceil.hpp b/include/utils/numerics/ceil.hpp similarity index 100% rename from src/utils/numerics/ceil.hpp rename to include/utils/numerics/ceil.hpp diff --git a/src/utils/placeholder.hpp b/include/utils/placeholder.hpp similarity index 100% rename from src/utils/placeholder.hpp rename to include/utils/placeholder.hpp diff --git a/src/utils/platform.hpp b/include/utils/platform.hpp similarity index 100% rename from src/utils/platform.hpp rename to include/utils/platform.hpp diff --git a/src/utils/random/fast_binomial.hpp b/include/utils/random/fast_binomial.hpp similarity index 97% rename from src/utils/random/fast_binomial.hpp rename to include/utils/random/fast_binomial.hpp index df08128f0..8a4819fa7 100644 --- a/src/utils/random/fast_binomial.hpp +++ b/include/utils/random/fast_binomial.hpp @@ -1,6 +1,6 @@ #pragma once -#include "xorshift128plus.hpp" +#include "utils/random/xorshift128plus.hpp" #include "utils/likely.hpp" template diff --git a/src/utils/random/xorshift128plus.hpp b/include/utils/random/xorshift128plus.hpp similarity index 100% rename from src/utils/random/xorshift128plus.hpp rename to include/utils/random/xorshift128plus.hpp diff --git a/src/utils/reference_wrapper.hpp b/include/utils/reference_wrapper.hpp similarity index 100% rename from src/utils/reference_wrapper.hpp rename to include/utils/reference_wrapper.hpp diff --git a/src/utils/stacktrace.hpp b/include/utils/stacktrace.hpp similarity index 100% rename from src/utils/stacktrace.hpp rename to include/utils/stacktrace.hpp diff --git a/src/utils/string/all.hpp b/include/utils/string/all.hpp similarity index 100% rename from src/utils/string/all.hpp rename to include/utils/string/all.hpp diff --git a/include/utils/string/file.hpp b/include/utils/string/file.hpp new file mode 100644 index 000000000..c1b580cf6 --- /dev/null +++ b/include/utils/string/file.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include + +namespace utils +{ + +std::string read_file(const char *filename); + +void write_file(const std::string& content, const std::string& path); + +} diff --git a/src/utils/string/intercalate.hpp b/include/utils/string/intercalate.hpp similarity index 100% rename from src/utils/string/intercalate.hpp rename to include/utils/string/intercalate.hpp diff --git a/include/utils/string/join.hpp b/include/utils/string/join.hpp new file mode 100644 index 000000000..509c080af --- /dev/null +++ b/include/utils/string/join.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include +#include + +namespace utils +{ + +std::string join(const std::vector& strings, + const char *separator); + +template +std::string prints(const Args&... args) +{ + std::vector strings = {args...}; + return join(strings, " "); +} + +} diff --git a/src/utils/string/linereader.hpp b/include/utils/string/linereader.hpp similarity index 100% rename from src/utils/string/linereader.hpp rename to include/utils/string/linereader.hpp diff --git a/src/utils/string/replace.hpp b/include/utils/string/replace.hpp similarity index 100% rename from src/utils/string/replace.hpp rename to include/utils/string/replace.hpp diff --git a/src/utils/string/split.hpp b/include/utils/string/split.hpp similarity index 100% rename from src/utils/string/split.hpp rename to include/utils/string/split.hpp diff --git a/src/utils/string/streq.hpp b/include/utils/string/streq.hpp similarity index 100% rename from src/utils/string/streq.hpp rename to include/utils/string/streq.hpp diff --git a/include/utils/string/transform.hpp b/include/utils/string/transform.hpp new file mode 100644 index 000000000..84f84aab3 --- /dev/null +++ b/include/utils/string/transform.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include +#include +#include + +namespace utils +{ + +void str_tolower(std::string& s); + +} diff --git a/src/utils/string/weak_string.hpp b/include/utils/string/weak_string.hpp similarity index 100% rename from src/utils/string/weak_string.hpp rename to include/utils/string/weak_string.hpp diff --git a/src/utils/sys.hpp b/include/utils/sys.hpp similarity index 100% rename from src/utils/sys.hpp rename to include/utils/sys.hpp diff --git a/src/utils/sysinfo/memory.hpp b/include/utils/sysinfo/memory.hpp similarity index 100% rename from src/utils/sysinfo/memory.hpp rename to include/utils/sysinfo/memory.hpp diff --git a/src/utils/terminate_handler.hpp b/include/utils/terminate_handler.hpp similarity index 100% rename from src/utils/terminate_handler.hpp rename to include/utils/terminate_handler.hpp diff --git a/src/utils/time/timer.hpp b/include/utils/time/timer.hpp similarity index 100% rename from src/utils/time/timer.hpp rename to include/utils/time/timer.hpp diff --git a/src/utils/timer/timer.hpp b/include/utils/timer/timer.hpp similarity index 97% rename from src/utils/timer/timer.hpp rename to include/utils/timer/timer.hpp index 1cf53ea2b..4fa64fd21 100644 --- a/src/utils/timer/timer.hpp +++ b/include/utils/timer/timer.hpp @@ -6,7 +6,7 @@ #include #include -#include "utils/log/logger.hpp" +#include "logging/default.hpp" /** @class Timer * @brief The timer contains counter and handler. @@ -116,7 +116,7 @@ public: while (is_running.load()) { std::this_thread::sleep_for(delta_time_type(delta_time)); timer_container.process(); - LOG_INFO("timer_container.process()"); + logging::info("timer_container.process()"); } }); } diff --git a/src/utils/total_ordering.hpp b/include/utils/total_ordering.hpp similarity index 100% rename from src/utils/total_ordering.hpp rename to include/utils/total_ordering.hpp diff --git a/src/utils/total_ordering_with.hpp b/include/utils/total_ordering_with.hpp similarity index 100% rename from src/utils/total_ordering_with.hpp rename to include/utils/total_ordering_with.hpp diff --git a/src/utils/type_discovery.hpp b/include/utils/type_discovery.hpp similarity index 100% rename from src/utils/type_discovery.hpp rename to include/utils/type_discovery.hpp diff --git a/src/utils/types/byte.hpp b/include/utils/types/byte.hpp similarity index 100% rename from src/utils/types/byte.hpp rename to include/utils/types/byte.hpp diff --git a/src/utils/underlying_cast.hpp b/include/utils/underlying_cast.hpp similarity index 100% rename from src/utils/underlying_cast.hpp rename to include/utils/underlying_cast.hpp diff --git a/src/utils/variadic/variadic.hpp b/include/utils/variadic/variadic.hpp similarity index 100% rename from src/utils/variadic/variadic.hpp rename to include/utils/variadic/variadic.hpp diff --git a/src/utils/visitor/visitable.hpp b/include/utils/visitor/visitable.hpp similarity index 100% rename from src/utils/visitor/visitable.hpp rename to include/utils/visitor/visitable.hpp diff --git a/src/utils/visitor/visitor.hpp b/include/utils/visitor/visitor.hpp similarity index 100% rename from src/utils/visitor/visitor.hpp rename to include/utils/visitor/visitor.hpp diff --git a/src/bolt/v1/messaging/messages.hpp b/src/bolt/v1/messaging/messages.hpp deleted file mode 100644 index 854f53936..000000000 --- a/src/bolt/v1/messaging/messages.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace bolt -{ - - - -} diff --git a/src/bolt/v1/serialization/record_stream.hpp b/src/bolt/v1/serialization/record_stream.hpp deleted file mode 100644 index ffd14f6e4..000000000 --- a/src/bolt/v1/serialization/record_stream.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "bolt_serializer.hpp" - -namespace bolt -{ - -class RecordStream : BoltSerializer -{ -public: - - -}; - -} diff --git a/src/bolt/v1/serialization/socket_serializer.hpp b/src/bolt/v1/serialization/socket_serializer.hpp deleted file mode 100644 index 7d16f6666..000000000 --- a/src/bolt/v1/serialization/socket_serializer.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "bolt/v1/transport/chunked_encoder.hpp" -#include "bolt/v1/transport/socket_stream.hpp" - -#include "bolt/v1/transport/bolt_encoder.hpp" - -namespace bolt -{ - -template -class SocketSerializer : public BoltEncoder> -{ -public: - SocketSerializer(Socket& socket) : BoltEncoder(encoder), stream(socket) {} - -private: - SocketStream stream; - ChunkedEncoder encoder {stream}; -}; - -} diff --git a/src/bolt/v1/session.hpp b/src/bolt/v1/session.hpp deleted file mode 100644 index af5c1a708..000000000 --- a/src/bolt/v1/session.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include "io/network/tcp/stream.hpp" -#include "io/network/socket.hpp" - -#include "bolt/v1/states/state.hpp" - -#include "bolt/v1/transport/bolt_decoder.hpp" -#include "bolt/v1/transport/bolt_encoder.hpp" - -#include "bolt/v1/serialization/socket_serializer.hpp" - -#include "bolt.hpp" -#include "logging/default.hpp" - -namespace bolt -{ - -class Session : public io::tcp::Stream -{ -public: - using Decoder = BoltDecoder; - using Encoder = SocketSerializer; - - Session(io::Socket&& socket, Bolt& bolt); - - bool alive() const; - - void execute(const byte* data, size_t len); - void close(); - - Bolt& bolt; - - Decoder decoder; - Encoder encoder {socket}; - - bool connected {false}; - State* state; - -protected: - Logger logger; -}; - -} diff --git a/src/bolt/v1/states.cpp b/src/bolt/v1/states.cpp deleted file mode 100644 index f7bdea07b..000000000 --- a/src/bolt/v1/states.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "states.hpp" - -#include "states/handshake.hpp" -#include "states/init.hpp" -#include "states/error.hpp" - -#include "states/executor.hpp" - -namespace bolt -{ - -States::States() -{ - handshake = std::make_unique(); - init = std::make_unique(); - executor = std::make_unique(); - error = std::make_unique(); -} - -} diff --git a/src/bolt/v1/states/error.cpp b/src/bolt/v1/states/error.cpp deleted file mode 100644 index c51eda182..000000000 --- a/src/bolt/v1/states/error.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "error.hpp" - -#include "bolt/v1/session.hpp" - -namespace bolt -{ - -State* Error::run(Session& session) -{ - auto message_type = session.decoder.read_byte(); - - if(message_type == MessageCode::AckFailure) - { - // todo reset current statement? is it even necessary? - - session.encoder.message_success_empty(); - session.encoder.flush(); - - return session.bolt.states.executor.get(); - } - else if(message_type == MessageCode::Reset) - { - // todo rollback current transaction - // discard all records waiting to be sent - - session.encoder.message_success_empty(); - session.encoder.flush(); - - return session.bolt.states.executor.get(); - } - - session.encoder.message_ignored(); - session.encoder.flush(); - - return this; -} - -} diff --git a/src/bolt/v1/states/error.hpp b/src/bolt/v1/states/error.hpp deleted file mode 100644 index 0ef5964bf..000000000 --- a/src/bolt/v1/states/error.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "bolt/v1/states/state.hpp" - -namespace bolt -{ - -class Error : public State -{ -public: - State* run(Session& session) override; -}; - -} diff --git a/src/bolt/v1/bolt.cpp b/src/communication/bolt/v1/bolt.cpp similarity index 70% rename from src/bolt/v1/bolt.cpp rename to src/communication/bolt/v1/bolt.cpp index 77dbe6d18..9efd1b10c 100644 --- a/src/bolt/v1/bolt.cpp +++ b/src/communication/bolt/v1/bolt.cpp @@ -1,7 +1,6 @@ -#include "bolt.hpp" +#include "communication/bolt/v1/bolt.hpp" -#include "session.hpp" -#include +#include "communication/bolt/v1/session.hpp" namespace bolt { @@ -14,6 +13,8 @@ Session* Bolt::create_session(io::Socket&& socket) { // TODO fix session lifecycle handling // dangling pointers are not cool :) + + // TODO attach currently active Db return new Session(std::forward(socket), *this); } diff --git a/src/bolt/v1/session.cpp b/src/communication/bolt/v1/session.cpp similarity index 90% rename from src/bolt/v1/session.cpp rename to src/communication/bolt/v1/session.cpp index dd437cdf0..69e9f1c7c 100644 --- a/src/bolt/v1/session.cpp +++ b/src/communication/bolt/v1/session.cpp @@ -1,4 +1,4 @@ -#include "session.hpp" +#include "communication/bolt/v1/session.hpp" namespace bolt { @@ -51,4 +51,9 @@ void Session::close() bolt.close(this); } +Db& Session::active_db() +{ + return bolt.dbms.active(); +} + } diff --git a/src/communication/bolt/v1/states.cpp b/src/communication/bolt/v1/states.cpp new file mode 100644 index 000000000..12d001aca --- /dev/null +++ b/src/communication/bolt/v1/states.cpp @@ -0,0 +1,19 @@ +#include "communication/bolt/v1/states.hpp" + +#include "communication/bolt/v1/states/handshake.hpp" +#include "communication/bolt/v1/states/init.hpp" +#include "communication/bolt/v1/states/error.hpp" +#include "communication/bolt/v1/states/executor.hpp" + +namespace bolt +{ + +States::States() +{ + handshake = std::make_unique(); + init = std::make_unique(); + executor = std::make_unique(); + error = std::make_unique(); +} + +} diff --git a/src/communication/bolt/v1/states/error.cpp b/src/communication/bolt/v1/states/error.cpp new file mode 100644 index 000000000..2a83c13fc --- /dev/null +++ b/src/communication/bolt/v1/states/error.cpp @@ -0,0 +1,37 @@ +#include "communication/bolt/v1/states/error.hpp" + +namespace bolt +{ + +State* Error::run(Session& session) +{ + auto message_type = session.decoder.read_byte(); + + if(message_type == MessageCode::AckFailure) + { + // TODO reset current statement? is it even necessary? + + session.output_stream.write_success_empty(); + session.output_stream.flush(); + + return session.bolt.states.executor.get(); + } + else if(message_type == MessageCode::Reset) + { + // TODO rollback current transaction + // discard all records waiting to be sent + + session.output_stream.write_success_empty(); + session.output_stream.flush(); + + + return session.bolt.states.executor.get(); + } + + session.output_stream.write_ignored(); + session.output_stream.flush(); + + return this; +} + +} diff --git a/src/bolt/v1/states/executor.cpp b/src/communication/bolt/v1/states/executor.cpp similarity index 62% rename from src/bolt/v1/states/executor.cpp rename to src/communication/bolt/v1/states/executor.cpp index 7306618ab..8f98db718 100644 --- a/src/bolt/v1/states/executor.cpp +++ b/src/communication/bolt/v1/states/executor.cpp @@ -1,6 +1,5 @@ -#include "executor.hpp" - -#include "bolt/v1/messaging/codes.hpp" +#include "communication/bolt/v1/states/executor.hpp" +#include "communication/bolt/v1/messaging/codes.hpp" namespace bolt { @@ -13,6 +12,8 @@ State* Executor::run(Session& session) // information contained in this byte session.decoder.read_byte(); + logger.debug("Run"); + auto message_type = session.decoder.read_byte(); if(message_type == MessageCode::Run) @@ -53,43 +54,28 @@ void Executor::run(Session& session, Query& query) { logger.trace("[Run] '{}'", query.statement); - session.encoder.message_success(); - session.encoder.write_map_header(1); + auto &db = session.active_db(); + logger.debug("[ActiveDB] '{}'", db.name()); - session.encoder.write_string("fields"); - session.encoder.write_list_header(1); - session.encoder.write_string("name"); - - session.encoder.flush(); + // TODO: hangle syntax error use case + query_engine.execute(query.statement, db, session.output_stream); } void Executor::pull_all(Session& session) { logger.trace("[PullAll]"); - session.encoder.message_record(); - session.encoder.write_list_header(1); - session.encoder.write_string("buda"); - - session.encoder.message_record(); - session.encoder.write_list_header(1); - session.encoder.write_string("domko"); - - session.encoder.message_record(); - session.encoder.write_list_header(1); - session.encoder.write_string("max"); - - session.encoder.message_success_empty(); - - session.encoder.flush(); + session.output_stream.flush(); } void Executor::discard_all(Session& session) { logger.trace("[DiscardAll]"); - session.encoder.message_success(); - session.encoder.flush(); + // TODO: discard state + + session.output_stream.write_success(); + session.output_stream.flush(); } } diff --git a/src/bolt/v1/states/handshake.cpp b/src/communication/bolt/v1/states/handshake.cpp similarity index 85% rename from src/bolt/v1/states/handshake.cpp rename to src/communication/bolt/v1/states/handshake.cpp index b685381d6..faaa4ee0c 100644 --- a/src/bolt/v1/states/handshake.cpp +++ b/src/communication/bolt/v1/states/handshake.cpp @@ -1,6 +1,6 @@ -#include "handshake.hpp" +#include "communication/bolt/v1/states/handshake.hpp" -#include "bolt/v1/session.hpp" +#include "communication/bolt/v1/session.hpp" namespace bolt { diff --git a/src/bolt/v1/states/init.cpp b/src/communication/bolt/v1/states/init.cpp similarity index 81% rename from src/bolt/v1/states/init.cpp rename to src/communication/bolt/v1/states/init.cpp index e1f30f690..323c1ad29 100644 --- a/src/bolt/v1/states/init.cpp +++ b/src/communication/bolt/v1/states/init.cpp @@ -1,7 +1,7 @@ -#include "init.hpp" +#include "communication/bolt/v1/states/init.hpp" -#include "bolt/v1/session.hpp" -#include "bolt/v1/messaging/codes.hpp" +#include "communication/bolt/v1/session.hpp" +#include "communication/bolt/v1/messaging/codes.hpp" #include "utils/likely.hpp" @@ -45,8 +45,8 @@ State* Init::execute(Session& session, Message& message) { logger.debug("Client connected '{}'", message.client_name); - session.encoder.message_success_empty(); - session.encoder.flush(); + session.output_stream.write_success_empty(); + session.output_stream.flush(); return session.bolt.states.executor.get(); } diff --git a/src/bolt/v1/transport/bolt_decoder.cpp b/src/communication/bolt/v1/transport/bolt_decoder.cpp similarity index 51% rename from src/bolt/v1/transport/bolt_decoder.cpp rename to src/communication/bolt/v1/transport/bolt_decoder.cpp index 9e16c2264..96248a8fc 100644 --- a/src/bolt/v1/transport/bolt_decoder.cpp +++ b/src/communication/bolt/v1/transport/bolt_decoder.cpp @@ -1,30 +1,24 @@ -#include "bolt_decoder.hpp" +#include "communication/bolt/v1/transport/bolt_decoder.hpp" +#include "communication/bolt/v1/packing/codes.hpp" -#include - -#include "utils/bswap.hpp" #include "logging/default.hpp" - -#include "bolt/v1/packing/codes.hpp" +#include "utils/bswap.hpp" namespace bolt { -void BoltDecoder::handshake(const byte*& data, size_t len) +void BoltDecoder::handshake(const byte *&data, size_t len) { buffer.write(data, len); data += len; } -bool BoltDecoder::decode(const byte*& data, size_t len) +bool BoltDecoder::decode(const byte *&data, size_t len) { return decoder(data, len); } -bool BoltDecoder::empty() const -{ - return pos == buffer.size(); -} +bool BoltDecoder::empty() const { return pos == buffer.size(); } void BoltDecoder::reset() { @@ -32,34 +26,28 @@ void BoltDecoder::reset() pos = 0; } -byte BoltDecoder::peek() const -{ - return buffer[pos]; -} +byte BoltDecoder::peek() const { return buffer[pos]; } -byte BoltDecoder::read_byte() -{ - return buffer[pos++]; -} +byte BoltDecoder::read_byte() { return buffer[pos++]; } -void BoltDecoder::read_bytes(void* dest, size_t n) +void BoltDecoder::read_bytes(void *dest, size_t n) { std::memcpy(dest, buffer.data() + pos, n); pos += n; } template -T parse(const void* data) +T parse(const void *data) { // reinterpret bytes as the target value - auto value = reinterpret_cast(data); + auto value = reinterpret_cast(data); // swap values to little endian return bswap(*value); } template -T parse(Buffer& buffer, size_t& pos) +T parse(Buffer &buffer, size_t &pos) { // get a pointer to the data we're converting auto ptr = buffer.data() + pos; @@ -71,35 +59,17 @@ T parse(Buffer& buffer, size_t& pos) return parse(ptr); } -int16_t BoltDecoder::read_int16() -{ - return parse(buffer, pos); -} +int16_t BoltDecoder::read_int16() { return parse(buffer, pos); } -uint16_t BoltDecoder::read_uint16() -{ - return parse(buffer, pos); -} +uint16_t BoltDecoder::read_uint16() { return parse(buffer, pos); } -int32_t BoltDecoder::read_int32() -{ - return parse(buffer, pos); -} +int32_t BoltDecoder::read_int32() { return parse(buffer, pos); } -uint32_t BoltDecoder::read_uint32() -{ - return parse(buffer, pos); -} +uint32_t BoltDecoder::read_uint32() { return parse(buffer, pos); } -int64_t BoltDecoder::read_int64() -{ - return parse(buffer, pos); -} +int64_t BoltDecoder::read_int64() { return parse(buffer, pos); } -uint64_t BoltDecoder::read_uint64() -{ - return parse(buffer, pos); -} +uint64_t BoltDecoder::read_uint64() { return parse(buffer, pos); } double BoltDecoder::read_float64() { @@ -115,44 +85,33 @@ std::string BoltDecoder::read_string() uint32_t size; // if the first 4 bits equal to 1000 (0x8), this is a tiny string - if((marker & 0xF0) == pack::TinyString) - { + if ((marker & 0xF0) == pack::TinyString) { // size is stored in the lower 4 bits of the marker byte size = marker & 0x0F; } // if the marker is 0xD0, size is an 8-bit unsigned integer - if(marker == pack::String8) - { + if (marker == pack::String8) { size = read_byte(); } // if the marker is 0xD1, size is a 16-bit big-endian unsigned integer - else if(marker == pack::String16) - { + else if (marker == pack::String16) { size = read_uint16(); } // if the marker is 0xD2, size is a 32-bit big-endian unsigned integer - else if(marker == pack::String32) - { + else if (marker == pack::String32) { size = read_uint32(); - } - else - { + } else { // TODO error? return res; } - if(size == 0) - return res; + if (size == 0) return res; - res.append(reinterpret_cast(raw()), size); + res.append(reinterpret_cast(raw()), size); pos += size; return res; } -const byte* BoltDecoder::raw() const -{ - return buffer.data() + pos; -} - +const byte *BoltDecoder::raw() const { return buffer.data() + pos; } } diff --git a/src/bolt/v1/transport/buffer.cpp b/src/communication/bolt/v1/transport/buffer.cpp similarity index 76% rename from src/bolt/v1/transport/buffer.cpp rename to src/communication/bolt/v1/transport/buffer.cpp index 05a0769da..3406135e6 100644 --- a/src/bolt/v1/transport/buffer.cpp +++ b/src/communication/bolt/v1/transport/buffer.cpp @@ -1,4 +1,4 @@ -#include "buffer.hpp" +#include "communication/bolt/v1/transport/buffer.hpp" namespace bolt { diff --git a/src/communication/gate/init.cpp b/src/communication/gate/init.cpp new file mode 100644 index 000000000..70b786d12 --- /dev/null +++ b/src/communication/gate/init.cpp @@ -0,0 +1 @@ +// TODO diff --git a/src/communication/http/init.cpp b/src/communication/http/init.cpp new file mode 100644 index 000000000..70b786d12 --- /dev/null +++ b/src/communication/http/init.cpp @@ -0,0 +1 @@ +// TODO diff --git a/src/cypher/lexertl b/src/cypher/lexertl deleted file mode 160000 index 7d4d36a35..000000000 --- a/src/cypher/lexertl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7d4d36a357027df0e817453cc9cf948f71047ca9 diff --git a/src/cypher/parser.hpp b/src/cypher/parser.hpp index d33183867..f3f53e011 100644 --- a/src/cypher/parser.hpp +++ b/src/cypher/parser.hpp @@ -4,6 +4,7 @@ #include "token.hpp" #include "ast/tree.hpp" #include "tokenizer/cypher_lexer.hpp" +#include "logging/default.hpp" void* cypher_parserAlloc(void* (*allocProc)(size_t)); void cypher_parser(void*, int, Token*, ast::Ast* ast); @@ -15,7 +16,7 @@ namespace cypher class Parser { public: - Parser() + Parser() : logger(logging::log->logger("LexicalParser")) { parser = cypher_parserAlloc(malloc); } @@ -34,7 +35,8 @@ public: { tokens.emplace_back(tokenizer.lookup()); auto& token = tokens.back(); - std::cout << token << std::endl; + // TODO: resolve fmt error with { + // logger.debug(token.repr()); cypher_parser(parser, token.id, &token, &tree); } while(tokens.back().id != 0); @@ -42,6 +44,9 @@ public: return std::move(tree); } +protected: + Logger logger; + private: void* parser; }; diff --git a/src/cypher/token.hpp b/src/cypher/token.hpp index 1df4bcf21..fb21e6d06 100644 --- a/src/cypher/token.hpp +++ b/src/cypher/token.hpp @@ -1,9 +1,10 @@ #pragma once +#include #include - #include #include +#include struct Token { @@ -25,6 +26,16 @@ struct Token return id > 0; } + /* + * String representation. + */ + std::string repr() const + { + // TODO: wrap fmt format + // return fmt::format("TOKEN id = {}, value = {}", id, value); + return ""; + } + /* * Ostream operator * @@ -32,7 +43,6 @@ struct Token */ friend std::ostream& operator<<(std::ostream& stream, const Token& token) { - return stream << "TOKEN id = " << token.id - << ", value = '" << token.value << "'"; + return stream << token.repr(); } }; diff --git a/src/dbms/dbms.hpp b/src/dbms/dbms.hpp index a71c2ad24..d63af620c 100644 --- a/src/dbms/dbms.hpp +++ b/src/dbms/dbms.hpp @@ -1,8 +1,46 @@ #pragma once +#include + +#include "database/db.hpp" + class Dbms { public: + Dbms() { create_default(); } + // returns active database + Db &active() + { + if (UNLIKELY(active_db == nullptr)) create_default(); + return *active_db; + } + + // set active database + // if active database doesn't exist create one + Db &active(const std::string &name) + { + // create db if it doesn't exist + if (dbs.find(name) == dbs.end()) { + dbs.emplace(std::piecewise_construct, std::forward_as_tuple(name), + std::forward_as_tuple(name)); + } + + // set and return active db + auto &db = dbs.at(name); + return active_db = &db, *active_db; + } + + // TODO: DELETE action + +private: + // dbs container + std::map dbs; + + // currently active database + Db *active_db; + + // creates default database + void create_default() { active("default"); } }; diff --git a/src/dbms/server/bolt.hpp b/src/dbms/server/bolt.hpp deleted file mode 100644 index c11568cb6..000000000 --- a/src/dbms/server/bolt.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -class BoltServer -{ -public: - BoltServer() = default; - - -}; diff --git a/src/examples/bolt.cpp b/src/examples/bolt.cpp deleted file mode 100644 index 2b2b7f317..000000000 --- a/src/examples/bolt.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#include "bolt/v1/server/server.hpp" -#include "bolt/v1/server/worker.hpp" - -#include "io/network/socket.hpp" - -#include "logging/default.hpp" -#include "logging/streams/stdout.hpp" - -static bolt::Server* serverptr; - -Logger logger; - -void sigint_handler(int s) -{ - auto signal = s == SIGINT ? "SIGINT" : "SIGABRT"; - - logger.info("Recieved signal {}", signal); - logger.info("Shutting down..."); - - std::exit(EXIT_SUCCESS); -} - -static constexpr const char* interface = "0.0.0.0"; -static constexpr const char* port = "7687"; - -int main(void) -{ - logging::init_sync(); - logging::log->pipe(std::make_unique()); - logger = logging::log->logger("Main"); - - signal(SIGINT, sigint_handler); - signal(SIGABRT, sigint_handler); - - io::Socket socket; - - try - { - socket = io::Socket::bind(interface, port); - } - catch(io::NetworkError e) - { - logger.error("Cannot bind to socket on {} at {}", interface, port); - logger.error("{}", e.what()); - - std::exit(EXIT_FAILURE); - } - - socket.set_non_blocking(); - socket.listen(1024); - - logger.info("Listening on {} at {}", interface, port); - - bolt::Server server(std::move(socket)); - serverptr = &server; - - constexpr size_t N = 1; - - logger.info("Starting {} workers", N); - server.start(N); - - logger.info("Shutting down..."); - - return EXIT_SUCCESS; -} diff --git a/src/examples/bolt_py_client/.initial_test.py.swn b/src/examples/bolt_py_client/.initial_test.py.swn new file mode 100644 index 000000000..a7f394ee9 Binary files /dev/null and b/src/examples/bolt_py_client/.initial_test.py.swn differ diff --git a/src/examples/bolt_py_client/initial_test.py b/src/examples/bolt_py_client/initial_test.py new file mode 100644 index 000000000..75dfad463 --- /dev/null +++ b/src/examples/bolt_py_client/initial_test.py @@ -0,0 +1,38 @@ +from neo4j.v1 import GraphDatabase, basic_auth, types + +# create session +driver = GraphDatabase.driver("bolt://localhost", + auth=basic_auth("neo4j", "neo4j"), + encrypted=0) +session = driver.session() + +queries = []; + +queries.append((True, "CREATE (n {name: \"Max\", age: 21}) RETURN n")) +queries.append((False, "CREATE (n {name: \"Paul\", age: 21}) RETURN n")) +queries.append((False, "CREATE (n:PERSON {name: \"Chris\", age: 20}) RETURN n")) +queries.append((False, "CREATE (n:PERSON:STUDENT {name: \"Marko\", age: 19}) RETURN n")) +queries.append((False, "CREATE (n:TEST {string: \"Properties test\", integer: 100, float: 232.2323, bool: True}) RETURN n")) + +queries.append((False, "MATCH (n) WHERE ID(n)=0 RETURN n")) +queries.append((False, "MATCH (n) WHERE ID(n)=1 RETURN n")) +queries.append((False, "MATCH (n) WHERE ID(n)=2 RETURN n")) +queries.append((False, "MATCH (n) WHERE ID(n)=3 RETURN n")) +queries.append((False, "MATCH (n) WHERE ID(n)=4 RETURN n")) + +queries.append((False, "MATCH (n1), (n2) WHERE ID(n1)=0 AND ID(n2)=1 CREATE (n1)-[r:IS]->(n2) RETURN r")) +queries.append((False, "MATCH (n1), (n2) WHERE ID(n1)=0 AND ID(n2)=1 CREATE (n1)-[r:IS {name: \"test\", age: 23}]->(n2) RETURN r")) +queries.append((False, "MATCH (n1), (n2) WHERE ID(n1)=0 AND ID(n2)=1 CREATE (n1)-[r:IS {name: \"test\", age: 23}]->(n2) RETURN r")) + +queries.append((False, "MATCH ()-[r]-() WHERE ID(r)=0 RETURN r")) +queries.append((False, "MATCH ()-[r]-() WHERE ID(r)=1 RETURN r")) +queries.append((False, "MATCH ()-[r]-() WHERE ID(r)=2 RETURN r")) + +queries.append((False, "MATCH (n) WHERE ID(n)=1 SET n.name = \"updated_name\" RETURN n")) +queries.append((False, "MATCH (n) WHERE ID(n)=1 RETURN n")) +queries.append((False, "MATCH ()-[r]-() WHERE ID(r)=1 SET r.name = \"TEST100\" RETURN r")) +queries.append((False, "MATCH ()-[r]-() WHERE ID(r)=1 RETURN r")) + +for active, query in queries: + if active: + session.run(query) diff --git a/src/examples/bolt_py_client/requirements.txt b/src/examples/bolt_py_client/requirements.txt new file mode 100644 index 000000000..791428506 --- /dev/null +++ b/src/examples/bolt_py_client/requirements.txt @@ -0,0 +1 @@ +neo4j-driver==1.0.2 diff --git a/src/examples/compile-bolt.sh b/src/examples/compile-bolt.sh deleted file mode 100644 index 855539e59..000000000 --- a/src/examples/compile-bolt.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -clang++ -g -rdynamic ../bolt/v1/states/error.cpp ../bolt/v1/states/executor.cpp ../logging/streams/stdout.cpp ../logging/levels.cpp ../logging/logs/sync_log.cpp ../logging/logs/async_log.cpp ../logging/default.cpp ../logging/log.cpp ../bolt/v1/bolt.cpp ../bolt/v1/states/init.cpp ../bolt/v1/states.cpp ../bolt/v1/states/handshake.cpp ../bolt/v1/transport/bolt_decoder.cpp ../bolt/v1/transport/buffer.cpp ../bolt/v1/session.cpp bolt.cpp ../io/network/tls.cpp -o bolt -std=c++14 -I ../ -I ../../libs/fmt/ -pthread -lcppformat -lssl -lcrypto diff --git a/src/io/network/tls.cpp b/src/io/network/tls.cpp index d35ffe8df..921d56c4b 100644 --- a/src/io/network/tls.cpp +++ b/src/io/network/tls.cpp @@ -1,5 +1,5 @@ -#include "tls.hpp" -#include "tls_error.hpp" +#include "io/network/tls.hpp" +#include "io/network/tls_error.hpp" namespace io { diff --git a/src/io/uv/tcpstream.inl b/src/io/uv/tcpstream.inl index 669bb63e0..be1bc2169 100644 --- a/src/io/uv/tcpstream.inl +++ b/src/io/uv/tcpstream.inl @@ -1,6 +1,6 @@ #pragma once -#include "tcpstream.hpp" +#include "io/uv/tcpstream.hpp" namespace uv { diff --git a/src/io/uv/uvbuffer.inl b/src/io/uv/uvbuffer.inl index 219f3e794..7192e0b40 100644 --- a/src/io/uv/uvbuffer.inl +++ b/src/io/uv/uvbuffer.inl @@ -3,7 +3,7 @@ #include #include -#include "uvbuffer.hpp" +#include "io/uv/uvbuffer.hpp" namespace uv { diff --git a/src/logging/default.cpp b/src/logging/default.cpp index 914d50417..fe3bcf627 100644 --- a/src/logging/default.cpp +++ b/src/logging/default.cpp @@ -1,4 +1,4 @@ -#include "default.hpp" +#include "logging/default.hpp" #include "logging/logs/async_log.hpp" #include "logging/logs/sync_log.hpp" @@ -20,6 +20,16 @@ Logger init_debug_logger() Logger debug_logger = init_debug_logger(); +std::unique_ptr info_log = std::make_unique(); + +Logger init_info_logger() +{ + info_log->pipe(std::make_unique()); + return info_log->logger("INFO"); +} + +Logger info_logger = init_info_logger(); + void init_async() { log = std::make_unique(); diff --git a/src/logging/levels.cpp b/src/logging/levels.cpp index d5982677b..48955fe9b 100644 --- a/src/logging/levels.cpp +++ b/src/logging/levels.cpp @@ -1,4 +1,4 @@ -#include "levels.hpp" +#include "logging/levels.hpp" std::string Trace::text = "TRACE"; std::string Debug::text = "DEBUG"; diff --git a/src/logging/log.cpp b/src/logging/log.cpp index 586e58424..fe91905b2 100644 --- a/src/logging/log.cpp +++ b/src/logging/log.cpp @@ -1,7 +1,7 @@ #include -#include "log.hpp" -#include "logger.hpp" +#include "logging/log.hpp" +#include "logging/logger.hpp" Logger Log::logger(const std::string& name) { diff --git a/src/logging/logs/async_log.cpp b/src/logging/logs/async_log.cpp index e95ba2f29..b5b942811 100644 --- a/src/logging/logs/async_log.cpp +++ b/src/logging/logs/async_log.cpp @@ -1,4 +1,4 @@ -#include "async_log.hpp" +#include "logging/logs/async_log.hpp" AsyncLog::~AsyncLog() { diff --git a/src/logging/logs/sync_log.cpp b/src/logging/logs/sync_log.cpp index 498a8828b..1cd0cf5e0 100644 --- a/src/logging/logs/sync_log.cpp +++ b/src/logging/logs/sync_log.cpp @@ -1,4 +1,4 @@ -#include "sync_log.hpp" +#include "logging/logs/sync_log.hpp" void SyncLog::emit(Record::uptr record) { diff --git a/src/logging/streams/stdout.cpp b/src/logging/streams/stdout.cpp index 8ffb97234..17d04806d 100644 --- a/src/logging/streams/stdout.cpp +++ b/src/logging/streams/stdout.cpp @@ -1,4 +1,4 @@ -#include "stdout.hpp" +#include "logging/streams/stdout.hpp" #include #include diff --git a/src/memgraph_bolt.cpp b/src/memgraph_bolt.cpp index fb59219de..64797e160 100644 --- a/src/memgraph_bolt.cpp +++ b/src/memgraph_bolt.cpp @@ -1,17 +1,74 @@ +#include +#include + +#include "communication/bolt/v1/server/server.hpp" +#include "communication/bolt/v1/server/worker.hpp" + +#include "io/network/socket.hpp" + +#include "logging/default.hpp" +#include "logging/streams/stdout.hpp" + #include "utils/terminate_handler.hpp" -int main(int argc, char *argv[]) +static bolt::Server* serverptr; + +Logger logger; + +void sigint_handler(int s) { - if (argc < 2) { - std::cout << "Port not defined" << std::endl; - std::exit(0); - } + auto signal = s == SIGINT ? "SIGINT" : "SIGABRT"; - auto port = std::stoi(argv[1]); + logger.info("Recieved signal {}", signal); + logger.info("Shutting down..."); - std::cout << "Port is: " << port << std::endl; + std::exit(EXIT_SUCCESS); +} +static constexpr const char* interface = "0.0.0.0"; +static constexpr const char* port = "7687"; + +int main(void) +{ + // TODO figure out what is the relationship between this and signals + // that are configured below std::set_terminate(&terminate_handler); - return 0; + logging::init_async(); + logging::log->pipe(std::make_unique()); + logger = logging::log->logger("Main"); + + signal(SIGINT, sigint_handler); + signal(SIGABRT, sigint_handler); + + io::Socket socket; + + try + { + socket = io::Socket::bind(interface, port); + } + catch(io::NetworkError e) + { + logger.error("Cannot bind to socket on {} at {}", interface, port); + logger.error("{}", e.what()); + + std::exit(EXIT_FAILURE); + } + + socket.set_non_blocking(); + socket.listen(1024); + + logger.info("Listening on {} at {}", interface, port); + + bolt::Server server(std::move(socket)); + serverptr = &server; + + constexpr size_t N = 1; + + logger.info("Starting {} workers", N); + server.start(N); + + logger.info("Shutting down..."); + + return EXIT_SUCCESS; } diff --git a/src/mvcc/atom.hpp b/src/mvcc/atom.hpp index 75f20dadc..6349bc79c 100644 --- a/src/mvcc/atom.hpp +++ b/src/mvcc/atom.hpp @@ -1,33 +1,31 @@ #pragma once #include "mvcc/id.hpp" +#include "mvcc/version.hpp" #include "threading/sync/lockable.hpp" #include "transactions/transaction.hpp" -#include "version.hpp" namespace mvcc { +// TODO: this can be deleted !! DEPRICATED !! + template -class Atom : public Version, - public Lockable +class Atom : public Version, public Lockable { public: - Atom(const Id& id, T* first) : Version(first), id(id) + Atom(const Id &id, T *first) : Version(first), id(id) { // it's illegal that the first version is nullptr. there should be at // least one version of a record assert(first != nullptr); } - T* first() - { - return this->newer(); - } + T *first() { return this->newer(); } // inspects the record change history and returns the record version visible // to the current transaction if it exists, otherwise it returns nullptr - T* latest_visible(const tx::Transaction& t) + T *latest_visible(const tx::Transaction &t) { return first()->latest_visible(t); } @@ -37,7 +35,6 @@ public: // to reuse indices for deleted nodes. Id id; - std::atomic*> next; + std::atomic *> next; }; - } diff --git a/src/mvcc/id.cpp b/src/mvcc/id.cpp index 1fae0047f..1049d97e3 100644 --- a/src/mvcc/id.cpp +++ b/src/mvcc/id.cpp @@ -1,6 +1,5 @@ #include "mvcc/id.hpp" - Id::Id(uint64_t id) : id(id) {} bool operator<(const Id& a, const Id& b) diff --git a/src/mvcc/id.hpp b/src/mvcc/id.hpp deleted file mode 100644 index 465986ff8..000000000 --- a/src/mvcc/id.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include -#include "utils/total_ordering.hpp" - -class Id : public TotalOrdering -{ -public: - Id() = default; - - Id(uint64_t id) : id(id) {} - - friend bool operator<(const Id& a, const Id& b) - { - return a.id < b.id; - } - - friend bool operator==(const Id& a, const Id& b) - { - return a.id == b.id; - } - - friend std::ostream& operator<<(std::ostream& stream, const Id& id) - { - return stream << id.id; - } - - operator uint64_t() const - { - return id; - } - -private: - uint64_t id {0}; -}; diff --git a/src/mvcc/store.hpp b/src/mvcc/store.hpp index 2ba0d7ec3..809720769 100644 --- a/src/mvcc/store.hpp +++ b/src/mvcc/store.hpp @@ -10,6 +10,8 @@ // some interesting concepts described there, keep in mind for the future // Serializable Isolation for Snapshot Databases, J. Cahill, et al. +// TODO: remove if not in use !! DEPRICATED !! + namespace mvcc { diff --git a/src/query_engine/code_compiler.hpp b/src/query_engine/code_compiler.hpp deleted file mode 100644 index 05bf2528e..000000000 --- a/src/query_engine/code_compiler.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include - -#include "exceptions/exceptions.hpp" -#include "utils/string/join.hpp" - -// TODO: -// * all libraries have to be compiled in the server compile time -// * compile command has to be generated -#include - -class CodeCompiler -{ -public: - 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 -DDEBUG", // compile flags - in_file, // input file - "-o", out_file, // ouput file - "-I./include", // include paths (TODO: parameter) - "-I./src", "-I../../libs/fmt", - "-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"); - } - - // TODO: use logger - std::cout << fmt::format("SUCCESS: Query Code Compilation: {} -> {}", - in_file, out_file) - << std::endl; - } -}; diff --git a/src/query_engine/i_code_cpu.hpp b/src/query_engine/i_code_cpu.hpp deleted file mode 100644 index 200de8483..000000000 --- a/src/query_engine/i_code_cpu.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "database/db.hpp" -#include "query_engine/query_result.hpp" -#include "query_stripped.hpp" - -class ICodeCPU -{ -public: - virtual QueryResult::sptr run(Db &db, code_args_t &args) = 0; - virtual ~ICodeCPU() {} -}; - -using produce_t = ICodeCPU *(*)(); -using destruct_t = void (*)(ICodeCPU *); diff --git a/src/query_engine/query_engine.hpp b/src/query_engine/query_engine.hpp deleted file mode 100644 index 933a06bad..000000000 --- a/src/query_engine/query_engine.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "program_executor.hpp" -#include "program_loader.hpp" -#include "query_result.hpp" - -// -// Current arhitecture: -// query -> code_loader -> query_stripper -> [code_generator] -// -> [code_compiler] -> code_executor - -// TODO -// * query engine will get a pointer to currently active database -// * TCP server session will have pointer to dbms and currently active -// * database - -class QueryEngine -{ -public: - auto execute(const std::string &query) - { - // TODO: error handling - auto program = program_loader.load(query); - auto result = program_executor.execute(program); - return result; - } - -private: - ProgramExecutor program_executor; - ProgramLoader program_loader; -}; diff --git a/src/query_engine/template/template_code_cpu.cpp b/src/query_engine/template/template_code_cpu.cpp index 88db46c4e..c271cb922 100644 --- a/src/query_engine/template/template_code_cpu.cpp +++ b/src/query_engine/template/template_code_cpu.cpp @@ -14,9 +14,11 @@ class {{class_name}} : public ICodeCPU { public: - QueryResult::sptr run(Db& db, code_args_t& args) override + bool run(Db& db, code_args_t& args, + communication::OutputStream& stream) override { -{{code}} } +{{code}} + } ~{{class_name}}() {} }; diff --git a/src/query_engine/util.cpp b/src/query_engine/util.cpp new file mode 100644 index 000000000..9a980826e --- /dev/null +++ b/src/query_engine/util.cpp @@ -0,0 +1,23 @@ +#include "query_engine/util.hpp" + +void print_props(const Properties &properties) +{ + StringBuffer buffer; + JsonWriter writer(buffer); + properties.accept(writer); + cout << buffer.str() << endl; +} + +void cout_properties(const Properties &properties) +{ + ConsoleWriter writer; + properties.accept(writer); + cout << "----" << endl; +} + +void cout_property(const std::string &key, const Property &property) +{ + ConsoleWriter writer; + writer.handle(key, property); + cout << "----" << endl; +} diff --git a/src/storage/edges.cpp b/src/storage/edges.cpp new file mode 100644 index 000000000..a0e0d9bbc --- /dev/null +++ b/src/storage/edges.cpp @@ -0,0 +1,35 @@ +#include "storage/edges.hpp" + +Edge::Accessor Edges::find(tx::Transaction &t, const Id &id) +{ + auto edges_accessor = edges.access(); + auto edges_iterator = edges_accessor.find(id); + + if (edges_iterator == edges_accessor.end()) return Edge::Accessor(); + + // find edge + auto edge = edges_iterator->second.find(t); + + if (edge == nullptr) return Edge::Accessor(); + + return Edge::Accessor(edge, &edges_iterator->second, this); +} + +Edge::Accessor Edges::insert(tx::Transaction &t) +{ + // get next vertex id + auto next = counter.next(std::memory_order_acquire); + + // create new vertex record + EdgeRecord edge_record(next); + + // insert the new vertex record into the vertex store + auto edges_accessor = edges.access(); + auto result = edges_accessor.insert(next, std::move(edge_record)); + + // create new vertex + auto inserted_edge_record = result.first; + auto edge = inserted_edge_record->second.insert(t); + + return Edge::Accessor(edge, &inserted_edge_record->second, this); +} diff --git a/src/storage/edges.hpp b/src/storage/edges.hpp deleted file mode 100644 index 2126fa9b8..000000000 --- a/src/storage/edges.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "common.hpp" -#include "data_structures/concurrent/concurrent_map.hpp" -#include "edge_accessor.hpp" - -class Edges -{ -public: - Edge::Accessor find(tx::Transaction &t, const Id &id) - { - auto edges_accessor = edges.access(); - auto edges_iterator = edges_accessor.find(id); - - if (edges_iterator == edges_accessor.end()) return Edge::Accessor(); - - // find edge - auto edge = edges_iterator->second.find(t); - - if (edge == nullptr) return Edge::Accessor(); - - return Edge::Accessor(edge, &edges_iterator->second, this); - } - - Edge::Accessor insert(tx::Transaction &t, VertexRecord *from, - VertexRecord *to) - { - // get next vertex id - auto next = counter.next(std::memory_order_acquire); - - // create new vertex record - EdgeRecord edge_record(next, from, to); - - // insert the new vertex record into the vertex store - auto edges_accessor = edges.access(); - auto result = edges_accessor.insert(next, std::move(edge_record)); - - // create new vertex - auto inserted_edge_record = result.first; - auto edge = inserted_edge_record->second.insert(t); - - return Edge::Accessor(edge, &inserted_edge_record->second, this); - } - -private: - ConcurrentMap edges; - AtomicCounter counter; -}; diff --git a/src/storage/model/vertex_model.hpp b/src/storage/model/vertex_model.hpp deleted file mode 100644 index 2a80a4bd5..000000000 --- a/src/storage/model/vertex_model.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "edge_list.hpp" -#include "property_model.hpp" -#include "storage/label/label_collection.hpp" -#include "storage/model/edge_map.hpp" - -class VertexModel : public PropertyModel -{ -public: - EdgeList out; - EdgeMap in; - LabelCollection labels; -}; diff --git a/src/utils/log/logger.hpp b/src/utils/log/logger.hpp deleted file mode 100644 index 8273e1a45..000000000 --- a/src/utils/log/logger.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -class Logger -{ -public: - Logger(Logger& other) = delete; - Logger(Logger&& other) = delete; - -private: - Logger() = default; - - // TODO logger name support - - // TODO level support - - // TODO handlers support: - // * log format support - - // TODO merge with debug/log.hpp - -public: - static Logger& instance() - { - static Logger logger; - return logger; - } - - void info(const std::string& text) - { - stdout_log(text); - } - -private: - void stdout_log(const std::string& text) - { - auto now = std::time(nullptr); - std::cout << std::put_time(std::gmtime(&now), "[%F %T]: ") - << text << std::endl; - } -}; - -#ifdef NOT_LOG_INFO -# define LOG_INFO(_) -#else -# define LOG_INFO(_MESSAGE_) Logger::instance().info(_MESSAGE_); -#endif - - diff --git a/src/utils/string/file.hpp b/src/utils/string/file.cpp similarity index 78% rename from src/utils/string/file.hpp rename to src/utils/string/file.cpp index 465d36505..bb29c4b5c 100644 --- a/src/utils/string/file.hpp +++ b/src/utils/string/file.cpp @@ -1,13 +1,4 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include +#include "utils/string/file.hpp" namespace utils { diff --git a/src/utils/string/join.hpp b/src/utils/string/join.cpp similarity index 52% rename from src/utils/string/join.hpp rename to src/utils/string/join.cpp index be3492d49..11aac5afb 100644 --- a/src/utils/string/join.hpp +++ b/src/utils/string/join.cpp @@ -1,9 +1,4 @@ -#pragma once - -#include -#include -#include -#include +#include "utils/string/join.hpp" namespace utils { @@ -16,11 +11,4 @@ std::string join(const std::vector& strings, const char *separator) return oss.str(); } -template -std::string prints(const Args&... args) -{ - std::vector strings = {args...}; - return join(strings, " "); -} - } diff --git a/src/utils/string/transform.hpp b/src/utils/string/transform.cpp similarity index 77% rename from src/utils/string/transform.hpp rename to src/utils/string/transform.cpp index 22197d1bd..20a06f2d7 100644 --- a/src/utils/string/transform.hpp +++ b/src/utils/string/transform.cpp @@ -1,8 +1,4 @@ -#pragma once - -#include -#include -#include +#include "utils/string/transform.hpp" namespace utils { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 86c7db65c..23d98d829 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -63,19 +63,20 @@ endforeach() # test hard coded queries add_executable(integration_queries integration/queries.cpp) target_link_libraries(integration_queries memgraph) +target_link_libraries(integration_queries Threads::Threads) target_link_libraries(integration_queries ${fmt_static_lib}) add_test(NAME integration_queries COMMAND integration_queries) set_property(TARGET integration_queries PROPERTY CXX_STANDARD 14) # test query engine add_executable(integration_query_engine integration/query_engine.cpp) -# target_link_libraries() +target_link_libraries(integration_query_engine Threads::Threads) add_test(NAME integration_query_engine COMMAND integration_query_engine) set_property(TARGET integration_query_engine PROPERTY CXX_STANDARD 14) # test memgraph with bolt protocol add_executable(integration_memgraph_bolt integration/memgraph_bolt.cpp) -# target_link_libraries() +target_link_libraries(integration_memgraph_bolt Threads::Threads) add_test(NAME integration_memgraph_bolt COMMAND integration_memgraph_bolt) set_property(TARGET integration_memgraph_bolt PROPERTY CXX_STANDARD 14) @@ -84,6 +85,7 @@ set_property(TARGET integration_memgraph_bolt PROPERTY CXX_STANDARD 14) # cypher_ast add_executable(manual_cypher_ast manual/cypher_ast.cpp) target_link_libraries(manual_cypher_ast memgraph) +target_link_libraries(manual_cypher_ast Threads::Threads) target_link_libraries(manual_cypher_ast ${fmt_static_lib}) target_link_libraries(manual_cypher_ast cypher_lib) set_property(TARGET manual_cypher_ast PROPERTY CXX_STANDARD 14) @@ -91,6 +93,7 @@ set_property(TARGET manual_cypher_ast PROPERTY CXX_STANDARD 14) # queries add_executable(manual_queries manual/queries.cpp) target_link_libraries(manual_queries memgraph) +target_link_libraries(manual_queries Threads::Threads) target_link_libraries(manual_queries ${fmt_static_lib}) target_link_libraries(manual_queries cypher_lib) set_property(TARGET manual_queries PROPERTY CXX_STANDARD 14) @@ -101,6 +104,7 @@ target_link_libraries(manual_query_engine memgraph) target_link_libraries(manual_query_engine ${fmt_static_lib}) target_link_libraries(manual_query_engine dl) target_link_libraries(manual_query_engine cypher_lib) +target_link_libraries(manual_query_engine Threads::Threads) set_property(TARGET manual_query_engine PROPERTY CXX_STANDARD 14) # query_hasher diff --git a/tests/concurrent/timer.cpp b/tests/concurrent/timer.cpp index 4d97693f3..3b79aa5f4 100644 --- a/tests/concurrent/timer.cpp +++ b/tests/concurrent/timer.cpp @@ -1,7 +1,7 @@ #include #include -#include "utils/log/logger.hpp" +#include "logging/default.cpp" #include "utils/timer/timer.hpp" using namespace std::chrono_literals; @@ -9,7 +9,7 @@ using namespace std::chrono_literals; Timer::sptr create_test_timer(int64_t counter) { return std::make_shared( - counter, [](){ LOG_INFO("Timer timeout"); } + counter, [](){ logging::info("Timer timeout"); } ); } diff --git a/tests/manual/query_engine.cpp b/tests/manual/query_engine.cpp index beb3368f3..2bb44d7b7 100644 --- a/tests/manual/query_engine.cpp +++ b/tests/manual/query_engine.cpp @@ -7,6 +7,7 @@ #include "query_engine/query_engine.hpp" #include "utils/time/timer.hpp" #include "utils/terminate_handler.hpp" +#include "communication/communication.hpp" using std::cout; using std::endl; @@ -16,7 +17,11 @@ int main(void) { std::set_terminate(&terminate_handler); + Db db; QueryEngine engine; + // TODO: write dummy socket that is going to execute test + io::Socket socket; + communication::OutputStream stream(socket); cout << "-- Memgraph query engine --" << endl; @@ -30,7 +35,7 @@ int main(void) // execute command try { - engine.execute(command); + engine.execute(command, db, stream); } catch (const std::exception& e) { cout << e.what() << endl; } catch (const QueryEngineException& e) { diff --git a/tests/unit/chunked_decoder.cpp b/tests/unit/chunked_decoder.cpp index 4c950293d..4890affdb 100644 --- a/tests/unit/chunked_decoder.cpp +++ b/tests/unit/chunked_decoder.cpp @@ -5,7 +5,7 @@ #include #include -#include "bolt/v1/transport/chunked_decoder.hpp" +#include "communication/bolt/v1/transport/chunked_decoder.hpp" using byte = unsigned char; diff --git a/tests/unit/chunked_encoder.cpp b/tests/unit/chunked_encoder.cpp index 804d695ea..0cbee4143 100644 --- a/tests/unit/chunked_encoder.cpp +++ b/tests/unit/chunked_encoder.cpp @@ -3,7 +3,7 @@ #include #include -#include "bolt/v1/transport/chunked_encoder.hpp" +#include "communication/bolt/v1/transport/chunked_encoder.hpp" using byte = unsigned char;