diff --git a/CMakeLists.txt b/CMakeLists.txt index 19dd2bff6..0a2b34d66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,7 @@ set(yaml_static_lib ${yaml_source_dir}/libyaml-cpp.a) set(catch_source_dir "${libs_dir}/Catch") # load cmake modules: cmake/*.cmake +include(gtest) include(gbenchmark) # build memgraph's cypher grammar @@ -134,188 +135,7 @@ 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}/barrier/barrier.hpp DESTINATION ${build_include_dir}/barrier) -FILE(COPY ${include_dir}/database/db.hpp DESTINATION ${build_include_dir}/database) -FILE(COPY ${include_dir}/database/db_transaction.hpp DESTINATION ${build_include_dir}/database) -FILE(COPY ${include_dir}/database/db_accessor.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_record.hpp DESTINATION ${build_include_dir}/storage) -FILE(COPY ${include_dir}/storage/vertex_record.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}/storage/model/edge_map.hpp DESTINATION ${build_include_dir}/storage/model) -FILE(COPY ${include_dir}/storage/model/properties/flags.hpp DESTINATION ${build_include_dir}/storage/model/properties) -FILE(COPY ${include_dir}/storage/model/properties/stored_property.hpp DESTINATION ${build_include_dir}/storage/model/properties) -FILE(COPY ${include_dir}/storage/model/properties/property_holder.hpp DESTINATION ${build_include_dir}/storage/model/properties) -FILE(COPY ${include_dir}/storage/type_group_edge.hpp DESTINATION ${build_include_dir}/storage) -FILE(COPY ${include_dir}/storage/type_group_vertex.hpp DESTINATION ${build_include_dir}/storage) - -FILE(COPY ${include_dir}/query/util.hpp DESTINATION ${build_include_dir}/query) -FILE(COPY ${include_dir}/query/i_plan_cpu.hpp DESTINATION ${build_include_dir}/query) -FILE(COPY ${include_dir}/query/strip/stripped.hpp DESTINATION ${build_include_dir}/query/strip) - -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/concurrent_list.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/map/rh_hashmultimap.hpp DESTINATION ${build_include_dir}/data_structures/map) -FILE(COPY ${include_dir}/data_structures/map/rh_common.hpp DESTINATION ${build_include_dir}/data_structures/map) - -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}/garbage) -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}/transactions/transaction_read.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/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/null.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/array.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/property_family.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_record.hpp DESTINATION ${build_include_dir}/storage/indexes) -FILE(COPY ${include_dir}/storage/indexes/index_base.hpp DESTINATION ${build_include_dir}/storage/indexes) -FILE(COPY ${include_dir}/storage/indexes/impl/nonunique_unordered_index.hpp DESTINATION ${build_include_dir}/storage/indexes/impl) -FILE(COPY ${include_dir}/storage/indexes/index_holder.hpp DESTINATION ${build_include_dir}/storage/indexes) -FILE(COPY ${include_dir}/storage/indexes/index_definition.hpp DESTINATION ${build_include_dir}/storage/indexes) -FILE(COPY ${include_dir}/storage/indexes/index_update.hpp DESTINATION ${build_include_dir}/storage/indexes) - -FILE(COPY ${include_dir}/storage/garbage/delete_sensitive.hpp DESTINATION ${build_include_dir}/storage/garbage) -FILE(COPY ${include_dir}/storage/garbage/garbage.hpp DESTINATION ${build_include_dir}/storage/garbage) - -FILE(COPY ${include_dir}/utils/sys.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/char_str.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/void.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/array_store.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/bswap.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/stacktrace.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/auto_scope.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/assert.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/reference_wrapper.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/underlying_cast.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/total_ordering.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/crtp.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/placeholder.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/likely.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/cpu_relax.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/counters/atomic_counter.hpp DESTINATION ${build_include_dir}/utils/counters) -FILE(COPY ${include_dir}/utils/counters/simple_counter.hpp DESTINATION ${build_include_dir}/utils/counters) -FILE(COPY ${include_dir}/utils/random/fast_binomial.hpp DESTINATION ${build_include_dir}/utils/random) -FILE(COPY ${include_dir}/utils/random/xorshift128plus.hpp DESTINATION ${build_include_dir}/utils/random) -FILE(COPY ${include_dir}/utils/exceptions/basic_exception.hpp DESTINATION ${build_include_dir}/utils/exceptions) -FILE(COPY ${include_dir}/utils/datetime/timestamp.hpp DESTINATION ${build_include_dir}/utils/datetime) -FILE(COPY ${include_dir}/utils/datetime/datetime_error.hpp DESTINATION ${build_include_dir}/utils/datetime) -FILE(COPY ${include_dir}/utils/types/byte.hpp DESTINATION ${build_include_dir}/utils/types) -FILE(COPY ${include_dir}/utils/option_ptr.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/option.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/border.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/order.hpp DESTINATION ${build_include_dir}/utils) -FILE(COPY ${include_dir}/utils/numerics/saturate.hpp DESTINATION ${build_include_dir}/utils/numerics) - -FILE(COPY ${include_dir}/utils/iterator/iterator_base.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/virtual_iter.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/iterator.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/composable.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/count.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/accessor.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/combined.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/count.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/filter.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/flat_map.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/for_all.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/inspect.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/iterator_accessor.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/lambda_iterator.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/limited_map.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/map.hpp DESTINATION ${build_include_dir}/utils/iterator) -FILE(COPY ${include_dir}/utils/iterator/range_iterator.hpp DESTINATION ${build_include_dir}/utils/iterator) - -FILE(COPY ${include_dir}/communication/communication.hpp DESTINATION ${build_include_dir}/communication) -FILE(COPY ${include_dir}/communication/bolt/v1/config.hpp DESTINATION ${build_include_dir}/communication/bolt/v1) -FILE(COPY ${include_dir}/communication/bolt/v1/serialization/record_stream.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/serialization) -FILE(COPY ${include_dir}/communication/bolt/v1/serialization/bolt_serializer.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/serialization) -FILE(COPY ${include_dir}/communication/bolt/v1/transport/bolt_encoder.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) -FILE(COPY ${include_dir}/communication/bolt/v1/transport/chunked_buffer.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) -FILE(COPY ${include_dir}/communication/bolt/v1/transport/chunked_encoder.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) -FILE(COPY ${include_dir}/communication/bolt/v1/transport/socket_stream.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) -FILE(COPY ${include_dir}/communication/bolt/v1/transport/stream_error.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) -FILE(COPY ${include_dir}/communication/bolt/v1/packing/codes.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/packing) -FILE(COPY ${include_dir}/communication/bolt/v1/messaging/codes.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/messaging) - -FILE(COPY ${include_dir}/io/network/socket.hpp DESTINATION ${build_include_dir}/io/network) -FILE(COPY ${include_dir}/io/network/addrinfo.hpp DESTINATION ${build_include_dir}/io/network) -FILE(COPY ${include_dir}/io/network/network_error.hpp DESTINATION ${build_include_dir}/io/network) -FILE(COPY ${include_dir}/io/network/socket.hpp DESTINATION ${build_include_dir}/io/network) - -FILE(COPY ${include_dir}/logging/default.hpp DESTINATION ${build_include_dir}/logging) -FILE(COPY ${include_dir}/logging/log.hpp DESTINATION ${build_include_dir}/logging) -FILE(COPY ${include_dir}/logging/logger.hpp DESTINATION ${build_include_dir}/logging) -FILE(COPY ${include_dir}/logging/levels.hpp DESTINATION ${build_include_dir}/logging) - -FILE(COPY ${include_dir}/snapshot/snapshot_engine.hpp DESTINATION ${build_include_dir}/snapshot) -# ----------------------------------------------------------------------------- +include(copy_includes) # add all cpp file recursive into sourceFiles varibale # FILE(GLOB_RECURSE sourceFiles ${src_dir}/*.cpp) @@ -417,16 +237,6 @@ message(STATUS "TESTS binaries: ${TESTS}") option(BENCHMARK "Build benchmark binaries" ON) message(STATUS "BENCHMARK binaries: ${BENCHMARK}") # -- binaries ----------------------------------------------------------------- -# -- barrier - this is the way how the engine is isolated so it can be shipped -# wherever, the code is completely hidden behind the barrier, during the -# development the barrier can be turned off because it is much easier to -# debug -option(BARRIER "Barrier" ON) -message(STATUS "BARRIER: ${BARRIER} (Source code isolation)") -if(BARRIER) - add_definitions( -DBARRIER ) -endif() -# -- barrier ------------------------------------------------------------------ # -- configure defines -------------------------------------------------------- # -- includes ----------------------------------------------------------------- @@ -460,7 +270,6 @@ set(memgraph_src_files ${src_dir}/utils/string/join.cpp ${src_dir}/utils/string/file.cpp ${src_dir}/utils/numerics/saturate.cpp - ${src_dir}/query_engine/util.cpp ${src_dir}/communication/bolt/v1/bolt.cpp ${src_dir}/communication/bolt/v1/states.cpp ${src_dir}/communication/bolt/v1/session.cpp @@ -482,6 +291,7 @@ set(memgraph_src_files ${src_dir}/storage/label/label.cpp ${src_dir}/storage/label/label_collection.cpp ${src_dir}/storage/label/label_store.cpp + ${src_dir}/storage/label/labels_writer.cpp ${src_dir}/storage/edge_type/edge_type.cpp ${src_dir}/storage/edge_type/edge_type_store.cpp ${src_dir}/storage/model/properties/null.cpp @@ -531,15 +341,6 @@ add_library(memgraph STATIC ${memgraph_src_files}) add_library(memgraph_pic STATIC ${memgraph_src_files}) set_property(TARGET memgraph_pic PROPERTY POSITION_INDEPENDENT_CODE TRUE) -if (BARRIER) - # create static barrier lib - add_library(barrier STATIC ${memgraph_src_files}) - - # create pic static barrier lib - add_library(barrier_pic STATIC ${memgraph_src_files}) - set_property(TARGET barrier_pic PROPERTY POSITION_INDEPENDENT_CODE TRUE) -endif() - # tests if (TESTS) enable_testing() @@ -583,12 +384,7 @@ message(STATUS "Release flags: ${CMAKE_CXX_FLAGS_RELEASE}") if (MEMGRAPH) add_executable(${MEMGRAPH_BUILD_NAME} ${src_dir}/memgraph_bolt.cpp) - if (BARRIER) - target_link_libraries(${MEMGRAPH_BUILD_NAME} barrier) - elseif (NOT BARRIER) - target_link_libraries(${MEMGRAPH_BUILD_NAME} memgraph) - endif () - + target_link_libraries(${MEMGRAPH_BUILD_NAME} memgraph) target_link_libraries(${MEMGRAPH_BUILD_NAME} stdc++fs) target_link_libraries(${MEMGRAPH_BUILD_NAME} Threads::Threads) target_link_libraries(${MEMGRAPH_BUILD_NAME} cypher_lib) diff --git a/cmake/copy_includes.cmake b/cmake/copy_includes.cmake new file mode 100644 index 000000000..bdf2b667c --- /dev/null +++ b/cmake/copy_includes.cmake @@ -0,0 +1,186 @@ +# ----------------------------------------------------------------------------- +# COPY header files required by query engine (query compiler) +# TODO: create a copy function, COPY_RELATIVE(base relative_path dst) +# 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}/database/db_transaction.hpp DESTINATION ${build_include_dir}/database) +FILE(COPY ${include_dir}/database/db_accessor.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_record.hpp DESTINATION ${build_include_dir}/storage) +FILE(COPY ${include_dir}/storage/vertex_record.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}/storage/label/labels_writer.hpp DESTINATION ${build_include_dir}/storage/label) +FILE(COPY ${include_dir}/storage/model/edge_map.hpp DESTINATION ${build_include_dir}/storage/model) +FILE(COPY ${include_dir}/storage/model/properties/flags.hpp DESTINATION ${build_include_dir}/storage/model/properties) +FILE(COPY ${include_dir}/storage/model/properties/stored_property.hpp DESTINATION ${build_include_dir}/storage/model/properties) +FILE(COPY ${include_dir}/storage/model/properties/property_holder.hpp DESTINATION ${build_include_dir}/storage/model/properties) +FILE(COPY ${include_dir}/storage/type_group_edge.hpp DESTINATION ${build_include_dir}/storage) +FILE(COPY ${include_dir}/storage/type_group_vertex.hpp DESTINATION ${build_include_dir}/storage) + +FILE(COPY ${include_dir}/query/util.hpp DESTINATION ${build_include_dir}/query) +FILE(COPY ${include_dir}/query/i_plan_cpu.hpp DESTINATION ${build_include_dir}/query) +FILE(COPY ${include_dir}/query/strip/stripped.hpp DESTINATION ${build_include_dir}/query/strip) + +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/concurrent_list.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/map/rh_hashmultimap.hpp DESTINATION ${build_include_dir}/data_structures/map) +FILE(COPY ${include_dir}/data_structures/map/rh_common.hpp DESTINATION ${build_include_dir}/data_structures/map) + +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}/transactions/transaction_read.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/json_writer.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/null.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/array.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/property_family.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_record.hpp DESTINATION ${build_include_dir}/storage/indexes) +FILE(COPY ${include_dir}/storage/indexes/index_base.hpp DESTINATION ${build_include_dir}/storage/indexes) +FILE(COPY ${include_dir}/storage/indexes/impl/nonunique_unordered_index.hpp DESTINATION ${build_include_dir}/storage/indexes/impl) +FILE(COPY ${include_dir}/storage/indexes/index_holder.hpp DESTINATION ${build_include_dir}/storage/indexes) +FILE(COPY ${include_dir}/storage/indexes/index_definition.hpp DESTINATION ${build_include_dir}/storage/indexes) +FILE(COPY ${include_dir}/storage/indexes/index_update.hpp DESTINATION ${build_include_dir}/storage/indexes) + +FILE(COPY ${include_dir}/storage/garbage/delete_sensitive.hpp DESTINATION ${build_include_dir}/storage/garbage) +FILE(COPY ${include_dir}/storage/garbage/garbage.hpp DESTINATION ${build_include_dir}/storage/garbage) + +FILE(COPY ${include_dir}/utils/string_buffer.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/handle_write.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/sys.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/char_str.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/void.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/array_store.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/bswap.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/stacktrace.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/auto_scope.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/assert.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/reference_wrapper.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/underlying_cast.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/total_ordering.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/crtp.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/placeholder.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/likely.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/cpu_relax.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/counters/atomic_counter.hpp DESTINATION ${build_include_dir}/utils/counters) +FILE(COPY ${include_dir}/utils/counters/simple_counter.hpp DESTINATION ${build_include_dir}/utils/counters) +FILE(COPY ${include_dir}/utils/random/fast_binomial.hpp DESTINATION ${build_include_dir}/utils/random) +FILE(COPY ${include_dir}/utils/random/xorshift128plus.hpp DESTINATION ${build_include_dir}/utils/random) +FILE(COPY ${include_dir}/utils/exceptions/basic_exception.hpp DESTINATION ${build_include_dir}/utils/exceptions) +FILE(COPY ${include_dir}/utils/datetime/timestamp.hpp DESTINATION ${build_include_dir}/utils/datetime) +FILE(COPY ${include_dir}/utils/datetime/datetime_error.hpp DESTINATION ${build_include_dir}/utils/datetime) +FILE(COPY ${include_dir}/utils/types/byte.hpp DESTINATION ${build_include_dir}/utils/types) +FILE(COPY ${include_dir}/utils/option_ptr.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/option.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/border.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/order.hpp DESTINATION ${build_include_dir}/utils) +FILE(COPY ${include_dir}/utils/numerics/saturate.hpp DESTINATION ${build_include_dir}/utils/numerics) + +FILE(COPY ${include_dir}/utils/iterator/iterator_base.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/virtual_iter.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/iterator.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/composable.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/count.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/accessor.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/combined.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/count.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/filter.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/flat_map.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/for_all.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/inspect.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/iterator_accessor.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/lambda_iterator.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/limited_map.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/map.hpp DESTINATION ${build_include_dir}/utils/iterator) +FILE(COPY ${include_dir}/utils/iterator/range_iterator.hpp DESTINATION ${build_include_dir}/utils/iterator) + +FILE(COPY ${include_dir}/communication/communication.hpp DESTINATION ${build_include_dir}/communication) +FILE(COPY ${include_dir}/communication/bolt/v1/config.hpp DESTINATION ${build_include_dir}/communication/bolt/v1) +FILE(COPY ${include_dir}/communication/bolt/v1/serialization/record_stream.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/serialization) +FILE(COPY ${include_dir}/communication/bolt/v1/serialization/bolt_serializer.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/serialization) +FILE(COPY ${include_dir}/communication/bolt/v1/transport/bolt_encoder.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) +FILE(COPY ${include_dir}/communication/bolt/v1/transport/chunked_buffer.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) +FILE(COPY ${include_dir}/communication/bolt/v1/transport/chunked_encoder.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) +FILE(COPY ${include_dir}/communication/bolt/v1/transport/socket_stream.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) +FILE(COPY ${include_dir}/communication/bolt/v1/transport/stream_error.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/transport) +FILE(COPY ${include_dir}/communication/bolt/v1/packing/codes.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/packing) +FILE(COPY ${include_dir}/communication/bolt/v1/messaging/codes.hpp DESTINATION ${build_include_dir}/communication/bolt/v1/messaging) + +FILE(COPY ${include_dir}/io/network/socket.hpp DESTINATION ${build_include_dir}/io/network) +FILE(COPY ${include_dir}/io/network/addrinfo.hpp DESTINATION ${build_include_dir}/io/network) +FILE(COPY ${include_dir}/io/network/network_error.hpp DESTINATION ${build_include_dir}/io/network) +FILE(COPY ${include_dir}/io/network/socket.hpp DESTINATION ${build_include_dir}/io/network) + +FILE(COPY ${include_dir}/logging/default.hpp DESTINATION ${build_include_dir}/logging) +FILE(COPY ${include_dir}/logging/log.hpp DESTINATION ${build_include_dir}/logging) +FILE(COPY ${include_dir}/logging/logger.hpp DESTINATION ${build_include_dir}/logging) +FILE(COPY ${include_dir}/logging/levels.hpp DESTINATION ${build_include_dir}/logging) +FILE(COPY ${include_dir}/logging/loggable.hpp DESTINATION ${build_include_dir}/logging) + +FILE(COPY ${include_dir}/snapshot/snapshot_engine.hpp DESTINATION ${build_include_dir}/snapshot) +# ----------------------------------------------------------------------------- diff --git a/cmake/gtest.cmake b/cmake/gtest.cmake new file mode 100644 index 000000000..fd32785ae --- /dev/null +++ b/cmake/gtest.cmake @@ -0,0 +1,19 @@ +if (CMAKE_VERSION VERSION_LESS 3.2) + set(UPDATE_DISCONNECTED_IF_AVAILABLE "") +else() + set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1") +endif() + +include(DownloadProject/DownloadProject) + +download_project( + PROJ googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + ${UPDATE_DISCONNECTED_IF_AVAILABLE} +) + +add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) + +include_directories("${googletest_SOURCE_DIR}/googletest/include") +include_directories("${googletest_SOURCE_DIR}/googlemock/include") diff --git a/config/memgraph.yaml b/config/memgraph.yaml index 7ba6c4a8c..45e503188 100644 --- a/config/memgraph.yaml +++ b/config/memgraph.yaml @@ -1,8 +1,27 @@ +########################### +# MEMGRAPH DEFAULT CONFIG # +########################### + +# NOTE: all paths are relative to the run folder +# (where the executable is runned) + +# path to the codes which will be compiled compile_cpu_path: "./compiled/cpu/" + +# path to the template (cpp) for codes generation template_cpu_cpp_path: "./template/template_code_cpu.cpp" -barrier_template_cpu_cpp_path: "./template/barrier_template_code_cpu.cpp" + +# path to the template (hpp) for codes generation template_cpu_hpp_path: "./template/template_code_cpu.hpp" + +# path to the folder with snapshots snapshots_path: "snapshots" + +# leaning cycle interval cleaning_cycle_sec: "300" + +# snapshot cycle interval snapshot_cycle_sec: "60" + +# max number of snapshots which will be kept on the disk at some point max_retained_snapshots: "3" diff --git a/docker/memgraph.dockerfile b/docker/memgraph.dockerfile deleted file mode 100644 index 357b53a8b..000000000 --- a/docker/memgraph.dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM ubuntu:16.04 - -# apt-get setup -RUN apt-get update \ - && apt-get install -y cmake git python clang wget \ - && apt-get install -y check libpcre3 libpcre3-dev libjemalloc-dev \ - libjemalloc1 build-essential libtool automake \ - autoconf pkg-config -# && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -# prepare source -RUN mkdir -p /memgraph/build -RUN mkdir -p /memgraph/libs -COPY libs/setup.sh /memgraph/libs/setup.sh -COPY src /memgraph/src -COPY tests /memgraph/tests -COPY CMakeLists.txt /memgraph/CMakeLists.txt - -# setup libs -WORKDIR /memgraph/libs -RUN ./setup.sh - -# build -WORKDIR /memgraph/build -RUN cmake -DCMAKE_C_COMPILER=clang \ - -DCMAKE_CXX_COMPILER=clang++ \ - -DRUNTIME_ASSERT=OFF \ - -DTHROW_EXCEPTION_ON_ERROR=OFF \ - -DNDEBUG=OFF .. -RUN make - -# run -CMD /memgraph/build/memgraph 7474 diff --git a/include/barrier/barrier.hpp b/include/barrier/barrier.hpp deleted file mode 100644 index 8d19a69e5..000000000 --- a/include/barrier/barrier.hpp +++ /dev/null @@ -1,588 +0,0 @@ -#pragma once - -#ifdef BARRIER - -#include "barrier/common.hpp" - -// This namespace is holding header parts of barrier classes. Barrier class -// object is in fact object from other class inside memgraph. Main purpose of -// barrier classes is to hide real classes from outside viewers. This header -// should be only to be included from memgraph into generated/compiled query. -// And this header must ensure that it defines all classes and methods required -// for querys. -namespace barrier -{ -// Every class from database which must be visible to outside the barrier should -// have there barrier class defined here. - -// ************ Here should be forward declarations of Sized barrier classes -// ACCESSORS -class DbAccessor; -class VertexAccessor; -class EdgeAccessor; - -// GENERIC ITERATORS -class VertexIterator; -class EdgeIterator; - -// TYPED ITERATORS -class VertexAccessIterator; -class EdgeAccessIterator; -class OutEdgesIterator; -class InEdgesIterator; - -// PROPERTY -class VertexPropertyKey; -class EdgePropertyKey; -template -class VertexPropertyType; -template -class EdgePropertyType; - -// BOLT -template -class RecordStream; - -// ************ Here should be forward declarations of Unsized barrier classes -// COMMON -class Db; -class Label; -class EdgeType; - -// GENERIC INDEXES -template -class VertexIndex; -template -class EdgeIndex; - -// PROPERTY -class VertexPropertyFamily; -class EdgePropertyFamily; - -// ************* Here should be defined usings -using label_ref_t = ReferenceWrapper; -using VertexStoredProperty = PropertyHolder; -using EdgeStoredProperty = PropertyHolder; - -// ************ Here should be definitions of Sized barrier classes -// Original class should have Sized barrier class if it can't be Unsized. -// Sized barrier classes should: -// --Have same name as original class. -// --Inherit Sized class from common.hpp as public. Blueprint: -// class class_name: public Sized -// --Sized template arguments must be hardcoded numbers equal to sizeof(T) and -// alignof(T) where T is original class. -// --It should have undefined public constructor which is specialized in .cpp -// Blueprint: -// public: -// template class_name(T &&d); -// --It should delete or specify following methods depending on the behavior of -// the original class: -// public: -// class_name(const class_name &other); -// class_name(class_name &&other); -// ~class_name(); -// class_name &operator=(const class_name &other); -// class_name &operator=(class_name &&other); -// --It should specify public methods which can be called on the original class. -// -// Blueprint: -// class class_name : public Sized<,> -// { -// public: -// template -// class_name(T &&d); -// -// class_name(const class_name &other); -// class_name(class_name &&other); -// ~class_name(); -// -// class_name &operator=(const class_name &other); -// class_name &operator=(class_name &&other); -// -// }; - -// TODO: Extract methods od RecordAccessor for VertexAccessor and EdgeAccessor -// into joined class. -class VertexAccessor : private Sized<24, 8> -{ -public: - template - VertexAccessor(T &&d); - - VertexAccessor(VertexAccessor &other); - VertexAccessor(const VertexAccessor &other); - VertexAccessor(VertexAccessor &&other); - VertexAccessor(VertexAccessor const &&other); - ~VertexAccessor(); - - VertexAccessor &operator=(const VertexAccessor &other); - VertexAccessor &operator=(VertexAccessor &&other); - - bool isolated() const; - - size_t out_degree() const; - - size_t in_degree() const; - - size_t degree() const; - - bool add_label(const Label &label); - - bool remove_label(const Label &label); - - bool has_label(const Label &label) const; - - const std::vector &labels() const; - - OutEdgesIterator out() const; - - InEdgesIterator in() const; - - bool in_contains(VertexAccessor const &other) const; - - bool empty() const; - - bool fill() const; - - const Id &id() const; - - VertexAccessor update() const; - - void remove() const; - - // template - // bool contains(property_key &key) const; - - const VertexStoredProperty &at(VertexPropertyFamily &key) const; - - const VertexStoredProperty &at(VertexPropertyKey &key) const; - - template - OptionPtr at(VertexPropertyType &key) const; - - void set(VertexPropertyKey &key, Property &&value); - - void clear(VertexPropertyKey &key); - - void clear(VertexPropertyFamily &key); - - template - void accept(Handler &handler) const; - - explicit operator bool() const; - - friend bool operator==(const VertexAccessor &a, const VertexAccessor &b); - - friend bool operator!=(const VertexAccessor &a, const VertexAccessor &b); -}; - -class EdgeAccessor : private Sized<24, 8> -{ -public: - template - EdgeAccessor(T &&d); - - EdgeAccessor(EdgeAccessor &other); - EdgeAccessor(const EdgeAccessor &other); - EdgeAccessor(EdgeAccessor &&other); - EdgeAccessor(EdgeAccessor const &&other); - ~EdgeAccessor(); - - EdgeAccessor &operator=(const EdgeAccessor &other); - EdgeAccessor &operator=(EdgeAccessor &&other); - - void edge_type(const EdgeType &edge_type); - - const EdgeType &edge_type() const; - - const VertexAccessor from() const; - - const VertexAccessor to() const; - - bool empty() const; - - bool fill() const; - - const Id &id() const; - - EdgeAccessor update() const; - - void remove() const; - - const EdgeStoredProperty &at(EdgePropertyFamily &key) const; - - const EdgeStoredProperty &at(EdgePropertyKey &key) const; - - template - OptionPtr at(EdgePropertyType &key) const; - - void set(EdgePropertyKey &key, Property &&value); - - void clear(EdgePropertyKey &key); - - void clear(EdgePropertyFamily &key); - - template - void accept(Handler &handler) const; - - explicit operator bool() const; - - friend bool operator==(const EdgeAccessor &a, const EdgeAccessor &b); - - friend bool operator!=(const EdgeAccessor &a, const EdgeAccessor &b); -}; - -class DbAccessor : protected Sized<40, 8> -{ -public: - DbAccessor(Db &d); - - DbAccessor(const DbAccessor &other) = delete; - DbAccessor(DbAccessor &&other) = delete; - ~DbAccessor(); - - DbAccessor &operator=(const DbAccessor &other) = delete; - DbAccessor &operator=(DbAccessor &&other) = delete; - - VertexAccessIterator vertex_access(); - - Option vertex_find(const Id &id); - - VertexAccessor vertex_insert(); - - EdgeAccessIterator edge_access(); - - Option edge_find(const Id &id); - - EdgeAccessor edge_insert(VertexAccessor const &from, - VertexAccessor const &to); - - const Label &label_find_or_create(const char *name); - - bool label_contains(const char *name); - - const EdgeType &type_find_or_create(const char *name); - - bool type_contains(const char *name); - - VertexPropertyFamily &vertex_property_family_get(const std::string &name); - - EdgePropertyFamily &edge_property_family_get(const std::string &name); - - VertexPropertyKey vertex_property_key(const std::string &name, Type type); - - EdgePropertyKey edge_property_key(const std::string &name, Type type); - - template - VertexPropertyType vertex_property_key(const std::string &name); - - template - EdgePropertyType edge_property_key(const std::string &name); - - bool commit(); - void abort(); -}; - -class VertexIterator - : public Sized<8, 8>, - public iter::Composable -{ -public: - template - VertexIterator(T &&d); - - VertexIterator(const VertexIterator &other) = delete; - VertexIterator(VertexIterator &&other); - ~VertexIterator(); - VertexIterator &operator=(const VertexIterator &other) = delete; - VertexIterator &operator=(VertexIterator &&other) = delete; - - Option next(); - - Count count(); -}; - -// NOTE: This large size is because of SkipList accessor which is embeded into -// iterator. The accessor has 64 fields of pointers which is in total 512 B. -class VertexAccessIterator - : public Sized<560, 8>, - public iter::Composable -{ -public: - template - VertexAccessIterator(T &&d); - - VertexAccessIterator(const VertexAccessIterator &other) = delete; - VertexAccessIterator(VertexAccessIterator &&other); - ~VertexAccessIterator(); - VertexAccessIterator &operator=(const VertexAccessIterator &other) = delete; - VertexAccessIterator &operator=(VertexAccessIterator &&other) = delete; - - Option next(); - - Count count(); -}; - -// NOTE: This large size is because of SkipList accessor which is embeded into -// iterator. The accessor has 64 fields of pointers which is in total 512 B. -class EdgeAccessIterator - : public Sized<560, 8>, - public iter::Composable -{ -public: - template - EdgeAccessIterator(T &&d); - - EdgeAccessIterator(const EdgeAccessIterator &other) = delete; - EdgeAccessIterator(EdgeAccessIterator &&other); - ~EdgeAccessIterator(); - EdgeAccessIterator &operator=(const EdgeAccessIterator &other) = delete; - EdgeAccessIterator &operator=(EdgeAccessIterator &&other) = delete; - - Option next(); - - Count count(); -}; - -class OutEdgesIterator - : public Sized<48, 8>, - public iter::Composable -{ -public: - template - OutEdgesIterator(T &&d); - - OutEdgesIterator(const OutEdgesIterator &other) = delete; - OutEdgesIterator(OutEdgesIterator &&other); - ~OutEdgesIterator(); - OutEdgesIterator &operator=(const OutEdgesIterator &other) = delete; - OutEdgesIterator &operator=(OutEdgesIterator &&other) = delete; - - Option next(); - - Count count(); -}; - -class InEdgesIterator - : public Sized<64, 8>, - public iter::Composable -{ -public: - template - InEdgesIterator(T &&d); - - InEdgesIterator(const InEdgesIterator &other) = delete; - InEdgesIterator(InEdgesIterator &&other); - ~InEdgesIterator(); - InEdgesIterator &operator=(const InEdgesIterator &other) = delete; - InEdgesIterator &operator=(InEdgesIterator &&other) = delete; - - Option next(); - - Count count(); -}; - -class EdgeIterator : public Sized<8, 8>, - public iter::Composable -{ -public: - template - EdgeIterator(T &&d); - - EdgeIterator(const EdgeIterator &other) = delete; - EdgeIterator(EdgeIterator &&other); - ~EdgeIterator(); - EdgeIterator &operator=(const EdgeIterator &other) = delete; - EdgeIterator &operator=(EdgeIterator &&other) = delete; - - Option next(); - - Count count(); - - EdgeIterator &operator->() { return *this; } -}; - -class VertexPropertyKey : private Sized<8, 8> -{ -public: - template - VertexPropertyKey(T &&d); - - VertexPropertyKey(const VertexPropertyKey &other) = default; - VertexPropertyKey(VertexPropertyKey &&other) = default; - ~VertexPropertyKey(); - - VertexPropertyKey &operator=(const VertexPropertyKey &other) = default; - VertexPropertyKey &operator=(VertexPropertyKey &&other) = default; - - Type get_type() const; -}; - -class EdgePropertyKey : private Sized<8, 8> -{ -public: - template - EdgePropertyKey(T &&d); - - EdgePropertyKey(const EdgePropertyKey &other) = default; - EdgePropertyKey(EdgePropertyKey &&other) = default; - ~EdgePropertyKey(); - - EdgePropertyKey &operator=(const EdgePropertyKey &other) = default; - EdgePropertyKey &operator=(EdgePropertyKey &&other) = default; - - Type get_type() const; -}; - -template -class VertexPropertyType : private Sized<8, 8> -{ -public: - template - VertexPropertyType(T &&d); - - VertexPropertyType(const VertexPropertyType &other) = default; - VertexPropertyType(VertexPropertyType &&other) = default; - ~VertexPropertyType(){}; - - VertexPropertyType &operator=(const VertexPropertyType &other) = default; - VertexPropertyType &operator=(VertexPropertyType &&other) = default; -}; - -template -class EdgePropertyType : private Sized<8, 8> -{ -public: - template - EdgePropertyType(T &&d); - - EdgePropertyType(const EdgePropertyType &other) = default; - EdgePropertyType(EdgePropertyType &&other) = default; - ~EdgePropertyType(){}; - - EdgePropertyType &operator=(const EdgePropertyType &other) = default; - EdgePropertyType &operator=(EdgePropertyType &&other) = default; -}; - -template -class RecordStream : private Sized<8, 8> -{ -public: - template - RecordStream(T &&d); - - RecordStream(const RecordStream &other) = default; - RecordStream(RecordStream &&other) = default; - ~RecordStream(); - - RecordStream &operator=(const RecordStream &other) = default; - RecordStream &operator=(RecordStream &&other) = default; - - void write(const VertexAccessor &vertex); - void write(const EdgeAccessor &edge); - void write(const VertexStoredProperty &prop); - void write(const EdgeStoredProperty &prop); - void write(const Null &v); - void write(const Bool &prop); - void write(const Float &prop); - void write(const Double &prop); - void write(const Int32 &prop); - void write(const Int64 &prop); - void write(const String &prop); - void write(const ArrayBool &); - void write(const ArrayInt32 &); - void write(const ArrayInt64 &); - void write(const ArrayFloat &); - void write(const ArrayDouble &); - void write(const ArrayString &); - - void write_empty_fields(); - void write_success(); - void write_success_empty(); - void write_ignored(); - void write_fields(const std::vector &fields); - void write_field(const std::string &field); - void write_list_header(size_t size); - void write_record(); - void write_meta(const std::string &type); - void write_failure(const std::map &data); - void send(); - void chunk(); -}; - -// ************ Here should be definitions of Unsized barrier classes -// Original class can be Unsized barrier class if they are only used outside the -// barrier through reference/pointer. -// Usized barrier classes should: -// --Have same name as original class or somethin more specific if it is -// partialy specialized. -// --Inherit Unsized class from common.hpp as protected. Blueprint: -// class class_name: protected Unsized -// --It should specify public methods which can be called on the original class. -// -// Blueprint: -// class class_name : protected Unsized -// { -// public: -// -// }; - -class VertexPropertyFamily : protected Unsized -{ -public: - OptionPtr> index(); -}; - -class EdgePropertyFamily : protected Unsized -{ -public: - OptionPtr> index(); -}; - -class Label : protected Unsized -{ -public: - VertexIndex &index() const; -}; - -class EdgeType : protected Unsized -{ -public: - friend bool operator<(const EdgeType &lhs, const EdgeType &rhs); - - friend bool operator==(const EdgeType &lhs, const EdgeType &rhs); - - EdgeIndex &index() const; -}; - -template -class VertexIndex : protected Unsized -{ -public: - // TODO: This iterator sometimes has known type. It can be added to this - // border to avoid dynamic dispatch - VertexIterator for_range(DbAccessor &, Border from = Border(), - Border to = Border()); - - IndexType type(); -}; - -template -class EdgeIndex : protected Unsized -{ -public: - // TODO: This iterator has known type. It can be added to this border to - // avoid dynamic dispatch - EdgeIterator for_range(DbAccessor &, Border from = Border(), - Border to = Border()); - - IndexType type(); -}; - -class Db : protected Unsized -{ -}; -} - -#endif diff --git a/include/barrier/common.hpp b/include/barrier/common.hpp deleted file mode 100644 index f0eb17725..000000000 --- a/include/barrier/common.hpp +++ /dev/null @@ -1,142 +0,0 @@ -#pragma once - -#ifdef BARRIER - -#include -#include -#include -#include -#include - -// This shoul be the only place to include code from memgraph other than -// barrier.cpp -#include "mvcc/id.hpp" -#include "storage/indexes/index_definition.hpp" -#include "storage/model/properties/all.hpp" -#include "storage/model/properties/property.hpp" -#include "utils/border.hpp" -#include "utils/iterator/iterator.hpp" -#include "utils/option_ptr.hpp" -#include "utils/reference_wrapper.hpp" - -// Contains common classes and functions for barrier.hpp and barrier.cpp. -namespace barrier -{ - -// This define accepts other define which accepts property type to instantiate -// template. Recieved define will be called for all property types. -#define INSTANTIATE_FOR_PROPERTY(x) \ - x(Int32) x(Int64) x(Float) x(Double) x(Bool) x(String) x(ArrayInt32) \ - x(ArrayInt64) x(ArrayFloat) x(ArrayDouble) x(ArrayBool) x(ArrayString) - -// **************************** HELPER FUNCTIONS **************************** // -// CASTS FROM& -> TO& -template -TO &ref_as(FROM &ref) -{ - return (*reinterpret_cast(&ref)); -} - -// CASTS FROM const& -> TO const& -template -TO const &ref_as(FROM const &ref) -{ - return (*reinterpret_cast(&ref)); -} - -// CASTS FROM* -> TO* -template -TO *ptr_as(FROM *ref) -{ - return (reinterpret_cast(ref)); -} - -// CASTS FROM const* -> TO const* -template -TO const *ptr_as(FROM const *ref) -{ - return (reinterpret_cast(ref)); -} - -// CASTS FROM&& -> TO&& -template -TO &&value_as(FROM &&ref) -{ - static_assert(sizeof(TO) == sizeof(FROM), "Border class size mismatch"); - static_assert(alignof(TO) == alignof(FROM), - "Border class aligment mismatch"); - return (reinterpret_cast(std::move(ref))); -} - -// CASTS FROM const&& -> TO const&& -template -const TO &&value_as(const FROM &&ref) -{ - static_assert(sizeof(TO) == sizeof(FROM), "Border class size mismatch"); - static_assert(alignof(TO) == alignof(FROM), - "Border class aligment mismatch"); - return (reinterpret_cast(std::move(ref))); -} - -// Barrier classes which will be used only through reference/pointer should -// inherit this class. Outside of barrier derived classes will be used only -// through reference/pointer. -class Unsized -{ -public: - // Deleting following constructors/destroyers and opertators will assure - // that this class/derived classes can't be created,copyed,deleted or moved. - // This way the other side can't "accidentaly" create/copy/destroy or move - // objects which inherit this class because that would be erroneous. - Unsized() = delete; - Unsized(const Unsized &other) = delete; - Unsized(Unsized &&other) = delete; - ~Unsized() = delete; - Unsized &operator=(const Unsized &other) = delete; - Unsized &operator=(Unsized &&other) = delete; -}; - -// Barrier classes which will be used as value should inherit this class. -// Template accepts size_B in B of object of original class from memgraph. -// Template accepts alignment_B in B of object of original class from memgraph. -template -class Sized -{ -protected: - // This will ensure that this/derived class can't be instantiated. - // Something outside the barrier can't "accidentaly" create this/derived - // type because that would be erroneous. - Sized() = delete; - - // This constructor serves as a check for correctness of size_B and - // alignment_B template parametars. Derived class MUST call this constructor - // with T which it holds where T is original class from memgraph. - template - Sized(T &&d) - { - new (ptr_as(&data)) T(std::move(d)); - static_assert(size_B == sizeof(T), "Border class size mismatch"); - static_assert(alignment_B == alignof(T), - "Border class aligment mismatch"); - } - - // This constructor serves as a check for correctness of size_B and - // alignment_B template parametars. Derived class MUST call this constructor - // with T which it holds where T is original class from memgraph. - template - Sized(const T &&d) - { - new (ptr_as(&data)) T(std::move(d)); - static_assert(size_B == sizeof(T), "Border class size mismatch"); - static_assert(alignment_B == alignof(T), - "Border class aligment mismatch"); - } - -private: - // Here is the aligned storage which imitates size and aligment of object of - // original class from memgraph. - typename std::aligned_storage::type data; -}; -} - -#endif diff --git a/include/barrier/trans.hpp b/include/barrier/trans.hpp deleted file mode 100644 index 2e02b18b8..000000000 --- a/include/barrier/trans.hpp +++ /dev/null @@ -1,269 +0,0 @@ -#pragma once - -#ifdef BARRIER - -#include "barrier/barrier.hpp" - -// This is the place for imports from memgraph .hpp -#include "communication/bolt/v1/serialization/bolt_serializer.hpp" -#include "communication/bolt/v1/serialization/record_stream.hpp" -#include "database/db.hpp" -#include "database/db_accessor.hpp" -#include "io/network/socket.hpp" -#include "storage/edge_type/edge_type.hpp" -#include "storage/edge_x_vertex.hpp" -#include "storage/label/label.hpp" - -// This is the place for imports from memgraph .cpp - -// **************************** HELPER DEFINES *******************************// -// Creates 8 functions for transformation of refereces between types x and y. -// Where x is a border type. -// DANGEROUS -#define TRANSFORM_REF(x, y) \ - x &trans(y &l) { return ref_as(l); } \ - x const &trans(y const &l) { return ref_as(l); } \ - y &trans(x &l) { return ref_as(l); } \ - y const &trans(x const &l) { return ref_as(l); } \ - x *trans(y *l) { return ptr_as(l); } \ - x const *trans(y const *l) { return ptr_as(l); } \ - y *trans(x *l) { return ptr_as(l); } \ - y const *trans(x const *l) { return ptr_as(l); } - -// Creates 4 functions for transformation of refereces between types x and y. -// Where x is a sized border type. -// DANGEROUS -#define TRANSFORM_REF_SIZED(x, y) \ - y &trans(x &l) { return ref_as(l._data_ref()); } \ - y const &trans(x const &l) \ - { \ - return ref_as(l._data_ref_const()); \ - } \ - y *trans(x *l) { return ptr_as(&(l->_data_ref())); } \ - y const *trans(x const *l) \ - { \ - return ptr_as(&(l->_data_ref_const())); \ - } - -// Creates 8 functions for transformation of refereces between types x and y. -// Where both x and y are templates over T. Where x is a border type. -// DANGEROUS -#define TRANSFORM_REF_TEMPLATED(x, y) \ - x &trans(y &l) { return ref_as(l); } \ - template \ - x const &trans(y const &l) \ - { \ - return ref_as(l); \ - } \ - template \ - y &trans(x &l) \ - { \ - return ref_as(l); \ - } \ - template \ - y const &trans(x const &l) \ - { \ - return ref_as(l); \ - } \ - template \ - x *trans(y *l) \ - { \ - return ptr_as(l); \ - } \ - template \ - const x *trans(const y *l) \ - { \ - return ptr_as(l); \ - } \ - template \ - y *trans(x *l) \ - { \ - return ptr_as(l); \ - } \ - template \ - const y *trans(const x *l) \ - { \ - return ptr_as(l); \ - } - -// For certain classes trans evaluates into ref which doesnt work for Sized -// constructor. This Move forces type y. -// DANGEROUS -#define MOVE_CONSTRUCTOR_FORCED(x, y) \ - x::x(x &&other) : Sized(value_as(std::move(other))) {} - -// Creates constructor x(y) where x is border type and y shpuld be his original -// type. -// DANGEROUS -#define VALID_CONSTRUCTION(x, y) \ - template <> \ - barrier::x::x(y &&d) : Sized(std::move(d)) \ - { \ - } - -// Creates const constructor x(y) where x is border type and y shpuld be his -// original type. -// DANGEROUS -#define VALID_CONSTRUCTION_CONST(x, y) \ - template <> \ - barrier::x::x(y const &&d) : Sized(std::move(d)) \ - { \ - } - -// Creates value transformation function from original type y to border type x. -// DANGEROUS -#define TRANSFORM_VALUE_ONE_RAW(x, y) \ - x trans(y &&d) { return x(std::move(d)); } - -// Creates value transformation function and constructor from original type y to -// border type x. -// DANGEROUS -#define TRANSFORM_VALUE_ONE(x, y) \ - VALID_CONSTRUCTION(x, y) \ - x trans(y &&d) { return x(std::move(d)); } - -// Creates value transformation functions and constructor between border type x -// and original type y. Only mutable values. -// DANGEROUS -#define TRANSFORM_VALUE_MUT(x, y) \ - TRANSFORM_VALUE_ONE(x, y) \ - y trans(x &&d) { return value_as(std::move(d)); } - -// Creates value transformation functions and constructors between border type x -// and original type y. -// DANGEROUS -#define TRANSFORM_VALUE(x, y) \ - TRANSFORM_VALUE_MUT(x, y) \ - VALID_CONSTRUCTION_CONST(x, y) \ - const x trans(const y &&d) { return x(std::move(d)); } \ - const y trans(const x &&d) { return value_as(std::move(d)); } - -// Duplicates given x to call y with x and ::x -#define DUP(x, y) y(x, ::x) - -// ********************** TYPES OF AUTO -using vertex_access_iterator_t = - decltype(((::DbAccessor *)(std::nullptr_t()))->vertex_access()); - -using edge_access_iterator_t = - decltype(((::DbAccessor *)(std::nullptr_t()))->edge_access()); - -using out_edge_iterator_t = - decltype(((::VertexAccessor *)(std::nullptr_t()))->out()); - -using in_edge_iterator_t = - decltype(((::VertexAccessor *)(std::nullptr_t()))->in()); - -// ******************** OVERLOADED trans FUNCTIONS. -// This enclosure is the only dangerous part of barrier except of Sized class in -// common.hpp -namespace barrier -{ -// Blueprint for valid transformation of references: -// TRANSFORM_REF(, ::); -// template TRANSFORM_REF_TEMPLATED(,::); -// TODO: Strongest assurance that evertyhing is correct is for all of following -// transformation to use DUP for defining theres transformation. This would mean -// that names of classes exported in barrier and names from real class in -// database are equal. - -// ***************** TRANSFORMS of reference and pointers -DUP(Label, TRANSFORM_REF); -DUP(EdgeType, TRANSFORM_REF); -DUP(VertexPropertyFamily, TRANSFORM_REF); -DUP(EdgePropertyFamily, TRANSFORM_REF); -DUP(VertexAccessor, TRANSFORM_REF); -DUP(EdgeAccessor, TRANSFORM_REF); -DUP(Db, TRANSFORM_REF); -DUP(DbAccessor, TRANSFORM_REF); -TRANSFORM_REF(std::vector, std::vector<::label_ref_t>); -TRANSFORM_REF(VertexPropertyKey, - ::VertexPropertyFamily::PropertyType::PropertyFamilyKey); -TRANSFORM_REF(EdgePropertyKey, - ::EdgePropertyFamily::PropertyType::PropertyFamilyKey); -TRANSFORM_REF(VertexStoredProperty, ::StoredProperty); -TRANSFORM_REF(EdgeStoredProperty, ::StoredProperty); - -// ITERATORS -TRANSFORM_REF(VertexIterator, ::iter::Virtual); -TRANSFORM_REF(EdgeIterator, ::iter::Virtual); -TRANSFORM_REF(VertexAccessIterator, vertex_access_iterator_t); -TRANSFORM_REF(EdgeAccessIterator, edge_access_iterator_t); -TRANSFORM_REF(OutEdgesIterator, out_edge_iterator_t); -TRANSFORM_REF(InEdgesIterator, in_edge_iterator_t); - -template -TRANSFORM_REF_TEMPLATED(VertexIndex, VertexIndexBase); -template -TRANSFORM_REF_TEMPLATED(EdgeIndex, EdgeIndexBase); -template -TRANSFORM_REF_TEMPLATED(RecordStream, ::bolt::RecordStream); - -template -TRANSFORM_REF_TEMPLATED( - VertexPropertyType, - ::VertexPropertyFamily::PropertyType::PropertyTypeKey); - -template -TRANSFORM_REF_TEMPLATED(EdgePropertyType, - ::EdgePropertyFamily::PropertyType::PropertyTypeKey); - -// ****************** TRANSFORMS of value -// Blueprint for valid transformation of value: -// TRANSFORM_VALUE(, ::); -DUP(VertexAccessor, TRANSFORM_VALUE); -DUP(EdgeAccessor, TRANSFORM_VALUE); -TRANSFORM_VALUE(EdgePropertyKey, - ::EdgePropertyFamily::PropertyType::PropertyFamilyKey); -TRANSFORM_VALUE(VertexPropertyKey, - ::VertexPropertyFamily::PropertyType::PropertyFamilyKey); -TRANSFORM_VALUE_ONE(VertexAccessIterator, vertex_access_iterator_t); -MOVE_CONSTRUCTOR_FORCED(VertexAccessIterator, vertex_access_iterator_t); -TRANSFORM_VALUE_ONE(EdgeAccessIterator, edge_access_iterator_t); -MOVE_CONSTRUCTOR_FORCED(EdgeAccessIterator, edge_access_iterator_t); -TRANSFORM_VALUE_ONE(OutEdgesIterator, out_edge_iterator_t); -MOVE_CONSTRUCTOR_FORCED(OutEdgesIterator, out_edge_iterator_t); -TRANSFORM_VALUE_ONE(InEdgesIterator, in_edge_iterator_t); -MOVE_CONSTRUCTOR_FORCED(InEdgesIterator, in_edge_iterator_t); -TRANSFORM_VALUE_ONE(VertexIterator, ::iter::Virtual); -MOVE_CONSTRUCTOR_FORCED(VertexIterator, - ::iter::Virtual); -TRANSFORM_VALUE_ONE(EdgeIterator, ::iter::Virtual); -MOVE_CONSTRUCTOR_FORCED(EdgeIterator, ::iter::Virtual); - -template -TRANSFORM_VALUE_ONE_RAW( - VertexPropertyType, - ::VertexPropertyFamily::PropertyType::PropertyTypeKey); -template -TRANSFORM_VALUE_ONE_RAW(EdgePropertyType, - ::EdgePropertyFamily::PropertyType::PropertyTypeKey) - -template -TRANSFORM_VALUE_ONE_RAW(RecordStream, ::bolt::RecordStream) - -// ********************* SPECIAL CONSTRUCTORS -#define VertexPropertyType_constructor(x) \ - template <> \ - template <> \ - VertexPropertyType::VertexPropertyType( \ - ::VertexPropertyFamily::PropertyType::PropertyTypeKey &&d) \ - : Sized(std::move(d)) \ - { \ - } -INSTANTIATE_FOR_PROPERTY(VertexPropertyType_constructor); - -#define EdgePropertyType_constructor(x) \ - template <> \ - template <> \ - EdgePropertyType::EdgePropertyType( \ - ::EdgePropertyFamily::PropertyType::PropertyTypeKey &&d) \ - : Sized(std::move(d)) \ - { \ - } -INSTANTIATE_FOR_PROPERTY(EdgePropertyType_constructor); - -DbAccessor::DbAccessor(Db &db) : Sized(::DbAccessor(trans(db))) {} -} - -#endif diff --git a/include/communication/bolt/v1/serialization/record_stream.hpp b/include/communication/bolt/v1/serialization/record_stream.hpp index 25b51acd3..8e9cdca5e 100644 --- a/include/communication/bolt/v1/serialization/record_stream.hpp +++ b/include/communication/bolt/v1/serialization/record_stream.hpp @@ -105,10 +105,32 @@ public: serializer.write_failure(data); chunk(); } - // -- BOLT SPECIFIC METHODS ----------------------------------------------- + + void write_count(const size_t count) + { + write_record(); + write_list_header(1); + write(Int64(count)); + chunk(); + } void write(const VertexAccessor &vertex) { serializer.write(vertex); } + void write_vertex_record(const VertexAccessor& va) + { + write_record(); + write_list_header(1); + write(va); + chunk(); + } + void write(const EdgeAccessor &edge) { serializer.write(edge); } + void write_edge_record(const EdgeAccessor& ea) + { + write_record(); + write_list_header(1); + write(ea); + chunk(); + } void write(const StoredProperty &prop) { diff --git a/include/config/config.hpp b/include/config/config.hpp index 0fb9e42cb..fb15307f3 100644 --- a/include/config/config.hpp +++ b/include/config/config.hpp @@ -20,8 +20,6 @@ public: // -- all possible Memgraph's keys -- constexpr const char *COMPILE_CPU_PATH = "compile_cpu_path"; constexpr const char *TEMPLATE_CPU_CPP_PATH = "template_cpu_cpp_path"; -constexpr const char *BARRIER_TEMPLATE_CPU_CPP_PATH = - "barrier_template_cpu_cpp_path"; constexpr const char *SNAPSHOTS_PATH = "snapshots_path"; constexpr const char *CLEANING_CYCLE_SEC = "cleaning_cycle_sec"; constexpr const char *SNAPSHOT_CYCLE_SEC = "snapshot_cycle_sec"; diff --git a/include/database/db_accessor.hpp b/include/database/db_accessor.hpp index f24acdd49..e3afbbdb1 100644 --- a/include/database/db_accessor.hpp +++ b/include/database/db_accessor.hpp @@ -49,9 +49,11 @@ class DbAccessor public: DbAccessor(Db &db); - DbAccessor(Db &db, tx::Transaction &t); + DbAccessor(const DbAccessor& other) = delete; + DbAccessor(DbAccessor&& other) = delete; + //*******************VERTEX METHODS // Returns iterator of VertexAccessor for all vertices. // TODO: Implement class specaily for this return @@ -140,6 +142,7 @@ public: .template type_key(); } + bool update_indexes(); // ******************** TRANSACTION METHODS // True if commit was successful, or false if transaction was aborted. diff --git a/include/database/db_transaction.hpp b/include/database/db_transaction.hpp index 355cf94eb..f0f7806d1 100644 --- a/include/database/db_transaction.hpp +++ b/include/database/db_transaction.hpp @@ -1,5 +1,6 @@ #pragma once +#include "logging/loggable.hpp" #include "storage/indexes/index_update.hpp" #include "transactions/transaction.hpp" @@ -13,13 +14,19 @@ using index_updates_t = std::vector; // its methods. // Also serves as a barrier for calling methods defined public but meant for // internal use. That kind of method should request DbTransaction&. -class DbTransaction +class DbTransaction : public Loggable { friend DbAccessor; public: DbTransaction(Db &db); - DbTransaction(Db &db, tx::Transaction &trans) : db(db), trans(trans) {} + DbTransaction(Db &db, tx::Transaction &trans) + : Loggable("DbTransaction"), db(db), trans(trans) + { + } + + DbTransaction(const DbTransaction& other) = delete; + DbTransaction(DbTransaction&& other) = default; // Global transactional algorithms,operations and general methods meant for // internal use should be here or should be routed through this object. @@ -48,14 +55,9 @@ public: // with call update_indexes template void to_update_index(typename TG::vlist_t *vlist, - typename TG::record_t *record) - { - index_updates.push_back(make_index_update(vlist, record)); - } + typename TG::record_t *record); index_updates_t index_updates; - - tx::Transaction &trans; - Db &db; + tx::Transaction &trans; }; diff --git a/include/logging/loggable.hpp b/include/logging/loggable.hpp index 15b7d985e..42b7a42ea 100644 --- a/include/logging/loggable.hpp +++ b/include/logging/loggable.hpp @@ -5,7 +5,10 @@ class Loggable { public: - Loggable(const std::string& name) : logger(logging::log->logger(name)) {} + Loggable(std::string &&name) + : logger(logging::log->logger(std::forward(name))) + { + } virtual ~Loggable() {} diff --git a/include/logging/logger.hpp b/include/logging/logger.hpp index 49c50864a..90f0a66c9 100644 --- a/include/logging/logger.hpp +++ b/include/logging/logger.hpp @@ -76,8 +76,10 @@ public: template void debug(Args&&... args) { +#ifndef NDEBUG #ifndef LOG_NO_DEBUG emit(std::forward(args)...); +#endif #endif } diff --git a/include/query/backend/cpp_old/cypher.hpp b/include/query/backend/cpp_old/cypher.hpp index 938c08554..18da45286 100644 --- a/include/query/backend/cpp_old/cypher.hpp +++ b/include/query/backend/cpp_old/cypher.hpp @@ -14,13 +14,8 @@ class CypherBackend public: CypherBackend() : logger(logging::log->logger("CypherBackend")) { -// load template file -#ifdef BARRIER - std::string template_path = - CONFIG(config::BARRIER_TEMPLATE_CPU_CPP_PATH); -#else + // load template file std::string template_path = CONFIG(config::TEMPLATE_CPU_CPP_PATH); -#endif template_text = utils::read_text(fs::path(template_path)); } @@ -46,11 +41,7 @@ public: template_text.str(), {{"class_name", "CodeCPU"}, {"stripped_hash", std::to_string(stripped_hash)}, {"query", query}, -#ifdef BARRIER - {"stream", "RecordStream<::io::Socket>"}, -#else {"stream", type_name().to_string()}, -#endif {"code", cpp_traverser.code}}); logger.trace("generated code: {}", generated); diff --git a/include/query/hardcode/dressipi.hpp b/include/query/hardcode/dressipi.hpp deleted file mode 100644 index 3c489de59..000000000 --- a/include/query/hardcode/dressipi.hpp +++ /dev/null @@ -1,123 +0,0 @@ -#pragma once - -#include "includes.hpp" - -namespace hardcode -{ - -// TODO: decouple hashes from the code because hashes could and should be -// tested separately - -auto load_dressipi_functions(Db &db) -{ - query_functions_t functions; - - // Query: CREATE (n {garment_id: 1234, garment_category_id: 1}) RETURN n - // Hash: 12139093029838549530 - functions[12139093029838549530u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: CREATE (p:profile {profile_id: 111, partner_id: 55}) RETURN p - // Hash: 17158428452166262783 - functions[17158428452166262783u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (g:garment {garment_id: 1234}) SET g:FF RETURN labels(g) - // Hash: 11123780635391515946 - functions[11123780635391515946u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g:garment{garment_id: 1234}) SET s.score = 1550 RETURN s.score - // Hash: 674581607834128909 - functions[674581607834128909u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (g:garment {garment_id: 3456}) SET g.reveals = 50 RETURN g - // Hash: 2839969099736071844 - functions[2839969099736071844u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MERGE (g1:garment {garment_id: 1234})-[r:default_outfit]-(g2:garment {garment_id: 2345}) RETURN r - // Hash: 3782642357973971504 - functions[3782642357973971504u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MERGE (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g.garment {garment_id: 1234}) SET s.score=1500 RETURN s - // Hash: 7871009397157280694 - functions[7871009397157280694u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g.garment {garment_id: 1234}) DELETE s - // Hash: 9459600951073026137 - functions[9459600951073026137u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (p:profile {profile_id: 113}) DELETE p - // Hash: 6763665709953344106 - functions[6763665709953344106u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (n) DETACH DELETE n - // Hash: 4798158026600988079 - functions[4798158026600988079u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (p:profile) RETURN p - // Hash: 15599970964909894866 - functions[15599970964909894866u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (g:garment) RETURN COUNT(g) - // Hash: 11458306387621940265 - functions[11458306387621940265u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (g:garment {garment_id: 1234}) RETURN g - // Hash: 7756609649964321221 - functions[7756609649964321221u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (p:profile {partner_id: 55}) RETURN p - // Hash: 17506488413143988006 - functions[17506488413143988006u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - // Query: MATCH (n) RETURN count(n) - // Hash: 10510787599699014973 - functions[10510787599699014973u] = [&db](properties_t &&args) { - DbAccessor t(db); - return t.commit(); - }; - - return functions; -} - -} diff --git a/include/query/hardcode/includes.hpp b/include/query/hardcode/includes.hpp deleted file mode 100644 index c755f8d92..000000000 --- a/include/query/hardcode/includes.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "communication/bolt/v1/serialization/bolt_serializer.hpp" -#include "communication/bolt/v1/serialization/record_stream.hpp" -#include "database/db.hpp" -#include "database/db.hpp" -#include "database/db_accessor.hpp" -#include "database/db_accessor.hpp" -#include "io/network/socket.hpp" -#include "mvcc/id.hpp" -#include "query/util.hpp" -#include "storage/edge_type/edge_type.hpp" -#include "storage/edge_x_vertex.hpp" -#include "storage/indexes/index_definition.hpp" -#include "storage/label/label.hpp" -#include "storage/model/properties/all.hpp" -#include "storage/model/properties/property.hpp" -#include "utils/border.hpp" -#include "utils/iterator/iterator.hpp" -#include "utils/iterator/iterator.hpp" -#include "utils/option_ptr.hpp" -#include "utils/reference_wrapper.hpp" - -using namespace std; - -namespace hardcode -{ -using query_functions_t = - std::map>; -} diff --git a/include/query/i_plan_cpu.hpp b/include/query/i_plan_cpu.hpp index 395bd7108..0e2fbfa9e 100644 --- a/include/query/i_plan_cpu.hpp +++ b/include/query/i_plan_cpu.hpp @@ -1,25 +1,15 @@ #pragma once -#include "query/strip/stripped.hpp" - -#ifdef BARRIER -#include "barrier/barrier.hpp" -#include "io/network/socket.hpp" -#else #include "communication/communication.hpp" #include "database/db.hpp" #include "database/db_accessor.hpp" -#endif +#include "query/strip/stripped.hpp" template class IPlanCPU { public: -#ifdef BARRIER - virtual bool run(barrier::Db &db, plan_args_t &args, Stream &stream) = 0; -#else virtual bool run(Db &db, plan_args_t &args, Stream &stream) = 0; -#endif virtual ~IPlanCPU() {} }; diff --git a/include/query/language/cypher/visitor/traverser.hpp b/include/query/language/cypher/visitor/traverser.hpp index 619211572..708410548 100644 --- a/include/query/language/cypher/visitor/traverser.hpp +++ b/include/query/language/cypher/visitor/traverser.hpp @@ -6,7 +6,6 @@ class Traverser : public ast::AstVisitor { public: - using uptr = std::unique_ptr; using sptr = std::shared_ptr; diff --git a/include/query/plan/program_executor.hpp b/include/query/plan/program_executor.hpp index 8a00828e8..38537afc4 100644 --- a/include/query/plan/program_executor.hpp +++ b/include/query/plan/program_executor.hpp @@ -12,14 +12,6 @@ // execution // postprocess the results -// BARRIER! -#ifdef BARRIER -namespace barrier -{ -Db &trans(::Db &ref); -} -#endif - template class ProgramExecutor { @@ -29,13 +21,7 @@ public: auto execute(QueryProgram &program, Db &db, Stream &stream) { try { -// TODO: return result of query/code exection -#ifdef BARRIER - return program.plan->run(barrier::trans(db), - program.stripped.arguments, stream); -#else return program.plan->run(db, program.stripped.arguments, stream); -#endif // TODO: catch more exceptions } catch (...) { throw PlanExecutionException(""); diff --git a/include/query/plan/program_loader.hpp b/include/query/plan/program_loader.hpp index 513289d0c..7e5e77530 100644 --- a/include/query/plan/program_loader.hpp +++ b/include/query/plan/program_loader.hpp @@ -80,6 +80,7 @@ private: // TODO ifdef MEMGRAPH64 problem, how to use this kind // of ifdef functions? // uint64_t depends on fnv function + // TODO: faster datastructure std::unordered_map code_libs; QueryPreprocessor preprocessor; diff --git a/include/query/util.hpp b/include/query/util.hpp index b7294dc21..2452be573 100644 --- a/include/query/util.hpp +++ b/include/query/util.hpp @@ -9,32 +9,17 @@ #include "logging/default.hpp" #include "storage/model/properties/properties.hpp" #include "storage/model/properties/property.hpp" -#include "storage/model/properties/traversers/consolewriter.hpp" -#include "storage/model/properties/traversers/jsonwriter.hpp" +#include "storage/model/properties/json_writer.hpp" #include "utils/types/byte.hpp" #include "utils/exceptions/basic_exception.hpp" using std::cout; using std::endl; -template -void print_props(const Properties &properties); - -#ifdef NDEBUG -#define PRINT_PROPS(_) -#else -#define PRINT_PROPS(_PROPS_) print_props(_PROPS_); -#endif - -template -void cout_properties(const Properties &properties); - -template -void cout_property(const StoredProperty &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 +// but sometimes that might be a problem namespace { @@ -61,9 +46,9 @@ std::string code_line(const std::string &format_str, const Args &... args) } using name_properties_t = std::vector>; +using indices_t = std::map; -auto query_properties(const std::map &indices, - properties_t &values) +auto query_properties(indices_t &indices, properties_t &values) { name_properties_t properties; for (auto &property_index : indices) { diff --git a/include/storage/edge.hpp b/include/storage/edge.hpp index ca0cddc45..5bff367d1 100644 --- a/include/storage/edge.hpp +++ b/include/storage/edge.hpp @@ -2,9 +2,15 @@ #include "mvcc/record.hpp" #include "storage/model/edge_model.hpp" +#include "utils/string_buffer.hpp" +#include "storage/model/properties/json_writer.hpp" +#include "utils/handle_write.hpp" class Edge : public mvcc::Record { + using buffer_t = utils::StringBuffer; + using props_writer_t = JsonWriter; + public: class Accessor; @@ -19,4 +25,14 @@ public: Edge &operator=(Edge &&) = delete; EdgeModel data; + + template + void stream_repr(Stream &stream) const + { + auto props = handle_write(data.props); + + stream << "Edge(cre = " << tx.cre() << ", " + << "exp = " << tx.exp() << ", " + << "props = " << props.str() << ")"; + } }; diff --git a/include/storage/edge_accessor.hpp b/include/storage/edge_accessor.hpp index 197cf378d..40e0eee24 100644 --- a/include/storage/edge_accessor.hpp +++ b/include/storage/edge_accessor.hpp @@ -19,8 +19,9 @@ class EdgeAccessor : public RecordAccessor public: using RecordAccessor::RecordAccessor; - typedef Edge record_t; - typedef EdgeRecord record_list_t; + + using record_t = Edge; + using record_list_t = EdgeRecord; // Removes self and disconects vertices from it. void remove() const; @@ -34,4 +35,21 @@ public: // EdgeAccessor doesnt need to be filled VertexAccessor to() const; + + template + void stream_repr(Stream& stream) const + { + auto from_va = from(); + auto to_va = to(); + + from_va.fill(); + to_va.fill(); + + from_va.stream_repr(stream); + stream << '-'; + this->record->stream_repr(stream); + stream << "->"; + to_va.stream_repr(stream); + stream << '\n'; + } }; diff --git a/include/storage/edge_x_vertex.hpp b/include/storage/edge_x_vertex.hpp index 382fe4a0c..0bdde5d30 100644 --- a/include/storage/edge_x_vertex.hpp +++ b/include/storage/edge_x_vertex.hpp @@ -8,6 +8,8 @@ auto VertexAccessor::out() const { DbTransaction &t = this->db; + std::cout << "VA OUT" << std::endl; + std::cout << record->data.out.size() << std::endl; return iter::make_map(iter::make_iter_ref(record->data.out), [&](auto e) -> auto { return EdgeAccessor(*e, t); }); } diff --git a/include/storage/indexes/index_base.hpp b/include/storage/indexes/index_base.hpp index cbe12503a..9ce62918b 100644 --- a/include/storage/indexes/index_base.hpp +++ b/include/storage/indexes/index_base.hpp @@ -7,6 +7,7 @@ #include "mvcc/id.hpp" // #include "storage/indexes/index_record.hpp" +#include "logging/loggable.hpp" #include "storage/garbage/delete_sensitive.hpp" #include "storage/indexes/index_definition.hpp" #include "utils/border.hpp" @@ -26,13 +27,14 @@ class Transaction; // TG type group // K type of key on which records are ordered template -class IndexBase : public DeleteSensitive +class IndexBase : public DeleteSensitive, public Loggable { public: // Created with the database - IndexBase(IndexDefinition &&it); + IndexBase(IndexDefinition &&it, std::string &&logger_name = "IndexBase"); - IndexBase(IndexDefinition &&it, const tx::Transaction &t); + IndexBase(IndexDefinition &&it, const tx::Transaction &t, + std::string &&logger_name = "IndexBase"); virtual ~IndexBase(){}; @@ -70,6 +72,9 @@ public: const IndexDefinition &definition() const { return it; } +protected: + Logger logger; + private: const IndexDefinition it; // Id of transaction which created this index. diff --git a/include/storage/label/label_collection.hpp b/include/storage/label/label_collection.hpp index 831578da4..564c29392 100644 --- a/include/storage/label/label_collection.hpp +++ b/include/storage/label/label_collection.hpp @@ -2,7 +2,6 @@ #include -// #include "storage/label/label.hpp" #include "utils/reference_wrapper.hpp" class Label; @@ -11,13 +10,13 @@ using label_ref_t = ReferenceWrapper; class LabelCollection { public: - auto begin() { return _labels.begin(); } - auto begin() const { return _labels.begin(); } - auto cbegin() const { return _labels.begin(); } + auto begin() { return labels_.begin(); } + auto begin() const { return labels_.begin(); } + auto cbegin() const { return labels_.begin(); } - auto end() { return _labels.end(); } - auto end() const { return _labels.end(); } - auto cend() const { return _labels.end(); } + auto end() { return labels_.end(); } + auto end() const { return labels_.end(); } + auto cend() const { return labels_.end(); } bool add(const Label &label); bool has(const Label &label) const; @@ -26,6 +25,13 @@ public: void clear(); const std::vector &operator()() const; + template + void handle(Handler &handler) const + { + for (auto &label : labels_) + handler.handle(label.get()); + } + private: - std::vector _labels; + std::vector labels_; }; diff --git a/include/storage/label/labels_writer.hpp b/include/storage/label/labels_writer.hpp new file mode 100644 index 000000000..a495bae81 --- /dev/null +++ b/include/storage/label/labels_writer.hpp @@ -0,0 +1,15 @@ +#pragma once + +class Label; + +template +class LabelsWriter +{ +public: + LabelsWriter(Buffer &buffer) : buffer_(buffer) {} + + void handle(const Label& label); + +private: + Buffer& buffer_; +}; diff --git a/include/storage/model/edge_list.hpp b/include/storage/model/edge_list.hpp index cf139a4e5..15703beef 100644 --- a/include/storage/model/edge_list.hpp +++ b/include/storage/model/edge_list.hpp @@ -16,7 +16,7 @@ public: auto end() const { return edges.end(); } auto cend() const { return edges.end(); } - void add(EdgeRecord *edge) { edges.push_back(edge); } + void add(EdgeRecord *edge) { edges.emplace_back(edge); } size_t degree() const { return edges.size(); } diff --git a/include/storage/model/properties/traversers/jsonwriter.hpp b/include/storage/model/properties/json_writer.hpp similarity index 81% rename from include/storage/model/properties/traversers/jsonwriter.hpp rename to include/storage/model/properties/json_writer.hpp index 486e6bdf4..1f2d07369 100644 --- a/include/storage/model/properties/traversers/jsonwriter.hpp +++ b/include/storage/model/properties/json_writer.hpp @@ -70,30 +70,3 @@ private: bool first{true}; Buffer &buffer; }; - -class StringBuffer -{ -public: - StringBuffer &operator<<(const std::string &str) - { - data += str; - return *this; - } - - StringBuffer &operator<<(const char *str) - { - data += str; - return *this; - } - - StringBuffer &operator<<(char c) - { - data += c; - return *this; - } - - std::string &str() { return data; } - -private: - std::string data; -}; diff --git a/include/storage/model/properties/traversers/consolewriter.hpp b/include/storage/model/properties/traversers/consolewriter.hpp deleted file mode 100644 index 09a7e08aa..000000000 --- a/include/storage/model/properties/traversers/consolewriter.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include - -#include "storage/model/properties/properties.hpp" -#include "storage/type_group_edge.hpp" -#include "storage/type_group_vertex.hpp" - -using std::cout; -using std::endl; - -class ConsoleWriter -{ -public: - ConsoleWriter() {} - - void handle(const StoredProperty &value) - { - handle(value); - } - - void handle(const StoredProperty &value) - { - handle(value); - } - - template - void handle(StoredProperty const &value) - { - cout << "KEY: " << value.key.family_name() << "; VALUE: "; - - value.accept(*this); - - // value.accept(*this); - - cout << endl; - } - - void handle(const Null &v) { cout << "NULL"; } - - void handle(const Bool &b) { cout << b; } - - void handle(const String &s) { cout << s; } - - void handle(const Int32 &int32) { cout << int32; } - - void handle(const Int64 &int64) { cout << int64; } - - void handle(const Float &f) { cout << f; } - - void handle(const Double &d) { cout << d; } - - // Not yet implemented - void handle(const ArrayBool &) { assert(false); } - - // Not yet implemented - void handle(const ArrayInt32 &) { assert(false); } - - // Not yet implemented - void handle(const ArrayInt64 &) { assert(false); } - - // Not yet implemented - void handle(const ArrayFloat &) { assert(false); } - - // Not yet implemented - void handle(const ArrayDouble &) { assert(false); } - - // Not yet implemented - void handle(const ArrayString &) { assert(false); } - - void finish() {} -}; diff --git a/include/storage/vertex.hpp b/include/storage/vertex.hpp index 14d5b2d17..309cd5af9 100644 --- a/include/storage/vertex.hpp +++ b/include/storage/vertex.hpp @@ -1,11 +1,18 @@ #pragma once #include "mvcc/record.hpp" -#include "storage/model/properties/traversers/jsonwriter.hpp" +#include "storage/label/labels_writer.hpp" +#include "storage/model/properties/json_writer.hpp" #include "storage/model/vertex_model.hpp" +#include "utils/handle_write.hpp" +#include "utils/string_buffer.hpp" class Vertex : public mvcc::Record { + using buffer_t = utils::StringBuffer; + using props_writer_t = JsonWriter; + using labels_writer_t = LabelsWriter; + public: class Accessor; @@ -14,24 +21,22 @@ public: Vertex(VertexModel &&data) : data(std::move(data)) {} Vertex(const Vertex &) = delete; - Vertex(Vertex &&) = delete; + Vertex(Vertex &&) = delete; Vertex &operator=(const Vertex &) = delete; Vertex &operator=(Vertex &&) = delete; VertexModel data; + + template + void stream_repr(Stream &stream) const + { + auto props = handle_write(data.props); + auto labels = handle_write(data.labels); + + stream << "Vertex(cre = " << tx.cre() << ", " + << "exp = " << tx.exp() << ", " + << "props = " << props.str() << ", " + << "labels = " << labels.str() << ")"; + } }; - -inline std::ostream &operator<<(std::ostream &stream, const Vertex &record) -{ - StringBuffer buffer; - JsonWriter writer(buffer); - - // dump properties in this buffer - record.data.props.handle(writer); - writer.finish(); - - return stream << "Vertex" - << "(cre = " << record.tx.cre() - << ", exp = " << record.tx.exp() << "): " << buffer.str(); -} diff --git a/include/storage/vertex_accessor.hpp b/include/storage/vertex_accessor.hpp index 60b6247bc..13d39380a 100644 --- a/include/storage/vertex_accessor.hpp +++ b/include/storage/vertex_accessor.hpp @@ -1,5 +1,6 @@ #pragma once +#include "storage/label/label_collection.hpp" #include "storage/record_accessor.hpp" #include "storage/vertex.hpp" #include "utils/iterator/iterator.hpp" @@ -15,7 +16,7 @@ class VertexAccessor : public RecordAccessor public: using RecordAccessor::RecordAccessor; - using record_t = Vertex; + using record_t = Vertex; using record_list_t = VertexRecord; // Removes self and all edges connected to it. @@ -51,4 +52,14 @@ public: // True if there exists edge between other vertex and this vertex. bool in_contains(VertexAccessor const &other) const; + + template + void stream_repr(Stream& stream) const + { + if (this->record != nullptr) + this->record->stream_repr(stream); + else + std::cout << "TRACE: record is nullptr" << std::endl; + + } }; diff --git a/include/transactions/transaction_read.hpp b/include/transactions/transaction_read.hpp index 4eef554a6..8897f8744 100644 --- a/include/transactions/transaction_read.hpp +++ b/include/transactions/transaction_read.hpp @@ -1,4 +1,3 @@ - #pragma once #include diff --git a/include/query/exception/out_of_memory.hpp b/include/utils/exceptions/out_of_memory.hpp similarity index 100% rename from include/query/exception/out_of_memory.hpp rename to include/utils/exceptions/out_of_memory.hpp diff --git a/include/utils/handle_write.hpp b/include/utils/handle_write.hpp new file mode 100644 index 000000000..f815df959 --- /dev/null +++ b/include/utils/handle_write.hpp @@ -0,0 +1,16 @@ +#pragma once + +/* + * Source object is going to be traversed by Writer and Writer will + * write that data into the Destination object. + * + * Writer object defines write format. + */ +template +Destination handle_write(const Source& source) +{ + Destination destination; + Writer writter(destination); + source.handle(writter); + return destination; +} diff --git a/include/utils/iterator/combined.hpp b/include/utils/iterator/combined.hpp index adb3aa73b..a9b2a6355 100644 --- a/include/utils/iterator/combined.hpp +++ b/include/utils/iterator/combined.hpp @@ -6,7 +6,8 @@ namespace iter { -// Class which Combined two iterators IT1 and IT2. Both return values T +// Class which Combined two iterators IT1 and IT2. +// Both return values T // T - type of return value // IT1 - first iterator type // IT2 - second iterator type diff --git a/include/utils/iterator/composable.hpp b/include/utils/iterator/composable.hpp index be3394ec0..b1a1aac74 100644 --- a/include/utils/iterator/composable.hpp +++ b/include/utils/iterator/composable.hpp @@ -116,6 +116,12 @@ public: move(), [](auto vr) { return vr.out().fill(); }); } + auto in() + { + return iter::make_flat_map( + move(), [](auto vr) { return vr.in().fill(); }); + } + // Filters with label on from vertex. template auto from_label(LABEL const &label) @@ -153,6 +159,12 @@ public: move(), [&](auto &v) mutable { t = Option(v); }); } + // auto clone_to(Option &t) + // { + // return iter::make_inspect( + // move(), [&](auto &e) mutable { t = Option(e); }); + // } + // Filters with call to method fill() auto fill() { diff --git a/include/utils/iterator/inspect.hpp b/include/utils/iterator/inspect.hpp index 73c30088f..88c7745ae 100644 --- a/include/utils/iterator/inspect.hpp +++ b/include/utils/iterator/inspect.hpp @@ -6,27 +6,31 @@ namespace iter { -// Class which inspects values returned by I iterator before passing thenm as -// result. +// Class which inspects values returned by I iterator +// before passing them as a result. // function. // T - type of return value // I - iterator type // OP - type of inspector function. OP: T&->void template -class Inspect : public IteratorBase, public Composable> +class Inspect : public IteratorBase, + public Composable> { - public: Inspect() = delete; - // Inspect operation is designed to be used in chained calls which operate - // on a - // iterator. Inspect will in that usecase receive other iterator by value - // and + // Inspect operation is designed to be used + // in chained calls which operate on an + // iterator. Inspect will in that usecase + // receive other iterator by value and // std::move is a optimization for it. - Inspect(I &&iter, OP &&op) : iter(std::move(iter)), op(std::move(op)) {} + Inspect(I &&iter, OP &&op) : + iter(std::move(iter)), + op(std::move(op)) + {} - Inspect(Inspect &&m) : iter(std::move(m.iter)), op(std::move(m.op)) {} + Inspect(Inspect &&m) : + iter(std::move(m.iter)), op(std::move(m.op)) {} ~Inspect() final {} @@ -52,7 +56,7 @@ template auto make_inspect(I &&iter, OP &&op) { // Compiler cant deduce type T. decltype is here to help with it. - return Inspect(std::move(iter), - std::move(op)); + return Inspect + (std::move(iter), std::move(op)); } } diff --git a/include/utils/memory/stack_allocator.hpp b/include/utils/memory/stack_allocator.hpp index 40b6bf014..f69f565b3 100644 --- a/include/utils/memory/stack_allocator.hpp +++ b/include/utils/memory/stack_allocator.hpp @@ -1,7 +1,8 @@ #pragma once #include -#include "query_engine/exceptions/exceptions.hpp" + +#include "utils/exceptions/out_of_memory.hpp" #include "utils/memory/block_allocator.hpp" // http://en.cppreference.com/w/cpp/language/new @@ -24,7 +25,8 @@ public: // until it eats all the memory. static_assert(sizeof(T) <= page_size, "Cant allocate objects larger than page_size"); - do { + do + { // Mask which has log2(alignof(T)) lower bits setted to 0 and the // rest to 1. // example: @@ -56,7 +58,8 @@ public: // If the new_head is greater than end that means that there isn't // enough space for object T in current block of memory. - if (LIKELY(new_head <= end)) { + if (LIKELY(new_head <= end)) + { // All is fine, head can become new_head head = new_head; @@ -99,7 +102,8 @@ public: // Relases all memory. void free() { - while (allocated_blocks.size() > 0) { + while (allocated_blocks.size() > 0) + { blocks.release(allocated_blocks.back()); allocated_blocks.pop_back(); } @@ -109,5 +113,5 @@ private: BlockAllocator blocks; std::vector allocated_blocks; char *head = {nullptr}; - char *end = {nullptr}; + char *end = {nullptr}; }; diff --git a/include/utils/option.hpp b/include/utils/option.hpp index a1a1eb47a..409c9b2b3 100644 --- a/include/utils/option.hpp +++ b/include/utils/option.hpp @@ -5,7 +5,8 @@ #include #include -// Optional object storage. It maybe has and maybe dosent have objet of type T. +// Optional object storage. It maybe has and maybe +// dosent have objet of type T. template class Option { @@ -33,12 +34,14 @@ public: std::memset(data._M_addr(), 0, sizeof(T)); } } - // Containers from std which have strong exception guarantees wont use move - // constructors and operators wihtout noexcept. "Optimized C++,2016 , Kurt - // Guntheroth, page: 142, title: Moving instances into std::vector" + + // Containers from std which have strong exception + // guarantees wont use move constructors and operators + // wihtout noexcept. "Optimized C++,2016 , Kurt + // Guntheroth, page: 142, title: Moving instances into + // std::vector" Option(Option &&other) noexcept { - if (other.initialized) { new (data._M_addr()) T(std::move(other.get())); other.initialized = false; @@ -69,6 +72,7 @@ public: return *this; } + Option &operator=(Option &&other) { if (initialized) { @@ -180,8 +184,9 @@ public: explicit operator bool() const { return initialized; } private: - // Aligned buffer is here to ensure aligment for data of type T. It isn't - // applicable to just put T field because the field has to be able to be + // Aligned buffer is here to ensure aligment for + // data of type T. It isn't applicable to just put T + // field because the field has to be able to be // uninitialized to fulfill the semantics of Option class. __gnu_cxx::__aligned_buffer data; bool initialized = false; diff --git a/include/utils/string_buffer.hpp b/include/utils/string_buffer.hpp new file mode 100644 index 000000000..90303c632 --- /dev/null +++ b/include/utils/string_buffer.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include + +namespace utils +{ + +class StringBuffer +{ +public: + StringBuffer &operator<<(const std::string &str) + { + data += str; + return *this; + } + + StringBuffer &operator<<(const char *str) + { + data += str; + return *this; + } + + StringBuffer &operator<<(char c) + { + data += c; + return *this; + } + + std::string &str() { return data; } + +private: + std::string data; +}; + +} diff --git a/poc/astar.cpp b/poc/astar.cpp index cdcf1576a..477b9a00d 100644 --- a/poc/astar.cpp +++ b/poc/astar.cpp @@ -9,11 +9,11 @@ #include #include +#include "communication/bolt/v1/serialization/bolt_serializer.hpp" #include "data_structures/map/rh_hashmap.hpp" #include "database/db.hpp" #include "database/db_accessor.cpp" #include "database/db_accessor.hpp" - #include "import/csv_import.hpp" #include "logging/default.hpp" #include "logging/streams/stdout.hpp" @@ -23,8 +23,6 @@ #include "storage/indexes/impl/nonunique_unordered_index.cpp" #include "storage/model/properties/properties.cpp" #include "storage/record_accessor.cpp" -// #include "storage/vertex_accessor.cpp" -#include "communication/bolt/v1/serialization/bolt_serializer.hpp" #include "storage/vertex_accessor.hpp" #include "storage/vertices.cpp" #include "storage/vertices.hpp" @@ -60,9 +58,10 @@ public: double sum_vertex_score() { - auto now = this; + auto now = this; double sum = 0; - do { + do + { sum += (now->vacc.at(tkey).get())->value(); now = now->parent; } while (now != nullptr); @@ -84,8 +83,11 @@ void found_result(Node *res) std::cout << "{score: " << sum << endl; auto bef = res; - while (bef != nullptr) { - std::cout << " " << *(bef->vacc.operator->()) << endl; + while (bef != nullptr) + { + std::cout << " "; + bef->vacc.operator->()->stream_repr(std::cout); + std::cout << std::endl; bef = bef->parent; } } @@ -113,18 +115,23 @@ bool vertex_filter_dummy(DbAccessor &t, VertexAccessor &va, Node *before) bool vertex_filter_contained_dummy(DbAccessor &t, VertexAccessor &v, Node *before) { - if (v.fill()) { + if (v.fill()) + { bool found; - do { - found = false; + do + { + found = false; before = before->parent; - if (before == nullptr) { + if (before == nullptr) + { return true; } auto it = before->vacc.out(); - for (auto e = it.next(); e.is_present(); e = it.next()) { + for (auto e = it.next(); e.is_present(); e = it.next()) + { VertexAccessor va = e.get().to(); - if (va == v) { + if (va == v) + { found = true; break; } @@ -136,12 +143,15 @@ bool vertex_filter_contained_dummy(DbAccessor &t, VertexAccessor &v, bool vertex_filter_contained(DbAccessor &t, VertexAccessor &v, Node *before) { - if (v.fill()) { + if (v.fill()) + { bool found; - do { - found = false; + do + { + found = false; before = before->parent; - if (before == nullptr) { + if (before == nullptr) + { return true; } } while (v.in_contains(before->vacc)); @@ -163,7 +173,9 @@ auto a_star( DbAccessor t(db); type_key_t type_key = - t.vertex_property_family_get("score").get(Flags::Double).type_key(); + t.vertex_property_family_get("score") + .get(Flags::Double) + .type_key(); auto best_found = new std::map[max_depth]; @@ -177,17 +189,20 @@ auto a_star( Node *start = new Node(start_vr.take(), 0, type_key); queue.push(start); int count = 0; - do { + do + { auto now = queue.top(); queue.pop(); // if(!visited.insert(now)){ // continue; // } - if (max_depth <= now->depth) { + if (max_depth <= now->depth) + { best.push_back(now); count++; - if (count >= limit) { + if (count >= limit) + { return best; } continue; @@ -202,11 +217,13 @@ auto a_star( // } iter::for_all(now->vacc.out(), [&](auto edge) { - if (e_filter[now->depth](t, edge, now)) { + if (e_filter[now->depth](t, edge, now)) + { VertexAccessor va = edge.to(); - if (v_filter[now->depth](t, va, now)) { + if (v_filter[now->depth](t, va, now)) + { auto cost = calc_heuristic_cost(type_key, edge, va); - Node *n = new Node(va, now->cost + cost, now, type_key); + Node *n = new Node(va, now->cost + cost, now, type_key); queue.push(n); } } @@ -238,15 +255,16 @@ int main(int argc, char **argv) // CONF std::srand(time(0)); - auto best_n = 10; - auto bench_n = 1000; + auto best_n = 10; + auto bench_n = 1000; auto best_print_n = 10; bool pick_best_found = strcmp(get_argument(para, "-p", "true").c_str(), "true") == 0; double sum = 0; std::vector best; - for (int i = 0; i < bench_n; i++) { + for (int i = 0; i < bench_n; i++) + { auto start_vertex_index = std::rand() % loaded.first; auto begin = clock(); @@ -260,12 +278,14 @@ int main(int argc, char **argv) if ((best.size() < best_print_n && found.size() > best.size()) || (pick_best_found && found.size() > 0 && found.front()->sum_vertex_score() > - best.front()->sum_vertex_score())) { + best.front()->sum_vertex_score())) + { best = found; } // Just to be safe - if (i + 1 == bench_n && best.size() == 0) { + if (i + 1 == bench_n && best.size() == 0) + { bench_n++; } } @@ -274,7 +294,8 @@ int main(int argc, char **argv) << " results has runing time of:\n avg: " << sum / bench_n << " [ms]\n"; std::cout << "\nExample of best result:\n"; - for (int i = 0; i < best_print_n && best.size() > 0; i++) { + for (int i = 0; i < best_print_n && best.size() > 0; i++) + { found_result(best.front()); best.erase(best.begin()); } @@ -292,7 +313,8 @@ void add_scores(Db &db) int i = 1; iter::for_all(t.vertex_access(), [&](auto v) { - if (v.fill()) { + if (v.fill()) + { // any random number is OK std::srand(i ^ 0x7482616); v.set(StoredProperty( diff --git a/poc/astar_query.cpp b/poc/astar_query.cpp index 7543d7d1f..925848a95 100644 --- a/poc/astar_query.cpp +++ b/poc/astar_query.cpp @@ -1,7 +1,3 @@ -#include "queries/astar.cpp" - -#include "barrier/barrier.cpp" - #include #include #include @@ -21,6 +17,7 @@ #include "import/csv_import.hpp" #include "logging/default.hpp" #include "logging/streams/stdout.hpp" +#include "queries/astar.hpp" #include "storage/edge_x_vertex.hpp" #include "storage/edges.cpp" #include "storage/edges.hpp" @@ -41,21 +38,23 @@ int main(int argc, char **argv) auto para = all_arguments(argc, argv); Db db("astar"); - barrier::CodeCPU cp; + PlanCPU plan; int bench_n = 1000; - do { + do + { double sum = 0; - for (int i = 0; i < bench_n; i++) { + for (int i = 0; i < bench_n; i++) + { auto start_vertex_index = std::rand() % db.graph.vertices.access().size(); auto begin = clock(); - code_args_t args; + plan_args_t args; args.push_back(Property(Int64(start_vertex_index), Int64::type)); - cp.run(barrier::trans(db), args, std::cout); + plan.run(db, args, std::cout); clock_t end = clock(); @@ -63,7 +62,7 @@ int main(int argc, char **argv) sum += elapsed_ms; } - std::cout << "\nSearch for best " << barrier::limit + std::cout << "\nSearch for best " << limit << " results has runing time of:\n avg: " << sum / bench_n << " [ms]\n"; } while (true); diff --git a/poc/profile.cpp b/poc/profile.cpp index 9245feb7f..11bc4f447 100644 --- a/poc/profile.cpp +++ b/poc/profile.cpp @@ -4,9 +4,6 @@ #include #include -// TODO: remove barrier -#include "barrier/barrier.cpp" - #include "database/db.hpp" #include "database/db_accessor.hpp" #include "communication/bolt/v1/serialization/bolt_serializer.hpp" @@ -20,7 +17,7 @@ using namespace std; // (company, {type_name, score}) using company_profile_type = - pair>; + pair>; // Accepted flags for CSV import. // -db name # will create database with that name. @@ -44,7 +41,7 @@ int main(int argc, char **argv) // query benchmark auto begin = clock(); - int n = for_all_companys(barrier::trans(t), company_profiles); + int n = for_all_companys(t, company_profiles); clock_t end = clock(); double elapsed_s = (double(end - begin) / CLOCKS_PER_SEC); @@ -71,8 +68,8 @@ int main(int argc, char **argv) for (auto &company_profile : company_profiles) { auto prop_vertex_id = t.vertex_property_key("company_id"); auto db_company_id = - *barrier::trans(company_profile.first).at(prop_vertex_id).get(); - if (db_company_id == company_id) { + company_profile.first.at(prop_vertex_id).get(); + if (db_company_id->value() == company_id) { cout << endl << "CompanyID: " << company_id << endl; for (auto e : company_profile.second) { cout << e.first << " = " << e.second << endl; diff --git a/poc/profile.hpp b/poc/profile.hpp index 0c7efd8e7..cd781163a 100644 --- a/poc/profile.hpp +++ b/poc/profile.hpp @@ -8,13 +8,10 @@ #include #include -#include "barrier/barrier.hpp" +#include "storage/edge_x_vertex.hpp" using namespace std; -namespace barrier -{ - // TODO: Turn next template, expand on it, standardize it, and use it for query // generation. @@ -334,10 +331,9 @@ size_t for_all_companys( int i = 0; iter::for_all_fill( t.label_find_or_create("Company").index().for_range(t), [&](auto v) { - coll.push_back(make_pair(v, barrier::query(t, v.id()))); + coll.push_back(make_pair(v, query(t, v.id()))); i++; return false; }); return i; } -} diff --git a/poc/queries/astar.cpp b/poc/queries/astar.hpp similarity index 72% rename from poc/queries/astar.cpp rename to poc/queries/astar.hpp index 03f1930f6..4e6a04fc8 100644 --- a/poc/queries/astar.cpp +++ b/poc/queries/astar.hpp @@ -3,8 +3,10 @@ #include #include -#include "query/i_code_cpu.hpp" +#include "query/i_plan_cpu.hpp" #include "storage/model/properties/all.hpp" +#include "storage/vertex_accessor.hpp" +#include "storage/edge_x_vertex.hpp" #include "utils/memory/stack_allocator.hpp" using std::cout; @@ -12,15 +14,10 @@ using std::endl; // Dressipi astar query of 4 clicks. -// BARRIER! -namespace barrier -{ - -using STREAM = std::ostream; -// using STREAM = RecordStream<::io::Socket>; +using Stream = std::ostream; constexpr size_t max_depth = 3; -constexpr size_t limit = 10; +constexpr size_t limit = 10; class Node { @@ -45,9 +42,10 @@ public: double sum_vertex_score() { - auto now = this; + auto now = this; double sum = 0; - do { + do + { sum += (now->vacc.at(tkey).get())->value(); now = now->parent; } while (now != nullptr); @@ -57,12 +55,15 @@ public: bool vertex_filter_contained(DbAccessor &t, VertexAccessor &v, Node *before) { - if (v.fill()) { + if (v.fill()) + { bool found; - do { - found = false; + do + { + found = false; before = before->parent; - if (before == nullptr) { + if (before == nullptr) + { return true; } } while (v.in_contains(before->vacc)); @@ -70,7 +71,7 @@ bool vertex_filter_contained(DbAccessor &t, VertexAccessor &v, Node *before) return false; } -void astar(DbAccessor &t, code_args_t &args, STREAM &stream) +void astar(DbAccessor &t, plan_args_t &args, Stream &stream) { StackAllocator stack; VertexPropertyType tkey = t.vertex_property_key("score"); @@ -79,7 +80,8 @@ void astar(DbAccessor &t, code_args_t &args, STREAM &stream) std::priority_queue, decltype(cmp)> queue(cmp); auto start_vr = t.vertex_find(Id(args[0].as().value())); - if (!start_vr.is_present()) { + if (!start_vr.is_present()) + { // stream.write_failure({{}}); return; } @@ -89,15 +91,18 @@ void astar(DbAccessor &t, code_args_t &args, STREAM &stream) queue.push(start); int count = 0; - do { + do + { auto now = queue.top(); queue.pop(); - if (max_depth <= now->depth) { + if (max_depth <= now->depth) + { // stream.write_success_empty(); // best.push_back(now); count++; - if (count >= limit) { + if (count >= limit) + { break; } continue; @@ -105,9 +110,10 @@ void astar(DbAccessor &t, code_args_t &args, STREAM &stream) iter::for_all(now->vacc.out(), [&](auto edge) { VertexAccessor va = edge.to(); - if (vertex_filter_contained(t, va, now)) { + if (vertex_filter_contained(t, va, now)) + { auto cost = 1 - va.at(tkey).get()->value(); - Node *n = new (stack.allocate()) + Node *n = new (stack.allocate()) Node(va, now->cost + cost, now, tkey); queue.push(n); } @@ -117,10 +123,10 @@ void astar(DbAccessor &t, code_args_t &args, STREAM &stream) stack.free(); } -class CodeCPU : public ICodeCPU +class PlanCPU : public IPlanCPU { public: - bool run(Db &db, code_args_t &args, STREAM &stream) override + bool run(Db &db, plan_args_t &args, Stream &stream) override { DbAccessor t(db); @@ -129,14 +135,9 @@ public: return t.commit(); } - ~CodeCPU() {} + ~PlanCPU() {} }; -} -extern "C" ICodeCPU *produce() -{ - // BARRIER! - return new barrier::CodeCPU(); -} +extern "C" IPlanCPU *produce() { return new PlanCPU(); } -extern "C" void destruct(ICodeCPU *p) { delete p; } +extern "C" void destruct(IPlanCPU *p) { delete p; } diff --git a/poc/size_aligment.cpp b/poc/size_aligment.cpp index d4151328a..eee45fc23 100644 --- a/poc/size_aligment.cpp +++ b/poc/size_aligment.cpp @@ -11,8 +11,6 @@ #include "storage/edge_x_vertex.hpp" #include "storage/indexes/impl/nonunique_unordered_index.cpp" #include "storage/model/properties/properties.cpp" -// #include "storage/record_accessor.cpp" -// #include "storage/vertex_accessor.cpp" #include "utils/command_line/arguments.hpp" using namespace std; diff --git a/release/barrier.dockerfile b/release/barrier.dockerfile deleted file mode 100644 index 17bac8105..000000000 --- a/release/barrier.dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM ubuntu:16.04 - -RUN apt-get update \ - && apt-get install -y clang libssl-dev \ - && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -RUN mkdir -p /libs - -ENV BINARY_NAME memgraph_414_dba2610_dev_debug - -COPY barrier_$BINARY_NAME /memgraph -COPY libs/fmt /libs/fmt - -WORKDIR /memgraph - -CMD ./$BINARY_NAME diff --git a/release/barrier.sh b/release/barrier.sh deleted file mode 100755 index aa939d8af..000000000 --- a/release/barrier.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash - -binary_name=$1 - -cd .. - -release_folder="barrier_$binary_name" -release_path="release/$release_folder" -compile_template_path="template/barrier_template_code_cpu.cpp" - -mkdir -p $release_path/compiled/cpu - -mkdir -p $release_path/include/barrier -mkdir -p $release_path/include/query/strip -mkdir -p $release_path/include/query/exception -mkdir -p $release_path/include/io/network -mkdir -p $release_path/include/logging -mkdir -p $release_path/include/mvcc -mkdir -p $release_path/include/storage/indexes -mkdir -p $release_path/include/storage/model/properties/traversers -mkdir -p $release_path/include/storage/model/properties/utils -mkdir -p $release_path/include/utils/datetime -mkdir -p $release_path/include/utils/exceptions -mkdir -p $release_path/include/utils/iterator -mkdir -p $release_path/include/utils/memory -mkdir -p $release_path/include/utils/numerics - -mkdir -p $release_path/template - -# COPY -# dressipi query -# TODO: for loop -# hardcoded_queries="135757557963690525.cpp" -# for query in $hardcoded_queries -# do -# cp build/compiled/cpu/hardcode/$query $release_path/compiled/cpu/hardcode/$query -# done - -cp src/query_engine/$compile_template_path $release_path/$compile_template_path - -paths="barrier/barrier.hpp barrier/common.hpp storage/model/properties/floating.hpp storage/model/properties/all.hpp storage/model/properties/bool.hpp storage/model/properties/traversers/consolewriter.hpp storage/model/properties/traversers/jsonwriter.hpp storage/model/properties/array.hpp storage/model/properties/property_family.hpp storage/model/properties/property.hpp storage/model/properties/properties.hpp storage/model/properties/integral.hpp storage/model/properties/double.hpp storage/model/properties/string.hpp storage/model/properties/utils/math_operations.hpp storage/model/properties/utils/unary_negation.hpp storage/model/properties/utils/modulo.hpp storage/model/properties/property_holder.hpp storage/model/properties/float.hpp storage/model/properties/null.hpp storage/model/properties/flags.hpp storage/model/properties/int32.hpp storage/model/properties/number.hpp storage/model/properties/int64.hpp logging/default.hpp logging/log.hpp logging/logger.hpp logging/levels.hpp io/network/addrinfo.hpp io/network/network_error.hpp io/network/socket.hpp mvcc/id.hpp utils/exceptions/basic_exception.hpp utils/border.hpp utils/total_ordering.hpp utils/auto_scope.hpp utils/crtp.hpp utils/order.hpp utils/likely.hpp utils/option.hpp utils/option_ptr.hpp utils/memory/block_allocator.hpp utils/memory/stack_allocator.hpp utils/iterator/query.hpp utils/iterator/composable.hpp utils/iterator/for_all.hpp utils/iterator/range_iterator.hpp utils/iterator/limited_map.hpp utils/iterator/iterator_accessor.hpp utils/iterator/count.hpp utils/iterator/iterator_base.hpp utils/iterator/filter.hpp utils/iterator/inspect.hpp utils/iterator/accessor.hpp utils/iterator/map.hpp utils/iterator/virtual_iter.hpp utils/iterator/flat_map.hpp utils/iterator/combined.hpp utils/iterator/lambda_iterator.hpp utils/iterator/iterator.hpp utils/array_store.hpp utils/void.hpp storage/indexes/index_definition.hpp utils/stacktrace.hpp utils/datetime/datetime_error.hpp utils/datetime/timestamp.hpp utils/reference_wrapper.hpp utils/underlying_cast.hpp utils/numerics/saturate.hpp query/i_plan_cpu.hpp query/property_util.hpp query/strip/stripped.hpp query/exception/cpp_code_generator.hpp query/exception/decoder_exception.hpp query/exception/out_of_memory.hpp query/exception/plan_compilation.hpp query/exception/plan_execution.hpp query/exception/query_engine.hpp" - -for path in $paths -do - cp include/$path $release_path/include/$path -done - -cp config/memgraph.yaml $release_path/config.yaml - -cp build/$binary_name $release_path/$binary_name -cp build/libmemgraph_pic.a $release_path/libmemgraph_pic.a -cp build/libbarrier_pic.a $release_path/libbarrier_pic.a - -echo "DONE" diff --git a/src/barrier/barrier.cpp b/src/barrier/barrier.cpp deleted file mode 100644 index 052d04447..000000000 --- a/src/barrier/barrier.cpp +++ /dev/null @@ -1,766 +0,0 @@ -#include "barrier/trans.hpp" - -// ************************* Implementations -// This file should contain all implementations of methods from barrier classes -// defined in barrier.hpp. -// Implementations should follow the form: -// border_return_type border_class::method_name(arguments){ -// return -// CALL(method_name(trans(arguments))) -// or -// HALF_CALL(method_name(trans(arguments))); -// } - -// **************************** HELPER DEFINES *******************************// -// returns transformed this pointer -#define THIS (trans(this)) -// In border class performs call x on original class. -#define HALF_CALL(x) (THIS->x) -// In border class performs call x on original class and produces transformed -// output. -#define CALL(x) trans(HALF_CALL(x)) - -// Creates destructor for border type x which is original type y. -#define DESTRUCTOR(x, y) \ - x::~x() { HALF_CALL(~y()); } - -// Creates copy constructor for mutable ref to border class x which is original -// class y. -#define COPY_CONSTRUCTOR_MUT(x, y) \ - x::x(x &other) : Sized(y(trans(other))) {} - -// Creates copy constructor for const ref to border class x which is original -// class y. -#define COPY_CONSTRUCTOR(x, y) \ - x::x(const x &other) : Sized(y(trans(other))) {} - -// Creates move constructor for mutable border type x. -#define MOVE_CONSTRUCTOR(x) \ - x::x(x &&other) : Sized(trans(std::move(other))) {} - -// Creates move constructor for const border type x. -#define MOVE_CONST_CONSTRUCTOR(x) \ - x::x(x const &&other) : Sized(trans(std::move(other))) {} - -// Creates copy operator for border type x. -#define COPY_OPERATOR(x) \ - x &x::operator=(const x &other) \ - { \ - HALF_CALL(operator=(trans(other))); \ - return *this; \ - } - -// Creates move operator for border type x. -#define MOVE_OPERATOR(x) \ - x &x::operator=(x &&other) \ - { \ - HALF_CALL(operator=(trans(std::move(other)))); \ - return *this; \ - } - -namespace barrier -{ - -// ***************** Label -VertexIndex &Label::index() const { return CALL(index()); } - -// **************** EdgeType -bool operator<(const EdgeType &lhs, const EdgeType &rhs) -{ - return trans(lhs) < trans(rhs); -} - -bool operator==(const EdgeType &lhs, const EdgeType &rhs) -{ - return trans(lhs) == trans(rhs); -} - -EdgeIndex &EdgeType::index() const { return CALL(index()); } - -// **************** VertexIndex -template -VertexIterator VertexIndex::for_range(DbAccessor &t, Border from, - Border to) -{ - return CALL(for_range(trans(t), std::move(from), std::move(to))); -} - -template -IndexType VertexIndex::type() -{ - return HALF_CALL(type()); -} - -// INSTANCES OF VERTEX INDEX -template class VertexIndex; - -// **************** EdgeIndex -template -EdgeIterator EdgeIndex::for_range(DbAccessor &t, Border from, - Border to) -{ - return CALL(for_range(trans(t), std::move(from), std::move(to))); -} - -template -IndexType EdgeIndex::type() -{ - return HALF_CALL(type()); -} - -// INSTANCES OF EDGE INDEX -template class EdgeIndex; - -// ************************* DbAccessor -DESTRUCTOR(DbAccessor, DbAccessor); - -VertexAccessIterator DbAccessor::vertex_access() -{ - return CALL(vertex_access()); -} - -Option DbAccessor::vertex_find(const Id &id) -{ - return HALF_CALL(vertex_find(id)).map(); -} - -VertexAccessor DbAccessor::vertex_insert() { return CALL(vertex_insert()); } - -EdgeAccessIterator DbAccessor::edge_access() { return CALL(edge_access()); } - -Option DbAccessor::edge_find(const Id &id) -{ - return HALF_CALL(edge_find(id)).map(); -} - -EdgeAccessor DbAccessor::edge_insert(VertexAccessor const &from, - VertexAccessor const &to) -{ - return CALL(edge_insert(trans(from), trans(to))); -} - -const Label &DbAccessor::label_find_or_create(const char *name) -{ - return CALL(label_find_or_create(name)); -} - -bool DbAccessor::label_contains(const char *name) -{ - return HALF_CALL(label_contains(name)); -} - -const EdgeType &DbAccessor::type_find_or_create(const char *name) -{ - return CALL(type_find_or_create(name)); -} - -bool DbAccessor::type_contains(const char *name) -{ - return HALF_CALL(type_contains(name)); -} - -VertexPropertyFamily & -DbAccessor::vertex_property_family_get(const std::string &name) -{ - return CALL(vertex_property_family_get(name)); -} - -EdgePropertyFamily & -DbAccessor::edge_property_family_get(const std::string &name) -{ - return CALL(edge_property_family_get(name)); -} - -VertexPropertyKey DbAccessor::vertex_property_key(const std::string &name, - Type type) -{ - return CALL(vertex_property_key(name, type)); -} - -EdgePropertyKey DbAccessor::edge_property_key(const std::string &name, - Type type) -{ - return CALL(edge_property_key(name, type)); -} - -template -VertexPropertyType DbAccessor::vertex_property_key(const std::string &name) -{ - return CALL(vertex_property_key(name)); -} -#define DbAccessor_vertex_property_key(x) \ - template VertexPropertyType DbAccessor::vertex_property_key( \ - const std::string &name); -INSTANTIATE_FOR_PROPERTY(DbAccessor_vertex_property_key) - -template -EdgePropertyType DbAccessor::edge_property_key(const std::string &name) -{ - return CALL(edge_property_key(name)); -} -#define DbAccessor_edge_property_key(x) \ - template EdgePropertyType DbAccessor::edge_property_key( \ - const std::string &name); -INSTANTIATE_FOR_PROPERTY(DbAccessor_edge_property_key) - -bool DbAccessor::commit() { return HALF_CALL(commit()); } -void DbAccessor::abort() { HALF_CALL(abort()); } - -// ************************** VertexAccessor -DUP(VertexAccessor, COPY_CONSTRUCTOR); -DUP(VertexAccessor, COPY_CONSTRUCTOR_MUT); -MOVE_CONSTRUCTOR(VertexAccessor); -MOVE_CONST_CONSTRUCTOR(VertexAccessor); -DESTRUCTOR(VertexAccessor, VertexAccessor); -COPY_OPERATOR(VertexAccessor); -MOVE_OPERATOR(VertexAccessor); - -bool VertexAccessor::isolated() const { return HALF_CALL(isolated()); } - -size_t VertexAccessor::out_degree() const { return HALF_CALL(out_degree()); } - -size_t VertexAccessor::in_degree() const { return HALF_CALL(in_degree()); } - -size_t VertexAccessor::degree() const { return HALF_CALL(degree()); } - -bool VertexAccessor::add_label(const Label &label) -{ - return HALF_CALL(add_label(trans(label))); -} - -bool VertexAccessor::remove_label(const Label &label) -{ - return HALF_CALL(remove_label(trans(label))); -} - -bool VertexAccessor::has_label(const Label &label) const -{ - return HALF_CALL(has_label(trans(label))); -} - -const std::vector &VertexAccessor::labels() const -{ - return CALL(labels()); -} - -OutEdgesIterator VertexAccessor::out() const { return CALL(out()); } - -InEdgesIterator VertexAccessor::in() const { return CALL(in()); } - -bool VertexAccessor::in_contains(VertexAccessor const &other) const -{ - return HALF_CALL(in_contains(trans(other))); -} - -bool VertexAccessor::empty() const { return HALF_CALL(empty()); } - -bool VertexAccessor::fill() const { return HALF_CALL(fill()); } - -const Id &VertexAccessor::id() const { return HALF_CALL(id()); } - -VertexAccessor VertexAccessor::update() const { return CALL(update()); } - -void VertexAccessor::remove() const { HALF_CALL(remove()); } - -const VertexStoredProperty &VertexAccessor::at(VertexPropertyFamily &key) const -{ - return CALL(at(trans(key))); -} - -const VertexStoredProperty &VertexAccessor::at(VertexPropertyKey &key) const -{ - return CALL(at(trans(key))); -} - -// template -// bool VertexAccessor::contains(property_key &key) const -// { -// return HALF_CALL(contains(key)); -// } - -template -OptionPtr VertexAccessor::at(VertexPropertyType &key) const -{ - return HALF_CALL(at(trans(key))); -} -#define VertexAccessor_at(x) \ - template OptionPtr VertexAccessor::at(VertexPropertyType &key) \ - const; -INSTANTIATE_FOR_PROPERTY(VertexAccessor_at); - -void VertexAccessor::set(VertexPropertyKey &key, Property &&value) -{ - HALF_CALL(set(trans(key), std::move(value))); -} - -void VertexAccessor::clear(VertexPropertyKey &key) -{ - HALF_CALL(clear(trans(key))); -} - -void VertexAccessor::clear(VertexPropertyFamily &key) -{ - HALF_CALL(clear(trans(key))); -} - -// NOTE: I am not quite sure if this method will have any use -template -void VertexAccessor::accept(Handler &handler) const -{ - HALF_CALL(accept(handler)); -} - -VertexAccessor::operator bool() const { return HALF_CALL(operator bool()); } - -bool operator==(const VertexAccessor &a, const VertexAccessor &b) -{ - return trans(a) == trans(b); -} - -bool operator!=(const VertexAccessor &a, const VertexAccessor &b) -{ - return trans(a) != trans(b); -} - -// ************************** EdgeAccessor -DUP(EdgeAccessor, COPY_CONSTRUCTOR); -DUP(EdgeAccessor, COPY_CONSTRUCTOR_MUT); -MOVE_CONSTRUCTOR(EdgeAccessor); -MOVE_CONST_CONSTRUCTOR(EdgeAccessor); -DESTRUCTOR(EdgeAccessor, EdgeAccessor); -COPY_OPERATOR(EdgeAccessor); -MOVE_OPERATOR(EdgeAccessor); - -void EdgeAccessor::edge_type(const EdgeType &edge_type) -{ - HALF_CALL(edge_type(trans(edge_type))); -} - -const EdgeType &EdgeAccessor::edge_type() const { return CALL(edge_type()); } - -const VertexAccessor EdgeAccessor::from() const { return CALL(from()); } - -const VertexAccessor EdgeAccessor::to() const { return CALL(to()); } - -bool EdgeAccessor::empty() const { return HALF_CALL(empty()); } - -bool EdgeAccessor::fill() const { return HALF_CALL(fill()); } - -const Id &EdgeAccessor::id() const { return HALF_CALL(id()); } - -EdgeAccessor EdgeAccessor::update() const { return CALL(update()); } - -void EdgeAccessor::remove() const { HALF_CALL(remove()); } - -const EdgeStoredProperty &EdgeAccessor::at(EdgePropertyFamily &key) const -{ - return CALL(at(trans(key))); -} - -const EdgeStoredProperty &EdgeAccessor::at(EdgePropertyKey &key) const -{ - return CALL(at(trans(key))); -} - -template -OptionPtr EdgeAccessor::at(EdgePropertyType &key) const -{ - return HALF_CALL(at(trans(key))); -} -#define EdgeAccessor_at(x) \ - template OptionPtr EdgeAccessor::at(EdgePropertyType &key) \ - const; -INSTANTIATE_FOR_PROPERTY(EdgeAccessor_at); - -void EdgeAccessor::set(EdgePropertyKey &key, Property &&value) -{ - HALF_CALL(set(trans(key), std::move(value))); -} - -void EdgeAccessor::clear(EdgePropertyKey &key) { HALF_CALL(clear(trans(key))); } - -void EdgeAccessor::clear(EdgePropertyFamily &key) -{ - HALF_CALL(clear(trans(key))); -} - -// NOTE: I am not quite sure if this method will have any use -template -void EdgeAccessor::accept(Handler &handler) const -{ - HALF_CALL(accept(handler)); -} - -EdgeAccessor::operator bool() const { return HALF_CALL(operator bool()); } - -bool operator==(const EdgeAccessor &a, const EdgeAccessor &b) -{ - return trans(a) == trans(b); -} - -bool operator!=(const EdgeAccessor &a, const EdgeAccessor &b) -{ - return trans(a) != trans(b); -} - -// ************************* VertexIterator -DESTRUCTOR(VertexIterator, Virtual); - -Option VertexIterator::next() -{ - return HALF_CALL(next()).map(); -} - -Count VertexIterator::count() { return HALF_CALL(count()); } - -// ************************* EdgeIterator -DESTRUCTOR(EdgeIterator, Virtual); - -Option EdgeIterator::next() -{ - return HALF_CALL(next()).map(); -} - -Count EdgeIterator::count() { return HALF_CALL(count()); } - -// ************************* OutEdgesIterator -DESTRUCTOR(OutEdgesIterator, out_edge_iterator_t); - -Option OutEdgesIterator::next() -{ - return HALF_CALL(next()).map(); -} - -Count OutEdgesIterator::count() { return HALF_CALL(count()); } - -// ************************* InEdgesIterator -DESTRUCTOR(InEdgesIterator, in_edge_iterator_t); - -Option InEdgesIterator::next() -{ - return HALF_CALL(next()).map(); -} - -Count InEdgesIterator::count() { return HALF_CALL(count()); } - -// ************************* VertexAccessIterator -DESTRUCTOR(VertexAccessIterator, vertex_access_iterator_t); - -Option VertexAccessIterator::next() -{ - return HALF_CALL(next()).map(); -} - -Count VertexAccessIterator::count() { return HALF_CALL(count()); } - -// ************************* EdgeAccessIterator -DESTRUCTOR(EdgeAccessIterator, edge_access_iterator_t); - -Option EdgeAccessIterator::next() -{ - return HALF_CALL(next()).map(); -} - -Count EdgeAccessIterator::count() { return HALF_CALL(count()); } - -// ************************* VertexPropertyKey -DESTRUCTOR(VertexPropertyKey, PropertyFamilyKey); - -Type VertexPropertyKey::get_type() const { return HALF_CALL(get_type()); } - -// ************************* EdgePropertyKey -DESTRUCTOR(EdgePropertyKey, PropertyFamilyKey); - -Type EdgePropertyKey::get_type() const { return HALF_CALL(get_type()); } - -// ************************* VertexPropertyType -#define VERTEX_PROPERTY_TYPE(x) template class VertexPropertyType; -INSTANTIATE_FOR_PROPERTY(VERTEX_PROPERTY_TYPE) - -// ************************* VertexPropertyFamily -OptionPtr> VertexPropertyFamily::index() -{ - OptionPtr> ret = - THIS->index.get_read(); - if (ret.is_present()) { - return OptionPtr>(&trans(*ret.get())); - } else { - return OptionPtr>(); - } -} - -// ************************* VertexPropertyFamily -OptionPtr> EdgePropertyFamily::index() -{ - OptionPtr> ret = - THIS->index.get_read(); - if (ret.is_present()) { - return OptionPtr>(&trans(*ret.get())); - } else { - return OptionPtr>(); - } -} - -// ************************* BOLT SERIALIZER -template -RecordStream::~RecordStream() -{ - // TODO: solve this - // THIS->~RecordStream(); -} - -template -void RecordStream::write(const VertexAccessor &vertex) -{ - HALF_CALL(write(trans(vertex))); -} - -template -void RecordStream::write(const EdgeAccessor &edge) -{ - HALF_CALL(write(trans(edge))); -} - -template -void RecordStream::write(const VertexStoredProperty &prop) -{ - HALF_CALL(write(trans(prop))); -} - -template -void RecordStream::write(const EdgeStoredProperty &prop) -{ - HALF_CALL(write(trans(prop))); -} - -template -void RecordStream::write(const Null &v) -{ - HALF_CALL(write(v)); -} - -template -void RecordStream::write(const Bool &prop) -{ - HALF_CALL(write(prop)); -} - -template -void RecordStream::write(const Float &prop) -{ - HALF_CALL(write(prop)); -} - -template -void RecordStream::write(const Double &prop) -{ - HALF_CALL(write(prop)); -} - -template -void RecordStream::write(const Int32 &prop) -{ - HALF_CALL(write(prop)); -} - -template -void RecordStream::write(const Int64 &prop) -{ - HALF_CALL(write(prop)); -} - -template -void RecordStream::write(const String &value) -{ - HALF_CALL(write(value)); -} - -template -void RecordStream::write(const ArrayBool &arr) -{ - HALF_CALL(write(arr)); -} - -template -void RecordStream::write(const ArrayInt32 &arr) -{ - HALF_CALL(write(arr)); -} - -template -void RecordStream::write(const ArrayInt64 &arr) -{ - HALF_CALL(write(arr)); -} - -template -void RecordStream::write(const ArrayFloat &arr) -{ - HALF_CALL(write(arr)); -} - -template -void RecordStream::write(const ArrayDouble &arr) -{ - HALF_CALL(write(arr)); -} - -template -void RecordStream::write(const ArrayString &arr) -{ - HALF_CALL(write(arr)); -} - -template -void RecordStream::write_empty_fields() -{ - HALF_CALL(write_empty_fields()); -} - -template -void RecordStream::write_success() -{ - HALF_CALL(write_success()); -} - -template -void RecordStream::write_success_empty() -{ - HALF_CALL(write_success_empty()); -} - -template -void RecordStream::write_ignored() -{ - HALF_CALL(write_ignored()); -} - -template -void RecordStream::write_fields(const std::vector &fields) -{ - HALF_CALL(write_fields(fields)); -} - -template -void RecordStream::write_field(const std::string &field) -{ - HALF_CALL(write_field(field)); -} - -template -void RecordStream::write_list_header(size_t size) -{ - HALF_CALL(write_list_header(size)); -} - -template -void RecordStream::write_record() -{ - HALF_CALL(write_record()); -} - -template -void RecordStream::write_meta(const std::string &type) -{ - HALF_CALL(write_meta(type)); -} - -template -void RecordStream::write_failure( - const std::map &data) -{ - HALF_CALL(write_failure(data)); -} - -template -void RecordStream::send() -{ - HALF_CALL(send()); -} - -template -void RecordStream::chunk() -{ - HALF_CALL(chunk()); -} - -template class RecordStream; -} - -// **************************** ERROR EXAMPLES ****************************** // -// **************************** COMPILE TIME -/* -### error: -../libmemgraph.a(barrier.cpp.o): In function `Option Option::map()': -/home/ktf/Workspace/memgraph/include/utils/option.hpp:111: undefined reference -to `barrier::VertexAccessor::VertexAccessor(VertexAccessor -const&&)' - -# description: -Constructor VertexAccessor<::VertexAccessor const>(::VertexAccessor const&&) -isn't written. - - -### error: -../libmemgraph.a(barrier.cpp.o): In function `barrier::EdgeAccessor::from() -const': -/home/ktf/Workspace/memgraph/src/barrier/barrier.cpp:501: undefined reference to -`barrier::VertexAccessor::VertexAccessor(barrier::VertexAccessor const&&)' - -# description: -Move constructor VertexAccessor(VertexAccessor const&&) -isn't defined. - - -### error: -/home/ktf/Workspace/memgraph/src/barrier/barrier.cpp:282:12: error: call to -'trans' is ambiguous - return CALL(at(trans(key))); - ^~~~~~~~~~~~~~~~~~~~ -/home/ktf/Workspace/memgraph/src/barrier/barrier.cpp:18:17: note: expanded from -macro 'CALL' -#define CALL(x) trans(HALF_CALL(x)) - ^~~~~ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:208:21: note: candidate -function -DUP(VertexAccessor, TRANSFORM_VALUE); - ^ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:169:21: note: candidate -function -DUP(VertexAccessor, TRANSFORM_REF); - ^ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:170:19: note: candidate -function -DUP(EdgeAccessor, TRANSFORM_REF); - ^ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:174:1: note: candidate -function -TRANSFORM_REF(VertexPropertyKey, -^ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:25:14: note: expanded -from macro 'TRANSFORM_REF' - y const &trans(x const &l) { return ref_as(l); } \ - ^ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:176:1: note: candidate -function -TRANSFORM_REF(EdgePropertyKey, -^ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:25:14: note: expanded -from macro 'TRANSFORM_REF' - y const &trans(x const &l) { return ref_as(l); } \ - ^ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:182:1: note: candidate -function -TRANSFORM_REF(VertexIterator, ::iter::Virtual); -^ -/home/ktf/Workspace/memgraph/include/barrier/trans.hpp:23:14: note: expanded -from macro 'TRANSFORM_REF' - x const &trans(y const &l) { return ref_as(l); } \ -... - -# description: -There is no valid transformation for types on which trans is called. - -*/ diff --git a/src/database/db_accessor.cpp b/src/database/db_accessor.cpp index 8aff9c566..74e0a4025 100644 --- a/src/database/db_accessor.cpp +++ b/src/database/db_accessor.cpp @@ -3,12 +3,12 @@ #include "utils/iterator/iterator.hpp" DbAccessor::DbAccessor(Db &db) - : db_transaction(DbTransaction(db, db.tx_engine.begin())) + : db_transaction(std::move(DbTransaction(db, db.tx_engine.begin()))) { } DbAccessor::DbAccessor(Db &db, tx::Transaction &t) - : db_transaction(DbTransaction(db, t)) + : db_transaction(std::move(DbTransaction(db, t))) { } @@ -105,6 +105,11 @@ DbAccessor::edge_property_key(const std::string &name, Type type) return edge_property_family_get(name).get(type).family_key(); } +bool DbAccessor::update_indexes() +{ + return db_transaction.update_indexes(); +} + // TRANSACTION METHODS bool DbAccessor::commit() { diff --git a/src/database/db_transaction.cpp b/src/database/db_transaction.cpp index 1ac9e4f94..7c57fa1d3 100644 --- a/src/database/db_transaction.cpp +++ b/src/database/db_transaction.cpp @@ -9,18 +9,24 @@ #include "storage/vertex.hpp" #define TRY(x) \ - if (!x) { \ + if (!x) \ + { \ return false; \ } -DbTransaction::DbTransaction(Db &db) : db(db), trans(db.tx_engine.begin()) {} +DbTransaction::DbTransaction(Db &db) + : Loggable("DbTransaction"), db(db), trans(db.tx_engine.begin()) +{ +} // Cleaning for version lists template void clean_version_lists(A &&acc, Id oldest_active) { - for (auto &vlist : acc) { - if (vlist.second.gc_deleted(oldest_active)) { + for (auto &vlist : acc) + { + if (vlist.second.gc_deleted(oldest_active)) + { // TODO: Optimization, iterator with remove method. bool succ = acc.remove(vlist.first); assert(succ); // There is other cleaner here @@ -48,8 +54,7 @@ void DbTransaction::clean_vertex_section() Id oldest_active = trans.oldest_active(); // Clean indexes - db.indexes().vertex_indexes( - [&](auto &in) { in.clean(oldest_active); }); + db.indexes().vertex_indexes([&](auto &in) { in.clean(oldest_active); }); // Clean vertex list clean_version_lists(db.graph.vertices.access(), oldest_active); @@ -57,36 +62,58 @@ void DbTransaction::clean_vertex_section() bool DbTransaction::update_indexes() { - while (!index_updates.empty()) { - auto iu = index_updates.back(); + logger.debug("index_updates: {}, instance: {}, transaction: {}", + index_updates.size(), static_cast(this), trans.id); - if (iu.tag == IndexUpdate::EDGE) { - auto e = iu.e; + while (!index_updates.empty()) + { + auto index_update = index_updates.back(); + + if (index_update.tag == IndexUpdate::EDGE) + { + auto edge = index_update.e; // TODO: This could be done in batch // NOTE: This assumes that type index is created with the database. - TRY(e.record->data.edge_type->index().insert( - EdgeTypeIndexRecord(std::nullptr_t(), e.record, e.vlist))); + TRY(edge.record->data.edge_type->index().insert(EdgeTypeIndexRecord( + std::nullptr_t(), edge.record, edge.vlist))); - TRY(db.indexes().update_property_indexes( - e, trans)); + TRY(db.indexes().update_property_indexes(edge, + trans)); + } + else + { + auto vertex = index_update.v; - } else { - auto v = iu.v; - - for (auto l : v.record->data.labels()) { + for (auto label : vertex.record->data.labels()) + { // TODO: This could be done in batch // NOTE: This assumes that label index is created with the // database. - TRY(l.get().index().insert( - LabelIndexRecord(std::nullptr_t(), v.record, v.vlist))); + TRY(label.get().index().insert(LabelIndexRecord( + std::nullptr_t(), vertex.record, vertex.vlist))); } - TRY(db.indexes().update_property_indexes( - v, trans)); + TRY(db.indexes().update_property_indexes(vertex, + trans)); } index_updates.pop_back(); } return true; } + +template +void DbTransaction::to_update_index(typename TG::vlist_t *vlist, + typename TG::record_t *record) +{ + index_updates.emplace_back(make_index_update(vlist, record)); + logger.debug("update_index, updates_no: {}, instance: {}, transaction: {}", + index_updates.size(), static_cast(this), trans.id); +} + +template void DbTransaction::to_update_index( + TypeGroupVertex::vlist_t *vlist, TypeGroupVertex::record_t *record); +template void +DbTransaction::to_update_index(TypeGroupEdge::vlist_t *vlist, + TypeGroupEdge::record_t *record); diff --git a/src/dc/example/memsql.cpp b/src/dc/example/memsql.cpp deleted file mode 100644 index b8fa37ef4..000000000 --- a/src/dc/example/memsql.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "db.hpp" - -class memsql : public db -{ -public: - - void name() const override - { - cout << "MemSQL" << endl; - } - - void type() const override - { - cout << "InMemory" << endl; - } - - ~memsql() {} -}; - -extern "C" db* produce() -{ - return new memsql(); -} - -extern "C" void destruct(db* p) -{ - delete p; -} diff --git a/src/dc/example/mysql.cpp b/src/dc/example/mysql.cpp deleted file mode 100644 index 3b6c1bb2c..000000000 --- a/src/dc/example/mysql.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "db.hpp" - -class mysql : public db -{ -public: - - virtual void name() const - { - cout << "MySQL" << endl; - } - - virtual void type() const - { - cout << "Relational" << endl; - } - - ~mysql() {} -}; - -extern "C" db* produce() -{ - return new mysql(); -} - -extern "C" void destruct(db* p) -{ - delete p; -} diff --git a/src/logging/default.cpp b/src/logging/default.cpp index fe3bcf627..4b540673c 100644 --- a/src/logging/default.cpp +++ b/src/logging/default.cpp @@ -8,28 +8,9 @@ namespace logging { +// per object log source std::unique_ptr log; -std::unique_ptr debug_log = std::make_unique(); - -Logger init_debug_logger() -{ - debug_log->pipe(std::make_unique()); - return debug_log->logger("DEBUG"); -} - -Logger debug_logger = init_debug_logger(); - -std::unique_ptr info_log = std::make_unique(); - -Logger init_info_logger() -{ - info_log->pipe(std::make_unique()); - return info_log->logger("INFO"); -} - -Logger info_logger = init_info_logger(); - void init_async() { log = std::make_unique(); @@ -40,4 +21,26 @@ void init_sync() log = std::make_unique(); } +// "global" DEBUG logger +std::unique_ptr debug_log = std::make_unique(); + +Logger init_debug_logger() +{ + debug_log->pipe(std::make_unique()); + return debug_log->logger("DEBUG"); +} + +Logger debug_logger = init_debug_logger(); + +// "global" INFO logger +std::unique_ptr info_log = std::make_unique(); + +Logger init_info_logger() +{ + info_log->pipe(std::make_unique()); + return info_log->logger("INFO"); +} + +Logger info_logger = init_info_logger(); + } diff --git a/src/query_engine/template/barrier_template_code_cpu.cpp b/src/query_engine/template/barrier_template_code_cpu.cpp deleted file mode 100644 index 4a6ffe8f5..000000000 --- a/src/query_engine/template/barrier_template_code_cpu.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -#include "query/property_util.hpp" -#include "query/i_plan_cpu.hpp" -#include "storage/model/properties/all.hpp" - -using std::cout; -using std::endl; - -// query: {{query}} - -// BARRIER! -namespace barrier -{ - -class {{class_name}} : public IPlanCPU<{{stream}}> -{ -public: - - bool run(Db &db, plan_args_t &args, - {{stream}} &stream) override - { -{{code}} - } - - ~{{class_name}}() {} -}; - -} - - -extern "C" IPlanCPU* produce() -{ - // BARRIER! - return new barrier::{{class_name}}(); -} - -extern "C" void destruct(IPlanCPU* p) -{ - delete p; -} diff --git a/src/query_engine/util.cpp b/src/query_engine/util.cpp deleted file mode 100644 index 811f2762b..000000000 --- a/src/query_engine/util.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "query/util.hpp" - -#include "storage/type_group_edge.hpp" -#include "storage/type_group_vertex.hpp" - -template -void print_props(const Properties &properties) -{ - StringBuffer buffer; - JsonWriter writer(buffer); - properties.accept(writer); - cout << buffer.str() << endl; -} - -template -void cout_properties(const Properties &properties) -{ - ConsoleWriter writer; - properties.accept(writer); - cout << "----" << endl; -} - -template -void cout_property(const StoredProperty &property) -{ - ConsoleWriter writer; - property.accept(writer); - cout << "----" << endl; -} - -template void -print_props(const Properties &properties); - -template void -print_props(const Properties &properties); - -template void -cout_properties(const Properties &properties); - -template void -cout_properties(const Properties &properties); - -template void -cout_property(const StoredProperty &property); - -template void -cout_property(const StoredProperty &property); diff --git a/src/storage/edge_accessor.cpp b/src/storage/edge_accessor.cpp index d4d167422..c8267e91b 100644 --- a/src/storage/edge_accessor.cpp +++ b/src/storage/edge_accessor.cpp @@ -3,22 +3,20 @@ #include #include "storage/vertex_record.hpp" +#include "storage/edge_type/edge_type.hpp" void EdgeAccessor::remove() const { RecordAccessor::remove(); - auto from_v = from(); - bool f_from = from_v.fill(); - assert(f_from); + auto from_va = from(); + assert(from_va.fill()); - auto to_v = to(); - bool f_to = to_v.fill(); - assert(f_to); + auto to_va = to(); + assert(to_va.fill()); - // Detach edge from vertices. - from_v.update().record->data.out.remove(vlist); - to_v.update().record->data.in.remove(vlist); + from_va.update().record->data.out.remove(vlist); + to_va.update().record->data.in.remove(vlist); } void EdgeAccessor::edge_type(const EdgeType &edge_type) diff --git a/src/storage/indexes/impl/nonunique_unordered_index.cpp b/src/storage/indexes/impl/nonunique_unordered_index.cpp index b38a3d3c9..b4652131a 100644 --- a/src/storage/indexes/impl/nonunique_unordered_index.cpp +++ b/src/storage/indexes/impl/nonunique_unordered_index.cpp @@ -14,14 +14,16 @@ template NonUniqueUnorderedIndex::NonUniqueUnorderedIndex(IndexLocation &&loc) - : IndexBase(IndexDefinition{loc, IndexType{false, None}}) + : IndexBase(IndexDefinition{loc, IndexType{false, None}}, + "NonUniqueUnorderedIndex") { } template NonUniqueUnorderedIndex::NonUniqueUnorderedIndex(IndexLocation &&loc, tx::Transaction const &t) - : IndexBase(IndexDefinition{loc, IndexType{false, None}}, t) + : IndexBase(IndexDefinition{loc, IndexType{false, None}}, t, + "NonUniqueUnorderedIndex") { } @@ -49,18 +51,22 @@ auto NonUniqueUnorderedIndex::for_range_exact(DbAccessor &t_v, return iter::make_iterator( [ it = list.cbegin(), end = list.cend(), from = from_v, to = to_v, - t = t_v - ]() mutable->auto { + // &t_v is passed by reference because otherwise + // DbAccessor would be copied that means that t_v.db_transaction would + // also be copied and that wouldn't be good because + // db_transaction contains index_updates + t = &t_v + ]() mutable -> auto { // NonUniqueUnorderedIndex is stupid so it must iterate through all // index records to determine which are iniside borders. while (it != end) { const IndexRecord &r = *it; if (from < r.key && to > r.key && - r.is_valid(t.db_transaction.trans)) { + r.is_valid(t->db_transaction.trans)) { // record r is inside borders and is valid for current // transaction. const typename T::accessor_t acc = - r.access(t.db_transaction); + r.access(t->db_transaction); it++; return make_option(std::move(acc)); } diff --git a/src/storage/indexes/impl/unique_ordered_index.cpp b/src/storage/indexes/impl/unique_ordered_index.cpp index 2ad6bba52..9b6481801 100644 --- a/src/storage/indexes/impl/unique_ordered_index.cpp +++ b/src/storage/indexes/impl/unique_ordered_index.cpp @@ -18,14 +18,16 @@ template UniqueOrderedIndex::UniqueOrderedIndex(IndexLocation loc, Order order) - : IndexBase(IndexDefinition{loc, IndexType{true, order}}) + : IndexBase(IndexDefinition{loc, IndexType{true, order}}, + "UniqueOrderedIndex") { } template UniqueOrderedIndex::UniqueOrderedIndex(IndexLocation loc, Order order, tx::Transaction const &t) - : IndexBase(IndexDefinition{loc, IndexType{true, order}}, t) + : IndexBase(IndexDefinition{loc, IndexType{true, order}}, + t, "UniqueOrderedIndex") { } @@ -72,7 +74,7 @@ auto UniqueOrderedIndex::for_range_exact(DbAccessor &t_v, return iter::make_iterator( [ - it = std::move(begin), b_end = std::move(end), t = t_v, + it = std::move(begin), b_end = std::move(end), t = &t_v, hold_acc = std::move(acc) ]() mutable->auto { // UniqueOrderedIndex is smart so he has to iterate only through @@ -81,11 +83,11 @@ auto UniqueOrderedIndex::for_range_exact(DbAccessor &t_v, // reached end border. while (b_end >= it->key) { const IndexRecord &r = *it; - if (r.is_valid(t.db_transaction.trans)) { + if (r.is_valid(t->db_transaction.trans)) { // record r is inside borders and is valid for current // transaction. const typename T::accessor_t acc = - r.access(t.db_transaction); + r.access(t->db_transaction); it++; return make_option(std::move(acc)); } diff --git a/src/storage/indexes/index_base.cpp b/src/storage/indexes/index_base.cpp index eec8dd57c..226befd22 100644 --- a/src/storage/indexes/index_base.cpp +++ b/src/storage/indexes/index_base.cpp @@ -5,14 +5,14 @@ #include "transactions/transaction.hpp" template -IndexBase::IndexBase(IndexDefinition &&it) - : it(it), created(Id(0)), active(true) +IndexBase::IndexBase(IndexDefinition &&it, std::string&& logger_name) + : Loggable(std::forward(logger_name)), it(it), created(Id(0)), active(true) { } template -IndexBase::IndexBase(IndexDefinition &&it, const tx::Transaction &t) - : it(it), created(t.id) +IndexBase::IndexBase(IndexDefinition &&it, const tx::Transaction &t, std::string&& logger_name) + : Loggable(std::forward(logger_name)), it(it), created(t.id) { } diff --git a/src/storage/indexes/index_record.cpp b/src/storage/indexes/index_record.cpp index ba7a02397..31cebd655 100644 --- a/src/storage/indexes/index_record.cpp +++ b/src/storage/indexes/index_record.cpp @@ -2,6 +2,7 @@ #include "storage/type_group_edge.hpp" #include "storage/type_group_vertex.hpp" +#include "transactions/transaction.hpp" template IndexRecord::IndexRecord(K key, typename TG::record_t *record, @@ -28,7 +29,15 @@ template bool IndexRecord::is_valid(tx::Transaction &t) const { assert(!empty()); - return record == vlist->find(t); + // TODO: this has to be tested extensively + // before here was only (record == newest_record) + // but it doesn't work if single transaction updates something from + // this index and then tries to access to the same element again through + // the same index + auto newest_record = vlist->find(t); + if (newest_record == nullptr) + return false; + return (record == newest_record) || (newest_record->tx.cre() == t.id); } template diff --git a/src/storage/label/label_collection.cpp b/src/storage/label/label_collection.cpp index 9a02fd3e9..48f0890c8 100644 --- a/src/storage/label/label_collection.cpp +++ b/src/storage/label/label_collection.cpp @@ -7,15 +7,14 @@ bool LabelCollection::add(const Label &label) if (has(label)) { return false; } else { - _labels.push_back(label_ref_t(label)); + labels_.push_back(label_ref_t(label)); return true; } - // return _labels.(label_ref_t(label)).second; } bool LabelCollection::has(const Label &label) const { - for (auto l : _labels) { + for (auto l : labels_) { if (l == label) { return true; } @@ -23,14 +22,14 @@ bool LabelCollection::has(const Label &label) const return false; } -size_t LabelCollection::count() const { return _labels.size(); } +size_t LabelCollection::count() const { return labels_.size(); } bool LabelCollection::remove(const Label &label) { - auto end = _labels.end(); - for (auto it = _labels.begin(); it != end; it++) { + auto end = labels_.end(); + for (auto it = labels_.begin(); it != end; it++) { if (*it == label) { - _labels.erase(it); + labels_.erase(it); return true; } } @@ -38,9 +37,9 @@ bool LabelCollection::remove(const Label &label) return false; } -void LabelCollection::clear() { _labels.clear(); } +void LabelCollection::clear() { labels_.clear(); } const std::vector &LabelCollection::operator()() const { - return _labels; + return labels_; } diff --git a/src/storage/label/labels_writer.cpp b/src/storage/label/labels_writer.cpp new file mode 100644 index 000000000..7eb5342c8 --- /dev/null +++ b/src/storage/label/labels_writer.cpp @@ -0,0 +1,13 @@ +#include "storage/label/labels_writer.hpp" + +#include "storage/label/label.hpp" +#include "utils/string_buffer.hpp" + +template +void LabelsWriter::handle(const Label& label) +{ + buffer_ << ':' << label.str(); +} + +// NOTE! template instantiations +template class LabelsWriter; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d0b46b38f..238dfd423 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,10 +7,6 @@ set(src_dir ${CMAKE_SOURCE_DIR}/src) include_directories(${catch_source_dir}/include) # TODO: modular approach (REFACTOR) -# add_executable() -# target_link_libraries() -# add_test(NAME COMMAND) -# set_property(TARGET PROPERTY CXX_STANDARD 14) ## UNIT TESTS @@ -111,15 +107,6 @@ target_link_libraries(manual_cypher_ast ${yaml_static_lib}) target_link_libraries(manual_cypher_ast cypher_lib) set_property(TARGET manual_cypher_ast PROPERTY CXX_STANDARD 14) -# queries -add_executable(manual_queries manual/queries.cpp) -target_link_libraries(manual_queries memgraph) -target_link_libraries(manual_queries Threads::Threads) -target_link_libraries(manual_queries ${fmt_static_lib}) -target_link_libraries(manual_queries ${yaml_static_lib}) -target_link_libraries(manual_queries cypher_lib) -set_property(TARGET manual_queries PROPERTY CXX_STANDARD 14) - # query_engine add_executable(manual_query_engine manual/query_engine.cpp) target_link_libraries(manual_query_engine stdc++fs) @@ -139,10 +126,3 @@ target_link_libraries(manual_query_hasher ${fmt_static_lib}) target_link_libraries(manual_query_hasher ${yaml_static_lib}) target_link_libraries(manual_query_hasher Threads::Threads) set_property(TARGET manual_query_hasher PROPERTY CXX_STANDARD 14) - -# query_action_processor -add_executable(manual_cpp_generator manual/cpp_generator.cpp) -target_link_libraries(manual_cpp_generator memgraph) -target_link_libraries(manual_cpp_generator ${fmt_static_lib}) -target_link_libraries(manual_cpp_generator ${yaml_static_lib}) -set_property(TARGET manual_cpp_generator PROPERTY CXX_STANDARD 14) diff --git a/tests/data/queries/core/dressipi.txt b/tests/data/queries/core/dressipi.txt index 892e783a7..01c308c6d 100644 --- a/tests/data/queries/core/dressipi.txt +++ b/tests/data/queries/core/dressipi.txt @@ -1,15 +1,41 @@ -CREATE (n {garment_id: 1234, garment_category_id: 1}) RETURN n -CREATE (p:profile {profile_id: 111, partner_id: 55}) RETURN p -MATCH (g:garment {garment_id: 1234}) SET g:FF RETURN labels(g) -MATCH (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g:garment{garment_id: 1234}) SET s.score = 1550 RETURN s.score -MATCH (g:garment {garment_id: 3456}) SET g.reveals = 50 RETURN g -MERGE (g1:garment {garment_id: 1234})-[r:default_outfit]-(g2:garment {garment_id: 2345}) RETURN r -MERGE (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g.garment {garment_id: 1234}) SET s.score=1500 RETURN s -MATCH (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g.garment {garment_id: 1234}) DELETE s -MATCH (p:profile {profile_id: 113}) DELETE p -MATCH (n) DETACH DELETE n -MATCH (p:profile) RETURN p +CREATE (g:garment {garment_id: 1, garment_category_id: 1}) RETURN g +CREATE (g:garment {garment_id: 2, garment_category_id: 2}) RETURN g +CREATE (g:garment {garment_id: 3, garment_category_id: 3}) RETURN g + +MATCH (g:garment {garment_id: 3}) SET g.reveals = 50 RETURN g + +MERGE (g1:garment {garment_id: 1})-[r:default_outfit]-(g2:garment {garment_id: 2}) RETURN r +MERGE (g1:garment {garment_id: 2})-[r:default_outfit]-(g2:garment {garment_id: 3}) RETURN r +MERGE (g1:garment {garment_id: 3})-[r:default_outfit]-(g2:garment {garment_id: 1}) RETURN r + +CREATE (p:profile {profile_id: 1, partner_id: 1}) RETURN p +CREATE (p:profile {profile_id: 2, partner_id: 2}) RETURN p +CREATE (p:profile {profile_id: 3, partner_id: 2}) RETURN p + MATCH (g:garment) RETURN COUNT(g) -MATCH (g:garment {garment_id: 1234}) RETURN g -MATCH (p:profile {partner_id: 55}) RETURN p +MATCH (g:garment) RETURN g + +MATCH (p:profile) RETURN count(p) +MATCH (p:profile) RETURN p + +MATCH (g:garment {garment_id: 1}) RETURN g +MATCH (p:profile {partner_id: 1}) RETURN p + +MATCH (n) RETURN count(n) + +MATCH (g:garment {garment_id: 2}) SET g:FF RETURN labels(g) + +MERGE (p:profile {profile_id: 1, partner_id: 1})-[s:score]-(g.garment {garment_id: 1}) SET s.score = 1500 RETURN s +MATCH (p:profile {profile_id: 1, partner_id: 1})-[s:score]-(g:garment {garment_id: 1}) SET s.score = 1550 RETURN s.score +MATCH (p:profile {profile_id: 1, partner_id: 1})-[s:score]-(g.garment {garment_id: 1}) DELETE s + +MATCH (g:garment {garment_id: 1}) DELETE g +MATCH (p:profile {profile_id: 1}) DELETE p + +MATCH (n) RETURN count(n) + +MATCH (g:garment) RETURN COUNT(g) + +MATCH (n) DETACH DELETE n + MATCH (n) RETURN count(n) diff --git a/tests/data/queries/core/pool.txt b/tests/data/queries/core/pool.txt new file mode 100644 index 000000000..71f8fd00b --- /dev/null +++ b/tests/data/queries/core/pool.txt @@ -0,0 +1,2 @@ +MERGE (g1:garment {garment_id: 1234})-[r:default_outfit]-(g2:garment {garment_id: 2345}) RETURN r +MATCH (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g.garment {garment_id: 1234}) DELETE s diff --git a/include/query/hardcode/basic.hpp b/tests/integration/_hardcoded_query/basic.hpp similarity index 98% rename from include/query/hardcode/basic.hpp rename to tests/integration/_hardcoded_query/basic.hpp index add5db3ef..91b07e5cd 100644 --- a/include/query/hardcode/basic.hpp +++ b/tests/integration/_hardcoded_query/basic.hpp @@ -305,7 +305,7 @@ auto load_basic_functions(Db &db) }); } else { - // Going through edges wiil probably be faster + // Going through edges will probably be faster it_type.to().for_all([&](auto m) { // PRINT m }); @@ -319,7 +319,8 @@ auto load_basic_functions(Db &db) DbAccessor t(db); auto &type = t.type_find_or_create("TYPE"); - auto prop_name = t.vertex_property_key("name", args[0].key.flags()); + auto prop_name = + t.vertex_property_key("name", args[0].key.flags()); Option n; Option r; @@ -437,7 +438,7 @@ auto load_basic_functions(Db &db) // MATCH (n:LABEL {name: "TEST01"}) RETURN n; auto match_label_property = [&db](properties_t &&args) { - std::map indices{{"name", 0}}; + indices_t indices{{"name", 0}}; auto properties = query_properties(indices, args); DbAccessor t(db); try { diff --git a/tests/integration/_hardcoded_query/dressipi.hpp b/tests/integration/_hardcoded_query/dressipi.hpp new file mode 100644 index 000000000..582c5eb23 --- /dev/null +++ b/tests/integration/_hardcoded_query/dressipi.hpp @@ -0,0 +1,632 @@ +#pragma once + +#include "includes.hpp" + +namespace hardcode +{ + +// TODO: decouple hashes from the code because hashes could and should be +// tested separately + +auto load_dressipi_functions(Db &db) +{ + query_functions_t functions; + + // Query: CREATE (g:garment {garment_id: 1234, garment_category_id: 1}) RETURN g + // Hash: 18071907865596388702 + functions[18071907865596388702u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto garment_id = + t.vertex_property_key("garment_id", args[0].key.flags()); + auto garment_category_id = + t.vertex_property_key("garment_category_id", args[1].key.flags()); + + // vertex_accessor + auto va = t.vertex_insert(); + va.set(garment_id, std::move(args[0])); + va.set(garment_category_id, std::move(args[1])); + + auto &garment = t.label_find_or_create("garment"); + va.add_label(garment); + + // stream.write_field("g"); + // stream.write_vertex_record(va); + // stream.write_meta("w"); + + print_entities(t); + + return t.commit(); + }; + + // Query: CREATE (p:profile {profile_id: 111, partner_id: 55}) RETURN p + // Hash: 17158428452166262783 + functions[17158428452166262783u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto profile_id = + t.vertex_property_key("profile_id", args[0].key.flags()); + auto partner_id = + t.vertex_property_key("partner_id", args[1].key.flags()); + + auto va = t.vertex_insert(); + va.set(profile_id, std::move(args[0])); + va.set(partner_id, std::move(args[1])); + + auto &profile = t.label_find_or_create("profile"); + va.add_label(profile); + + // stream.write_field("p"); + // stream.write_vertex_record(va); + // stream.write_meta("w"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (g:garment {garment_id: 1234}) SET g:FF RETURN labels(g) + // Hash: 11123780635391515946 + functions[11123780635391515946u] = [&db](properties_t &&args) { + DbAccessor t(db); + + indices_t indices = {{"garment_id", 0}}; + auto properties = query_properties(indices, args); + + auto &label = t.label_find_or_create("garment"); + + // stream.write_field("labels(g)"); + + label.index() + .for_range(t) + .properties_filter(t, properties) + .for_all([&](auto va) -> void { + va.stream_repr(std::cout); + auto &ff_label = t.label_find_or_create("FF"); + va.add_label(ff_label); + auto &labels = va.labels(); + + // stream.write_record(); + // stream.write_list_header(1); + // stream.write_list_header(labels.size()); + + for (auto &label : labels) + { + // stream.write(label.get().str()); + + utils::println("LABELS: ", label.get().str()); + } + // stream.chunk(); + }); + // stream.write_meta(\"rw"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (p:profile {profile_id: 111, partner_id:55})-[s:score]-(g:garment {garment_id: 1234}) SET s.score = 1550 RETURN s.score + // Hash: 674581607834128909 + functions[674581607834128909u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto &profile = t.label_find_or_create("profile"); + auto &score = t.type_find_or_create("score"); + auto &garment = t.label_find_or_create("garment"); + + indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}}; + indices_t garment_ind = {{"garment_id", 2}}; + + auto profile_prop = query_properties(profile_ind, args); + auto garment_prop = query_properties(garment_ind, args); + + auto score_key = t.edge_property_key("score", args[3].key.flags()); + + // TODO: decide path (which index is better) + // 3 options p->s->g, g->s->p, g<-s->p + // NOTE! both direections have to be chacked + // because pattern is non directional + // OR + // even better, use index on label and property + + // just one option p->s->g! + Option e1; + profile.index() + .for_range(t) + .properties_filter(t, profile_prop) + .out() + .type(score) + .clone_to(e1) + .to() + .label(garment) + .properties_filter(t, garment_prop) + .for_all([&](auto va) -> void { + auto ea = e1.get().update(); + ea.set(score_key, std::move(args[3])); + }); + + Option e2; + profile.index() + .for_range(t) + .properties_filter(t, profile_prop) + .in() + .type(score) + .clone_to(e1) + .from() + .label(garment) + .properties_filter(t, garment_prop) + .for_all([&](auto va) -> void { + auto ea = e2.get().update(); + ea.set(score_key, std::move(args[3])); + }); + + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (g:garment {garment_id: 3456}) SET g.reveals = 50 RETURN g + // Hash: 2839969099736071844 + functions[2839969099736071844u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto reveals_key = + t.vertex_property_key("reveals", args[1].key.flags()); + + indices_t indices = {{"garment_id", 0}}; + auto properties = query_properties(indices, args); + + auto &label = t.label_find_or_create("garment"); + + // stream.write_field("g"); + + label.index() + .for_range(t) + .properties_filter(t, properties) + .fill() + .for_all([&](auto va) { + va.set(reveals_key, args[1]); + + // stream.write_vertex_record(va); + }); + + // stream.write_meta("w"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MERGE (g1:garment {garment_id:1234})-[r:default_outfit]-(g2:garment {garment_id: 2345}) RETURN r + // Hash: 3782642357973971504 + functions[3782642357973971504u] = [&db](properties_t &&args) { + DbAccessor t(db); + + // TODO: support for index on label and property + + // prepare iterator for g1 + indices_t indices_1 = {{"garment_id", 0}}; + auto properties_1 = query_properties(indices_1, args); + auto &label_1 = t.label_find_or_create("garment"); + + auto it_vertex_1 = + label_1.index().for_range(t).properties_filter(t, properties_1); + + // prepare iterator for g1 + indices_t indices_2 = {{"garment_id", 1}}; + auto properties_2 = query_properties(indices_2, args); + auto &label_2 = t.label_find_or_create("garment"); + + auto it_vertex_2 = + label_2.index().for_range(t).properties_filter(t, properties_2); + + auto &edge_type = t.type_find_or_create("default_outfit"); + + // TODO: create g1 and g2 if don't exist + + // TODO: figure out something better + + // stream.write_field("r"); + + it_vertex_1.fill().for_all([&](auto va1) -> void { + it_vertex_2.fill().for_all([&](auto va2) -> void { + auto edge_accessor = t.edge_insert(va1, va2); + edge_accessor.edge_type(edge_type); + + // stream.write_edge_record(edge_accessor); + }); + }); + + // stream.write_meta("w"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MERGE (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g.garment {garment_id: 1234}) SET s.score=1500 RETURN s + // Hash: 7871009397157280694 + functions[7871009397157280694u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto &profile = t.label_find_or_create("profile"); + auto &score = t.type_find_or_create("score"); + auto &garment = t.label_find_or_create("garment"); + + indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}}; + indices_t garment_ind = {{"garment_id", 2}}; + + auto profile_prop = query_properties(profile_ind, args); + auto garment_prop = query_properties(garment_ind, args); + + auto score_key = t.edge_property_key("score", args[3].key.flags()); + + // TODO: implement + bool exists = false; + Option e1; + profile.index() + .for_range(t) + .properties_filter(t, profile_prop) + .out() + .type(score) + .clone_to(e1) + .to() + .label(garment) + .properties_filter(t, garment_prop) + .for_all([&](auto va) -> void { + exists = true; + auto ea = e1.get().update(); + ea.set(score_key, args[3]); + }); + + Option e2; + profile.index() + .for_range(t) + .properties_filter(t, profile_prop) + .in() + .type(score) + .clone_to(e1) + .from() + .label(garment) + .properties_filter(t, garment_prop) + .for_all([&](auto va) -> void { + exists = true; + auto ea = e2.get().update(); + ea.set(score_key, args[3]); + }); + + if (!exists) { + auto it_vertex_garment = + garment.index().for_range(t).properties_filter(t, garment_prop); + auto it_vertex_profile = + profile.index().for_range(t).properties_filter(t, profile_prop); + + it_vertex_profile.fill().for_all([&](auto va1) -> void { + it_vertex_garment.fill().for_all([&](auto va2) -> void { + auto ea = t.edge_insert(va1, va2); + ea.edge_type(score); + ea.set(score_key, args[3]); + }); + }); + } + + // stream.write_field("r.score"); + // write_record(); + // write_list_header(1); + // write(Float(args[3])); + // chunk(); + // stream.write_field("w"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (p:profile {profile_id: 111, partner_id:55})-[s:score]-(g.garment {garment_id: 1234}) DELETE s + // Hash: 9459600951073026137 + functions[9459600951073026137u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto &profile = t.label_find_or_create("profile"); + auto &score = t.type_find_or_create("score"); + auto &garment = t.label_find_or_create("garment"); + + indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}}; + indices_t garment_ind = {{"garment_id", 2}}; + + auto profile_prop = query_properties(profile_ind, args); + auto garment_prop = query_properties(garment_ind, args); + + auto score_key = t.edge_property_key("score", args[3].key.flags()); + + // TODO: decide path (which index is better) + // 3 options p->s->g, g->s->p, g<-s->p + // NOTE! both direections have to be chacked + // because pattern is non directional + // OR + // even better, use index on label and property + + // just one option p->s->g! + Option e1; + profile.index() + .for_range(t) + .properties_filter(t, profile_prop) + .out() + .type(score) + .clone_to(e1) + .to() + .label(garment) + .properties_filter(t, garment_prop) + .for_all([&](auto va) -> void { + auto ea = e1.get().update(); + ea.remove(); + }); + + Option e2; + profile.index() + .for_range(t) + .properties_filter(t, profile_prop) + .in() + .type(score) + .clone_to(e1) + .from() + .label(garment) + .properties_filter(t, garment_prop) + .for_all([&](auto va) -> void { + auto ea = e2.get().update(); + ea.remove(); + }); + + // stream.write_empty_fields(); + // stream.write_meta("w"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (p:garment {garment_id: 1}) DELETE g + // Hash: 11538263096707897794 + functions[11538263096707897794u] = [&db](properties_t &&args) { + DbAccessor t(db); + + indices_t indices = {{"garment_id", 0}}; + auto properties = query_properties(indices, args); + + auto &label = t.label_find_or_create("garment"); + + label.index() + .for_range(t) + .properties_filter(t, properties) + .for_all([&](auto va) { va.remove(); }); + + // stream.write_empty_fields(); + // stream.write_meta("w"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (p:profile {profile_id: 1}) DELETE p + // Hash: 6763665709953344106 + functions[6763665709953344106u] = [&db](properties_t &&args) { + DbAccessor t(db); + + indices_t indices = {{"profile_id", 0}}; + auto properties = query_properties(indices, args); + + auto &label = t.label_find_or_create("profile"); + + label.index() + .for_range(t) + .properties_filter(t, properties) + .for_all([&](auto va) { va.remove(); }); + + // stream.write_empty_fields(); + // stream.write_meta("w"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (n) RETURN n + // Hash: 5949923385370229113 + functions[5949923385370229113u] = [&db](properties_t &&args) { + DbAccessor t(db); + + // stream.write_field("n"); + + t.vertex_access().fill().for_all([&](auto va) { + // stream.write_vertex_record(va); + + va.stream_repr(std::cout); + utils::println(""); + }); + + // stream.write_meta("r"); + + return t.commit(); + }; + + // Query: MATCH (g:garment) RETURN g + // Hash: 2645003052555435977 + functions[2645003052555435977u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto &label = t.label_find_or_create("garment"); + + // stream.write_field("p"); + label.index().for_range(t).for_all([&](auto va) -> void { + // stream.write_vertex_record(va); + + va.stream_repr(std::cout); + utils::println(""); + }); + + // stream.write_meta("r"); + + return t.commit(); + }; + + // Query: MATCH (p:profile) RETURN p + // Hash: 15599970964909894866 + functions[15599970964909894866u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto &label = t.label_find_or_create("profile"); + + // stream.write_field("p"); + + label.index().for_range(t).for_all([&](auto va) { + + // stream.write_vertex_record(va); + + va.stream_repr(std::cout); + utils::println(""); + }); + + // stream.write_meta("r"); + + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (g:garment {garment_id: 1}) RETURN g + // Hash: 7756609649964321221 + functions[7756609649964321221u] = [&db](properties_t &&args) { + DbAccessor t(db); + + indices_t indices = {{"garment_id", 0}}; + auto properties = query_properties(indices, args); + + auto &label = t.label_find_or_create("garment"); + + // stream.write_field("g"); + + label.index() + .for_range(t) + .properties_filter(t, properties) + .for_all([&](auto va) -> void { + // stream.write_vertex_record(va); + + va.stream_repr(std::cout); + }); + + // stream.write_meta("w"); + + utils::println(""); + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (p:profile {partner_id: 1}) RETURN p + // Hash: 17506488413143988006 + functions[17506488413143988006u] = [&db](properties_t &&args) { + DbAccessor t(db); + + indices_t indices = {{"partner_id", 0}}; + auto properties = query_properties(indices, args); + + auto &label = t.label_find_or_create("profile"); + + // stream.write_field("p"); + + label.index() + .for_range(t) + .properties_filter(t, properties) + .for_all([&](auto va) { + // stream.write_vertex_record(va); + + va.stream_repr(std::cout); + }); + + // stream.write_meta("r"); + + utils::println(""); + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (n) RETURN count(n) + // Hash: 10510787599699014973 + functions[10510787599699014973u] = [&db](properties_t &&args) { + DbAccessor t(db); + + size_t count = 0; + t.vertex_access().fill().for_all([&](auto va) { ++count; }); + + // stream.write_field("count(n)"); + // stream.write_count(count); + // stream.write_meta("r"); + + utils::println("COUNT: ", count); + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (g:garment) RETURN count(g) + // Hash: 11458306387621940265 + functions[11458306387621940265u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto &label = t.label_find_or_create("garment"); + + size_t count = 0; + label.index().for_range(t).for_all([&](auto va) { ++count; }); + + // stream.write_field("count(g)"); + // stream.write_count(count); + // stream.write_meta("r"); + + utils::println("COUNT: ", count); + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (p:profile) RETURN count(p) + // Hash: 7104933247859974916 + functions[7104933247859974916u] = [&db](properties_t &&args) { + DbAccessor t(db); + + auto &label = t.label_find_or_create("profile"); + + size_t count = 0; + label.index().for_range(t).for_all([&](auto va) { ++count; }); + + // stream.write_field("count(p)"); + // stream.write_count(count); + // stream.write_meta("r"); + + utils::println("COUNT: ", count); + print_entities(t); + + return t.commit(); + }; + + // Query: MATCH (n) DETACH DELETE n + // Hash: 4798158026600988079 + functions[4798158026600988079u] = [&db](properties_t &&args) { + DbAccessor t(db); + + t.edge_access().fill().for_all([&](auto e) { e.remove(); }); + t.vertex_access().fill().isolated().for_all( + [&](auto a) { a.remove(); }); + + // stream.write_empty_fields(); + // stream.write_meta("w"); + + print_entities(t); + + return t.commit(); + }; + + return functions; +} +} diff --git a/tests/integration/_hardcoded_query/includes.hpp b/tests/integration/_hardcoded_query/includes.hpp new file mode 100644 index 000000000..810a9ce23 --- /dev/null +++ b/tests/integration/_hardcoded_query/includes.hpp @@ -0,0 +1,110 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "communication/bolt/v1/serialization/bolt_serializer.hpp" +#include "communication/bolt/v1/serialization/record_stream.hpp" +#include "database/db.hpp" +#include "database/db.hpp" +#include "database/db_accessor.hpp" +#include "database/db_accessor.hpp" +#include "io/network/socket.hpp" +#include "mvcc/id.hpp" +#include "query/util.hpp" +#include "storage/edge_type/edge_type.hpp" +#include "storage/edge_x_vertex.hpp" +#include "storage/indexes/index_definition.hpp" +#include "storage/label/label.hpp" +#include "storage/model/properties/all.hpp" +#include "storage/model/properties/property.hpp" +#include "utils/border.hpp" +#include "utils/iterator/iterator.hpp" +#include "utils/iterator/iterator.hpp" +#include "utils/option_ptr.hpp" +#include "utils/reference_wrapper.hpp" +#include "utils/variadic/variadic.hpp" + +using namespace std; + +namespace hardcode +{ + +using namespace utils; + +using query_functions_t = + std::map>; + +size_t edge_count(DbAccessor& t) +{ + size_t count = 0; + t.edge_access().fill().for_all([&](auto ea) { ++count; }); + return count; +} + +size_t vertex_count(DbAccessor& t) +{ + size_t count = 0; + t.vertex_access().fill().for_all([&](auto va) { ++count; }); + return count; +} + +// DEBUG HELPER METHODS + +void print(const VertexAccessor& va) +{ + va.stream_repr(std::cout); +} + +void print(const EdgeAccessor& ea) +{ + ea.stream_repr(std::cout); +} + +void print_vertices(DbAccessor& t) +{ + utils::println("Vertices:"); + t.vertex_access().fill().for_all( + [&](auto va) { + va.stream_repr(std::cout); + utils::println(""); + } + ); + utils::println(""); +} + +void print_edges(DbAccessor& t) +{ + utils::println("Edges:"); + t.edge_access().fill().for_all( + [&](auto ea) { + ea.stream_repr(std::cout); + println(""); + } + ); +} + +void print_entities(DbAccessor& t) +{ + print_vertices(t); + print_edges(t); +} + +void print_edge_count_(DbAccessor& t) +{ + utils::println(""); + utils::println("__EDGE_COUNT:", edge_count(t)); +} + +void print_vertex_count_(DbAccessor& t) +{ + utils::println(""); + utils::println("__VERTEX_COUNT:", vertex_count(t)); +} + +} diff --git a/tests/integration/cleaning.cpp b/tests/integration/cleaning.cpp index 60adb81f5..7bdbb3bf8 100644 --- a/tests/integration/cleaning.cpp +++ b/tests/integration/cleaning.cpp @@ -1,6 +1,6 @@ +#include "_hardcoded_query/basic.hpp" #include "logging/default.hpp" #include "logging/streams/stdout.hpp" -#include "query/hardcode/basic.hpp" #include "query/strip/stripper.hpp" #include "utils/sysinfo/memory.hpp" diff --git a/tests/integration/hardcoded_query/18071907865596388702.cpp b/tests/integration/hardcoded_query/18071907865596388702.cpp new file mode 100644 index 000000000..89310b8f4 --- /dev/null +++ b/tests/integration/hardcoded_query/18071907865596388702.cpp @@ -0,0 +1,52 @@ +#include +#include + +#include "query/util.hpp" +#include "query/i_plan_cpu.hpp" +#include "storage/model/properties/all.hpp" +#include "using.hpp" + +using std::cout; +using std::endl; + +// query: CREATE (g:garment {garment_id: 1234, garment_category_id: 1}) RETURN g + +class CodeCPU : public IPlanCPU +{ +public: + + bool run(Db &db, plan_args_t &args, Stream &stream) override + { + DbAccessor t(db); + + auto garment_id = + t.vertex_property_key("garment_id", args[0].key.flags()); + auto garment_category_id = + t.vertex_property_key("garment_category_id", args[1].key.flags()); + + auto va = t.vertex_insert(); + va.set(garment_id, std::move(args[0])); + va.set(garment_category_id, std::move(args[1])); + + auto &garment = t.label_find_or_create("garment"); + va.add_label(garment); + + stream.write_field("g"); + stream.write_vertex_record(va); + stream.write_meta("w"); + + return t.commit(); + } + + ~CodeCPU() {} +}; + +extern "C" IPlanCPU* produce() +{ + return new CodeCPU(); +} + +extern "C" void destruct(IPlanCPU* p) +{ + delete p; +} diff --git a/tests/integration/hardcoded_query/template b/tests/integration/hardcoded_query/template new file mode 100644 index 000000000..f5cd0bd6a --- /dev/null +++ b/tests/integration/hardcoded_query/template @@ -0,0 +1,33 @@ +#include +#include + +#include "query/util.hpp" +#include "query/i_plan_cpu.hpp" +#include "storage/model/properties/all.hpp" + +using std::cout; +using std::endl; + +// query: + +class CodeCPU : public IPlanCPU<{{stream}}> +{ +public: + + bool run(Db &db, plan_args_t &args, {{stream}} &stream) override + { +{{code}} + } + + ~{{class_name}}() {} +}; + +extern "C" IPlanCPU<{{stream}}>* produce() +{ + return new {{class_name}}(); +} + +extern "C" void destruct(IPlanCPU<{{stream}}>* p) +{ + delete p; +} diff --git a/tests/integration/hardcoded_query/using.hpp b/tests/integration/hardcoded_query/using.hpp new file mode 100644 index 000000000..59e58811d --- /dev/null +++ b/tests/integration/hardcoded_query/using.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include "communication/communication.hpp" + +using Stream = communication::OutputStream; diff --git a/tests/integration/index.cpp b/tests/integration/index.cpp index 42bc96aad..6afc345b6 100644 --- a/tests/integration/index.cpp +++ b/tests/integration/index.cpp @@ -1,6 +1,6 @@ #include -#include "query/hardcode/basic.hpp" +#include "_hardcoded_query/basic.hpp" #include "logging/default.hpp" #include "logging/streams/stdout.hpp" #include "query/strip/stripper.hpp" diff --git a/tests/integration/queries.cpp b/tests/integration/queries.cpp index 46a25bcc5..6876821a7 100644 --- a/tests/integration/queries.cpp +++ b/tests/integration/queries.cpp @@ -2,13 +2,15 @@ #include "database/db.hpp" #include "logging/default.hpp" #include "logging/streams/stdout.hpp" -#include "query/hardcode/basic.hpp" -#include "query/hardcode/dressipi.hpp" +#include "_hardcoded_query/basic.hpp" +#include "_hardcoded_query/dressipi.hpp" #include "query/strip/stripper.hpp" #include "utils/string/file.hpp" #include "utils/variadic/variadic.hpp" #include "utils/command_line/arguments.hpp" +Logger logger; + int main(int argc, char *argv[]) { auto arguments = all_arguments(argc, argv); @@ -19,8 +21,10 @@ int main(int argc, char *argv[]) auto work_mode = get_argument(arguments, "-w", "query_execution"); // init logging - logging::init_async(); + logging::init_sync(); logging::log->pipe(std::make_unique()); + auto log = logging::log->logger("test"); + log.info("bla"); // init db, functions and stripper Db db; @@ -42,10 +46,16 @@ int main(int argc, char *argv[]) // execute all queries for (auto &query : queries) { + if (query.empty()) + continue; + + utils::println(""); utils::println("Query: ", query); auto stripped = stripper.strip(query); utils::println("Hash: ", stripped.hash); + + utils::println("------------------------"); // TODO: more robust solution (enum like) if (work_mode == "hash_generation") continue; @@ -54,7 +64,7 @@ int main(int argc, char *argv[]) query_functions[stripped.hash](std::move(stripped.arguments)); permanent_assert(result == true, "Result retured from query function is not true"); - utils::println("------------------------ PASS"); + utils::println("------------------------"); } return 0; diff --git a/tests/integration/snapshot.cpp b/tests/integration/snapshot.cpp index 682618950..6c8309e44 100644 --- a/tests/integration/snapshot.cpp +++ b/tests/integration/snapshot.cpp @@ -2,7 +2,7 @@ #include "logging/default.hpp" #include "logging/streams/stdout.hpp" -#include "query/hardcode/basic.hpp" +#include "_hardcoded_query/basic.hpp" #include "query/strip/stripper.hpp" #include "storage/indexes/indexes.hpp" #include "utils/sysinfo/memory.hpp" diff --git a/tests/manual/cpp_generator.cpp b/tests/manual/cpp_generator.cpp deleted file mode 100644 index 113686d4a..000000000 --- a/tests/manual/cpp_generator.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include - -#include "query/backend/cpp_old/cypher.hpp" - -using ParameterIndexKey::Type::InternalId; -using ParameterIndexKey::Type::Projection; - -auto main() -> int -{ - CppGenerator generator; - - // MATCH - generator.add_action(QueryAction::Match); - - auto& data_match = generator.action_data(); - data_match.actions["n1"] = ClauseAction::MatchNode; - data_match.actions["n2"] = ClauseAction::MatchNode; - - // CREATE - generator.add_action(QueryAction::Create); - - auto& data_create = generator.action_data(); - data_create.actions["r"] = ClauseAction::CreateRelationship; - - // RETURN - generator.add_action(QueryAction::Return); - - auto& data_return = generator.action_data(); - data_return.actions["r"] = ClauseAction::ReturnRelationship; - - generator.generate(); - - return 0; -} diff --git a/tests/manual/queries.cpp b/tests/manual/queries.cpp deleted file mode 100644 index 01da7ef8a..000000000 --- a/tests/manual/queries.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include - -#include "communication/bolt/v1/serialization/bolt_serializer.hpp" -#include "database/db.hpp" -#include "logging/default.hpp" -#include "logging/streams/stdout.hpp" -#include "query/hardcode/basic.hpp" -#include "query/hardcode/dressipi.hpp" -#include "query/strip/stripper.hpp" -#include "storage/edges.cpp" -#include "storage/edges.hpp" -#include "storage/vertices.cpp" -#include "storage/vertices.hpp" - -using namespace std; - -int main(int argc, char **argv) -{ - logging::init_async(); - logging::log->pipe(std::make_unique()); - - Db db; - auto queries = hardcode::load_basic_functions(db); - - auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL); - - vector history; - string command; - cout << "-- Memgraph query engine --" << endl; - do - { - - cout << "> "; - getline(cin, command); - history.push_back(command); - auto stripped = stripper.strip(command); - - if (queries.find(stripped.hash) == queries.end()) - { - cout << "unsupported query" << endl; - continue; - } - - auto result = queries[stripped.hash](std::move(stripped.arguments)); - cout << "RETURN: " << result << endl; - - } while (command != "quit"); - - return 0; -}