From 6cce530b6c77c1f08d37373bdc08859642cbe9b7 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Thu, 13 Oct 2016 15:42:19 +0200 Subject: [PATCH] barrier ifdefs (TODO: barrier should be removed) --- CMakeLists.txt | 25 ++++++++---- include/barrier/barrier.hpp | 4 ++ include/barrier/common.hpp | 4 ++ include/barrier/trans.hpp | 4 ++ .../code_generator/cypher_state.hpp | 11 +++++- .../code_generator/handlers/return.hpp | 14 +++++++ include/query_engine/hardcode/queries.hpp | 38 ++++++++++++++++++- include/query_engine/traverser/code.hpp | 13 +++++++ .../query_engine/traverser/cpp_traverser.hpp | 11 ++++-- tests/integration/cleaning.cpp | 6 +++ tests/integration/index.cpp | 14 +++++++ tests/integration/queries.cpp | 6 +++ tests/integration/snapshot.cpp | 13 +++++++ tests/manual/queries.cpp | 6 +++ 14 files changed, 154 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f3c7de67f..fbb8198d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,12 +14,6 @@ find_package(Threads REQUIRED) # c++14 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y") -# glibcxx debug (useful for gdb) -# the problem is that the query engine doesn't work as it should work if -# this flag is present -# TODO: find more appropriate way to use this flag only when it is needed -# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG") - # functions # prints all included directories @@ -305,7 +299,10 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") endif() # release flags -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") +set(CMAKE_CXX_FLAGS_RELEASE "-O2 ${CMAKE_CXX_FLAGS_RELEASE}") + +#debug flags +set(CMAKE_CXX_FLAGS_DEBUG "-g2 ${CMAKE_CXX_FLAGS_DEBUG}") # TODO: find a way how to applay the defines at the query compile time # -- configure defines -- default is ON | true | enabled ---------------------- @@ -367,6 +364,16 @@ if(NDEBUG) add_definitions( -DNDEBUG ) endif() # -- ndebug ------------------------------------------------------------------- +# -- GLIBCXX_DEBUG ------------------------------------------------------------ +# glibcxx debug (useful for gdb) +# the problem is that the query engine doesn't work as it should work if +# this flag is present +option(GLIBCXX_DEBUG "glibc debug" OFF) +message(STATUS "GLIBCXX_DEBUG: ${GLIBCXX_DEBUG} (solves problem with _M_dataplus member during a debugging process") +if(GLIBCXX_DEBUG) + set(CMAKE_CXX_FLAGS_DEBUG "-D_GLIBCXX_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}") +endif() +# ----------------------------------------------------------------------------- # -- binaries ----------------------------------------------------------------- option(MEMGRAPH "Build memgraph binary" ON) message(STATUS "MEMGRAPH binary: ${MEMGRAPH}") @@ -537,6 +544,10 @@ string(STRIP ${COMMIT_HASH} COMMIT_HASH) set(MEMGRAPH_BUILD_NAME "memgraph_${COMMIT_NO}_${COMMIT_HASH}_${COMMIT_BRANCH}_${CMAKE_BUILD_TYPE}") +message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}") +message(STATUS "Debug flags: ${CMAKE_CXX_FLAGS_DEBUG}") +message(STATUS "Release flags: ${CMAKE_CXX_FLAGS_RELEASE}") + # memgraph main executable if (MEMGRAPH) add_executable(${MEMGRAPH_BUILD_NAME} ${src_dir}/memgraph_bolt.cpp) diff --git a/include/barrier/barrier.hpp b/include/barrier/barrier.hpp index c19ef6751..800909505 100644 --- a/include/barrier/barrier.hpp +++ b/include/barrier/barrier.hpp @@ -1,5 +1,7 @@ #pragma once +#ifdef BARRIER + #include "barrier/common.hpp" // This namespace is holding header parts of barrier classes. Barrier class @@ -578,3 +580,5 @@ class Db : protected Unsized { }; } + +#endif diff --git a/include/barrier/common.hpp b/include/barrier/common.hpp index 376353e22..f0eb17725 100644 --- a/include/barrier/common.hpp +++ b/include/barrier/common.hpp @@ -1,5 +1,7 @@ #pragma once +#ifdef BARRIER + #include #include #include @@ -136,3 +138,5 @@ private: typename std::aligned_storage::type data; }; } + +#endif diff --git a/include/barrier/trans.hpp b/include/barrier/trans.hpp index 641b99526..2e02b18b8 100644 --- a/include/barrier/trans.hpp +++ b/include/barrier/trans.hpp @@ -1,5 +1,7 @@ #pragma once +#ifdef BARRIER + #include "barrier/barrier.hpp" // This is the place for imports from memgraph .hpp @@ -263,3 +265,5 @@ INSTANTIATE_FOR_PROPERTY(EdgePropertyType_constructor); DbAccessor::DbAccessor(Db &db) : Sized(::DbAccessor(trans(db))) {} } + +#endif diff --git a/include/query_engine/code_generator/cypher_state.hpp b/include/query_engine/code_generator/cypher_state.hpp index 91b701b0b..9cac08287 100644 --- a/include/query_engine/code_generator/cypher_state.hpp +++ b/include/query_engine/code_generator/cypher_state.hpp @@ -54,8 +54,6 @@ private: std::map entity_source; std::map> entity_tags; - // TODO: container that keeps track about c++ variable names - public: bool exist(const std::string &name) const { @@ -130,4 +128,13 @@ public: { entity_tags[name] = tags; } + + void tag(const std::string& name, const std::string& new_tag) + { + if (entity_tags.find(name) != entity_tags.end()) + { + entity_tags[name] = std::vector{}; + } + entity_tags[name].emplace_back(new_tag); + } }; diff --git a/include/query_engine/code_generator/handlers/return.hpp b/include/query_engine/code_generator/handlers/return.hpp index e9aad4b63..259ae9f1e 100644 --- a/include/query_engine/code_generator/handlers/return.hpp +++ b/include/query_engine/code_generator/handlers/return.hpp @@ -73,12 +73,26 @@ auto return_query_action = for (auto const &kv : action_data.actions) { auto name = kv.first; + if (kv.second == ClauseAction::ReturnCount) { if (cypher_data.source(name) == EntitySource::MainStorage) { code += code_line(code::count, name); } + + if (cypher_data.source(name) == EntitySource::LabelIndex) + { + auto tags = cypher_data.tags(name); + if (tags.size() == 1) { + auto label = tags.at(0); + code += code_line(code::count_vertices_for_one_label, + name, label); + } + // TODO: do for more, isn't easy because of + // multiple iterators, but we have iterator infrastructure + // to do that + } } if (kv.second == ClauseAction::ReturnLabels) { diff --git a/include/query_engine/hardcode/queries.hpp b/include/query_engine/hardcode/queries.hpp index 53b4dbdbe..9fc41fa84 100644 --- a/include/query_engine/hardcode/queries.hpp +++ b/include/query_engine/hardcode/queries.hpp @@ -3,12 +3,43 @@ #include #include -#include "barrier/barrier.hpp" - using namespace std; +#ifdef BARRIER + +#include "barrier/barrier.hpp" namespace barrier { + +#else + +#include +#include +#include +#include +#include +#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" +#include "database/db.hpp" +#include "database/db_accessor.hpp" +#include "utils/iterator/iterator.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" + +#endif + auto load_queries(Db &db) { std::map> queries; @@ -475,4 +506,7 @@ auto load_queries(Db &db) return queries; } + +#ifdef BARRIER } +#endif diff --git a/include/query_engine/traverser/code.hpp b/include/query_engine/traverser/code.hpp index 2f3a1fba3..4bbfa2271 100644 --- a/include/query_engine/traverser/code.hpp +++ b/include/query_engine/traverser/code.hpp @@ -105,6 +105,19 @@ const std::string find_and_write_edges_by_type = " }});\n" " stream.write_meta(\"rw\");\n"; +const std::string count_vertices_for_one_label = + "size_t count = 0;\n" + "auto &label = t.label_find_or_create(\"{1}\");\n" + " label.index().for_range(t).for_all([&](auto vertex) {{\n" + " count++;\n" + " }});\n" + " stream.write_field(\"count({0})\");\n" + " stream.write_record();\n" + " stream.write_list_header(1);\n" + " stream.write(Int64(count));\n" + " stream.chunk();\n" + " stream.write_meta(\"r\");\n"; + // TODO: vertices and edges const std::string count = "size_t count = 0;\n" diff --git a/include/query_engine/traverser/cpp_traverser.hpp b/include/query_engine/traverser/cpp_traverser.hpp index 7dc69ebf3..788404b59 100644 --- a/include/query_engine/traverser/cpp_traverser.hpp +++ b/include/query_engine/traverser/cpp_traverser.hpp @@ -209,7 +209,6 @@ public: query_action = QueryAction::Return; Traverser::visit(ast_return); - } void visit(ast::ReturnList &ast_return_list) override @@ -374,6 +373,7 @@ public: void visit(ast::LabelList &ast_label_list) override { auto &action_data = generator.action_data(); + auto &cypher_data = generator.cypher_data(); if (!ast_label_list.has_value()) return; @@ -382,6 +382,9 @@ public: action_data.add_entity_tag(entity, label); action_data.csm.search_cost(entity, entity_search::search_label_index, entity_search::label_cost); + cypher_data.tag(entity, label); + // TODO: it shouldn't be decided here + cypher_data.source(entity, EntitySource::LabelIndex); Traverser::visit(ast_label_list); } @@ -525,9 +528,9 @@ public: auto &action_data = generator.action_data(); auto &cypher_data = generator.cypher_data(); - if (state == CypherState::Return) - { + // if (state == CypherState::Return) + // { action_data.actions[ast_count.argument] = ClauseAction::ReturnCount; - } + // } } }; diff --git a/tests/integration/cleaning.cpp b/tests/integration/cleaning.cpp index 3ce07a6f4..6f6cbd619 100644 --- a/tests/integration/cleaning.cpp +++ b/tests/integration/cleaning.cpp @@ -1,6 +1,8 @@ #include "query_engine/hardcode/queries.hpp" +#ifdef BARRIER #include "barrier/barrier.cpp" +#endif #include "logging/default.hpp" #include "logging/streams/stdout.hpp" @@ -35,7 +37,11 @@ int main(void) Db db("cleaning"); +#ifdef BARRIER auto query_functions = load_queries(barrier::trans(db)); +#else + auto query_functions = load_queries(db); +#endif auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL); diff --git a/tests/integration/index.cpp b/tests/integration/index.cpp index cbf9dba35..9d13aea5f 100644 --- a/tests/integration/index.cpp +++ b/tests/integration/index.cpp @@ -2,7 +2,9 @@ #include +#ifdef BARRIER #include "barrier/barrier.cpp" +#endif #include "logging/default.hpp" #include "logging/streams/stdout.hpp" @@ -21,7 +23,13 @@ auto rand_gen(size_t n) void run(size_t n, std::string &query, Db &db) { auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL); + +#ifdef BARRIER auto qf = load_queries(barrier::trans(db)); +#else + auto qf = load_queries(db); +#endif + auto stripped = stripper.strip(query); std::cout << "Running query [" << stripped.hash << "] for " << n << " time." << std::endl; @@ -34,7 +42,13 @@ void run(size_t n, std::string &query, Db &db) void add_edge(size_t n, Db &db) { auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL); + +#ifdef BARRIER auto qf = load_queries(barrier::trans(db)); +#else + auto qf = load_queries(db); +#endif + std::string query = "MATCH (n1), (n2) WHERE ID(n1)=0 AND " "ID(n2)=1 CREATE (n1)<-[r:IS {age: " "25,weight: 70}]-(n2) RETURN r"; diff --git a/tests/integration/queries.cpp b/tests/integration/queries.cpp index 900183d72..5dcf19c2b 100644 --- a/tests/integration/queries.cpp +++ b/tests/integration/queries.cpp @@ -1,6 +1,8 @@ #include "query_engine/hardcode/queries.hpp" +#ifdef BARRIER #include "barrier/barrier.cpp" +#endif #include "communication/bolt/v1/serialization/bolt_serializer.hpp" #include "database/db.hpp" @@ -20,7 +22,11 @@ int main(void) Db db; +#ifdef BARRIER auto query_functions = load_queries(barrier::trans(db)); +#else + auto query_functions = load_queries(db); +#endif auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL); diff --git a/tests/integration/snapshot.cpp b/tests/integration/snapshot.cpp index 50975722d..34725d059 100644 --- a/tests/integration/snapshot.cpp +++ b/tests/integration/snapshot.cpp @@ -2,7 +2,9 @@ #include +#ifdef BARRIER #include "barrier/barrier.cpp" +#endif #include "logging/default.hpp" #include "logging/streams/stdout.hpp" @@ -21,7 +23,13 @@ auto rand_gen(size_t n) void run(size_t n, std::string &query, Db &db) { auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL); + +#ifdef BARRIER auto qf = load_queries(barrier::trans(db)); +#else + auto qf = load_queries(db); +#endif + auto stripped = stripper.strip(query); std::cout << "Running query [" << stripped.hash << "] for " << n << " time." << std::endl; @@ -34,7 +42,12 @@ void run(size_t n, std::string &query, Db &db) void add_edge(size_t n, Db &db) { auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL); +#ifdef BARRIER auto qf = load_queries(barrier::trans(db)); +#else + auto qf = load_queries(db); +#endif + std::string query = "MATCH (n1), (n2) WHERE ID(n1)=0 AND " "ID(n2)=1 CREATE (n1)<-[r:IS {age: " "25,weight: 70}]-(n2) RETURN r"; diff --git a/tests/manual/queries.cpp b/tests/manual/queries.cpp index 06747b76e..540bfe1ea 100644 --- a/tests/manual/queries.cpp +++ b/tests/manual/queries.cpp @@ -2,7 +2,9 @@ #include "query_engine/hardcode/queries.hpp" +#ifdef BARRIER #include "barrier/barrier.cpp" +#endif #include "communication/bolt/v1/serialization/bolt_serializer.hpp" #include "database/db.hpp" @@ -17,7 +19,11 @@ using namespace std; int main(int argc, char **argv) { Db db; +#ifdef BARRIER auto queries = load_queries(barrier::trans(db)); +#else + auto queries = load_queries(db); +#endif // auto arguments = all_arguments(argc, argv); // auto input_query = extract_query(arguments);