From 93b174afd79616f34a2aa202d1f2495321a2440e Mon Sep 17 00:00:00 2001 From: Marko Budiselic <mbudiselicbuda@gmail.com> Date: Thu, 11 Aug 2016 04:47:30 +0100 Subject: [PATCH] First integration almost done. BOLT still doesn't work as expected, problem is only serialization order. --- CMakeLists.txt | 100 +++++++++++++++--- include/{ => communication}/bolt/v1/bolt.hpp | 2 +- .../{ => communication}/bolt/v1/config.hpp | 0 .../bolt/v1/messaging/codes.hpp | 0 .../bolt/v1/packing/codes.hpp | 0 .../bolt/v1/packing/types.hpp | 0 .../bolt/v1/serialization/bolt_serializer.hpp | 31 ++++-- .../bolt/v1/serialization/record_stream.hpp | 18 +++- .../bolt/v1/server/server.hpp | 2 +- .../bolt/v1/server/worker.hpp | 46 ++++---- .../{ => communication}/bolt/v1/session.hpp | 13 +-- .../{ => communication}/bolt/v1/states.hpp | 2 +- .../bolt/v1/states/error.hpp | 4 +- .../bolt/v1/states/executor.hpp | 4 +- .../bolt/v1/states/handshake.hpp | 2 +- .../bolt/v1/states/init.hpp | 2 +- .../bolt/v1/states/message_parser.hpp | 4 +- .../bolt/v1/states/state.hpp | 0 .../bolt/v1/transport/bolt_decoder.hpp | 4 +- .../bolt/v1/transport/bolt_encoder.hpp | 4 +- .../bolt/v1/transport/buffer.hpp | 0 .../bolt/v1/transport/chunked_buffer.hpp | 2 +- .../bolt/v1/transport/chunked_decoder.hpp | 0 .../bolt/v1/transport/chunked_encoder.hpp | 2 +- .../bolt/v1/transport/socket_stream.hpp | 2 +- .../bolt/v1/transport/stream_error.hpp | 0 include/communication/communication.hpp | 9 ++ include/communication/gate/init.hpp | 4 + include/communication/http/init.hpp | 3 + .../concurrent/skiplist_gc.hpp | 14 ++- {src => include}/io/network/.gitignore | 0 {src => include}/io/network/addrinfo.hpp | 2 +- {src => include}/io/network/client.hpp | 2 +- {src => include}/io/network/epoll.hpp | 2 +- .../io/network/event_listener.hpp | 2 +- {src => include}/io/network/event_loop.hpp | 2 +- {src => include}/io/network/network_error.hpp | 0 {src => include}/io/network/secure_socket.hpp | 0 .../io/network/secure_stream_reader.hpp | 2 +- {src => include}/io/network/server.hpp | 2 +- {src => include}/io/network/socket.hpp | 9 +- .../io/network/stream_dispatcher.hpp | 1 - .../io/network/stream_listener.hpp | 2 +- {src => include}/io/network/stream_reader.hpp | 2 +- {src => include}/io/network/tcp/stream.hpp | 0 {src => include}/io/network/tls.hpp | 0 {src => include}/io/network/tls_error.hpp | 0 {src => include}/io/uv/blockbuffer.hpp | 0 {src => include}/io/uv/core.hpp | 0 {src => include}/io/uv/tcpstream.hpp | 0 {src => include}/io/uv/uv.hpp | 0 {src => include}/io/uv/uv_error.hpp | 0 {src => include}/io/uv/uvbuffer.hpp | 0 {src => include}/io/uv/uvloop.hpp | 0 include/logging/default.hpp | 8 ++ include/query_engine/code_compiler.hpp | 35 +++--- include/query_engine/code_generator.hpp | 15 +-- .../code_generator/handlers/return.hpp | 7 +- .../handlers/transaction_commit.hpp | 2 +- include/query_engine/i_code_cpu.hpp | 5 +- include/query_engine/program_executor.hpp | 8 +- include/query_engine/program_loader.hpp | 18 ++-- include/query_engine/query_engine.hpp | 44 +++++--- include/query_engine/query_result.hpp | 3 + include/query_engine/traverser/code.hpp | 9 +- include/utils/log/logger.hpp | 58 ---------- include/utils/timer/timer.hpp | 4 +- src/bolt/v1/states.cpp | 19 ---- src/{ => communication}/bolt/v1/bolt.cpp | 5 +- src/{ => communication}/bolt/v1/session.cpp | 2 +- src/communication/bolt/v1/states.cpp | 19 ++++ .../bolt/v1/states/error.cpp | 2 +- .../bolt/v1/states/executor.cpp | 14 +-- .../bolt/v1/states/handshake.cpp | 4 +- .../bolt/v1/states/init.cpp | 6 +- .../bolt/v1/transport/bolt_decoder.cpp | 6 +- .../bolt/v1/transport/buffer.cpp | 2 +- src/communication/gate/init.cpp | 1 + src/communication/http/init.cpp | 1 + src/cypher/parser.hpp | 9 +- src/cypher/token.hpp | 16 ++- .../bolt_py_client/.initial_test.py.swn | Bin 0 -> 12288 bytes src/examples/bolt_py_client/initial_test.py | 39 +++++-- src/io/network/tls.cpp | 4 +- src/io/uv/tcpstream.inl | 2 +- src/io/uv/uvbuffer.inl | 2 +- src/logging/default.cpp | 10 ++ src/memgraph_bolt.cpp | 6 +- .../template/template_code_cpu.cpp | 6 +- tests/CMakeLists.txt | 8 +- tests/concurrent/timer.cpp | 4 +- tests/manual/query_engine.cpp | 6 +- tests/unit/chunked_decoder.cpp | 2 +- tests/unit/chunked_encoder.cpp | 2 +- 94 files changed, 430 insertions(+), 285 deletions(-) rename include/{ => communication}/bolt/v1/bolt.hpp (86%) rename include/{ => communication}/bolt/v1/config.hpp (100%) rename include/{ => communication}/bolt/v1/messaging/codes.hpp (100%) rename include/{ => communication}/bolt/v1/packing/codes.hpp (100%) rename include/{ => communication}/bolt/v1/packing/types.hpp (100%) rename include/{ => communication}/bolt/v1/serialization/bolt_serializer.hpp (84%) rename include/{ => communication}/bolt/v1/serialization/record_stream.hpp (84%) rename include/{ => communication}/bolt/v1/server/server.hpp (96%) rename include/{ => communication}/bolt/v1/server/worker.hpp (73%) rename include/{ => communication}/bolt/v1/session.hpp (59%) rename include/{ => communication}/bolt/v1/states.hpp (80%) rename include/{ => communication}/bolt/v1/states/error.hpp (55%) rename include/{ => communication}/bolt/v1/states/executor.hpp (86%) rename include/{ => communication}/bolt/v1/states/handshake.hpp (71%) rename include/{ => communication}/bolt/v1/states/init.hpp (82%) rename include/{ => communication}/bolt/v1/states/message_parser.hpp (88%) rename include/{ => communication}/bolt/v1/states/state.hpp (100%) rename include/{ => communication}/bolt/v1/transport/bolt_decoder.hpp (85%) rename include/{ => communication}/bolt/v1/transport/bolt_encoder.hpp (98%) rename include/{ => communication}/bolt/v1/transport/buffer.hpp (100%) rename include/{ => communication}/bolt/v1/transport/chunked_buffer.hpp (97%) rename include/{ => communication}/bolt/v1/transport/chunked_decoder.hpp (100%) rename include/{ => communication}/bolt/v1/transport/chunked_encoder.hpp (97%) rename include/{ => communication}/bolt/v1/transport/socket_stream.hpp (91%) rename include/{ => communication}/bolt/v1/transport/stream_error.hpp (100%) create mode 100644 include/communication/communication.hpp create mode 100644 include/communication/gate/init.hpp create mode 100644 include/communication/http/init.hpp rename {src => include}/io/network/.gitignore (100%) rename {src => include}/io/network/addrinfo.hpp (95%) rename {src => include}/io/network/client.hpp (94%) rename {src => include}/io/network/epoll.hpp (96%) rename {src => include}/io/network/event_listener.hpp (98%) rename {src => include}/io/network/event_loop.hpp (80%) rename {src => include}/io/network/network_error.hpp (100%) rename {src => include}/io/network/secure_socket.hpp (100%) rename {src => include}/io/network/secure_stream_reader.hpp (97%) rename {src => include}/io/network/server.hpp (94%) rename {src => include}/io/network/socket.hpp (96%) rename {src => include}/io/network/stream_dispatcher.hpp (85%) rename {src => include}/io/network/stream_listener.hpp (95%) rename {src => include}/io/network/stream_reader.hpp (98%) rename {src => include}/io/network/tcp/stream.hpp (100%) rename {src => include}/io/network/tls.hpp (100%) rename {src => include}/io/network/tls_error.hpp (100%) rename {src => include}/io/uv/blockbuffer.hpp (100%) rename {src => include}/io/uv/core.hpp (100%) rename {src => include}/io/uv/tcpstream.hpp (100%) rename {src => include}/io/uv/uv.hpp (100%) rename {src => include}/io/uv/uv_error.hpp (100%) rename {src => include}/io/uv/uvbuffer.hpp (100%) rename {src => include}/io/uv/uvloop.hpp (100%) delete mode 100644 include/utils/log/logger.hpp delete mode 100644 src/bolt/v1/states.cpp rename src/{ => communication}/bolt/v1/bolt.cpp (80%) rename src/{ => communication}/bolt/v1/session.cpp (95%) create mode 100644 src/communication/bolt/v1/states.cpp rename src/{ => communication}/bolt/v1/states/error.cpp (94%) rename src/{ => communication}/bolt/v1/states/executor.cpp (83%) rename src/{ => communication}/bolt/v1/states/handshake.cpp (85%) rename src/{ => communication}/bolt/v1/states/init.cpp (88%) rename src/{ => communication}/bolt/v1/transport/bolt_decoder.cpp (96%) rename src/{ => communication}/bolt/v1/transport/buffer.cpp (76%) create mode 100644 src/communication/gate/init.cpp create mode 100644 src/communication/http/init.cpp create mode 100644 src/examples/bolt_py_client/.initial_test.py.swn diff --git a/CMakeLists.txt b/CMakeLists.txt index c06c78362..74df3c068 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,6 +231,7 @@ FILE(COPY ${include_dir}/storage/indexes/index_record.hpp DESTINATION ${build_in 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) @@ -246,6 +247,31 @@ FILE(COPY ${include_dir}/utils/counters/simple_counter.hpp DESTINATION ${build_i 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 @@ -264,25 +290,67 @@ endif() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native -Wall -Werror") -# -- configure time variables ------------------------------------------------- -option(RUNTIME_ASSERT "Enable runtime assertions" OFF) +# -- 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 ----------------------------------------------------------------- include_directories(${CMAKE_SOURCE_DIR}/include) @@ -311,15 +379,15 @@ set(memgraph_src_files ${src_dir}/utils/string/join.cpp ${src_dir}/utils/string/file.cpp ${src_dir}/query_engine/util.cpp - ${src_dir}/bolt/v1/bolt.cpp - ${src_dir}/bolt/v1/states.cpp - ${src_dir}/bolt/v1/session.cpp - ${src_dir}/bolt/v1/states/error.cpp - ${src_dir}/bolt/v1/states/executor.cpp - ${src_dir}/bolt/v1/states/init.cpp - ${src_dir}/bolt/v1/states/handshake.cpp - ${src_dir}/bolt/v1/transport/bolt_decoder.cpp - ${src_dir}/bolt/v1/transport/buffer.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 diff --git a/include/bolt/v1/bolt.hpp b/include/communication/bolt/v1/bolt.hpp similarity index 86% rename from include/bolt/v1/bolt.hpp rename to include/communication/bolt/v1/bolt.hpp index 299e068ba..850aa5195 100644 --- a/include/bolt/v1/bolt.hpp +++ b/include/communication/bolt/v1/bolt.hpp @@ -1,6 +1,6 @@ #pragma once -#include "bolt/v1/states.hpp" +#include "communication/bolt/v1/states.hpp" #include "io/network/socket.hpp" #include "dbms/dbms.hpp" diff --git a/include/bolt/v1/config.hpp b/include/communication/bolt/v1/config.hpp similarity index 100% rename from include/bolt/v1/config.hpp rename to include/communication/bolt/v1/config.hpp diff --git a/include/bolt/v1/messaging/codes.hpp b/include/communication/bolt/v1/messaging/codes.hpp similarity index 100% rename from include/bolt/v1/messaging/codes.hpp rename to include/communication/bolt/v1/messaging/codes.hpp diff --git a/include/bolt/v1/packing/codes.hpp b/include/communication/bolt/v1/packing/codes.hpp similarity index 100% rename from include/bolt/v1/packing/codes.hpp rename to include/communication/bolt/v1/packing/codes.hpp diff --git a/include/bolt/v1/packing/types.hpp b/include/communication/bolt/v1/packing/types.hpp similarity index 100% rename from include/bolt/v1/packing/types.hpp rename to include/communication/bolt/v1/packing/types.hpp diff --git a/include/bolt/v1/serialization/bolt_serializer.hpp b/include/communication/bolt/v1/serialization/bolt_serializer.hpp similarity index 84% rename from include/bolt/v1/serialization/bolt_serializer.hpp rename to include/communication/bolt/v1/serialization/bolt_serializer.hpp index a405af22e..6d7248b6f 100644 --- a/include/bolt/v1/serialization/bolt_serializer.hpp +++ b/include/communication/bolt/v1/serialization/bolt_serializer.hpp @@ -1,7 +1,7 @@ #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 "storage/vertex_accessor.hpp" #include "storage/edge_accessor.hpp" @@ -17,6 +17,10 @@ class BoltSerializer { friend class Property; + // TODO: here shoud be friend but it doesn't work + // template <class Handler> + // friend void accept(const Property &property, Handler &h); + public: BoltSerializer(Stream& stream) : encoder(stream) {} @@ -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: - Stream& encoder; - template <class T> void handle(const T& prop) { write(prop); } + +protected: + Stream& encoder; }; } diff --git a/include/bolt/v1/serialization/record_stream.hpp b/include/communication/bolt/v1/serialization/record_stream.hpp similarity index 84% rename from include/bolt/v1/serialization/record_stream.hpp rename to include/communication/bolt/v1/serialization/record_stream.hpp index 5e914e25e..aa4ab438f 100644 --- a/include/bolt/v1/serialization/record_stream.hpp +++ b/include/communication/bolt/v1/serialization/record_stream.hpp @@ -1,9 +1,9 @@ #pragma once -#include "bolt/v1/serialization/bolt_serializer.hpp" -#include "bolt/v1/transport/chunked_buffer.hpp" -#include "bolt/v1/transport/chunked_encoder.hpp" -#include "bolt/v1/transport/socket_stream.hpp" +#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" @@ -57,6 +57,16 @@ public: 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); diff --git a/include/bolt/v1/server/server.hpp b/include/communication/bolt/v1/server/server.hpp similarity index 96% rename from include/bolt/v1/server/server.hpp rename to include/communication/bolt/v1/server/server.hpp index ea61154aa..a6493ea2d 100644 --- a/include/bolt/v1/server/server.hpp +++ b/include/communication/bolt/v1/server/server.hpp @@ -7,7 +7,7 @@ #include <cassert> #include "io/network/server.hpp" -#include "bolt/v1/bolt.hpp" +#include "communication/bolt/v1/bolt.hpp" namespace bolt { diff --git a/include/bolt/v1/server/worker.hpp b/include/communication/bolt/v1/server/worker.hpp similarity index 73% rename from include/bolt/v1/server/worker.hpp rename to include/communication/bolt/v1/server/worker.hpp index eb475e135..7a6ac0183 100644 --- a/include/bolt/v1/server/worker.hpp +++ b/include/communication/bolt/v1/server/worker.hpp @@ -1,19 +1,16 @@ #pragma once -#include <iomanip> -#include <cstdio> #include <atomic> -#include <sstream> - +#include <cstdio> +#include <iomanip> #include <memory> +#include <sstream> #include <thread> -#include "io/network/stream_reader.hpp" - -#include "bolt/v1/bolt.hpp" -#include "bolt/v1/session.hpp" - +#include "communication/bolt/v1/bolt.hpp" +#include "communication/bolt/v1/session.hpp" #include "logging/default.hpp" +#include "io/network/stream_reader.hpp" namespace bolt { @@ -28,19 +25,19 @@ class Worker : public io::StreamReader<Worker, Session> public: using sptr = std::shared_ptr<Worker>; - Worker(Bolt& bolt) : bolt(bolt) + Worker(Bolt &bolt) : bolt(bolt) { logger = logging::log->logger("Network"); } - Session& on_connect(io::Socket&& socket) + Session &on_connect(io::Socket &&socket) { logger.trace("Accepting connection on socket {}", socket.id()); return *bolt.get().create_session(std::forward<io::Socket>(socket)); } - void on_error(Session&) + void on_error(Session &) { logger.trace("[on_error] errno = {}", errno); @@ -50,43 +47,39 @@ public: #endif logger.error("Error occured in this session"); - } void on_wait_timeout() {} - Buffer on_alloc(Session&) + Buffer on_alloc(Session &) { /* logger.trace("[on_alloc] Allocating {}B", sizeof buf); */ - return Buffer { buf, sizeof buf }; + return Buffer{buf, sizeof buf}; } - void on_read(Session& session, Buffer& buf) + void on_read(Session &session, Buffer &buf) { logger.trace("[on_read] Received {}B", buf.len); #ifndef NDEBUG std::stringstream stream; - for(size_t i = 0; i < buf.len; ++i) + for (size_t i = 0; i < buf.len; ++i) stream << fmt::format("{:02X} ", static_cast<byte>(buf.ptr[i])); logger.trace("[on_read] {}", stream.str()); #endif - try - { - session.execute(reinterpret_cast<const byte*>(buf.ptr), buf.len); - } - catch(const std::exception& e) - { + try { + session.execute(reinterpret_cast<const byte *>(buf.ptr), buf.len); + } catch (const std::exception &e) { logger.error("Error occured while executing statement."); logger.error("{}", e.what()); } } - void on_close(Session& session) + void on_close(Session &session) { logger.trace("[on_close] Client closed the connection"); session.close(); @@ -100,13 +93,12 @@ protected: Logger logger; std::thread thread; - void start(std::atomic<bool>& alive) + void start(std::atomic<bool> &alive) { thread = std::thread([&, this]() { - while(alive) + while (alive) wait_and_process_events(); }); } }; - } diff --git a/include/bolt/v1/session.hpp b/include/communication/bolt/v1/session.hpp similarity index 59% rename from include/bolt/v1/session.hpp rename to include/communication/bolt/v1/session.hpp index b5fe46c0a..b0c5a147f 100644 --- a/include/bolt/v1/session.hpp +++ b/include/communication/bolt/v1/session.hpp @@ -3,11 +3,12 @@ #include "io/network/socket.hpp" #include "io/network/tcp/stream.hpp" -#include "bolt/v1/bolt.hpp" -#include "bolt/v1/serialization/record_stream.hpp" -#include "bolt/v1/states/state.hpp" -#include "bolt/v1/transport/bolt_decoder.hpp" -#include "bolt/v1/transport/bolt_encoder.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" @@ -18,7 +19,7 @@ class Session : public io::tcp::Stream<io::Socket> { public: using Decoder = BoltDecoder; - using OutputStream = RecordStream<io::Socket>; + using OutputStream = communication::OutputStream; Session(io::Socket &&socket, Bolt &bolt); diff --git a/include/bolt/v1/states.hpp b/include/communication/bolt/v1/states.hpp similarity index 80% rename from include/bolt/v1/states.hpp rename to include/communication/bolt/v1/states.hpp index a3398822d..d15a1b747 100644 --- a/include/bolt/v1/states.hpp +++ b/include/communication/bolt/v1/states.hpp @@ -1,6 +1,6 @@ #pragma once -#include "bolt/v1/states/state.hpp" +#include "communication/bolt/v1/states/state.hpp" #include "logging/log.hpp" namespace bolt diff --git a/include/bolt/v1/states/error.hpp b/include/communication/bolt/v1/states/error.hpp similarity index 55% rename from include/bolt/v1/states/error.hpp rename to include/communication/bolt/v1/states/error.hpp index 797dfe537..0748fc5e5 100644 --- a/include/bolt/v1/states/error.hpp +++ b/include/communication/bolt/v1/states/error.hpp @@ -1,7 +1,7 @@ #pragma once -#include "bolt/v1/session.hpp" -#include "bolt/v1/states/state.hpp" +#include "communication/bolt/v1/session.hpp" +#include "communication/bolt/v1/states/state.hpp" namespace bolt { diff --git a/include/bolt/v1/states/executor.hpp b/include/communication/bolt/v1/states/executor.hpp similarity index 86% rename from include/bolt/v1/states/executor.hpp rename to include/communication/bolt/v1/states/executor.hpp index e35ed68fd..649655fbb 100644 --- a/include/bolt/v1/states/executor.hpp +++ b/include/communication/bolt/v1/states/executor.hpp @@ -1,7 +1,7 @@ #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 diff --git a/include/bolt/v1/states/handshake.hpp b/include/communication/bolt/v1/states/handshake.hpp similarity index 71% rename from include/bolt/v1/states/handshake.hpp rename to include/communication/bolt/v1/states/handshake.hpp index fe6d7052a..8ca4c2e10 100644 --- a/include/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/include/bolt/v1/states/init.hpp b/include/communication/bolt/v1/states/init.hpp similarity index 82% rename from include/bolt/v1/states/init.hpp rename to include/communication/bolt/v1/states/init.hpp index dce0c2b83..b471e078d 100644 --- a/include/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/include/bolt/v1/states/message_parser.hpp b/include/communication/bolt/v1/states/message_parser.hpp similarity index 88% rename from include/bolt/v1/states/message_parser.hpp rename to include/communication/bolt/v1/states/message_parser.hpp index 9ad938722..0c86753b1 100644 --- a/include/bolt/v1/states/message_parser.hpp +++ b/include/communication/bolt/v1/states/message_parser.hpp @@ -1,7 +1,7 @@ #pragma once -#include "bolt/v1/session.hpp" -#include "bolt/v1/states/state.hpp" +#include "communication/bolt/v1/session.hpp" +#include "communication/bolt/v1/states/state.hpp" #include "utils/crtp.hpp" namespace bolt diff --git a/include/bolt/v1/states/state.hpp b/include/communication/bolt/v1/states/state.hpp similarity index 100% rename from include/bolt/v1/states/state.hpp rename to include/communication/bolt/v1/states/state.hpp diff --git a/include/bolt/v1/transport/bolt_decoder.hpp b/include/communication/bolt/v1/transport/bolt_decoder.hpp similarity index 85% rename from include/bolt/v1/transport/bolt_decoder.hpp rename to include/communication/bolt/v1/transport/bolt_decoder.hpp index 4399e4ed6..d80f3dc31 100644 --- a/include/bolt/v1/transport/bolt_decoder.hpp +++ b/include/communication/bolt/v1/transport/bolt_decoder.hpp @@ -1,7 +1,7 @@ #pragma once -#include "bolt/v1/transport/buffer.hpp" -#include "bolt/v1/transport/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 diff --git a/include/bolt/v1/transport/bolt_encoder.hpp b/include/communication/bolt/v1/transport/bolt_encoder.hpp similarity index 98% rename from include/bolt/v1/transport/bolt_encoder.hpp rename to include/communication/bolt/v1/transport/bolt_encoder.hpp index e8758bab4..cdeb8ab9a 100644 --- a/include/bolt/v1/transport/bolt_encoder.hpp +++ b/include/communication/bolt/v1/transport/bolt_encoder.hpp @@ -2,8 +2,8 @@ #include <string> -#include "bolt/v1/packing/codes.hpp" -#include "bolt/v1/messaging/codes.hpp" +#include "communication/bolt/v1/packing/codes.hpp" +#include "communication/bolt/v1/messaging/codes.hpp" #include "utils/types/byte.hpp" #include "utils/bswap.hpp" #include "logging/default.hpp" diff --git a/include/bolt/v1/transport/buffer.hpp b/include/communication/bolt/v1/transport/buffer.hpp similarity index 100% rename from include/bolt/v1/transport/buffer.hpp rename to include/communication/bolt/v1/transport/buffer.hpp diff --git a/include/bolt/v1/transport/chunked_buffer.hpp b/include/communication/bolt/v1/transport/chunked_buffer.hpp similarity index 97% rename from include/bolt/v1/transport/chunked_buffer.hpp rename to include/communication/bolt/v1/transport/chunked_buffer.hpp index 3a0846712..eb368431e 100644 --- a/include/bolt/v1/transport/chunked_buffer.hpp +++ b/include/communication/bolt/v1/transport/chunked_buffer.hpp @@ -4,7 +4,7 @@ #include <vector> #include <cstring> -#include "bolt/v1/config.hpp" +#include "communication/bolt/v1/config.hpp" #include "utils/types/byte.hpp" #include "logging/default.hpp" diff --git a/include/bolt/v1/transport/chunked_decoder.hpp b/include/communication/bolt/v1/transport/chunked_decoder.hpp similarity index 100% rename from include/bolt/v1/transport/chunked_decoder.hpp rename to include/communication/bolt/v1/transport/chunked_decoder.hpp diff --git a/include/bolt/v1/transport/chunked_encoder.hpp b/include/communication/bolt/v1/transport/chunked_encoder.hpp similarity index 97% rename from include/bolt/v1/transport/chunked_encoder.hpp rename to include/communication/bolt/v1/transport/chunked_encoder.hpp index 295cc03c2..e3fbcebbd 100644 --- a/include/bolt/v1/transport/chunked_encoder.hpp +++ b/include/communication/bolt/v1/transport/chunked_encoder.hpp @@ -5,7 +5,7 @@ #include <functional> #include "utils/likely.hpp" -#include "bolt/v1/config.hpp" +#include "communication/bolt/v1/config.hpp" #include "logging/default.hpp" namespace bolt diff --git a/include/bolt/v1/transport/socket_stream.hpp b/include/communication/bolt/v1/transport/socket_stream.hpp similarity index 91% rename from include/bolt/v1/transport/socket_stream.hpp rename to include/communication/bolt/v1/transport/socket_stream.hpp index aadeb681e..ca0688dc7 100644 --- a/include/bolt/v1/transport/socket_stream.hpp +++ b/include/communication/bolt/v1/transport/socket_stream.hpp @@ -5,7 +5,7 @@ #include <cstdio> #include "io/network/socket.hpp" -#include "bolt/v1/transport/stream_error.hpp" +#include "communication/bolt/v1/transport/stream_error.hpp" namespace bolt { diff --git a/include/bolt/v1/transport/stream_error.hpp b/include/communication/bolt/v1/transport/stream_error.hpp similarity index 100% rename from include/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<io::Socket>; +} 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/include/data_structures/concurrent/skiplist_gc.hpp b/include/data_structures/concurrent/skiplist_gc.hpp index 196b4c5d6..61777b7bf 100644 --- a/include/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 T, class lock_t = SpinLock> class SkiplistGC : public LazyGC<SkiplistGC<T, lock_t>, lock_t> { public: + SkiplistGC() : logger(logging::log->logger("SkiplistGC")) {} + // release_ref method should be called by a thread // when the thread finish it job over object // which has to be lazy cleaned @@ -33,9 +36,8 @@ public: } if (local_freelist.size() > 0) { - std::cout << "GC started" << std::endl; - std::cout << "Local list size: " << local_freelist.size() - << std::endl; + logger.trace("GC started"); + logger.trace("Local list size: {}", local_freelist.size()); long long counter = 0; // destroy all elements from local_freelist for (auto element : local_freelist) { @@ -45,13 +47,15 @@ public: counter++; } } - std::cout << "Number of destroyed elements " << counter - << std::endl; + logger.trace("Number of destroyed elements: {}", counter); } } void collect(T *node) { freelist.add(node); } +protected: + Logger logger; + private: FreeList<T> freelist; }; 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 <cstring> #include <netdb.h> -#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 <malloc.h> #include <sys/epoll.h> -#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 <openssl/ssl.h> -#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 <sys/epoll.h> #include <errno.h> -#include "addrinfo.hpp" +#include "io/network/addrinfo.hpp" #include "utils/likely.hpp" #include "logging/default.hpp" @@ -48,8 +48,9 @@ public: if(socket == -1) return; - - std::cout << "DELETING SOCKET" << std::endl; +#ifndef NDEBUG + logging::debug("DELETING SOCKET"); +#endif ::close(socket); } @@ -169,6 +170,7 @@ public: int write(const byte* data, size_t len) { + // TODO: use logger #ifndef NDEBUG std::stringstream stream; @@ -189,6 +191,7 @@ public: } protected: + Logger logger; int socket; }; 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/include/logging/default.hpp b/include/logging/default.hpp index ace13d31b..31344446b 100644 --- a/include/logging/default.hpp +++ b/include/logging/default.hpp @@ -16,6 +16,14 @@ void debug(Args&&... args) debug_logger.debug(std::forward<Args>(args)...); } +extern Logger info_logger; + +template <class... Args> +void info(Args&&... args) +{ + info_logger.info(std::forward<Args>(args)...); +} + void init_async(); void init_sync(); diff --git a/include/query_engine/code_compiler.hpp b/include/query_engine/code_compiler.hpp index f29133bef..21125d9c2 100644 --- a/include/query_engine/code_compiler.hpp +++ b/include/query_engine/code_compiler.hpp @@ -3,30 +3,32 @@ #include <string> #include "exceptions/exceptions.hpp" +#include "logging/default.hpp" #include "utils/string/join.hpp" // TODO: // * all libraries have to be compiled in the server compile time // * compile command has to be generated -#include <iostream> 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 -DDEBUG", // 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 - ); + 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()); @@ -38,9 +40,10 @@ public: "settings are wrong"); } - // TODO: use logger - std::cout << fmt::format("SUCCESS: Query Code Compilation: {} -> {}", - in_file, out_file) - << std::endl; + logger.debug("SUCCESS: Query Code Compilation: {} -> {}", in_file, + out_file); } + +protected: + Logger logger; }; diff --git a/include/query_engine/code_generator.hpp b/include/query_engine/code_generator.hpp index 1115b511b..e010c7a3c 100644 --- a/include/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 <iostream> +#include "logging/default.hpp" using std::string; class CodeGenerator { public: + CodeGenerator() : logger(logging::log->logger("CodeGenerator")) {} + void generate_cpp(const std::string &query, const uint64_t stripped_hash, const std::string &path) { @@ -33,6 +32,7 @@ public: try { tree = compiler.syntax_tree(query); } catch (const std::runtime_error &e) { + logger.error("Syntax error: {}", query); throw QueryEngineException(std::string(e.what())); } @@ -44,6 +44,7 @@ public: } catch (const SemanticError &e) { throw e; } catch (const std::exception &e) { + logger.error("AST traversal error: {}", std::string(e.what())); throw QueryEngineException("Unknown code generation error"); } @@ -54,12 +55,14 @@ public: {"query", query}, {"code", cpp_traverser.code}}); - // TODO: use logger, ifndef - std::cout << generated << std::endl; + logger.trace("generated code: {}", generated); utils::write_file(generated, path); } +protected: + Logger logger; + private: template_engine::TemplateEngine template_engine; ast::Ast tree; diff --git a/include/query_engine/code_generator/handlers/return.hpp b/include/query_engine/code_generator/handlers/return.hpp index 43592e2b3..eb64d8b4e 100644 --- a/include/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/include/query_engine/code_generator/handlers/transaction_commit.hpp b/include/query_engine/code_generator/handlers/transaction_commit.hpp index 41777fd3b..a19749dea 100644 --- a/include/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/include/query_engine/i_code_cpu.hpp b/include/query_engine/i_code_cpu.hpp index b4a49ba01..1735b067e 100644 --- a/include/query_engine/i_code_cpu.hpp +++ b/include/query_engine/i_code_cpu.hpp @@ -1,13 +1,14 @@ #pragma once +#include "communication/communication.hpp" #include "database/db.hpp" -#include "query_engine/query_result.hpp" #include "query_engine/query_stripped.hpp" class ICodeCPU { public: - virtual QueryResult::sptr run(Db &db, code_args_t &args) = 0; + virtual bool run(Db &db, code_args_t &args, + communication::OutputStream &stream) = 0; virtual ~ICodeCPU() {} }; diff --git a/include/query_engine/program_executor.hpp b/include/query_engine/program_executor.hpp index a13c98cd6..b0aa6df75 100644 --- a/include/query_engine/program_executor.hpp +++ b/include/query_engine/program_executor.hpp @@ -3,10 +3,9 @@ #include <string> #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,11 +14,12 @@ class ProgramExecutor { public: - auto execute(QueryProgram &program, Db& db) + 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"); diff --git a/include/query_engine/program_loader.hpp b/include/query_engine/program_loader.hpp index 93035aa33..c5e178466 100644 --- a/include/query_engine/program_loader.hpp +++ b/include/query_engine/program_loader.hpp @@ -4,8 +4,6 @@ #include <string> #include <unordered_map> -#define NOT_LOG_INFO - #include "config/config.hpp" #include "query_engine/code_compiler.hpp" #include "query_engine/code_generator.hpp" @@ -13,29 +11,28 @@ #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<CodeLib>; - 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<int, int, int, int> stripper; diff --git a/include/query_engine/query_engine.hpp b/include/query_engine/query_engine.hpp index 9ff785a52..940ef1c95 100644 --- a/include/query_engine/query_engine.hpp +++ b/include/query_engine/query_engine.hpp @@ -1,31 +1,45 @@ #pragma once +#include "database/db.hpp" +#include "logging/default.hpp" #include "program_executor.hpp" #include "program_loader.hpp" #include "query_result.hpp" -#include "database/db.hpp" -// -// Current arhitecture: -// query -> code_loader -> query_stripper -> [code_generator] -// -> [code_compiler] -> code_executor +/* + * 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, Db& db) + QueryEngine() : logger(logging::log->logger("QueryEngine")) {} + + auto execute(const std::string &query, Db &db, + communication::OutputStream &stream) { - // TODO: error handling - auto program = program_loader.load(query); - auto result = program_executor.execute(program, db); - return result; + 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/include/query_engine/query_result.hpp b/include/query_engine/query_result.hpp index f59e3578b..992df23c0 100644 --- a/include/query_engine/query_result.hpp +++ b/include/query_engine/query_result.hpp @@ -1,5 +1,8 @@ #pragma once +// !! DEPRICATED !! +// TODO: DELETE + #include <memory> #include <string> #include <unordered_map> diff --git a/include/query_engine/traverser/code.hpp b/include/query_engine/traverser/code.hpp index 23006c1c1..412716167 100644 --- a/include/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<Int64>().value);\n" " if (!{0}) return t.commit(), std::make_shared<QueryResult>();"; -const std::string return_empty_result = - "return std::make_shared<QueryResult>();"; +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[{}]);"; diff --git a/include/utils/log/logger.hpp b/include/utils/log/logger.hpp deleted file mode 100644 index 41b67d1e4..000000000 --- a/include/utils/log/logger.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -#include <string> -#include <iostream> -#include <ctime> -#include <iomanip> - -namespace logger -{ - -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::Logger::instance().info(_MESSAGE_); -#endif - - diff --git a/include/utils/timer/timer.hpp b/include/utils/timer/timer.hpp index 1cf53ea2b..4fa64fd21 100644 --- a/include/utils/timer/timer.hpp +++ b/include/utils/timer/timer.hpp @@ -6,7 +6,7 @@ #include <thread> #include <atomic> -#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/bolt/v1/states.cpp b/src/bolt/v1/states.cpp deleted file mode 100644 index 8039a75ee..000000000 --- a/src/bolt/v1/states.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "bolt/v1/states.hpp" - -#include "bolt/v1/states/handshake.hpp" -#include "bolt/v1/states/init.hpp" -#include "bolt/v1/states/error.hpp" -#include "bolt/v1/states/executor.hpp" - -namespace bolt -{ - -States::States() -{ - handshake = std::make_unique<Handshake>(); - init = std::make_unique<Init>(); - executor = std::make_unique<Executor>(); - error = std::make_unique<Error>(); -} - -} diff --git a/src/bolt/v1/bolt.cpp b/src/communication/bolt/v1/bolt.cpp similarity index 80% rename from src/bolt/v1/bolt.cpp rename to src/communication/bolt/v1/bolt.cpp index 56d85727d..9efd1b10c 100644 --- a/src/bolt/v1/bolt.cpp +++ b/src/communication/bolt/v1/bolt.cpp @@ -1,7 +1,6 @@ -#include "bolt/v1/bolt.hpp" +#include "communication/bolt/v1/bolt.hpp" -#include "bolt/v1/session.hpp" -#include <iostream> +#include "communication/bolt/v1/session.hpp" namespace bolt { diff --git a/src/bolt/v1/session.cpp b/src/communication/bolt/v1/session.cpp similarity index 95% rename from src/bolt/v1/session.cpp rename to src/communication/bolt/v1/session.cpp index 04f710b1e..69e9f1c7c 100644 --- a/src/bolt/v1/session.cpp +++ b/src/communication/bolt/v1/session.cpp @@ -1,4 +1,4 @@ -#include "bolt/v1/session.hpp" +#include "communication/bolt/v1/session.hpp" namespace bolt { 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<Handshake>(); + init = std::make_unique<Init>(); + executor = std::make_unique<Executor>(); + error = std::make_unique<Error>(); +} + +} diff --git a/src/bolt/v1/states/error.cpp b/src/communication/bolt/v1/states/error.cpp similarity index 94% rename from src/bolt/v1/states/error.cpp rename to src/communication/bolt/v1/states/error.cpp index 315fbf3e0..2a83c13fc 100644 --- a/src/bolt/v1/states/error.cpp +++ b/src/communication/bolt/v1/states/error.cpp @@ -1,4 +1,4 @@ -#include "bolt/v1/states/error.hpp" +#include "communication/bolt/v1/states/error.hpp" namespace bolt { diff --git a/src/bolt/v1/states/executor.cpp b/src/communication/bolt/v1/states/executor.cpp similarity index 83% rename from src/bolt/v1/states/executor.cpp rename to src/communication/bolt/v1/states/executor.cpp index db95fa65d..8f98db718 100644 --- a/src/bolt/v1/states/executor.cpp +++ b/src/communication/bolt/v1/states/executor.cpp @@ -1,5 +1,5 @@ -#include "bolt/v1/states/executor.hpp" -#include "bolt/v1/messaging/codes.hpp" +#include "communication/bolt/v1/states/executor.hpp" +#include "communication/bolt/v1/messaging/codes.hpp" namespace bolt { @@ -54,11 +54,11 @@ void Executor::run(Session& session, Query& query) { logger.trace("[Run] '{}'", query.statement); - // auto &db = session.active_db(); - // logger.info("[ActiveDB] '{}'", db.name()); - // query_engine.execute(query.statement, db); - - session.output_stream._write_test(); + auto &db = session.active_db(); + logger.debug("[ActiveDB] '{}'", db.name()); + + // TODO: hangle syntax error use case + query_engine.execute(query.statement, db, session.output_stream); } void Executor::pull_all(Session& session) 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 d31460878..faaa4ee0c 100644 --- a/src/bolt/v1/states/handshake.cpp +++ b/src/communication/bolt/v1/states/handshake.cpp @@ -1,6 +1,6 @@ -#include "bolt/v1/states/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 88% rename from src/bolt/v1/states/init.cpp rename to src/communication/bolt/v1/states/init.cpp index 33568f783..323c1ad29 100644 --- a/src/bolt/v1/states/init.cpp +++ b/src/communication/bolt/v1/states/init.cpp @@ -1,7 +1,7 @@ -#include "bolt/v1/states/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" diff --git a/src/bolt/v1/transport/bolt_decoder.cpp b/src/communication/bolt/v1/transport/bolt_decoder.cpp similarity index 96% rename from src/bolt/v1/transport/bolt_decoder.cpp rename to src/communication/bolt/v1/transport/bolt_decoder.cpp index e97dc2bff..96248a8fc 100644 --- a/src/bolt/v1/transport/bolt_decoder.cpp +++ b/src/communication/bolt/v1/transport/bolt_decoder.cpp @@ -1,10 +1,8 @@ -#include "bolt/v1/transport/bolt_decoder.hpp" - -#include <iostream> +#include "communication/bolt/v1/transport/bolt_decoder.hpp" +#include "communication/bolt/v1/packing/codes.hpp" #include "logging/default.hpp" #include "utils/bswap.hpp" -#include "bolt/v1/packing/codes.hpp" namespace bolt { 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 5beb75621..3406135e6 100644 --- a/src/bolt/v1/transport/buffer.cpp +++ b/src/communication/bolt/v1/transport/buffer.cpp @@ -1,4 +1,4 @@ -#include "bolt/v1/transport/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/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 <iostream> #include <ostream> - #include <cstdint> #include <string> +#include <fmt/format.h> 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/examples/bolt_py_client/.initial_test.py.swn b/src/examples/bolt_py_client/.initial_test.py.swn new file mode 100644 index 0000000000000000000000000000000000000000..a7f394ee91590bc445c2f14a13817bdd3aba74f0 GIT binary patch literal 12288 zcmeI2OK;Oa5XZMjAYOfl#|a^AT_J2Kb>gHF5R^(KF>MenRg%&}TZK)sZB3oESvyrr zRge%@J_&pR4shg#;0ti&zzt5lF&pxtucWA#qFL!Luf4mov%j4kD~e08$JuFm%N!$6 zh6uU#`R)Ac!2wddLP)7rVd`<W;(8_ScIyP~FO<RPyeHQJpOtyE%Bw4q`K!@DmZN-w zRehHS(URweMSrtcb{#Ils3V-vVQw+xL1_A$JxqgLkN^_cO`sMokKXQ|OT?|1Y8ugo z>E%mvyL;h15<mh-00|%gB!C2v01`j~|1p8k?;|f^eWx00ywSM!?YcH@@qz@901`j~ zNB{{S0VIF~kN^@u0!RP}oInDsLdcV|@Ynx2a322uZ~p%OI!MSD&_~c4&_mEL=nUvI zXlH<sAE0-j3g{~6Lq8#D&^^!)=-WkT2R#Q(fhIxUFA!1%{W?#`PtbeNE6@W_7PJF? zd;+b5#z862O_1{MItU9AKmter2_OL^fCP@40EH6pAaFck%9_xh)wtX=$g(GCy-FQX zuQ)tN5~3bK&1AmMMMa;UD5R&TZj3I-rBU6W^HX-trrC@xjg&=mc400zL#1XMZCu_i zP-zNQ<upYXwSt{5Sh3im*4?1!a6xpqAP#h4&j>ZSXir}AD=g%dqVlHgfwFg$HO0HT zeyj{*o%0>wsIZI()kVA$nPsG6bYdo>wh&ri57Rk&qF_TmOF5X#=INF~k%WCwAE+*B z5z1EJHlEmC8Xd2j>$>eHZsvVfb`aD~nnr4@xeq-DVB*LlTCvsh9Icbt^N3bF?HBm^ zedY!{(hilRI<a&s2&E%dRHV#G&*w6P#6g=u<A{*2aG9iVvLkfa^;oEaC~krh5nA#* zH%SY!#<z__i0qwu*3RW0%_Q@Mxr{vnPBepcn#nb<6|L5te=^%PmtK`l&@vZ~^<++K z9j3OSSypq~cC16~>^FXzZFCzBNpxZ9E*YVa-f2Cj6Vk}|&{UDmI+teSfo>4>LO8f^ zQI?xNWW-dgTUS;KS5qYxIOU?M>YCu**i%RtjfxQ=e<lYnCe>&085T0=&&@xNbxnO4 vpNvLbugu(4F9@{=tfDMAWaQ>Mi;!jMRcYO{xo%OX>U%Q$+a82d%M0=w<F`Rn literal 0 HcmV?d00001 diff --git a/src/examples/bolt_py_client/initial_test.py b/src/examples/bolt_py_client/initial_test.py index 1cd436e86..75dfad463 100644 --- a/src/examples/bolt_py_client/initial_test.py +++ b/src/examples/bolt_py_client/initial_test.py @@ -1,13 +1,38 @@ -from neo4j.v1 import GraphDatabase, basic_auth +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() -# session.run("CREATE (a:Person {age:25})") -result = session.run("MATCH (a:Person) RETURN a.name AS name") -for record in result: - print(record["name"]) - session.close() +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/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 <cstdlib> #include <cstring> -#include "uvbuffer.hpp" +#include "io/uv/uvbuffer.hpp" namespace uv { diff --git a/src/logging/default.cpp b/src/logging/default.cpp index 4111c546f..fe3bcf627 100644 --- a/src/logging/default.cpp +++ b/src/logging/default.cpp @@ -20,6 +20,16 @@ Logger init_debug_logger() Logger debug_logger = init_debug_logger(); +std::unique_ptr<Log> info_log = std::make_unique<SyncLog>(); + +Logger init_info_logger() +{ + info_log->pipe(std::make_unique<Stdout>()); + return info_log->logger("INFO"); +} + +Logger info_logger = init_info_logger(); + void init_async() { log = std::make_unique<AsyncLog>(); diff --git a/src/memgraph_bolt.cpp b/src/memgraph_bolt.cpp index 3df3f12c9..64797e160 100644 --- a/src/memgraph_bolt.cpp +++ b/src/memgraph_bolt.cpp @@ -1,8 +1,8 @@ #include <iostream> #include <signal.h> -#include "bolt/v1/server/server.hpp" -#include "bolt/v1/server/worker.hpp" +#include "communication/bolt/v1/server/server.hpp" +#include "communication/bolt/v1/server/worker.hpp" #include "io/network/socket.hpp" @@ -34,7 +34,7 @@ int main(void) // that are configured below std::set_terminate(&terminate_handler); - logging::init_sync(); + logging::init_async(); logging::log->pipe(std::make_unique<Stdout>()); logger = logging::log->logger("Main"); 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/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 <iostream> #include <chrono> -#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<Timer>( - 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 4964da656..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; @@ -18,6 +19,9 @@ int main(void) 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; @@ -31,7 +35,7 @@ int main(void) // execute command try { - engine.execute(command, db); + 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 <array> #include <vector> -#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 <cassert> #include <vector> -#include "bolt/v1/transport/chunked_encoder.hpp" +#include "communication/bolt/v1/transport/chunked_encoder.hpp" using byte = unsigned char;