diff --git a/include/data_structures/concurrent/concurrent_list.hpp b/include/data_structures/concurrent/concurrent_list.hpp index 8f16a504b..0393effa1 100644 --- a/include/data_structures/concurrent/concurrent_list.hpp +++ b/include/data_structures/concurrent/concurrent_list.hpp @@ -5,6 +5,7 @@ #include #include "utils/crtp.hpp" +// TODO: reimplement this template class List { @@ -183,19 +184,23 @@ private: private: void find_and_disconnect() { - auto it = It(list); + Node *bef = nullptr; + auto now = load(list->head); auto next = load(curr->next); - while (it.valid()) { - if (it.curr == curr) { - if (it.disconnect()) { + while (now != nullptr) { + if (now == curr) { + prev = bef; + if (disconnect()) { return; } - it.reset(); - } else if (it.curr == next) { // Comparison with next is - // optimization for early return. + bef = nullptr; + now = load(list->head); + } else if (now == next) { // Comparison with next is + // optimization for early return. return; } else { - it++; + bef = now; + now = load(now->next); } } } diff --git a/include/query_engine/hardcode/queries.hpp b/include/query_engine/hardcode/queries.hpp index f67b72fcd..464d4cfbd 100644 --- a/include/query_engine/hardcode/queries.hpp +++ b/include/query_engine/hardcode/queries.hpp @@ -36,6 +36,18 @@ auto load_queries(Db &db) return t.commit(); }; + auto create_labeled_and_named_node_v2 = [&db](const properties_t &args) { + DbAccessor t(db); + auto prop_key = t.vertex_property_key("name", args[0]->flags); + auto &label = t.label_find_or_create("OTHER"); + + auto vertex_accessor = t.vertex_insert(); + vertex_accessor.set(prop_key, args[0]); + vertex_accessor.add_label(label); + // cout_properties(vertex_accessor.properties()); + return t.commit(); + }; + auto create_account = [&db](const properties_t &args) { DbAccessor t(db); auto prop_id = t.vertex_property_key("id", args[0]->flags); @@ -393,6 +405,7 @@ auto load_queries(Db &db) queries[15648836733456301916u] = create_edge_v2; queries[10597108978382323595u] = create_account; queries[5397556489557792025u] = create_labeled_and_named_node; + queries[16090682663946456821u] = create_labeled_and_named_node_v2; queries[7939106225150551899u] = create_edge; queries[6579425155585886196u] = create_edge; queries[11198568396549106428u] = find_node_by_internal_id; diff --git a/include/utils/random/xorshift128plus.hpp b/include/utils/random/xorshift128plus.hpp index f98c558bc..cccc001db 100644 --- a/include/utils/random/xorshift128plus.hpp +++ b/include/utils/random/xorshift128plus.hpp @@ -17,8 +17,12 @@ public: { // use a slow, more complex rnd generator to initialize a fast one // make sure to call this before requesting any random numbers! - std::random_device rd; - std::mt19937_64 gen(rd()); + + // NOTE: Valgird complanis to next instruction + // std::random_device rd; + // std::mt19937_64 gen(rd()); + std::mt19937_64 gen(time(0)); + std::uniform_int_distribution dist; // the number generated by MT can be full of zeros and xorshift diff --git a/src/dbms/cleaner.cpp b/src/dbms/cleaner.cpp index 7ab29bcac..65a031eed 100644 --- a/src/dbms/cleaner.cpp +++ b/src/dbms/cleaner.cpp @@ -19,6 +19,7 @@ Cleaning::Cleaning(ConcurrentMap &dbs) : dbms(dbs) DbTransaction t(db.second); t.clean_edge_section(); t.clean_vertex_section(); + t.trans.commit(); } last_clean = now; } else { diff --git a/src/storage/label/label.cpp b/src/storage/label/label.cpp index 14196f5ec..b532c2d52 100644 --- a/src/storage/label/label.cpp +++ b/src/storage/label/label.cpp @@ -2,8 +2,7 @@ #include "storage/label/label.hpp" Label::Label(const char *name) - : name(std::string(name)), - index_v(std::unique_ptr(new label_index_t())) + : name(std::string(name)), index_v(std::make_unique()) { } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3897d862b..c893b2321 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -68,6 +68,14 @@ target_link_libraries(integration_queries ${fmt_static_lib}) add_test(NAME integration_queries COMMAND integration_queries) set_property(TARGET integration_queries PROPERTY CXX_STANDARD 14) +# test cleaning methods +add_executable(cleaning integration/cleaning.cpp) +target_link_libraries(cleaning memgraph) +target_link_libraries(cleaning Threads::Threads) +target_link_libraries(cleaning ${fmt_static_lib}) +add_test(NAME cleaning COMMAND cleaning) +set_property(TARGET cleaning PROPERTY CXX_STANDARD 14) + # test query engine add_executable(integration_query_engine integration/query_engine.cpp) target_link_libraries(integration_query_engine Threads::Threads) diff --git a/tests/integration/cleaning.cpp b/tests/integration/cleaning.cpp new file mode 100644 index 000000000..73936bed4 --- /dev/null +++ b/tests/integration/cleaning.cpp @@ -0,0 +1,94 @@ +#include "query_engine/hardcode/queries.hpp" + +#include "barrier/barrier.cpp" + +#include "logging/default.hpp" +#include "logging/streams/stdout.hpp" +#include "query_engine/query_stripper.hpp" +#include "utils/sysinfo/memory.hpp" + +template +void run(size_t n, std::string &query, S &stripper, Q &qf) +{ + auto stripped = stripper.strip(query); + std::cout << "Running query [" << stripped.hash << "] for " << n << " time." + << std::endl; + for (int i = 0; i < n; i++) { + assert(qf[stripped.hash](stripped.arguments)); + } +} + +void clean_vertex(Db &db) +{ + DbTransaction t(db); + t.clean_vertex_section(); + t.trans.commit(); +} + +int main(void) +{ + logging::init_async(); + logging::log->pipe(std::make_unique()); + + size_t cvl_n = 1000; + + Db db; + + auto query_functions = load_queries(barrier::trans(db)); + + auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL); + + std::string create_vertex_label = + "CREATE (n:LABEL {name: \"cleaner_test\"}) RETURN n"; + std::string create_vertex_other = + "CREATE (n:OTHER {name: \"cleaner_test\"}) RETURN n"; + std::string delete_label_vertices = "MATCH (n:LABEL) DELETE n"; + std::string delete_all_vertices = "MATCH (n) DELETE n"; + + // ******************************* TEST 1 ********************************// + // add vertices a + // clean vertices + // delete vertices a + // clean vertices + run(cvl_n, create_vertex_label, stripper, query_functions); + assert(db.graph.vertices.access().size() == cvl_n); + + clean_vertex(db); + assert(db.graph.vertices.access().size() == cvl_n); + + run(1, delete_label_vertices, stripper, query_functions); + assert(db.graph.vertices.access().size() == cvl_n); + + clean_vertex(db); + assert(db.graph.vertices.access().size() == 0); + + // ******************************* TEST 2 ********************************// + // add vertices a + // add vertices b + // clean vertices + // delete vertices a + // clean vertices + // delete vertices all + run(cvl_n, create_vertex_label, stripper, query_functions); + assert(db.graph.vertices.access().size() == cvl_n); + + run(cvl_n, create_vertex_other, stripper, query_functions); + assert(db.graph.vertices.access().size() == cvl_n * 2); + + clean_vertex(db); + assert(db.graph.vertices.access().size() == cvl_n * 2); + + run(1, delete_label_vertices, stripper, query_functions); + assert(db.graph.vertices.access().size() == cvl_n * 2); + + clean_vertex(db); + assert(db.graph.vertices.access().size() == cvl_n); + + run(1, delete_all_vertices, stripper, query_functions); + assert(db.graph.vertices.access().size() == cvl_n); + + clean_vertex(db); + assert(db.graph.vertices.access().size() == 0); + + return 0; +} diff --git a/tests/integration/queries.cpp b/tests/integration/queries.cpp index b242d9314..d9379f39f 100644 --- a/tests/integration/queries.cpp +++ b/tests/integration/queries.cpp @@ -24,6 +24,7 @@ int main(void) "CREATE (n:LABEL {name: \"TEST1\"}) RETURN n", "CREATE (n:LABEL {name: \"TEST2\"}) RETURN n", "CREATE (n:LABEL {name: \"TEST3\"}) RETURN n", + "CREATE (n:OTHER {name: \"TEST4\"}) RETURN n" "CREATE (n:ACCOUNT {id: 2322, name: \"TEST\", country: \"Croatia\", " "created_at: 2352352}) RETURN n", "MATCH (n {id: 0}) RETURN n", "MATCH (n {id: 1}) RETURN n", diff --git a/tests/integration/transaction_db.cpp b/tests/integration/transaction_db.cpp deleted file mode 100644 index caad9d9b8..000000000 --- a/tests/integration/transaction_db.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -#include "database/db.hpp" -// #include "storage/edges.cpp" -// #include "storage/edges.hpp" -// #include "storage/vertices.cpp" -// #include "storage/vertices.hpp" -// #include "utils/assert.hpp" - -int main(void) -{ - Db db; - - return 0; -} diff --git a/tests/integration/transaction_delete.cpp b/tests/integration/transaction_delete.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/integration/transaction_delete.hpp b/tests/integration/transaction_delete.hpp deleted file mode 100644 index e69de29bb..000000000