From 869da8dcdab1442d1918949fd52321458f2f3b40 Mon Sep 17 00:00:00 2001 From: Marko Budiselic <mbudiselicbuda@gmail.com> Date: Wed, 10 Aug 2016 09:39:02 +0100 Subject: [PATCH 1/3] All files for the Release are now isolated --- .gitignore | 1 + CMakeLists.txt | 221 +++++++++++++++--- README.md | 7 +- {src => include}/bolt/v1/bolt.hpp | 4 +- {src => include}/bolt/v1/messaging/codes.hpp | 0 include/bolt/v1/messaging/messages.hpp | 8 + {src => include}/bolt/v1/packing/codes.hpp | 0 {src => include}/bolt/v1/packing/types.hpp | 0 .../bolt/v1/serialization/bolt_serializer.hpp | 2 +- .../bolt/v1/serialization/record_stream.hpp | 2 +- .../v1/serialization/socket_serializer.hpp | 0 {src => include}/bolt/v1/server/server.hpp | 0 {src => include}/bolt/v1/server/worker.hpp | 0 {src => include}/bolt/v1/session.hpp | 6 +- {src => include}/bolt/v1/states.hpp | 2 +- {src => include}/bolt/v1/states/error.hpp | 3 +- {src => include}/bolt/v1/states/executor.hpp | 5 + {src => include}/bolt/v1/states/handshake.hpp | 0 {src => include}/bolt/v1/states/init.hpp | 0 .../bolt/v1/states/message_parser.hpp | 14 +- {src => include}/bolt/v1/states/state.hpp | 0 .../bolt/v1/transport/bolt_decoder.hpp | 18 +- .../bolt/v1/transport/bolt_encoder.hpp | 0 {src => include}/bolt/v1/transport/buffer.hpp | 0 .../bolt/v1/transport/chunked_decoder.hpp | 0 .../bolt/v1/transport/chunked_encoder.hpp | 0 .../bolt/v1/transport/socket_stream.hpp | 2 +- .../bolt/v1/transport/stream_error.hpp | 0 .../data_structures/bitset/dynamic_bitset.hpp | 0 .../data_structures/concurrent/common.hpp | 1 - .../concurrent/concurrent_map.hpp | 0 .../concurrent/concurrent_multimap.hpp | 0 .../concurrent/concurrent_multiset.hpp | 0 .../concurrent/concurrent_set.hpp | 0 .../data_structures/concurrent/skiplist.hpp | 0 .../concurrent/skiplist_gc.hpp | 0 include/database/db.hpp | 12 +- {src => include}/logging/default.hpp | 4 +- {src => include}/logging/levels.hpp | 0 {src => include}/logging/log.hpp | 0 {src => include}/logging/logger.hpp | 4 +- {src => include}/logging/logs/async_log.hpp | 0 {src => include}/logging/logs/sync_log.hpp | 0 {src => include}/logging/streams/stdout.hpp | 0 {src => include}/memory/freelist.hpp | 0 {src => include}/memory/lazy_gc.hpp | 0 {src => include}/mvcc/cre_exp.hpp | 0 {src => include}/mvcc/hints.hpp | 0 {src => include}/mvcc/mvcc_error.hpp | 0 {src => include}/mvcc/record.hpp | 6 +- {src => include}/mvcc/serialization_error.hpp | 0 {src => include}/mvcc/version.hpp | 0 {src => include}/mvcc/version_list.hpp | 0 .../query_engine/code_compiler.hpp | 4 +- .../query_engine/code_generator.hpp | 0 .../code_generator/clause_action.hpp | 0 .../code_generator/cpp_generator.hpp | 0 .../code_generator/cypher_state.hpp | 0 .../code_generator/entity_search.hpp | 0 .../code_generator/handlers/all.hpp | 0 .../code_generator/handlers/create.hpp | 0 .../code_generator/handlers/delete.hpp | 0 .../code_generator/handlers/includes.hpp | 5 + .../code_generator/handlers/match.hpp | 5 + .../code_generator/handlers/return.hpp | 0 .../code_generator/handlers/set.hpp | 0 .../handlers/transaction_begin.hpp | 0 .../handlers/transaction_commit.hpp | 0 .../code_generator/query_action.hpp | 0 .../code_generator/query_action_data.hpp | 0 .../code_generator/structures.hpp | 0 .../query_engine/exceptions/errors.hpp | 0 .../query_engine/exceptions/exceptions.hpp | 0 .../query_engine/hardcode/queries.hpp | 0 {src => include}/query_engine/i_code_cpu.hpp | 2 +- .../query_engine/memgraph_dynamic_lib.hpp | 7 +- .../query_engine/program_executor.hpp | 7 +- .../query_engine/program_loader.hpp | 10 +- .../query_engine/query_engine.hpp | 5 +- .../query_engine/query_hasher.hpp | 0 .../query_engine/query_program.hpp | 4 +- .../query_engine/query_result.hpp | 0 .../query_engine/query_stripped.hpp | 0 .../query_engine/query_stripper.hpp | 0 .../query_engine/traverser/code.hpp | 11 - .../query_engine/traverser/cpp_traverser.hpp | 24 +- {src => include}/query_engine/util.hpp | 38 ++- {src => include}/storage/common.hpp | 0 {src => include}/storage/edge.hpp | 4 +- {src => include}/storage/edge_accessor.hpp | 0 include/storage/edges.hpp | 16 ++ {src => include}/storage/graph.hpp | 2 +- {src => include}/storage/indexes/index.hpp | 0 .../storage/indexes/index_record.hpp | 0 .../indexes/index_record_collection.hpp | 0 .../storage/indexes/keys/index_key.hpp | 0 .../storage/indexes/keys/non_unique_key.hpp | 0 .../storage/indexes/keys/unique_key.hpp | 0 .../storage/indexes/sort_order.hpp | 0 .../storage/locking/lock_status.hpp | 0 {src => include}/storage/model/edge_list.hpp | 1 + {src => include}/storage/model/edge_model.hpp | 2 +- .../storage/model/properties/double.hpp | 2 +- .../storage/model/properties/float.hpp | 4 +- .../storage/model/properties/floating.hpp | 2 +- .../storage/model/properties/int32.hpp | 4 +- .../storage/model/properties/int64.hpp | 2 +- .../storage/model/properties/integral.hpp | 8 +- .../storage/model/properties/number.hpp | 4 +- .../properties/traversers/consolewriter.hpp | 0 .../properties/traversers/jsonwriter.hpp | 0 .../properties/utils/math_operations.hpp | 0 .../storage/model/properties/utils/modulo.hpp | 0 .../model/properties/utils/unary_negation.hpp | 0 .../storage/model/property_model.hpp | 0 .../storage/model/vertex_model.hpp | 4 +- {src => include}/storage/record_accessor.hpp | 0 {src => include}/storage/vertex.hpp | 4 +- {src => include}/threading/.gitignore | 0 {src => include}/threading/hazard_ptr.hpp | 0 {src => include}/threading/hazard_store.hpp | 0 {src => include}/threading/id.hpp | 0 {src => include}/threading/pool.hpp | 0 {src => include}/threading/sync/caslock.hpp | 0 {src => include}/threading/sync/futex.hpp | 2 +- .../threading/sync/lock_timeout_error.hpp | 0 {src => include}/threading/sync/lockable.hpp | 2 +- {src => include}/threading/sync/spinlock.hpp | 0 .../threading/sync/timed_spinlock.hpp | 0 {src => include}/threading/task.hpp | 0 {src => include}/threading/test.cpp | 0 {src => include}/threading/thread.hpp | 0 {src => include}/transactions/commit_log.hpp | 0 {src => include}/transactions/engine.hpp | 23 +- {src => include}/transactions/lock_store.hpp | 0 {src => include}/transactions/snapshot.hpp | 0 .../transactions/transaction_store.hpp | 0 {src => include}/utils/assert.hpp | 32 +-- {src => include}/utils/auto_scope.hpp | 0 {src => include}/utils/bash_colors.hpp | 0 {src => include}/utils/bswap.hpp | 0 {src => include}/utils/buffer.hpp | 0 .../utils/command_line/arguments.hpp | 0 {src => include}/utils/config/config.hpp | 0 .../utils/counters/atomic_counter.hpp | 0 .../utils/counters/ring_counter.hpp | 0 .../utils/counters/simple_counter.hpp | 0 {src => include}/utils/cpu_relax.hpp | 3 + {src => include}/utils/crtp.hpp | 0 {src => include}/utils/datetime/datetime.hpp | 0 .../utils/datetime/datetime_error.hpp | 0 {src => include}/utils/datetime/timestamp.hpp | 0 .../utils/exceptions/basic_exception.hpp | 0 {src => include}/utils/hashing/fnv.hpp | 6 +- {src => include}/utils/hashing/fnv32.hpp | 5 + {src => include}/utils/hashing/fnv64.hpp | 5 + {src => include}/utils/ioc/container.hpp | 0 {src => include}/utils/likely.hpp | 0 {src => include}/utils/log/logger.hpp | 7 +- {src => include}/utils/mark_ref.hpp | 0 {src => include}/utils/memory/allocator.hpp | 0 .../utils/memory/atomic_shared_ptr.hpp | 0 .../utils/memory/block_allocator.hpp | 0 {src => include}/utils/memory/maker.hpp | 0 {src => include}/utils/numerics/ceil.hpp | 0 {src => include}/utils/placeholder.hpp | 0 {src => include}/utils/platform.hpp | 0 .../utils/random/fast_binomial.hpp | 2 +- .../utils/random/xorshift128plus.hpp | 0 {src => include}/utils/reference_wrapper.hpp | 0 {src => include}/utils/stacktrace.hpp | 0 {src => include}/utils/string/all.hpp | 0 include/utils/string/file.hpp | 19 ++ {src => include}/utils/string/intercalate.hpp | 0 include/utils/string/join.hpp | 21 ++ {src => include}/utils/string/linereader.hpp | 0 {src => include}/utils/string/replace.hpp | 0 {src => include}/utils/string/split.hpp | 0 {src => include}/utils/string/streq.hpp | 0 include/utils/string/transform.hpp | 12 + {src => include}/utils/string/weak_string.hpp | 0 {src => include}/utils/sys.hpp | 0 {src => include}/utils/sysinfo/memory.hpp | 0 {src => include}/utils/terminate_handler.hpp | 0 {src => include}/utils/time/timer.hpp | 0 {src => include}/utils/timer/timer.hpp | 0 {src => include}/utils/total_ordering.hpp | 0 .../utils/total_ordering_with.hpp | 0 {src => include}/utils/type_discovery.hpp | 0 {src => include}/utils/types/byte.hpp | 0 {src => include}/utils/underlying_cast.hpp | 0 {src => include}/utils/variadic/variadic.hpp | 0 {src => include}/utils/visitor/visitable.hpp | 0 {src => include}/utils/visitor/visitor.hpp | 0 src/bolt/v1/bolt.cpp | 6 +- src/bolt/v1/messaging/messages.hpp | 8 - src/bolt/v1/session.cpp | 7 +- src/bolt/v1/states.cpp | 11 +- src/bolt/v1/states/error.cpp | 8 +- src/bolt/v1/states/executor.cpp | 12 +- src/bolt/v1/states/handshake.cpp | 2 +- src/bolt/v1/states/init.cpp | 2 +- src/bolt/v1/transport/bolt_decoder.cpp | 89 ++----- src/bolt/v1/transport/buffer.cpp | 2 +- src/cypher/lexertl | 1 - src/dbms/dbms.hpp | 38 +++ src/dbms/server/bolt.hpp | 9 - src/examples/bolt.cpp | 68 ------ src/examples/bolt_py_client/initial_test.py | 12 + src/examples/bolt_py_client/requirements.txt | 1 + src/examples/compile-bolt.sh | 3 - src/logging/default.cpp | 2 +- src/logging/levels.cpp | 2 +- src/logging/log.cpp | 4 +- src/logging/logs/async_log.cpp | 2 +- src/logging/logs/sync_log.cpp | 2 +- src/logging/streams/stdout.cpp | 2 +- src/memgraph_bolt.cpp | 73 +++++- src/mvcc/atom.hpp | 19 +- src/mvcc/id.cpp | 1 - src/mvcc/id.hpp | 36 --- src/mvcc/store.hpp | 2 + src/query_engine/util.cpp | 23 ++ src/storage/{edges.hpp => edges.cpp} | 24 +- src/utils/string/{file.hpp => file.cpp} | 11 +- src/utils/string/{join.hpp => join.cpp} | 14 +- .../string/{transform.hpp => transform.cpp} | 6 +- tests/manual/query_engine.cpp | 3 +- 228 files changed, 672 insertions(+), 475 deletions(-) rename {src => include}/bolt/v1/bolt.hpp (78%) rename {src => include}/bolt/v1/messaging/codes.hpp (100%) create mode 100644 include/bolt/v1/messaging/messages.hpp rename {src => include}/bolt/v1/packing/codes.hpp (100%) rename {src => include}/bolt/v1/packing/types.hpp (100%) rename {src => include}/bolt/v1/serialization/bolt_serializer.hpp (98%) rename {src => include}/bolt/v1/serialization/record_stream.hpp (62%) rename {src => include}/bolt/v1/serialization/socket_serializer.hpp (100%) rename {src => include}/bolt/v1/server/server.hpp (100%) rename {src => include}/bolt/v1/server/worker.hpp (100%) rename {src => include}/bolt/v1/session.hpp (93%) rename {src => include}/bolt/v1/states.hpp (84%) rename {src => include}/bolt/v1/states/error.hpp (60%) rename {src => include}/bolt/v1/states/executor.hpp (87%) rename {src => include}/bolt/v1/states/handshake.hpp (100%) rename {src => include}/bolt/v1/states/init.hpp (100%) rename {src => include}/bolt/v1/states/message_parser.hpp (71%) rename {src => include}/bolt/v1/states/state.hpp (100%) rename {src => include}/bolt/v1/transport/bolt_decoder.hpp (57%) rename {src => include}/bolt/v1/transport/bolt_encoder.hpp (100%) rename {src => include}/bolt/v1/transport/buffer.hpp (100%) rename {src => include}/bolt/v1/transport/chunked_decoder.hpp (100%) rename {src => include}/bolt/v1/transport/chunked_encoder.hpp (100%) rename {src => include}/bolt/v1/transport/socket_stream.hpp (92%) rename {src => include}/bolt/v1/transport/stream_error.hpp (100%) rename {src => include}/data_structures/bitset/dynamic_bitset.hpp (100%) rename {src => include}/data_structures/concurrent/common.hpp (98%) rename {src => include}/data_structures/concurrent/concurrent_map.hpp (100%) rename {src => include}/data_structures/concurrent/concurrent_multimap.hpp (100%) rename {src => include}/data_structures/concurrent/concurrent_multiset.hpp (100%) rename {src => include}/data_structures/concurrent/concurrent_set.hpp (100%) rename {src => include}/data_structures/concurrent/skiplist.hpp (100%) rename {src => include}/data_structures/concurrent/skiplist_gc.hpp (100%) rename {src => include}/logging/default.hpp (81%) rename {src => include}/logging/levels.hpp (100%) rename {src => include}/logging/log.hpp (100%) rename {src => include}/logging/logger.hpp (97%) rename {src => include}/logging/logs/async_log.hpp (100%) rename {src => include}/logging/logs/sync_log.hpp (100%) rename {src => include}/logging/streams/stdout.hpp (100%) rename {src => include}/memory/freelist.hpp (100%) rename {src => include}/memory/lazy_gc.hpp (100%) rename {src => include}/mvcc/cre_exp.hpp (100%) rename {src => include}/mvcc/hints.hpp (100%) rename {src => include}/mvcc/mvcc_error.hpp (100%) rename {src => include}/mvcc/record.hpp (98%) rename {src => include}/mvcc/serialization_error.hpp (100%) rename {src => include}/mvcc/version.hpp (100%) rename {src => include}/mvcc/version_list.hpp (100%) rename {src => include}/query_engine/code_compiler.hpp (93%) rename {src => include}/query_engine/code_generator.hpp (100%) rename {src => include}/query_engine/code_generator/clause_action.hpp (100%) rename {src => include}/query_engine/code_generator/cpp_generator.hpp (100%) rename {src => include}/query_engine/code_generator/cypher_state.hpp (100%) rename {src => include}/query_engine/code_generator/entity_search.hpp (100%) rename {src => include}/query_engine/code_generator/handlers/all.hpp (100%) rename {src => include}/query_engine/code_generator/handlers/create.hpp (100%) rename {src => include}/query_engine/code_generator/handlers/delete.hpp (100%) rename {src => include}/query_engine/code_generator/handlers/includes.hpp (98%) rename {src => include}/query_engine/code_generator/handlers/match.hpp (99%) rename {src => include}/query_engine/code_generator/handlers/return.hpp (100%) rename {src => include}/query_engine/code_generator/handlers/set.hpp (100%) rename {src => include}/query_engine/code_generator/handlers/transaction_begin.hpp (100%) rename {src => include}/query_engine/code_generator/handlers/transaction_commit.hpp (100%) rename {src => include}/query_engine/code_generator/query_action.hpp (100%) rename {src => include}/query_engine/code_generator/query_action_data.hpp (100%) rename {src => include}/query_engine/code_generator/structures.hpp (100%) rename {src => include}/query_engine/exceptions/errors.hpp (100%) rename {src => include}/query_engine/exceptions/exceptions.hpp (100%) rename {src => include}/query_engine/hardcode/queries.hpp (100%) rename {src => include}/query_engine/i_code_cpu.hpp (86%) rename {src => include}/query_engine/memgraph_dynamic_lib.hpp (89%) rename {src => include}/query_engine/program_executor.hpp (81%) rename {src => include}/query_engine/program_loader.hpp (91%) rename {src => include}/query_engine/query_engine.hpp (82%) rename {src => include}/query_engine/query_hasher.hpp (100%) rename {src => include}/query_engine/query_program.hpp (80%) rename {src => include}/query_engine/query_result.hpp (100%) rename {src => include}/query_engine/query_stripped.hpp (100%) rename {src => include}/query_engine/query_stripper.hpp (100%) rename {src => include}/query_engine/traverser/code.hpp (85%) rename {src => include}/query_engine/traverser/cpp_traverser.hpp (97%) rename {src => include}/query_engine/util.hpp (60%) rename {src => include}/storage/common.hpp (100%) rename {src => include}/storage/edge.hpp (79%) rename {src => include}/storage/edge_accessor.hpp (100%) create mode 100644 include/storage/edges.hpp rename {src => include}/storage/graph.hpp (100%) rename {src => include}/storage/indexes/index.hpp (100%) rename {src => include}/storage/indexes/index_record.hpp (100%) rename {src => include}/storage/indexes/index_record_collection.hpp (100%) rename {src => include}/storage/indexes/keys/index_key.hpp (100%) rename {src => include}/storage/indexes/keys/non_unique_key.hpp (100%) rename {src => include}/storage/indexes/keys/unique_key.hpp (100%) rename {src => include}/storage/indexes/sort_order.hpp (100%) rename {src => include}/storage/locking/lock_status.hpp (100%) rename {src => include}/storage/model/edge_list.hpp (99%) rename {src => include}/storage/model/edge_model.hpp (89%) rename {src => include}/storage/model/properties/double.hpp (80%) rename {src => include}/storage/model/properties/float.hpp (73%) rename {src => include}/storage/model/properties/floating.hpp (72%) rename {src => include}/storage/model/properties/int32.hpp (74%) rename {src => include}/storage/model/properties/int64.hpp (80%) rename {src => include}/storage/model/properties/integral.hpp (55%) rename {src => include}/storage/model/properties/number.hpp (88%) rename {src => include}/storage/model/properties/traversers/consolewriter.hpp (100%) rename {src => include}/storage/model/properties/traversers/jsonwriter.hpp (100%) rename {src => include}/storage/model/properties/utils/math_operations.hpp (100%) rename {src => include}/storage/model/properties/utils/modulo.hpp (100%) rename {src => include}/storage/model/properties/utils/unary_negation.hpp (100%) rename {src => include}/storage/model/property_model.hpp (100%) rename {src => include}/storage/model/vertex_model.hpp (66%) rename {src => include}/storage/record_accessor.hpp (100%) rename {src => include}/storage/vertex.hpp (89%) rename {src => include}/threading/.gitignore (100%) rename {src => include}/threading/hazard_ptr.hpp (100%) rename {src => include}/threading/hazard_store.hpp (100%) rename {src => include}/threading/id.hpp (100%) rename {src => include}/threading/pool.hpp (100%) rename {src => include}/threading/sync/caslock.hpp (100%) rename {src => include}/threading/sync/futex.hpp (98%) rename {src => include}/threading/sync/lock_timeout_error.hpp (100%) rename {src => include}/threading/sync/lockable.hpp (90%) rename {src => include}/threading/sync/spinlock.hpp (100%) rename {src => include}/threading/sync/timed_spinlock.hpp (100%) rename {src => include}/threading/task.hpp (100%) rename {src => include}/threading/test.cpp (100%) rename {src => include}/threading/thread.hpp (100%) rename {src => include}/transactions/commit_log.hpp (100%) rename {src => include}/transactions/engine.hpp (84%) rename {src => include}/transactions/lock_store.hpp (100%) rename {src => include}/transactions/snapshot.hpp (100%) rename {src => include}/transactions/transaction_store.hpp (100%) rename {src => include}/utils/assert.hpp (52%) rename {src => include}/utils/auto_scope.hpp (100%) rename {src => include}/utils/bash_colors.hpp (100%) rename {src => include}/utils/bswap.hpp (100%) rename {src => include}/utils/buffer.hpp (100%) rename {src => include}/utils/command_line/arguments.hpp (100%) rename {src => include}/utils/config/config.hpp (100%) rename {src => include}/utils/counters/atomic_counter.hpp (100%) rename {src => include}/utils/counters/ring_counter.hpp (100%) rename {src => include}/utils/counters/simple_counter.hpp (100%) rename {src => include}/utils/cpu_relax.hpp (56%) rename {src => include}/utils/crtp.hpp (100%) rename {src => include}/utils/datetime/datetime.hpp (100%) rename {src => include}/utils/datetime/datetime_error.hpp (100%) rename {src => include}/utils/datetime/timestamp.hpp (100%) rename {src => include}/utils/exceptions/basic_exception.hpp (100%) rename {src => include}/utils/hashing/fnv.hpp (96%) rename {src => include}/utils/hashing/fnv32.hpp (98%) rename {src => include}/utils/hashing/fnv64.hpp (98%) rename {src => include}/utils/ioc/container.hpp (100%) rename {src => include}/utils/likely.hpp (100%) rename {src => include}/utils/log/logger.hpp (89%) rename {src => include}/utils/mark_ref.hpp (100%) rename {src => include}/utils/memory/allocator.hpp (100%) rename {src => include}/utils/memory/atomic_shared_ptr.hpp (100%) rename {src => include}/utils/memory/block_allocator.hpp (100%) rename {src => include}/utils/memory/maker.hpp (100%) rename {src => include}/utils/numerics/ceil.hpp (100%) rename {src => include}/utils/placeholder.hpp (100%) rename {src => include}/utils/platform.hpp (100%) rename {src => include}/utils/random/fast_binomial.hpp (97%) rename {src => include}/utils/random/xorshift128plus.hpp (100%) rename {src => include}/utils/reference_wrapper.hpp (100%) rename {src => include}/utils/stacktrace.hpp (100%) rename {src => include}/utils/string/all.hpp (100%) create mode 100644 include/utils/string/file.hpp rename {src => include}/utils/string/intercalate.hpp (100%) create mode 100644 include/utils/string/join.hpp rename {src => include}/utils/string/linereader.hpp (100%) rename {src => include}/utils/string/replace.hpp (100%) rename {src => include}/utils/string/split.hpp (100%) rename {src => include}/utils/string/streq.hpp (100%) create mode 100644 include/utils/string/transform.hpp rename {src => include}/utils/string/weak_string.hpp (100%) rename {src => include}/utils/sys.hpp (100%) rename {src => include}/utils/sysinfo/memory.hpp (100%) rename {src => include}/utils/terminate_handler.hpp (100%) rename {src => include}/utils/time/timer.hpp (100%) rename {src => include}/utils/timer/timer.hpp (100%) rename {src => include}/utils/total_ordering.hpp (100%) rename {src => include}/utils/total_ordering_with.hpp (100%) rename {src => include}/utils/type_discovery.hpp (100%) rename {src => include}/utils/types/byte.hpp (100%) rename {src => include}/utils/underlying_cast.hpp (100%) rename {src => include}/utils/variadic/variadic.hpp (100%) rename {src => include}/utils/visitor/visitable.hpp (100%) rename {src => include}/utils/visitor/visitor.hpp (100%) delete mode 100644 src/bolt/v1/messaging/messages.hpp delete mode 160000 src/cypher/lexertl delete mode 100644 src/dbms/server/bolt.hpp delete mode 100644 src/examples/bolt.cpp create mode 100644 src/examples/bolt_py_client/initial_test.py create mode 100644 src/examples/bolt_py_client/requirements.txt delete mode 100644 src/examples/compile-bolt.sh delete mode 100644 src/mvcc/id.hpp create mode 100644 src/query_engine/util.cpp rename src/storage/{edges.hpp => edges.cpp} (71%) rename src/utils/string/{file.hpp => file.cpp} (78%) rename src/utils/string/{join.hpp => join.cpp} (52%) rename src/utils/string/{transform.hpp => transform.cpp} (77%) 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..c06c78362 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,16 +141,130 @@ 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/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) +# ----------------------------------------------------------------------------- + # 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 +# release flags +set(CMAKE_CXX_FLAGS_RELEASE + "${CMAKE_CXX_FLAGS_RELEASE} -march=native -Wall -Werror") + +# -- configure time variables ------------------------------------------------- option(RUNTIME_ASSERT "Enable runtime assertions" OFF) if(RUNTIME_ASSERT) add_definitions( -DRUNTIME_ASSERT_ON ) @@ -163,7 +280,11 @@ if(NDEBUG) add_definitions( -DNDEBUG ) endif() -# includes +option(MEMGRAPH "Build memgraph binary" ON) +option(POC "Build proof of concept binaries" ON) +option(TESTS "Build test binaries" ON) + +# -- includes ----------------------------------------------------------------- include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${src_dir}) include_directories(${build_include_dir}) @@ -173,6 +294,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 +305,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}/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}/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 +337,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 +354,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 +375,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/bolt/v1/bolt.hpp similarity index 78% rename from src/bolt/v1/bolt.hpp rename to include/bolt/v1/bolt.hpp index 3b42a200e..299e068ba 100644 --- a/src/bolt/v1/bolt.hpp +++ b/include/bolt/v1/bolt.hpp @@ -1,7 +1,8 @@ #pragma once -#include "states.hpp" +#include "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/src/bolt/v1/messaging/codes.hpp b/include/bolt/v1/messaging/codes.hpp similarity index 100% rename from src/bolt/v1/messaging/codes.hpp rename to include/bolt/v1/messaging/codes.hpp diff --git a/include/bolt/v1/messaging/messages.hpp b/include/bolt/v1/messaging/messages.hpp new file mode 100644 index 000000000..f89c48054 --- /dev/null +++ b/include/bolt/v1/messaging/messages.hpp @@ -0,0 +1,8 @@ +#pragma once + +namespace bolt +{ + +// TODO: what should be here? (Question for Dominik) + +} diff --git a/src/bolt/v1/packing/codes.hpp b/include/bolt/v1/packing/codes.hpp similarity index 100% rename from src/bolt/v1/packing/codes.hpp rename to include/bolt/v1/packing/codes.hpp diff --git a/src/bolt/v1/packing/types.hpp b/include/bolt/v1/packing/types.hpp similarity index 100% rename from src/bolt/v1/packing/types.hpp rename to include/bolt/v1/packing/types.hpp diff --git a/src/bolt/v1/serialization/bolt_serializer.hpp b/include/bolt/v1/serialization/bolt_serializer.hpp similarity index 98% rename from src/bolt/v1/serialization/bolt_serializer.hpp rename to include/bolt/v1/serialization/bolt_serializer.hpp index be791817b..bafca1ed6 100644 --- a/src/bolt/v1/serialization/bolt_serializer.hpp +++ b/include/bolt/v1/serialization/bolt_serializer.hpp @@ -3,7 +3,7 @@ #include "bolt/v1/transport/bolt_encoder.hpp" #include "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" diff --git a/src/bolt/v1/serialization/record_stream.hpp b/include/bolt/v1/serialization/record_stream.hpp similarity index 62% rename from src/bolt/v1/serialization/record_stream.hpp rename to include/bolt/v1/serialization/record_stream.hpp index ffd14f6e4..bb058d4fb 100644 --- a/src/bolt/v1/serialization/record_stream.hpp +++ b/include/bolt/v1/serialization/record_stream.hpp @@ -1,6 +1,6 @@ #pragma once -#include "bolt_serializer.hpp" +#include "bolt/v1/serialization/bolt_serializer.hpp" namespace bolt { diff --git a/src/bolt/v1/serialization/socket_serializer.hpp b/include/bolt/v1/serialization/socket_serializer.hpp similarity index 100% rename from src/bolt/v1/serialization/socket_serializer.hpp rename to include/bolt/v1/serialization/socket_serializer.hpp diff --git a/src/bolt/v1/server/server.hpp b/include/bolt/v1/server/server.hpp similarity index 100% rename from src/bolt/v1/server/server.hpp rename to include/bolt/v1/server/server.hpp diff --git a/src/bolt/v1/server/worker.hpp b/include/bolt/v1/server/worker.hpp similarity index 100% rename from src/bolt/v1/server/worker.hpp rename to include/bolt/v1/server/worker.hpp diff --git a/src/bolt/v1/session.hpp b/include/bolt/v1/session.hpp similarity index 93% rename from src/bolt/v1/session.hpp rename to include/bolt/v1/session.hpp index af5c1a708..dd8b772ec 100644 --- a/src/bolt/v1/session.hpp +++ b/include/bolt/v1/session.hpp @@ -4,13 +4,11 @@ #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/v1/bolt.hpp" -#include "bolt.hpp" #include "logging/default.hpp" namespace bolt @@ -31,6 +29,8 @@ public: Bolt& bolt; + Db& active_db(); + Decoder decoder; Encoder encoder {socket}; diff --git a/src/bolt/v1/states.hpp b/include/bolt/v1/states.hpp similarity index 84% rename from src/bolt/v1/states.hpp rename to include/bolt/v1/states.hpp index be4cbc344..a3398822d 100644 --- a/src/bolt/v1/states.hpp +++ b/include/bolt/v1/states.hpp @@ -1,6 +1,6 @@ #pragma once -#include "states/state.hpp" +#include "bolt/v1/states/state.hpp" #include "logging/log.hpp" namespace bolt diff --git a/src/bolt/v1/states/error.hpp b/include/bolt/v1/states/error.hpp similarity index 60% rename from src/bolt/v1/states/error.hpp rename to include/bolt/v1/states/error.hpp index 0ef5964bf..797dfe537 100644 --- a/src/bolt/v1/states/error.hpp +++ b/include/bolt/v1/states/error.hpp @@ -1,5 +1,6 @@ #pragma once +#include "bolt/v1/session.hpp" #include "bolt/v1/states/state.hpp" namespace bolt @@ -8,7 +9,7 @@ namespace bolt class Error : public State { public: - State* run(Session& session) override; + State *run(Session &session) override; }; } diff --git a/src/bolt/v1/states/executor.hpp b/include/bolt/v1/states/executor.hpp similarity index 87% rename from src/bolt/v1/states/executor.hpp rename to include/bolt/v1/states/executor.hpp index 5b1127a3a..e35ed68fd 100644 --- a/src/bolt/v1/states/executor.hpp +++ b/include/bolt/v1/states/executor.hpp @@ -2,6 +2,7 @@ #include "bolt/v1/states/state.hpp" #include "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/bolt/v1/states/handshake.hpp similarity index 100% rename from src/bolt/v1/states/handshake.hpp rename to include/bolt/v1/states/handshake.hpp diff --git a/src/bolt/v1/states/init.hpp b/include/bolt/v1/states/init.hpp similarity index 100% rename from src/bolt/v1/states/init.hpp rename to include/bolt/v1/states/init.hpp diff --git a/src/bolt/v1/states/message_parser.hpp b/include/bolt/v1/states/message_parser.hpp similarity index 71% rename from src/bolt/v1/states/message_parser.hpp rename to include/bolt/v1/states/message_parser.hpp index ff8b6952c..9ad938722 100644 --- a/src/bolt/v1/states/message_parser.hpp +++ b/include/bolt/v1/states/message_parser.hpp @@ -1,9 +1,8 @@ #pragma once -#include "state.hpp" -#include "utils/crtp.hpp" - #include "bolt/v1/session.hpp" +#include "bolt/v1/states/state.hpp" +#include "utils/crtp.hpp" namespace bolt { @@ -12,10 +11,9 @@ template <class Derived> class MessageParser : public State, public Crtp<Derived> { public: - MessageParser(Logger&& logger) - : logger(std::forward<Logger>(logger)) {} + MessageParser(Logger &&logger) : logger(std::forward<Logger>(logger)) {} - State* run(Session& session) override final + State *run(Session &session) override final { typename Derived::Message message; @@ -23,8 +21,7 @@ public: auto next = this->derived().parse(session, message); // return next state if parsing was unsuccessful (i.e. error state) - if(next != &this->derived()) - return next; + if (next != &this->derived()) return next; logger.debug("Executing state"); return this->derived().execute(session, message); @@ -33,5 +30,4 @@ public: protected: Logger logger; }; - } diff --git a/src/bolt/v1/states/state.hpp b/include/bolt/v1/states/state.hpp similarity index 100% rename from src/bolt/v1/states/state.hpp rename to include/bolt/v1/states/state.hpp diff --git a/src/bolt/v1/transport/bolt_decoder.hpp b/include/bolt/v1/transport/bolt_decoder.hpp similarity index 57% rename from src/bolt/v1/transport/bolt_decoder.hpp rename to include/bolt/v1/transport/bolt_decoder.hpp index c326f0548..4399e4ed6 100644 --- a/src/bolt/v1/transport/bolt_decoder.hpp +++ b/include/bolt/v1/transport/bolt_decoder.hpp @@ -1,8 +1,7 @@ #pragma once -#include "buffer.hpp" -#include "chunked_decoder.hpp" - +#include "bolt/v1/transport/buffer.hpp" +#include "bolt/v1/transport/chunked_decoder.hpp" #include "utils/types/byte.hpp" namespace bolt @@ -11,15 +10,15 @@ namespace bolt class BoltDecoder { public: - void handshake(const byte*& data, size_t len); - bool decode(const byte*& data, size_t len); + void handshake(const byte *&data, size_t len); + bool decode(const byte *&data, size_t len); bool empty() const; void reset(); byte peek() const; byte read_byte(); - void read_bytes(void* dest, size_t n); + void read_bytes(void *dest, size_t n); int16_t read_int16(); uint16_t read_uint16(); @@ -36,10 +35,9 @@ public: private: Buffer buffer; - ChunkedDecoder<Buffer> decoder {buffer}; - size_t pos {0}; + ChunkedDecoder<Buffer> decoder{buffer}; + size_t pos{0}; - const byte* raw() const; + const byte *raw() const; }; - } diff --git a/src/bolt/v1/transport/bolt_encoder.hpp b/include/bolt/v1/transport/bolt_encoder.hpp similarity index 100% rename from src/bolt/v1/transport/bolt_encoder.hpp rename to include/bolt/v1/transport/bolt_encoder.hpp diff --git a/src/bolt/v1/transport/buffer.hpp b/include/bolt/v1/transport/buffer.hpp similarity index 100% rename from src/bolt/v1/transport/buffer.hpp rename to include/bolt/v1/transport/buffer.hpp diff --git a/src/bolt/v1/transport/chunked_decoder.hpp b/include/bolt/v1/transport/chunked_decoder.hpp similarity index 100% rename from src/bolt/v1/transport/chunked_decoder.hpp rename to include/bolt/v1/transport/chunked_decoder.hpp diff --git a/src/bolt/v1/transport/chunked_encoder.hpp b/include/bolt/v1/transport/chunked_encoder.hpp similarity index 100% rename from src/bolt/v1/transport/chunked_encoder.hpp rename to include/bolt/v1/transport/chunked_encoder.hpp diff --git a/src/bolt/v1/transport/socket_stream.hpp b/include/bolt/v1/transport/socket_stream.hpp similarity index 92% rename from src/bolt/v1/transport/socket_stream.hpp rename to include/bolt/v1/transport/socket_stream.hpp index de41815bc..aadeb681e 100644 --- a/src/bolt/v1/transport/socket_stream.hpp +++ b/include/bolt/v1/transport/socket_stream.hpp @@ -5,7 +5,7 @@ #include <cstdio> #include "io/network/socket.hpp" -#include "stream_error.hpp" +#include "bolt/v1/transport/stream_error.hpp" namespace bolt { diff --git a/src/bolt/v1/transport/stream_error.hpp b/include/bolt/v1/transport/stream_error.hpp similarity index 100% rename from src/bolt/v1/transport/stream_error.hpp rename to include/bolt/v1/transport/stream_error.hpp 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<const K, T> *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 100% rename from src/data_structures/concurrent/skiplist_gc.hpp rename to include/data_structures/concurrent/skiplist_gc.hpp 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>; + 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/logging/default.hpp b/include/logging/default.hpp similarity index 81% rename from src/logging/default.hpp rename to include/logging/default.hpp index dd8357426..ace13d31b 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 { 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 <cassert> #include <fmt/format.h> -#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/src/query_engine/code_compiler.hpp b/include/query_engine/code_compiler.hpp similarity index 93% rename from src/query_engine/code_compiler.hpp rename to include/query_engine/code_compiler.hpp index 05bf2528e..f29133bef 100644 --- a/src/query_engine/code_compiler.hpp +++ b/include/query_engine/code_compiler.hpp @@ -19,11 +19,11 @@ public: auto compile_command = utils::prints("clang++", // "-std=c++1y -O2 -DNDEBUG", // compile flags - "-std=c++1y -DDEBUG", // 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./src", "-I../../libs/fmt", + "-I../libs/fmt", // TODO: load from config "-L./ -lmemgraph_pic", "-shared -fPIC" // shared library flags ); diff --git a/src/query_engine/code_generator.hpp b/include/query_engine/code_generator.hpp similarity index 100% rename from src/query_engine/code_generator.hpp rename to include/query_engine/code_generator.hpp 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 100% rename from src/query_engine/code_generator/handlers/return.hpp rename to include/query_engine/code_generator/handlers/return.hpp 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 100% rename from src/query_engine/code_generator/handlers/transaction_commit.hpp rename to include/query_engine/code_generator/handlers/transaction_commit.hpp 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/src/query_engine/i_code_cpu.hpp b/include/query_engine/i_code_cpu.hpp similarity index 86% rename from src/query_engine/i_code_cpu.hpp rename to include/query_engine/i_code_cpu.hpp index 200de8483..b4a49ba01 100644 --- a/src/query_engine/i_code_cpu.hpp +++ b/include/query_engine/i_code_cpu.hpp @@ -2,7 +2,7 @@ #include "database/db.hpp" #include "query_engine/query_result.hpp" -#include "query_stripped.hpp" +#include "query_engine/query_stripped.hpp" class 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<MemgraphDynamicLib>; + +} diff --git a/src/query_engine/program_executor.hpp b/include/query_engine/program_executor.hpp similarity index 81% rename from src/query_engine/program_executor.hpp rename to include/query_engine/program_executor.hpp index a12f4b667..a13c98cd6 100644 --- a/src/query_engine/program_executor.hpp +++ b/include/query_engine/program_executor.hpp @@ -15,7 +15,7 @@ class ProgramExecutor { public: - auto execute(QueryProgram &program) + auto execute(QueryProgram &program, Db& db) { try { // TODO: return result of query/code exection @@ -25,9 +25,4 @@ public: 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 91% rename from src/query_engine/program_loader.hpp rename to include/query_engine/program_loader.hpp index b8d4ef18e..93035aa33 100644 --- a/src/query_engine/program_loader.hpp +++ b/include/query_engine/program_loader.hpp @@ -6,12 +6,12 @@ #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" diff --git a/src/query_engine/query_engine.hpp b/include/query_engine/query_engine.hpp similarity index 82% rename from src/query_engine/query_engine.hpp rename to include/query_engine/query_engine.hpp index 933a06bad..9ff785a52 100644 --- a/src/query_engine/query_engine.hpp +++ b/include/query_engine/query_engine.hpp @@ -3,6 +3,7 @@ #include "program_executor.hpp" #include "program_loader.hpp" #include "query_result.hpp" +#include "database/db.hpp" // // Current arhitecture: @@ -17,11 +18,11 @@ class QueryEngine { public: - auto execute(const std::string &query) + auto execute(const std::string &query, Db& db) { // TODO: error handling auto program = program_loader.load(query); - auto result = program_executor.execute(program); + auto result = program_executor.execute(program, db); return result; } 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 100% rename from src/query_engine/query_result.hpp rename to include/query_engine/query_result.hpp 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 85% rename from src/query_engine/traverser/code.hpp rename to include/query_engine/traverser/code.hpp index cb5740f4d..23006c1c1 100644 --- a/src/query_engine/traverser/code.hpp +++ b/include/query_engine/traverser/code.hpp @@ -62,15 +62,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<StringBuffer> 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 <typename... Args> std::string format(const std::string &format_str, const Args &... args) { return fmt::format(format_str, args...); } -// wrapper for single code line template <typename... Args> 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<Edge> { 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<uint64_t, EdgeRecord> edges; + AtomicCounter<uint64_t> 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 99% rename from src/storage/model/edge_list.hpp rename to include/storage/model/edge_list.hpp index fccafa7b4..58deb8bde 100644 --- a/src/storage/model/edge_list.hpp +++ b/include/storage/model/edge_list.hpp @@ -1,6 +1,7 @@ #pragma once #include <vector> + #include "mvcc/version_list.hpp" class EdgeList diff --git a/src/storage/model/edge_model.hpp b/include/storage/model/edge_model.hpp similarity index 89% rename from src/storage/model/edge_model.hpp rename to include/storage/model/edge_model.hpp index 7903a0d1d..04ff085f6 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<Double> { 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<Float> { 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 <class Derived> struct Floating : public Number<Derived> 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<Int32> { 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<Int64> { 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 <class Derived> struct Integral : public Number<Derived>, public Modulo<Derived> @@ -10,7 +10,7 @@ struct Integral : public Number<Derived>, public Modulo<Derived> using Number<Derived>::Number; template <class T, typename = std::enable_if_t< - std::is_base_of<Floating<T>, T>::value>> + std::is_base_of<Floating<T>, 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 Derived> 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/src/storage/model/vertex_model.hpp b/include/storage/model/vertex_model.hpp similarity index 66% rename from src/storage/model/vertex_model.hpp rename to include/storage/model/vertex_model.hpp index 60be36072..5ed428c63 100644 --- a/src/storage/model/vertex_model.hpp +++ b/include/storage/model/vertex_model.hpp @@ -1,8 +1,8 @@ #pragma once -#include "property_model.hpp" #include "storage/label/label_collection.hpp" -#include "edge_list.hpp" +#include "storage/model/edge_list.hpp" +#include "storage/model/property_model.hpp" class VertexModel : public PropertyModel { 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<Vertex> { 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 <errno.h> #include <atomic> -#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 <mutex> -#include "spinlock.hpp" +#include "threading/sync/spinlock.hpp" template <class lock_t = SpinLock> 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 <atomic> #include <vector> +#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<Id> active; TransactionStore<uint64_t> 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 <iostream> #include <sstream> -#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 <class T> @@ -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 <cstdlib> #include <string> +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 <cstdlib> #include <string> +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/log/logger.hpp b/include/utils/log/logger.hpp similarity index 89% rename from src/utils/log/logger.hpp rename to include/utils/log/logger.hpp index 8273e1a45..41b67d1e4 100644 --- a/src/utils/log/logger.hpp +++ b/include/utils/log/logger.hpp @@ -5,6 +5,9 @@ #include <ctime> #include <iomanip> +namespace logger +{ + class Logger { public: @@ -44,10 +47,12 @@ private: } }; +} + #ifdef NOT_LOG_INFO # define LOG_INFO(_) #else -# define LOG_INFO(_MESSAGE_) Logger::instance().info(_MESSAGE_); +# define LOG_INFO(_MESSAGE_) logger::Logger::instance().info(_MESSAGE_); #endif 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 <size_t N, class R=Xorshift128plus> 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 <fstream> +#include <ostream> +#include <streambuf> +#include <string> +#include <cerrno> +#include <stdexcept> + +#include <fmt/format.h> + +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 <string> +#include <vector> +#include <sstream> +#include <iterator> + +namespace utils +{ + +std::string join(const std::vector<std::string>& strings, + const char *separator); + +template<typename... Args> +std::string prints(const Args&... args) +{ + std::vector<std::string> 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 <string> +#include <locale> +#include <algorithm> + +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 100% rename from src/utils/timer/timer.hpp rename to include/utils/timer/timer.hpp 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/bolt.cpp b/src/bolt/v1/bolt.cpp index 77dbe6d18..56d85727d 100644 --- a/src/bolt/v1/bolt.cpp +++ b/src/bolt/v1/bolt.cpp @@ -1,6 +1,6 @@ -#include "bolt.hpp" +#include "bolt/v1/bolt.hpp" -#include "session.hpp" +#include "bolt/v1/session.hpp" #include <iostream> namespace bolt @@ -14,6 +14,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<io::Socket>(socket), *this); } 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/session.cpp b/src/bolt/v1/session.cpp index dd437cdf0..04f710b1e 100644 --- a/src/bolt/v1/session.cpp +++ b/src/bolt/v1/session.cpp @@ -1,4 +1,4 @@ -#include "session.hpp" +#include "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/bolt/v1/states.cpp b/src/bolt/v1/states.cpp index f7bdea07b..8039a75ee 100644 --- a/src/bolt/v1/states.cpp +++ b/src/bolt/v1/states.cpp @@ -1,10 +1,9 @@ -#include "states.hpp" +#include "bolt/v1/states.hpp" -#include "states/handshake.hpp" -#include "states/init.hpp" -#include "states/error.hpp" - -#include "states/executor.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 { diff --git a/src/bolt/v1/states/error.cpp b/src/bolt/v1/states/error.cpp index c51eda182..98807d12d 100644 --- a/src/bolt/v1/states/error.cpp +++ b/src/bolt/v1/states/error.cpp @@ -1,6 +1,4 @@ -#include "error.hpp" - -#include "bolt/v1/session.hpp" +#include "bolt/v1/states/error.hpp" namespace bolt { @@ -11,7 +9,7 @@ State* Error::run(Session& session) if(message_type == MessageCode::AckFailure) { - // todo reset current statement? is it even necessary? + // TODO reset current statement? is it even necessary? session.encoder.message_success_empty(); session.encoder.flush(); @@ -20,7 +18,7 @@ State* Error::run(Session& session) } else if(message_type == MessageCode::Reset) { - // todo rollback current transaction + // TODO rollback current transaction // discard all records waiting to be sent session.encoder.message_success_empty(); diff --git a/src/bolt/v1/states/executor.cpp b/src/bolt/v1/states/executor.cpp index 7306618ab..08a370241 100644 --- a/src/bolt/v1/states/executor.cpp +++ b/src/bolt/v1/states/executor.cpp @@ -1,5 +1,4 @@ -#include "executor.hpp" - +#include "bolt/v1/states/executor.hpp" #include "bolt/v1/messaging/codes.hpp" namespace bolt @@ -53,6 +52,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.encoder.message_success(); session.encoder.write_map_header(1); @@ -67,6 +71,10 @@ void Executor::pull_all(Session& session) { logger.trace("[PullAll]"); + session.encoder.message_record(); + session.encoder.write_list_header(1); + session.encoder.write_string(session.active_db().name()); + session.encoder.message_record(); session.encoder.write_list_header(1); session.encoder.write_string("buda"); diff --git a/src/bolt/v1/states/handshake.cpp b/src/bolt/v1/states/handshake.cpp index b685381d6..d31460878 100644 --- a/src/bolt/v1/states/handshake.cpp +++ b/src/bolt/v1/states/handshake.cpp @@ -1,4 +1,4 @@ -#include "handshake.hpp" +#include "bolt/v1/states/handshake.hpp" #include "bolt/v1/session.hpp" diff --git a/src/bolt/v1/states/init.cpp b/src/bolt/v1/states/init.cpp index e1f30f690..2efe1fabe 100644 --- a/src/bolt/v1/states/init.cpp +++ b/src/bolt/v1/states/init.cpp @@ -1,4 +1,4 @@ -#include "init.hpp" +#include "bolt/v1/states/init.hpp" #include "bolt/v1/session.hpp" #include "bolt/v1/messaging/codes.hpp" diff --git a/src/bolt/v1/transport/bolt_decoder.cpp b/src/bolt/v1/transport/bolt_decoder.cpp index 9e16c2264..e97dc2bff 100644 --- a/src/bolt/v1/transport/bolt_decoder.cpp +++ b/src/bolt/v1/transport/bolt_decoder.cpp @@ -1,30 +1,26 @@ -#include "bolt_decoder.hpp" +#include "bolt/v1/transport/bolt_decoder.hpp" #include <iostream> -#include "utils/bswap.hpp" #include "logging/default.hpp" - +#include "utils/bswap.hpp" #include "bolt/v1/packing/codes.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 +28,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 <class T> -T parse(const void* data) +T parse(const void *data) { // reinterpret bytes as the target value - auto value = reinterpret_cast<const T*>(data); + auto value = reinterpret_cast<const T *>(data); // swap values to little endian return bswap(*value); } template <class T> -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 +61,17 @@ T parse(Buffer& buffer, size_t& pos) return parse<T>(ptr); } -int16_t BoltDecoder::read_int16() -{ - return parse<int16_t>(buffer, pos); -} +int16_t BoltDecoder::read_int16() { return parse<int16_t>(buffer, pos); } -uint16_t BoltDecoder::read_uint16() -{ - return parse<uint16_t>(buffer, pos); -} +uint16_t BoltDecoder::read_uint16() { return parse<uint16_t>(buffer, pos); } -int32_t BoltDecoder::read_int32() -{ - return parse<int32_t>(buffer, pos); -} +int32_t BoltDecoder::read_int32() { return parse<int32_t>(buffer, pos); } -uint32_t BoltDecoder::read_uint32() -{ - return parse<uint32_t>(buffer, pos); -} +uint32_t BoltDecoder::read_uint32() { return parse<uint32_t>(buffer, pos); } -int64_t BoltDecoder::read_int64() -{ - return parse<int64_t>(buffer, pos); -} +int64_t BoltDecoder::read_int64() { return parse<int64_t>(buffer, pos); } -uint64_t BoltDecoder::read_uint64() -{ - return parse<uint64_t>(buffer, pos); -} +uint64_t BoltDecoder::read_uint64() { return parse<uint64_t>(buffer, pos); } double BoltDecoder::read_float64() { @@ -115,44 +87,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<const char*>(raw()), size); + res.append(reinterpret_cast<const char *>(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/bolt/v1/transport/buffer.cpp index 05a0769da..5beb75621 100644 --- a/src/bolt/v1/transport/buffer.cpp +++ b/src/bolt/v1/transport/buffer.cpp @@ -1,4 +1,4 @@ -#include "buffer.hpp" +#include "bolt/v1/transport/buffer.hpp" namespace bolt { 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/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 <map> + +#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<std::string, Db> 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 <iostream> -#include <signal.h> - -#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<bolt::Worker>* 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<Stdout>()); - 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<bolt::Worker> 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 b/src/examples/bolt_py_client/initial_test.py new file mode 100644 index 000000000..300143edd --- /dev/null +++ b/src/examples/bolt_py_client/initial_test.py @@ -0,0 +1,12 @@ +from neo4j.v1 import GraphDatabase, basic_auth + +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.age AS age") +for record in result: + print(record["age"]) + session.close() 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/logging/default.cpp b/src/logging/default.cpp index 914d50417..4111c546f 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" 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 <iostream> -#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 <iostream> #include <fmt/format.h> diff --git a/src/memgraph_bolt.cpp b/src/memgraph_bolt.cpp index fb59219de..3df3f12c9 100644 --- a/src/memgraph_bolt.cpp +++ b/src/memgraph_bolt.cpp @@ -1,17 +1,74 @@ +#include <iostream> +#include <signal.h> + +#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" + #include "utils/terminate_handler.hpp" -int main(int argc, char *argv[]) +static bolt::Server<bolt::Worker>* 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_sync(); + logging::log->pipe(std::make_unique<Stdout>()); + 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<bolt::Worker> 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 T> -class Atom : public Version<T>, - public Lockable<SpinLock> +class Atom : public Version<T>, public Lockable<SpinLock> { public: - Atom(const Id& id, T* first) : Version<T>(first), id(id) + Atom(const Id &id, T *first) : Version<T>(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<Atom<T>*> next; + std::atomic<Atom<T> *> 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 <ostream> -#include <stdint.h> -#include "utils/total_ordering.hpp" - -class Id : public TotalOrdering<Id> -{ -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/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<StringBuffer> 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.hpp b/src/storage/edges.cpp similarity index 71% rename from src/storage/edges.hpp rename to src/storage/edges.cpp index 09c85ffdf..a0e0d9bbc 100644 --- a/src/storage/edges.hpp +++ b/src/storage/edges.cpp @@ -1,14 +1,7 @@ -#pragma once +#include "storage/edges.hpp" -#include "common.hpp" -#include "data_structures/concurrent/concurrent_map.hpp" -#include "edge_accessor.hpp" - -class Edges +Edge::Accessor Edges::find(tx::Transaction &t, const Id &id) { - public: - Edge::Accessor find(tx::Transaction &t, const Id &id) - { auto edges_accessor = edges.access(); auto edges_iterator = edges_accessor.find(id); @@ -20,10 +13,10 @@ class Edges if (edge == nullptr) return Edge::Accessor(); return Edge::Accessor(edge, &edges_iterator->second, this); - } +} - Edge::Accessor insert(tx::Transaction &t) - { +Edge::Accessor Edges::insert(tx::Transaction &t) +{ // get next vertex id auto next = counter.next(std::memory_order_acquire); @@ -39,9 +32,4 @@ class Edges auto edge = inserted_edge_record->second.insert(t); return Edge::Accessor(edge, &inserted_edge_record->second, this); - } - - private: - ConcurrentMap<uint64_t, EdgeRecord> edges; - AtomicCounter<uint64_t> counter; -}; +} 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 <fstream> -#include <ostream> -#include <streambuf> -#include <string> -#include <cerrno> -#include <stdexcept> - -#include <fmt/format.h> +#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 <string> -#include <vector> -#include <sstream> -#include <iterator> +#include "utils/string/join.hpp" namespace utils { @@ -16,11 +11,4 @@ std::string join(const std::vector<std::string>& strings, const char *separator) return oss.str(); } -template<typename... Args> -std::string prints(const Args&... args) -{ - std::vector<std::string> 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 <string> -#include <locale> -#include <algorithm> +#include "utils/string/transform.hpp" namespace utils { diff --git a/tests/manual/query_engine.cpp b/tests/manual/query_engine.cpp index beb3368f3..4964da656 100644 --- a/tests/manual/query_engine.cpp +++ b/tests/manual/query_engine.cpp @@ -16,6 +16,7 @@ int main(void) { std::set_terminate(&terminate_handler); + Db db; QueryEngine engine; cout << "-- Memgraph query engine --" << endl; @@ -30,7 +31,7 @@ int main(void) // execute command try { - engine.execute(command); + engine.execute(command, db); } catch (const std::exception& e) { cout << e.what() << endl; } catch (const QueryEngineException& e) { From 35d8f6d7ab1a1e0d1ff13c19dbc755299dac61f8 Mon Sep 17 00:00:00 2001 From: Marko Budiselic <mbudiselicbuda@gmail.com> Date: Wed, 10 Aug 2016 19:17:38 +0100 Subject: [PATCH 2/3] Bolt integration: RecordStream -> BoltSerializer -> BoltEncoder -> ChunkedEncoder -> ChunkedBuffer -> SockerStream --- include/bolt/v1/config.hpp | 14 +++ include/bolt/v1/messaging/messages.hpp | 8 -- .../bolt/v1/serialization/bolt_serializer.hpp | 4 +- .../bolt/v1/serialization/record_stream.hpp | 109 +++++++++++++++++- .../v1/serialization/socket_serializer.hpp | 22 ---- include/bolt/v1/session.hpp | 24 ++-- include/bolt/v1/transport/bolt_encoder.hpp | 10 +- include/bolt/v1/transport/buffer.hpp | 4 +- include/bolt/v1/transport/chunked_buffer.hpp | 74 ++++++++++++ include/bolt/v1/transport/chunked_decoder.hpp | 27 ++--- include/bolt/v1/transport/chunked_encoder.hpp | 18 ++- src/bolt/v1/states/error.cpp | 15 +-- src/bolt/v1/states/executor.cpp | 46 ++------ src/bolt/v1/states/init.cpp | 4 +- src/examples/bolt_py_client/initial_test.py | 7 +- 15 files changed, 269 insertions(+), 117 deletions(-) create mode 100644 include/bolt/v1/config.hpp delete mode 100644 include/bolt/v1/messaging/messages.hpp delete mode 100644 include/bolt/v1/serialization/socket_serializer.hpp create mode 100644 include/bolt/v1/transport/chunked_buffer.hpp diff --git a/include/bolt/v1/config.hpp b/include/bolt/v1/config.hpp new file mode 100644 index 000000000..afd953f91 --- /dev/null +++ b/include/bolt/v1/config.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include <cstddef> + +namespace bolt +{ + +namespace config +{ + static constexpr size_t N = 65535; /* chunk size */ + static constexpr size_t C = N + 2; /* end mark */ +} + +} diff --git a/include/bolt/v1/messaging/messages.hpp b/include/bolt/v1/messaging/messages.hpp deleted file mode 100644 index f89c48054..000000000 --- a/include/bolt/v1/messaging/messages.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace bolt -{ - -// TODO: what should be here? (Question for Dominik) - -} diff --git a/include/bolt/v1/serialization/bolt_serializer.hpp b/include/bolt/v1/serialization/bolt_serializer.hpp index bafca1ed6..a405af22e 100644 --- a/include/bolt/v1/serialization/bolt_serializer.hpp +++ b/include/bolt/v1/serialization/bolt_serializer.hpp @@ -18,7 +18,7 @@ class BoltSerializer friend class Property; public: - BoltSerializer() {} + BoltSerializer(Stream& stream) : encoder(stream) {} /* Serializes the vertex accessor into the packstream format * @@ -132,7 +132,7 @@ public: } protected: - BoltEncoder<Stream> encoder; + Stream& encoder; template <class T> void handle(const T& prop) diff --git a/include/bolt/v1/serialization/record_stream.hpp b/include/bolt/v1/serialization/record_stream.hpp index bb058d4fb..5e914e25e 100644 --- a/include/bolt/v1/serialization/record_stream.hpp +++ b/include/bolt/v1/serialization/record_stream.hpp @@ -1,15 +1,120 @@ #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 "logging/default.hpp" namespace bolt { -class RecordStream : BoltSerializer +// compiled queries have to use this class in order to return results +// query code should not know about bolt protocol + +template <class Socket> +class RecordStream { public: + RecordStream(Socket &socket) : socket(socket) + { + logger = logging::log->logger("Record Stream"); + } + // TODO: create apstract methods that are not bolt specific --------------- + void write_success() + { + logger.trace("write_success"); + bolt_encoder.message_success(); + } + void write_success_empty() + { + logger.trace("write_success_empty"); + bolt_encoder.message_success_empty(); + } + + void write_ignored() + { + logger.trace("write_ignored"); + bolt_encoder.message_ignored(); + } + + void write_fields(const std::vector<std::string> &fields) + { + // TODO: that should be one level below? + bolt_encoder.message_success(); + + bolt_encoder.write_map_header(1); + bolt_encoder.write_string("fields"); + write_list_header(fields.size()); + + for (auto &name : fields) { + bolt_encoder.write_string(name); + } + + flush(); + } + + void write_list_header(size_t size) + { + bolt_encoder.write_list_header(size); + } + + void write_record() + { + bolt_encoder.message_record(); + } + // -- BOLT SPECIFIC METHODS ----------------------------------------------- + + void write(const Vertex::Accessor &vertex) { serializer.write(vertex); } + void write(const Edge::Accessor &edge) { serializer.write(edge); } + + void write(const Property &prop) { serializer.write(prop); } + void write(const Bool& prop) { serializer.write(prop); } + void write(const Float& prop) { serializer.write(prop); } + void write(const Int32& prop) { serializer.write(prop); } + void write(const Int64& prop) { serializer.write(prop); } + void write(const Double& prop) { serializer.write(prop); } + void write(const String& prop) { serializer.write(prop); } + + void flush() + { + chunked_encoder.flush(); + chunked_buffer.flush(); + } + + void _write_test() + { + logger.trace("write_test"); + + write_fields({{"name"}}); + + write_record(); + write_list_header(1); + write(String("max")); + + write_record(); + write_list_header(1); + write(String("paul")); + + write_success_empty(); + } + +protected: + Logger logger; + +private: + using buffer_t = ChunkedBuffer<SocketStream>; + using chunked_encoder_t = ChunkedEncoder<buffer_t>; + using bolt_encoder_t = BoltEncoder<chunked_encoder_t>; + using bolt_serializer_t = BoltSerializer<bolt_encoder_t>; + + SocketStream socket; + buffer_t chunked_buffer{socket}; + chunked_encoder_t chunked_encoder{chunked_buffer}; + bolt_encoder_t bolt_encoder{chunked_encoder}; + bolt_serializer_t serializer{bolt_encoder}; }; - } diff --git a/include/bolt/v1/serialization/socket_serializer.hpp b/include/bolt/v1/serialization/socket_serializer.hpp deleted file mode 100644 index 7d16f6666..000000000 --- a/include/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 Socket> -class SocketSerializer : public BoltEncoder<ChunkedEncoder<SocketStream>> -{ -public: - SocketSerializer(Socket& socket) : BoltEncoder(encoder), stream(socket) {} - -private: - SocketStream stream; - ChunkedEncoder<SocketStream> encoder {stream}; -}; - -} diff --git a/include/bolt/v1/session.hpp b/include/bolt/v1/session.hpp index dd8b772ec..b5fe46c0a 100644 --- a/include/bolt/v1/session.hpp +++ b/include/bolt/v1/session.hpp @@ -1,13 +1,13 @@ #pragma once -#include "io/network/tcp/stream.hpp" #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 "bolt/v1/serialization/socket_serializer.hpp" -#include "bolt/v1/bolt.hpp" #include "logging/default.hpp" @@ -18,27 +18,25 @@ class Session : public io::tcp::Stream<io::Socket> { public: using Decoder = BoltDecoder; - using Encoder = SocketSerializer<io::Socket>; + using OutputStream = RecordStream<io::Socket>; - Session(io::Socket&& socket, Bolt& bolt); + Session(io::Socket &&socket, Bolt &bolt); bool alive() const; - void execute(const byte* data, size_t len); + void execute(const byte *data, size_t len); void close(); - Bolt& bolt; - - Db& active_db(); + Bolt &bolt; + Db &active_db(); Decoder decoder; - Encoder encoder {socket}; + OutputStream output_stream{socket}; - bool connected {false}; - State* state; + bool connected{false}; + State *state; protected: Logger logger; }; - } diff --git a/include/bolt/v1/transport/bolt_encoder.hpp b/include/bolt/v1/transport/bolt_encoder.hpp index fe26349b2..e8758bab4 100644 --- a/include/bolt/v1/transport/bolt_encoder.hpp +++ b/include/bolt/v1/transport/bolt_encoder.hpp @@ -6,6 +6,7 @@ #include "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/include/bolt/v1/transport/buffer.hpp b/include/bolt/v1/transport/buffer.hpp index ae44c7f19..51dc89ce6 100644 --- a/include/bolt/v1/transport/buffer.hpp +++ b/include/bolt/v1/transport/buffer.hpp @@ -4,14 +4,14 @@ #include <cstdlib> #include <vector> +#include "utils/types/byte.hpp" + namespace bolt { class Buffer { public: - using byte = uint8_t; - void write(const byte* data, size_t len); void clear(); diff --git a/include/bolt/v1/transport/chunked_buffer.hpp b/include/bolt/v1/transport/chunked_buffer.hpp new file mode 100644 index 000000000..3a0846712 --- /dev/null +++ b/include/bolt/v1/transport/chunked_buffer.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include <memory> +#include <vector> +#include <cstring> + +#include "bolt/v1/config.hpp" +#include "utils/types/byte.hpp" +#include "logging/default.hpp" + +namespace bolt +{ + +template <class Stream> +class ChunkedBuffer +{ + static constexpr size_t C = bolt::config::C; /* chunk size */ + +public: + ChunkedBuffer(Stream &stream) : stream(stream) + { + logger = logging::log->logger("Chunked Buffer"); + } + + void write(const byte *values, size_t n) + { + // TODO: think about shared pointer + // TODO: this is naive implementation, it can be implemented much better + + logger.trace("write {} bytes", n); + + byte *chunk = chunk = (byte *)std::malloc(n * sizeof(byte)); + last_size = n; + + std::memcpy(chunk, values, n); + + buffer.push_back(chunk); + } + + void flush() + { + logger.trace("Flush"); + + for (size_t i = 0; i < buffer.size(); ++i) { + if (i == buffer.size() - 1) + stream.get().write(buffer[i], last_size); + else + stream.get().write(buffer[i], C); + } + + destroy(); + } + + ~ChunkedBuffer() + { + destroy(); + } + +private: + Logger logger; + std::reference_wrapper<Stream> stream; + std::vector<byte *> buffer; + size_t last_size {0}; // last chunk size (it is going to be less than C) + + void destroy() + { + for (size_t i = 0; i < buffer.size(); ++i) { + std::free(buffer[i]); + } + buffer.clear(); + } +}; + +} diff --git a/include/bolt/v1/transport/chunked_decoder.hpp b/include/bolt/v1/transport/chunked_decoder.hpp index 6f1feb166..b7252b59f 100644 --- a/include/bolt/v1/transport/chunked_decoder.hpp +++ b/include/bolt/v1/transport/chunked_decoder.hpp @@ -1,13 +1,13 @@ #pragma once +#include <cassert> #include <cstring> #include <functional> -#include <cassert> - -#include "utils/exceptions/basic_exception.hpp" -#include "utils/likely.hpp" #include "logging/default.hpp" +#include "utils/exceptions/basic_exception.hpp" +#include "utils/likely.hpp" +#include "utils/types/byte.hpp" namespace bolt { @@ -22,8 +22,6 @@ public: using BasicException::BasicException; }; - using byte = unsigned char; - ChunkedDecoder(Stream& stream) : stream(stream) {} /* Decode chunked data @@ -33,14 +31,14 @@ public: * |Header| Data ||Header| Data || ... || End | * | 2B | size bytes || 2B | size bytes || ... ||00 00| */ - bool decode(const byte*& chunk, size_t n) + bool decode(const byte *&chunk, size_t n) { - while(n > 0) + while (n > 0) { // get size from first two bytes in the chunk auto size = get_size(chunk); - if(UNLIKELY(size + 2 > n)) + if (UNLIKELY(size + 2 > n)) throw DecoderError("Chunk size larger than available data."); // advance chunk to pass those two bytes @@ -48,8 +46,7 @@ public: n -= 2; // if chunk size is 0, we're done! - if(size == 0) - return true; + if (size == 0) return true; stream.get().write(chunk, size); @@ -60,18 +57,14 @@ public: return false; } - bool operator()(const byte*& chunk, size_t n) - { - return decode(chunk, n); - } + bool operator()(const byte *&chunk, size_t n) { return decode(chunk, n); } private: std::reference_wrapper<Stream> stream; - size_t get_size(const byte* chunk) + size_t get_size(const byte *chunk) { return size_t(chunk[0]) << 8 | chunk[1]; } }; - } diff --git a/include/bolt/v1/transport/chunked_encoder.hpp b/include/bolt/v1/transport/chunked_encoder.hpp index 9ded82c9a..295cc03c2 100644 --- a/include/bolt/v1/transport/chunked_encoder.hpp +++ b/include/bolt/v1/transport/chunked_encoder.hpp @@ -5,6 +5,8 @@ #include <functional> #include "utils/likely.hpp" +#include "bolt/v1/config.hpp" +#include "logging/default.hpp" namespace bolt { @@ -12,13 +14,16 @@ namespace bolt template <class Stream> class ChunkedEncoder { - static constexpr size_t N = 65535; - static constexpr size_t C = N + 2 /* end mark */; + static constexpr size_t N = bolt::config::N; + static constexpr size_t C = bolt::config::C; public: using byte = unsigned char; - ChunkedEncoder(Stream& stream) : stream(stream) {} + ChunkedEncoder(Stream& stream) : stream(stream) + { + logger = logging::log->logger("Chunked Encoder"); + } static constexpr size_t chunk_size = N - 2; @@ -32,6 +37,8 @@ public: void write(const byte* values, size_t n) { + logger.trace("write {} bytes", n); + while(n > 0) { auto size = n < N - pos ? n : N - pos; @@ -58,6 +65,7 @@ public: } private: + Logger logger; std::reference_wrapper<Stream> stream; std::array<byte, C> chunk; @@ -65,7 +73,9 @@ private: void end_chunk() { - write_chunk_header(); + // TODO: this call is unnecessary bacause the same method is called + // inside the flush method + // write_chunk_header(); flush(); } diff --git a/src/bolt/v1/states/error.cpp b/src/bolt/v1/states/error.cpp index 98807d12d..315fbf3e0 100644 --- a/src/bolt/v1/states/error.cpp +++ b/src/bolt/v1/states/error.cpp @@ -10,9 +10,9 @@ State* Error::run(Session& session) if(message_type == MessageCode::AckFailure) { // TODO reset current statement? is it even necessary? - - session.encoder.message_success_empty(); - session.encoder.flush(); + + session.output_stream.write_success_empty(); + session.output_stream.flush(); return session.bolt.states.executor.get(); } @@ -21,14 +21,15 @@ State* Error::run(Session& session) // TODO rollback current transaction // discard all records waiting to be sent - session.encoder.message_success_empty(); - session.encoder.flush(); + session.output_stream.write_success_empty(); + session.output_stream.flush(); + return session.bolt.states.executor.get(); } - session.encoder.message_ignored(); - session.encoder.flush(); + session.output_stream.write_ignored(); + session.output_stream.flush(); return this; } diff --git a/src/bolt/v1/states/executor.cpp b/src/bolt/v1/states/executor.cpp index 08a370241..db95fa65d 100644 --- a/src/bolt/v1/states/executor.cpp +++ b/src/bolt/v1/states/executor.cpp @@ -12,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) @@ -52,52 +54,28 @@ 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.encoder.message_success(); - session.encoder.write_map_header(1); - - session.encoder.write_string("fields"); - session.encoder.write_list_header(1); - session.encoder.write_string("name"); - - session.encoder.flush(); + // auto &db = session.active_db(); + // logger.info("[ActiveDB] '{}'", db.name()); + // query_engine.execute(query.statement, db); + + session.output_stream._write_test(); } void Executor::pull_all(Session& session) { logger.trace("[PullAll]"); - session.encoder.message_record(); - session.encoder.write_list_header(1); - session.encoder.write_string(session.active_db().name()); - - 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/init.cpp b/src/bolt/v1/states/init.cpp index 2efe1fabe..33568f783 100644 --- a/src/bolt/v1/states/init.cpp +++ b/src/bolt/v1/states/init.cpp @@ -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/examples/bolt_py_client/initial_test.py b/src/examples/bolt_py_client/initial_test.py index 300143edd..1cd436e86 100644 --- a/src/examples/bolt_py_client/initial_test.py +++ b/src/examples/bolt_py_client/initial_test.py @@ -5,8 +5,9 @@ driver = GraphDatabase.driver("bolt://localhost", encrypted=0) session = driver.session() -session.run("CREATE (a:Person {age:25})") -# result = session.run("MATCH (a:Person) RETURN a.age AS age") +# session.run("CREATE (a:Person {age:25})") +result = session.run("MATCH (a:Person) RETURN a.name AS name") + for record in result: - print(record["age"]) + print(record["name"]) session.close() 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 3/3] 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;