From 869da8dcdab1442d1918949fd52321458f2f3b40 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Wed, 10 Aug 2016 09:39:02 +0100 Subject: [PATCH] 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 MessageParser : public State, public Crtp { public: - MessageParser(Logger&& logger) - : logger(std::forward(logger)) {} + MessageParser(Logger &&logger) : logger(std::forward(logger)) {} - State* run(Session& session) override final + State *run(Session &session) override final { typename Derived::Message message; @@ -23,8 +21,7 @@ public: auto next = this->derived().parse(session, message); // return next state if parsing was unsuccessful (i.e. error state) - if(next != &this->derived()) - return next; + if (next != &this->derived()) return next; logger.debug("Executing state"); return this->derived().execute(session, message); @@ -33,5 +30,4 @@ public: protected: Logger logger; }; - } diff --git a/src/bolt/v1/states/state.hpp b/include/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 decoder {buffer}; - size_t pos {0}; + ChunkedDecoder decoder{buffer}; + size_t pos{0}; - const byte* raw() const; + const byte *raw() const; }; - } diff --git a/src/bolt/v1/transport/bolt_encoder.hpp b/include/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 #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 *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() = 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 #include -#include "log.hpp" -#include "levels.hpp" +#include "logging/log.hpp" +#include "logging/levels.hpp" class Logger { diff --git a/src/logging/logs/async_log.hpp b/include/logging/logs/async_log.hpp similarity index 100% rename from src/logging/logs/async_log.hpp rename to include/logging/logs/async_log.hpp diff --git a/src/logging/logs/sync_log.hpp b/include/logging/logs/sync_log.hpp similarity index 100% rename from src/logging/logs/sync_log.hpp rename to include/logging/logs/sync_log.hpp diff --git a/src/logging/streams/stdout.hpp b/include/logging/streams/stdout.hpp similarity index 100% rename from src/logging/streams/stdout.hpp rename to include/logging/streams/stdout.hpp diff --git a/src/memory/freelist.hpp b/include/memory/freelist.hpp similarity index 100% rename from src/memory/freelist.hpp rename to include/memory/freelist.hpp diff --git a/src/memory/lazy_gc.hpp b/include/memory/lazy_gc.hpp similarity index 100% rename from src/memory/lazy_gc.hpp rename to include/memory/lazy_gc.hpp diff --git a/src/mvcc/cre_exp.hpp b/include/mvcc/cre_exp.hpp similarity index 100% rename from src/mvcc/cre_exp.hpp rename to include/mvcc/cre_exp.hpp diff --git a/src/mvcc/hints.hpp b/include/mvcc/hints.hpp similarity index 100% rename from src/mvcc/hints.hpp rename to include/mvcc/hints.hpp diff --git a/src/mvcc/mvcc_error.hpp b/include/mvcc/mvcc_error.hpp similarity index 100% rename from src/mvcc/mvcc_error.hpp rename to include/mvcc/mvcc_error.hpp diff --git a/src/mvcc/record.hpp b/include/mvcc/record.hpp similarity index 98% rename from src/mvcc/record.hpp rename to include/mvcc/record.hpp index 8d74b61bc..2731c2b56 100644 --- a/src/mvcc/record.hpp +++ b/include/mvcc/record.hpp @@ -8,9 +8,9 @@ #include "transactions/engine.hpp" #include "mvcc/id.hpp" -#include "cre_exp.hpp" -#include "version.hpp" -#include "hints.hpp" +#include "mvcc/cre_exp.hpp" +#include "mvcc/version.hpp" +#include "mvcc/hints.hpp" #include "storage/locking/record_lock.hpp" // the mvcc implementation used here is very much like postgresql's diff --git a/src/mvcc/serialization_error.hpp b/include/mvcc/serialization_error.hpp similarity index 100% rename from src/mvcc/serialization_error.hpp rename to include/mvcc/serialization_error.hpp diff --git a/src/mvcc/version.hpp b/include/mvcc/version.hpp similarity index 100% rename from src/mvcc/version.hpp rename to include/mvcc/version.hpp diff --git a/src/mvcc/version_list.hpp b/include/mvcc/version_list.hpp similarity index 100% rename from src/mvcc/version_list.hpp rename to include/mvcc/version_list.hpp diff --git a/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; + +} 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 writer(buffer); - properties.accept(writer); - cout << buffer.str() << endl; -} +void print_props(const Properties &properties); -#ifdef DEBUG -#define PRINT_PROPS(_PROPS_) print_props(_PROPS_); -#else +#ifdef NDEBUG #define PRINT_PROPS(_) +#else +#define PRINT_PROPS(_PROPS_) print_props(_PROPS_); #endif -void cout_properties(const Properties &properties) -{ - ConsoleWriter writer; - properties.accept(writer); - cout << "----" << endl; -} +void cout_properties(const Properties &properties); -void cout_property(const std::string &key, const Property &property) -{ - ConsoleWriter writer; - writer.handle(key, property); - cout << "----" << endl; -} +void cout_property(const std::string &key, const Property &property); + +// this is a nice way how to avoid multiple definition problem with +// headers because it will create a unique namespace for each compilation unit +// http://stackoverflow.com/questions/2727582/multiple-definition-in-header-file +namespace +{ -// wrapper for fmt format template std::string format(const std::string &format_str, const Args &... args) { return fmt::format(format_str, args...); } -// wrapper for single code line template std::string code_line(const std::string &format_str, const Args &... args) { return "\t" + format(format_str, args...) + "\n"; } - +} diff --git a/src/storage/common.hpp b/include/storage/common.hpp similarity index 100% rename from src/storage/common.hpp rename to include/storage/common.hpp diff --git a/src/storage/edge.hpp b/include/storage/edge.hpp similarity index 79% rename from src/storage/edge.hpp rename to include/storage/edge.hpp index 507af2925..55a3ea182 100644 --- a/src/storage/edge.hpp +++ b/include/storage/edge.hpp @@ -1,8 +1,8 @@ #pragma once #include "mvcc/record.hpp" -#include "model/edge_model.hpp" -#include "model/properties/traversers/jsonwriter.hpp" +#include "storage/model/edge_model.hpp" +#include "storage/model/properties/traversers/jsonwriter.hpp" class Edge : public mvcc::Record { diff --git a/src/storage/edge_accessor.hpp b/include/storage/edge_accessor.hpp similarity index 100% rename from src/storage/edge_accessor.hpp rename to include/storage/edge_accessor.hpp diff --git a/include/storage/edges.hpp b/include/storage/edges.hpp new file mode 100644 index 000000000..67a51adda --- /dev/null +++ b/include/storage/edges.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "data_structures/concurrent/concurrent_map.hpp" +#include "storage/common.hpp" +#include "storage/edge_accessor.hpp" + +class Edges +{ +public: + Edge::Accessor find(tx::Transaction &t, const Id &id); + Edge::Accessor insert(tx::Transaction &t); + +private: + ConcurrentMap edges; + AtomicCounter counter; +}; diff --git a/src/storage/graph.hpp b/include/storage/graph.hpp similarity index 100% rename from src/storage/graph.hpp rename to include/storage/graph.hpp index 6637e51af..c14728658 100644 --- a/src/storage/graph.hpp +++ b/include/storage/graph.hpp @@ -10,8 +10,8 @@ class Graph public: Graph() {} - Edges edges; Vertices vertices; + Edges edges; LabelStore label_store; EdgeTypeStore edge_type_store; diff --git a/src/storage/indexes/index.hpp b/include/storage/indexes/index.hpp similarity index 100% rename from src/storage/indexes/index.hpp rename to include/storage/indexes/index.hpp diff --git a/src/storage/indexes/index_record.hpp b/include/storage/indexes/index_record.hpp similarity index 100% rename from src/storage/indexes/index_record.hpp rename to include/storage/indexes/index_record.hpp diff --git a/src/storage/indexes/index_record_collection.hpp b/include/storage/indexes/index_record_collection.hpp similarity index 100% rename from src/storage/indexes/index_record_collection.hpp rename to include/storage/indexes/index_record_collection.hpp diff --git a/src/storage/indexes/keys/index_key.hpp b/include/storage/indexes/keys/index_key.hpp similarity index 100% rename from src/storage/indexes/keys/index_key.hpp rename to include/storage/indexes/keys/index_key.hpp diff --git a/src/storage/indexes/keys/non_unique_key.hpp b/include/storage/indexes/keys/non_unique_key.hpp similarity index 100% rename from src/storage/indexes/keys/non_unique_key.hpp rename to include/storage/indexes/keys/non_unique_key.hpp diff --git a/src/storage/indexes/keys/unique_key.hpp b/include/storage/indexes/keys/unique_key.hpp similarity index 100% rename from src/storage/indexes/keys/unique_key.hpp rename to include/storage/indexes/keys/unique_key.hpp diff --git a/src/storage/indexes/sort_order.hpp b/include/storage/indexes/sort_order.hpp similarity index 100% rename from src/storage/indexes/sort_order.hpp rename to include/storage/indexes/sort_order.hpp diff --git a/src/storage/locking/lock_status.hpp b/include/storage/locking/lock_status.hpp similarity index 100% rename from src/storage/locking/lock_status.hpp rename to include/storage/locking/lock_status.hpp diff --git a/src/storage/model/edge_list.hpp b/include/storage/model/edge_list.hpp similarity index 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 + #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 { diff --git a/src/storage/model/properties/float.hpp b/include/storage/model/properties/float.hpp similarity index 73% rename from src/storage/model/properties/float.hpp rename to include/storage/model/properties/float.hpp index 64496ba0d..25d812c42 100644 --- a/src/storage/model/properties/float.hpp +++ b/include/storage/model/properties/float.hpp @@ -1,7 +1,7 @@ #pragma once -#include "floating.hpp" -#include "double.hpp" +#include "storage/model/properties/floating.hpp" +#include "storage/model/properties/double.hpp" class Float : public Floating { diff --git a/src/storage/model/properties/floating.hpp b/include/storage/model/properties/floating.hpp similarity index 72% rename from src/storage/model/properties/floating.hpp rename to include/storage/model/properties/floating.hpp index 04afd23a8..8b1f8174b 100644 --- a/src/storage/model/properties/floating.hpp +++ b/include/storage/model/properties/floating.hpp @@ -1,6 +1,6 @@ #pragma once -#include "number.hpp" +#include "storage/model/properties/number.hpp" template struct Floating : public Number diff --git a/src/storage/model/properties/int32.hpp b/include/storage/model/properties/int32.hpp similarity index 74% rename from src/storage/model/properties/int32.hpp rename to include/storage/model/properties/int32.hpp index ed588b4fd..644bd8c98 100644 --- a/src/storage/model/properties/int32.hpp +++ b/include/storage/model/properties/int32.hpp @@ -1,7 +1,7 @@ #pragma once -#include "integral.hpp" -#include "int64.hpp" +#include "storage/model/properties/integral.hpp" +#include "storage/model/properties/int64.hpp" class Int32 : public Integral { diff --git a/src/storage/model/properties/int64.hpp b/include/storage/model/properties/int64.hpp similarity index 80% rename from src/storage/model/properties/int64.hpp rename to include/storage/model/properties/int64.hpp index eb699ce06..333a0f8aa 100644 --- a/src/storage/model/properties/int64.hpp +++ b/include/storage/model/properties/int64.hpp @@ -1,6 +1,6 @@ #pragma once -#include "integral.hpp" +#include "storage/model/properties/integral.hpp" class Int64 : public Integral { diff --git a/src/storage/model/properties/integral.hpp b/include/storage/model/properties/integral.hpp similarity index 55% rename from src/storage/model/properties/integral.hpp rename to include/storage/model/properties/integral.hpp index e94bed313..4042c1a58 100644 --- a/src/storage/model/properties/integral.hpp +++ b/include/storage/model/properties/integral.hpp @@ -1,8 +1,8 @@ #pragma once -#include "number.hpp" -#include "floating.hpp" -#include "utils/modulo.hpp" +#include "storage/model/properties/floating.hpp" +#include "storage/model/properties/number.hpp" +#include "storage/model/properties/utils/modulo.hpp" template struct Integral : public Number, public Modulo @@ -10,7 +10,7 @@ struct Integral : public Number, public Modulo using Number::Number; template , T>::value>> + std::is_base_of, T>::value>> operator T() const { return T(this->derived().value); diff --git a/src/storage/model/properties/number.hpp b/include/storage/model/properties/number.hpp similarity index 88% rename from src/storage/model/properties/number.hpp rename to include/storage/model/properties/number.hpp index 1cc988818..396b2fa87 100644 --- a/src/storage/model/properties/number.hpp +++ b/include/storage/model/properties/number.hpp @@ -1,9 +1,9 @@ #pragma once #include "storage/model/properties/property.hpp" -#include "utils/math_operations.hpp" +#include "storage/model/properties/utils/math_operations.hpp" +#include "storage/model/properties/utils/unary_negation.hpp" #include "utils/total_ordering.hpp" -#include "utils/unary_negation.hpp" template class Number : public Property, diff --git a/src/storage/model/properties/traversers/consolewriter.hpp b/include/storage/model/properties/traversers/consolewriter.hpp similarity index 100% rename from src/storage/model/properties/traversers/consolewriter.hpp rename to include/storage/model/properties/traversers/consolewriter.hpp diff --git a/src/storage/model/properties/traversers/jsonwriter.hpp b/include/storage/model/properties/traversers/jsonwriter.hpp similarity index 100% rename from src/storage/model/properties/traversers/jsonwriter.hpp rename to include/storage/model/properties/traversers/jsonwriter.hpp diff --git a/src/storage/model/properties/utils/math_operations.hpp b/include/storage/model/properties/utils/math_operations.hpp similarity index 100% rename from src/storage/model/properties/utils/math_operations.hpp rename to include/storage/model/properties/utils/math_operations.hpp diff --git a/src/storage/model/properties/utils/modulo.hpp b/include/storage/model/properties/utils/modulo.hpp similarity index 100% rename from src/storage/model/properties/utils/modulo.hpp rename to include/storage/model/properties/utils/modulo.hpp diff --git a/src/storage/model/properties/utils/unary_negation.hpp b/include/storage/model/properties/utils/unary_negation.hpp similarity index 100% rename from src/storage/model/properties/utils/unary_negation.hpp rename to include/storage/model/properties/utils/unary_negation.hpp diff --git a/src/storage/model/property_model.hpp b/include/storage/model/property_model.hpp similarity index 100% rename from src/storage/model/property_model.hpp rename to include/storage/model/property_model.hpp diff --git a/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 { diff --git a/src/threading/.gitignore b/include/threading/.gitignore similarity index 100% rename from src/threading/.gitignore rename to include/threading/.gitignore diff --git a/src/threading/hazard_ptr.hpp b/include/threading/hazard_ptr.hpp similarity index 100% rename from src/threading/hazard_ptr.hpp rename to include/threading/hazard_ptr.hpp diff --git a/src/threading/hazard_store.hpp b/include/threading/hazard_store.hpp similarity index 100% rename from src/threading/hazard_store.hpp rename to include/threading/hazard_store.hpp diff --git a/src/threading/id.hpp b/include/threading/id.hpp similarity index 100% rename from src/threading/id.hpp rename to include/threading/id.hpp diff --git a/src/threading/pool.hpp b/include/threading/pool.hpp similarity index 100% rename from src/threading/pool.hpp rename to include/threading/pool.hpp diff --git a/src/threading/sync/caslock.hpp b/include/threading/sync/caslock.hpp similarity index 100% rename from src/threading/sync/caslock.hpp rename to include/threading/sync/caslock.hpp diff --git a/src/threading/sync/futex.hpp b/include/threading/sync/futex.hpp similarity index 98% rename from src/threading/sync/futex.hpp rename to include/threading/sync/futex.hpp index d4739a94f..e11dab3d5 100644 --- a/src/threading/sync/futex.hpp +++ b/include/threading/sync/futex.hpp @@ -4,7 +4,7 @@ #include #include -#include "lock_timeout_error.hpp" +#include "threading/sync/lock_timeout_error.hpp" #include "utils/cpu_relax.hpp" #include "utils/sys.hpp" diff --git a/src/threading/sync/lock_timeout_error.hpp b/include/threading/sync/lock_timeout_error.hpp similarity index 100% rename from src/threading/sync/lock_timeout_error.hpp rename to include/threading/sync/lock_timeout_error.hpp diff --git a/src/threading/sync/lockable.hpp b/include/threading/sync/lockable.hpp similarity index 90% rename from src/threading/sync/lockable.hpp rename to include/threading/sync/lockable.hpp index ce7141912..495634363 100644 --- a/src/threading/sync/lockable.hpp +++ b/include/threading/sync/lockable.hpp @@ -2,7 +2,7 @@ #include -#include "spinlock.hpp" +#include "threading/sync/spinlock.hpp" template class Lockable diff --git a/src/threading/sync/spinlock.hpp b/include/threading/sync/spinlock.hpp similarity index 100% rename from src/threading/sync/spinlock.hpp rename to include/threading/sync/spinlock.hpp diff --git a/src/threading/sync/timed_spinlock.hpp b/include/threading/sync/timed_spinlock.hpp similarity index 100% rename from src/threading/sync/timed_spinlock.hpp rename to include/threading/sync/timed_spinlock.hpp diff --git a/src/threading/task.hpp b/include/threading/task.hpp similarity index 100% rename from src/threading/task.hpp rename to include/threading/task.hpp diff --git a/src/threading/test.cpp b/include/threading/test.cpp similarity index 100% rename from src/threading/test.cpp rename to include/threading/test.cpp diff --git a/src/threading/thread.hpp b/include/threading/thread.hpp similarity index 100% rename from src/threading/thread.hpp rename to include/threading/thread.hpp diff --git a/src/transactions/commit_log.hpp b/include/transactions/commit_log.hpp similarity index 100% rename from src/transactions/commit_log.hpp rename to include/transactions/commit_log.hpp diff --git a/src/transactions/engine.hpp b/include/transactions/engine.hpp similarity index 84% rename from src/transactions/engine.hpp rename to include/transactions/engine.hpp index e18927cf5..2fb9d95d7 100644 --- a/src/transactions/engine.hpp +++ b/include/transactions/engine.hpp @@ -3,13 +3,12 @@ #include #include +#include "threading/sync/lockable.hpp" +#include "threading/sync/spinlock.hpp" +#include "transactions/commit_log.hpp" #include "transactions/transaction.hpp" #include "transactions/transaction_store.hpp" -#include "commit_log.hpp" - #include "utils/counters/simple_counter.hpp" -#include "threading/sync/spinlock.hpp" -#include "threading/sync/lockable.hpp" namespace tx { @@ -27,7 +26,7 @@ public: Engine() : counter(1) {} - Transaction& begin() + Transaction &begin() { auto guard = this->acquire_unique(); @@ -40,14 +39,13 @@ public: return *t; } - Transaction& advance(const Id& id) + Transaction &advance(const Id &id) { auto guard = this->acquire_unique(); - auto* t = store.get(id); + auto *t = store.get(id); - if(t == nullptr) - throw TransactionError("transaction does not exist"); + if (t == nullptr) throw TransactionError("transaction does not exist"); // this is a new command t->cid++; @@ -55,7 +53,7 @@ public: return *t; } - void commit(const Transaction& t) + void commit(const Transaction &t) { auto guard = this->acquire_unique(); clog.set_committed(t.id); @@ -63,7 +61,7 @@ public: finalize(t); } - void abort(const Transaction& t) + void abort(const Transaction &t) { auto guard = this->acquire_unique(); clog.set_aborted(t.id); @@ -94,7 +92,7 @@ public: CommitLog clog; private: - void finalize(const Transaction& t) + void finalize(const Transaction &t) { active.remove(t.id); @@ -106,5 +104,4 @@ private: Snapshot active; TransactionStore store; }; - } diff --git a/src/transactions/lock_store.hpp b/include/transactions/lock_store.hpp similarity index 100% rename from src/transactions/lock_store.hpp rename to include/transactions/lock_store.hpp diff --git a/src/transactions/snapshot.hpp b/include/transactions/snapshot.hpp similarity index 100% rename from src/transactions/snapshot.hpp rename to include/transactions/snapshot.hpp diff --git a/src/transactions/transaction_store.hpp b/include/transactions/transaction_store.hpp similarity index 100% rename from src/transactions/transaction_store.hpp rename to include/transactions/transaction_store.hpp diff --git a/src/utils/assert.hpp b/include/utils/assert.hpp similarity index 52% rename from src/utils/assert.hpp rename to include/utils/assert.hpp index f2ae72049..52c4ee49c 100644 --- a/src/utils/assert.hpp +++ b/include/utils/assert.hpp @@ -3,33 +3,33 @@ #include #include -#include "exceptions/basic_exception.hpp" +#include "utils/exceptions/basic_exception.hpp" // #define THROW_EXCEPTION_ON_ERROR // #define RUNTIME_ASSERT_ON -// handle assertion error -void assert_error_handler(const char *file_name, unsigned line_number, - const char *message) -{ -// this is a good place to put your debug breakpoint -// and add some other destination for error message -#ifdef THROW_EXCEPTION_ON_ERROR - throw BasicException(message); -#else - std::cerr << message << " in file " << file_name << " #" << line_number - << std::endl; - exit(1); -#endif -} +// // handle assertion error +// void assert_error_handler_(const char *file_name, unsigned line_number, +// const char *message) +// { +// // this is a good place to put your debug breakpoint +// // and add some other destination for error message +// #ifdef THROW_EXCEPTION_ON_ERROR +// throw BasicException(message); +// #else +// std::cerr << message << " in file " << file_name << " #" << line_number +// << std::endl; +// exit(1); +// #endif +// } // parmanant exception will always be executed #define permanent_assert(condition, message) \ if (!(condition)) { \ std::ostringstream s; \ s << message; \ - assert_error_handler(__FILE__, __LINE__, s.str().c_str()); \ } +// assert_error_handler_(__FILE__, __LINE__, s.str().c_str()); // runtime exception #ifdef RUNTIME_ASSERT_ON diff --git a/src/utils/auto_scope.hpp b/include/utils/auto_scope.hpp similarity index 100% rename from src/utils/auto_scope.hpp rename to include/utils/auto_scope.hpp diff --git a/src/utils/bash_colors.hpp b/include/utils/bash_colors.hpp similarity index 100% rename from src/utils/bash_colors.hpp rename to include/utils/bash_colors.hpp diff --git a/src/utils/bswap.hpp b/include/utils/bswap.hpp similarity index 100% rename from src/utils/bswap.hpp rename to include/utils/bswap.hpp diff --git a/src/utils/buffer.hpp b/include/utils/buffer.hpp similarity index 100% rename from src/utils/buffer.hpp rename to include/utils/buffer.hpp diff --git a/src/utils/command_line/arguments.hpp b/include/utils/command_line/arguments.hpp similarity index 100% rename from src/utils/command_line/arguments.hpp rename to include/utils/command_line/arguments.hpp diff --git a/src/utils/config/config.hpp b/include/utils/config/config.hpp similarity index 100% rename from src/utils/config/config.hpp rename to include/utils/config/config.hpp diff --git a/src/utils/counters/atomic_counter.hpp b/include/utils/counters/atomic_counter.hpp similarity index 100% rename from src/utils/counters/atomic_counter.hpp rename to include/utils/counters/atomic_counter.hpp diff --git a/src/utils/counters/ring_counter.hpp b/include/utils/counters/ring_counter.hpp similarity index 100% rename from src/utils/counters/ring_counter.hpp rename to include/utils/counters/ring_counter.hpp diff --git a/src/utils/counters/simple_counter.hpp b/include/utils/counters/simple_counter.hpp similarity index 100% rename from src/utils/counters/simple_counter.hpp rename to include/utils/counters/simple_counter.hpp diff --git a/src/utils/cpu_relax.hpp b/include/utils/cpu_relax.hpp similarity index 56% rename from src/utils/cpu_relax.hpp rename to include/utils/cpu_relax.hpp index 40cb4497a..eaf06be34 100644 --- a/src/utils/cpu_relax.hpp +++ b/include/utils/cpu_relax.hpp @@ -5,5 +5,8 @@ */ inline void cpu_relax() { + // if IBMPower + // HMT_very_low() + // http://stackoverflow.com/questions/5425506/equivalent-of-x86-pause-instruction-for-ppc asm("PAUSE"); } diff --git a/src/utils/crtp.hpp b/include/utils/crtp.hpp similarity index 100% rename from src/utils/crtp.hpp rename to include/utils/crtp.hpp diff --git a/src/utils/datetime/datetime.hpp b/include/utils/datetime/datetime.hpp similarity index 100% rename from src/utils/datetime/datetime.hpp rename to include/utils/datetime/datetime.hpp diff --git a/src/utils/datetime/datetime_error.hpp b/include/utils/datetime/datetime_error.hpp similarity index 100% rename from src/utils/datetime/datetime_error.hpp rename to include/utils/datetime/datetime_error.hpp diff --git a/src/utils/datetime/timestamp.hpp b/include/utils/datetime/timestamp.hpp similarity index 100% rename from src/utils/datetime/timestamp.hpp rename to include/utils/datetime/timestamp.hpp diff --git a/src/utils/exceptions/basic_exception.hpp b/include/utils/exceptions/basic_exception.hpp similarity index 100% rename from src/utils/exceptions/basic_exception.hpp rename to include/utils/exceptions/basic_exception.hpp diff --git a/src/utils/hashing/fnv.hpp b/include/utils/hashing/fnv.hpp similarity index 96% rename from src/utils/hashing/fnv.hpp rename to include/utils/hashing/fnv.hpp index 5259f5dc9..265f483c1 100644 --- a/src/utils/hashing/fnv.hpp +++ b/include/utils/hashing/fnv.hpp @@ -11,6 +11,9 @@ // fnv1a is recommended so use it as a default implementation. also use the // platform specific version of the function +namespace +{ + #ifdef MEMGRAPH64 template @@ -28,4 +31,5 @@ uint32_t fnv(const T& data) } #endif - + +} diff --git a/src/utils/hashing/fnv32.hpp b/include/utils/hashing/fnv32.hpp similarity index 98% rename from src/utils/hashing/fnv32.hpp rename to include/utils/hashing/fnv32.hpp index 7b02e6495..784861a16 100644 --- a/src/utils/hashing/fnv32.hpp +++ b/include/utils/hashing/fnv32.hpp @@ -3,6 +3,9 @@ #include #include +namespace +{ + #define OFFSET_BASIS32 2166136261u #define FNV_PRIME32 16777619u @@ -47,3 +50,5 @@ template<> uint32_t fnv1a32(const std::string& data) { return fnv1a32((const unsigned char*)data.c_str(), data.size()); } + +} diff --git a/src/utils/hashing/fnv64.hpp b/include/utils/hashing/fnv64.hpp similarity index 98% rename from src/utils/hashing/fnv64.hpp rename to include/utils/hashing/fnv64.hpp index 891163a76..ea741b956 100644 --- a/src/utils/hashing/fnv64.hpp +++ b/include/utils/hashing/fnv64.hpp @@ -3,6 +3,9 @@ #include #include +namespace +{ + #define OFFSET_BASIS64 14695981039346656037u #define FNV_PRIME64 1099511628211u @@ -47,3 +50,5 @@ template<> uint64_t fnv1a64(const std::string& data) { return fnv1a64((const unsigned char*)data.c_str(), data.size()); } + +} diff --git a/src/utils/ioc/container.hpp b/include/utils/ioc/container.hpp similarity index 100% rename from src/utils/ioc/container.hpp rename to include/utils/ioc/container.hpp diff --git a/src/utils/likely.hpp b/include/utils/likely.hpp similarity index 100% rename from src/utils/likely.hpp rename to include/utils/likely.hpp diff --git a/src/utils/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 #include +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 diff --git a/src/utils/random/xorshift128plus.hpp b/include/utils/random/xorshift128plus.hpp similarity index 100% rename from src/utils/random/xorshift128plus.hpp rename to include/utils/random/xorshift128plus.hpp diff --git a/src/utils/reference_wrapper.hpp b/include/utils/reference_wrapper.hpp similarity index 100% rename from src/utils/reference_wrapper.hpp rename to include/utils/reference_wrapper.hpp diff --git a/src/utils/stacktrace.hpp b/include/utils/stacktrace.hpp similarity index 100% rename from src/utils/stacktrace.hpp rename to include/utils/stacktrace.hpp diff --git a/src/utils/string/all.hpp b/include/utils/string/all.hpp similarity index 100% rename from src/utils/string/all.hpp rename to include/utils/string/all.hpp diff --git a/include/utils/string/file.hpp b/include/utils/string/file.hpp new file mode 100644 index 000000000..c1b580cf6 --- /dev/null +++ b/include/utils/string/file.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include + +namespace utils +{ + +std::string read_file(const char *filename); + +void write_file(const std::string& content, const std::string& path); + +} diff --git a/src/utils/string/intercalate.hpp b/include/utils/string/intercalate.hpp similarity index 100% rename from src/utils/string/intercalate.hpp rename to include/utils/string/intercalate.hpp diff --git a/include/utils/string/join.hpp b/include/utils/string/join.hpp new file mode 100644 index 000000000..509c080af --- /dev/null +++ b/include/utils/string/join.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include +#include + +namespace utils +{ + +std::string join(const std::vector& strings, + const char *separator); + +template +std::string prints(const Args&... args) +{ + std::vector strings = {args...}; + return join(strings, " "); +} + +} diff --git a/src/utils/string/linereader.hpp b/include/utils/string/linereader.hpp similarity index 100% rename from src/utils/string/linereader.hpp rename to include/utils/string/linereader.hpp diff --git a/src/utils/string/replace.hpp b/include/utils/string/replace.hpp similarity index 100% rename from src/utils/string/replace.hpp rename to include/utils/string/replace.hpp diff --git a/src/utils/string/split.hpp b/include/utils/string/split.hpp similarity index 100% rename from src/utils/string/split.hpp rename to include/utils/string/split.hpp diff --git a/src/utils/string/streq.hpp b/include/utils/string/streq.hpp similarity index 100% rename from src/utils/string/streq.hpp rename to include/utils/string/streq.hpp diff --git a/include/utils/string/transform.hpp b/include/utils/string/transform.hpp new file mode 100644 index 000000000..84f84aab3 --- /dev/null +++ b/include/utils/string/transform.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include +#include +#include + +namespace utils +{ + +void str_tolower(std::string& s); + +} diff --git a/src/utils/string/weak_string.hpp b/include/utils/string/weak_string.hpp similarity index 100% rename from src/utils/string/weak_string.hpp rename to include/utils/string/weak_string.hpp diff --git a/src/utils/sys.hpp b/include/utils/sys.hpp similarity index 100% rename from src/utils/sys.hpp rename to include/utils/sys.hpp diff --git a/src/utils/sysinfo/memory.hpp b/include/utils/sysinfo/memory.hpp similarity index 100% rename from src/utils/sysinfo/memory.hpp rename to include/utils/sysinfo/memory.hpp diff --git a/src/utils/terminate_handler.hpp b/include/utils/terminate_handler.hpp similarity index 100% rename from src/utils/terminate_handler.hpp rename to include/utils/terminate_handler.hpp diff --git a/src/utils/time/timer.hpp b/include/utils/time/timer.hpp similarity index 100% rename from src/utils/time/timer.hpp rename to include/utils/time/timer.hpp diff --git a/src/utils/timer/timer.hpp b/include/utils/timer/timer.hpp similarity index 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 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(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 -#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 -T parse(const void* data) +T parse(const void *data) { // reinterpret bytes as the target value - auto value = reinterpret_cast(data); + auto value = reinterpret_cast(data); // swap values to little endian return bswap(*value); } template -T parse(Buffer& buffer, size_t& pos) +T parse(Buffer &buffer, size_t &pos) { // get a pointer to the data we're converting auto ptr = buffer.data() + pos; @@ -71,35 +61,17 @@ T parse(Buffer& buffer, size_t& pos) return parse(ptr); } -int16_t BoltDecoder::read_int16() -{ - return parse(buffer, pos); -} +int16_t BoltDecoder::read_int16() { return parse(buffer, pos); } -uint16_t BoltDecoder::read_uint16() -{ - return parse(buffer, pos); -} +uint16_t BoltDecoder::read_uint16() { return parse(buffer, pos); } -int32_t BoltDecoder::read_int32() -{ - return parse(buffer, pos); -} +int32_t BoltDecoder::read_int32() { return parse(buffer, pos); } -uint32_t BoltDecoder::read_uint32() -{ - return parse(buffer, pos); -} +uint32_t BoltDecoder::read_uint32() { return parse(buffer, pos); } -int64_t BoltDecoder::read_int64() -{ - return parse(buffer, pos); -} +int64_t BoltDecoder::read_int64() { return parse(buffer, pos); } -uint64_t BoltDecoder::read_uint64() -{ - return parse(buffer, pos); -} +uint64_t BoltDecoder::read_uint64() { return parse(buffer, pos); } double BoltDecoder::read_float64() { @@ -115,44 +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(raw()), size); + res.append(reinterpret_cast(raw()), size); pos += size; return res; } -const byte* BoltDecoder::raw() const -{ - return buffer.data() + pos; -} - +const byte *BoltDecoder::raw() const { return buffer.data() + pos; } } diff --git a/src/bolt/v1/transport/buffer.cpp b/src/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 + +#include "database/db.hpp" + class Dbms { public: + Dbms() { create_default(); } + // returns active database + Db &active() + { + if (UNLIKELY(active_db == nullptr)) create_default(); + return *active_db; + } + + // set active database + // if active database doesn't exist create one + Db &active(const std::string &name) + { + // create db if it doesn't exist + if (dbs.find(name) == dbs.end()) { + dbs.emplace(std::piecewise_construct, std::forward_as_tuple(name), + std::forward_as_tuple(name)); + } + + // set and return active db + auto &db = dbs.at(name); + return active_db = &db, *active_db; + } + + // TODO: DELETE action + +private: + // dbs container + std::map dbs; + + // currently active database + Db *active_db; + + // creates default database + void create_default() { active("default"); } }; diff --git a/src/dbms/server/bolt.hpp b/src/dbms/server/bolt.hpp deleted file mode 100644 index c11568cb6..000000000 --- a/src/dbms/server/bolt.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -class BoltServer -{ -public: - BoltServer() = default; - - -}; diff --git a/src/examples/bolt.cpp b/src/examples/bolt.cpp deleted file mode 100644 index 2b2b7f317..000000000 --- a/src/examples/bolt.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#include "bolt/v1/server/server.hpp" -#include "bolt/v1/server/worker.hpp" - -#include "io/network/socket.hpp" - -#include "logging/default.hpp" -#include "logging/streams/stdout.hpp" - -static bolt::Server* serverptr; - -Logger logger; - -void sigint_handler(int s) -{ - auto signal = s == SIGINT ? "SIGINT" : "SIGABRT"; - - logger.info("Recieved signal {}", signal); - logger.info("Shutting down..."); - - std::exit(EXIT_SUCCESS); -} - -static constexpr const char* interface = "0.0.0.0"; -static constexpr const char* port = "7687"; - -int main(void) -{ - logging::init_sync(); - logging::log->pipe(std::make_unique()); - logger = logging::log->logger("Main"); - - signal(SIGINT, sigint_handler); - signal(SIGABRT, sigint_handler); - - io::Socket socket; - - try - { - socket = io::Socket::bind(interface, port); - } - catch(io::NetworkError e) - { - logger.error("Cannot bind to socket on {} at {}", interface, port); - logger.error("{}", e.what()); - - std::exit(EXIT_FAILURE); - } - - socket.set_non_blocking(); - socket.listen(1024); - - logger.info("Listening on {} at {}", interface, port); - - bolt::Server server(std::move(socket)); - serverptr = &server; - - constexpr size_t N = 1; - - logger.info("Starting {} workers", N); - server.start(N); - - logger.info("Shutting down..."); - - return EXIT_SUCCESS; -} diff --git a/src/examples/bolt_py_client/initial_test.py 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 -#include "log.hpp" -#include "logger.hpp" +#include "logging/log.hpp" +#include "logging/logger.hpp" Logger Log::logger(const std::string& name) { diff --git a/src/logging/logs/async_log.cpp b/src/logging/logs/async_log.cpp index e95ba2f29..b5b942811 100644 --- a/src/logging/logs/async_log.cpp +++ b/src/logging/logs/async_log.cpp @@ -1,4 +1,4 @@ -#include "async_log.hpp" +#include "logging/logs/async_log.hpp" AsyncLog::~AsyncLog() { diff --git a/src/logging/logs/sync_log.cpp b/src/logging/logs/sync_log.cpp index 498a8828b..1cd0cf5e0 100644 --- a/src/logging/logs/sync_log.cpp +++ b/src/logging/logs/sync_log.cpp @@ -1,4 +1,4 @@ -#include "sync_log.hpp" +#include "logging/logs/sync_log.hpp" void SyncLog::emit(Record::uptr record) { diff --git a/src/logging/streams/stdout.cpp b/src/logging/streams/stdout.cpp index 8ffb97234..17d04806d 100644 --- a/src/logging/streams/stdout.cpp +++ b/src/logging/streams/stdout.cpp @@ -1,4 +1,4 @@ -#include "stdout.hpp" +#include "logging/streams/stdout.hpp" #include #include diff --git a/src/memgraph_bolt.cpp b/src/memgraph_bolt.cpp index fb59219de..3df3f12c9 100644 --- a/src/memgraph_bolt.cpp +++ b/src/memgraph_bolt.cpp @@ -1,17 +1,74 @@ +#include +#include + +#include "bolt/v1/server/server.hpp" +#include "bolt/v1/server/worker.hpp" + +#include "io/network/socket.hpp" + +#include "logging/default.hpp" +#include "logging/streams/stdout.hpp" + #include "utils/terminate_handler.hpp" -int main(int argc, char *argv[]) +static bolt::Server* serverptr; + +Logger logger; + +void sigint_handler(int s) { - if (argc < 2) { - std::cout << "Port not defined" << std::endl; - std::exit(0); - } + auto signal = s == SIGINT ? "SIGINT" : "SIGABRT"; - auto port = std::stoi(argv[1]); + logger.info("Recieved signal {}", signal); + logger.info("Shutting down..."); - std::cout << "Port is: " << port << std::endl; + std::exit(EXIT_SUCCESS); +} +static constexpr const char* interface = "0.0.0.0"; +static constexpr const char* port = "7687"; + +int main(void) +{ + // TODO figure out what is the relationship between this and signals + // that are configured below std::set_terminate(&terminate_handler); - return 0; + logging::init_sync(); + logging::log->pipe(std::make_unique()); + logger = logging::log->logger("Main"); + + signal(SIGINT, sigint_handler); + signal(SIGABRT, sigint_handler); + + io::Socket socket; + + try + { + socket = io::Socket::bind(interface, port); + } + catch(io::NetworkError e) + { + logger.error("Cannot bind to socket on {} at {}", interface, port); + logger.error("{}", e.what()); + + std::exit(EXIT_FAILURE); + } + + socket.set_non_blocking(); + socket.listen(1024); + + logger.info("Listening on {} at {}", interface, port); + + bolt::Server server(std::move(socket)); + serverptr = &server; + + constexpr size_t N = 1; + + logger.info("Starting {} workers", N); + server.start(N); + + logger.info("Shutting down..."); + + return EXIT_SUCCESS; } diff --git a/src/mvcc/atom.hpp b/src/mvcc/atom.hpp index 75f20dadc..6349bc79c 100644 --- a/src/mvcc/atom.hpp +++ b/src/mvcc/atom.hpp @@ -1,33 +1,31 @@ #pragma once #include "mvcc/id.hpp" +#include "mvcc/version.hpp" #include "threading/sync/lockable.hpp" #include "transactions/transaction.hpp" -#include "version.hpp" namespace mvcc { +// TODO: this can be deleted !! DEPRICATED !! + template -class Atom : public Version, - public Lockable +class Atom : public Version, public Lockable { public: - Atom(const Id& id, T* first) : Version(first), id(id) + Atom(const Id &id, T *first) : Version(first), id(id) { // it's illegal that the first version is nullptr. there should be at // least one version of a record assert(first != nullptr); } - T* first() - { - return this->newer(); - } + T *first() { return this->newer(); } // inspects the record change history and returns the record version visible // to the current transaction if it exists, otherwise it returns nullptr - T* latest_visible(const tx::Transaction& t) + T *latest_visible(const tx::Transaction &t) { return first()->latest_visible(t); } @@ -37,7 +35,6 @@ public: // to reuse indices for deleted nodes. Id id; - std::atomic*> next; + std::atomic *> next; }; - } diff --git a/src/mvcc/id.cpp b/src/mvcc/id.cpp index 1fae0047f..1049d97e3 100644 --- a/src/mvcc/id.cpp +++ b/src/mvcc/id.cpp @@ -1,6 +1,5 @@ #include "mvcc/id.hpp" - Id::Id(uint64_t id) : id(id) {} bool operator<(const Id& a, const Id& b) diff --git a/src/mvcc/id.hpp b/src/mvcc/id.hpp deleted file mode 100644 index 465986ff8..000000000 --- a/src/mvcc/id.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include -#include "utils/total_ordering.hpp" - -class Id : public TotalOrdering -{ -public: - Id() = default; - - Id(uint64_t id) : id(id) {} - - friend bool operator<(const Id& a, const Id& b) - { - return a.id < b.id; - } - - friend bool operator==(const Id& a, const Id& b) - { - return a.id == b.id; - } - - friend std::ostream& operator<<(std::ostream& stream, const Id& id) - { - return stream << id.id; - } - - operator uint64_t() const - { - return id; - } - -private: - uint64_t id {0}; -}; diff --git a/src/mvcc/store.hpp b/src/mvcc/store.hpp index 2ba0d7ec3..809720769 100644 --- a/src/mvcc/store.hpp +++ b/src/mvcc/store.hpp @@ -10,6 +10,8 @@ // some interesting concepts described there, keep in mind for the future // Serializable Isolation for Snapshot Databases, J. Cahill, et al. +// TODO: remove if not in use !! DEPRICATED !! + namespace mvcc { diff --git a/src/query_engine/util.cpp b/src/query_engine/util.cpp new file mode 100644 index 000000000..9a980826e --- /dev/null +++ b/src/query_engine/util.cpp @@ -0,0 +1,23 @@ +#include "query_engine/util.hpp" + +void print_props(const Properties &properties) +{ + StringBuffer buffer; + JsonWriter writer(buffer); + properties.accept(writer); + cout << buffer.str() << endl; +} + +void cout_properties(const Properties &properties) +{ + ConsoleWriter writer; + properties.accept(writer); + cout << "----" << endl; +} + +void cout_property(const std::string &key, const Property &property) +{ + ConsoleWriter writer; + writer.handle(key, property); + cout << "----" << endl; +} diff --git a/src/storage/edges.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 edges; - AtomicCounter 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 -#include -#include -#include -#include -#include - -#include +#include "utils/string/file.hpp" namespace utils { diff --git a/src/utils/string/join.hpp b/src/utils/string/join.cpp similarity index 52% rename from src/utils/string/join.hpp rename to src/utils/string/join.cpp index be3492d49..11aac5afb 100644 --- a/src/utils/string/join.hpp +++ b/src/utils/string/join.cpp @@ -1,9 +1,4 @@ -#pragma once - -#include -#include -#include -#include +#include "utils/string/join.hpp" namespace utils { @@ -16,11 +11,4 @@ std::string join(const std::vector& strings, const char *separator) return oss.str(); } -template -std::string prints(const Args&... args) -{ - std::vector strings = {args...}; - return join(strings, " "); -} - } diff --git a/src/utils/string/transform.hpp b/src/utils/string/transform.cpp similarity index 77% rename from src/utils/string/transform.hpp rename to src/utils/string/transform.cpp index 22197d1bd..20a06f2d7 100644 --- a/src/utils/string/transform.hpp +++ b/src/utils/string/transform.cpp @@ -1,8 +1,4 @@ -#pragma once - -#include -#include -#include +#include "utils/string/transform.hpp" namespace utils { diff --git a/tests/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) {