From b374ae1dbb7d2de2747c26dd4c9634fec6377da2 Mon Sep 17 00:00:00 2001 From: Florijan Stamenkovic Date: Sat, 4 Feb 2017 09:01:15 +0100 Subject: [PATCH] storage and database major refactor in progress, also switching from properties to typed-value system. a lot of overdesigned functionalities cut down, new implementations just started. VERY UNSTABLE STATE --- CMakeLists.txt | 29 +- cmake/copy_includes.cmake | 52 +-- .../concurrent/concurrent_set.hpp | 94 +++--- include/database/creation_exception.hpp | 17 + include/database/db.hpp | 93 ------ include/database/db_accessor.hpp | 2 +- include/database/graph_db.hpp | 112 +++++++ include/database/graph_db_accessor.hpp | 24 ++ include/dbms/cleaner.hpp | 2 +- include/dbms/dbms.hpp | 2 +- include/mvcc/version_list.hpp | 4 +- include/query/engine.hpp | 2 +- include/query/i_plan_cpu.hpp | 2 +- include/query/plan/program_executor.hpp | 2 +- include/snapshot/snapshoter.hpp | 2 +- include/storage/common.hpp | 6 - include/storage/edge.hpp | 41 +-- include/storage/edge_accessor.hpp | 49 +-- include/storage/edge_record.hpp | 35 -- include/storage/edge_type/edge_type.hpp | 50 --- include/storage/edge_type/edge_type_store.hpp | 32 -- include/storage/edge_x_vertex.hpp | 20 -- include/storage/edges.hpp | 47 --- .../impl/nonunique_unordered_index.hpp | 42 --- .../indexes/impl/unique_ordered_index.hpp | 42 --- include/storage/indexes/index_base.hpp | 84 ----- include/storage/indexes/index_definition.hpp | 104 ------ include/storage/indexes/index_holder.hpp | 49 --- include/storage/indexes/index_record.hpp | 70 ---- include/storage/indexes/index_update.hpp | 45 --- include/storage/indexes/indexes.hpp | 308 ------------------ include/storage/indexes/keys/index_key.hpp | 20 -- .../storage/indexes/keys/non_unique_key.hpp | 18 - include/storage/indexes/keys/unique_key.hpp | 45 --- include/storage/iterator/graph_composable.hpp | 20 -- include/storage/iterator/graph_filter.hpp | 19 -- include/storage/label/label.hpp | 53 --- include/storage/label/label_collection.hpp | 37 --- include/storage/label/label_store.hpp | 25 -- include/storage/label/labels_writer.hpp | 23 -- include/storage/model/edge_list.hpp | 34 -- include/storage/model/edge_map.hpp | 34 -- include/storage/model/edge_model.hpp | 17 - include/storage/model/property_model.hpp | 10 - include/storage/model/vertex_model.hpp | 14 - include/storage/record_accessor.hpp | 226 ++++--------- include/storage/type_group_edge.hpp | 19 -- include/storage/type_group_vertex.hpp | 19 -- include/storage/{model => }/typed_value.hpp | 0 .../storage/{model => }/typed_value_store.hpp | 0 .../storage/{model => }/typed_value_utils.h | 2 +- include/storage/vertex.hpp | 46 +-- include/storage/vertex_accessor.hpp | 60 +--- include/storage/vertex_record.hpp | 12 - include/storage/vertices.hpp | 52 --- include/utils/pass_key.hpp | 22 ++ poc/add_double.cpp | 2 +- poc/astar.cpp | 2 +- poc/astar_query.cpp | 2 +- poc/csv_import.cpp | 2 +- poc/profile.cpp | 2 +- poc/size_aligment.cpp | 2 +- src/database/db.cpp | 21 -- src/database/db_accessor.cpp | 2 +- src/database/db_transaction.cpp | 2 +- src/database/graph_db.cpp | 77 +++++ src/memgraph_http.cpp | 2 +- src/storage/edge_accessor.cpp | 55 ++-- src/storage/edge_type/edge_type.cpp | 28 -- src/storage/edge_type/edge_type_store.cpp | 24 -- src/storage/edges.cpp | 60 ---- .../impl/nonunique_unordered_index.cpp | 93 ------ .../indexes/impl/unique_ordered_index.cpp | 115 ------- src/storage/indexes/index_base.cpp | 39 --- src/storage/indexes/index_holder.cpp | 71 ---- src/storage/indexes/index_record.cpp | 62 ---- src/storage/indexes/index_update.cpp | 14 - src/storage/indexes/indexes.cpp | 140 -------- src/storage/label/label.cpp | 39 --- src/storage/label/label_collection.cpp | 45 --- src/storage/label/label_store.cpp | 21 -- src/storage/label/labels_writer.cpp | 13 - src/storage/model/json/all.hpp | 11 - src/storage/model/json/array.hpp | 81 ----- src/storage/model/json/bool.hpp | 30 -- src/storage/model/json/integral.hpp | 30 -- src/storage/model/json/json.hpp | 44 --- src/storage/model/json/null.hpp | 27 -- src/storage/model/json/object.hpp | 103 ------ src/storage/model/json/primitive.hpp | 26 -- src/storage/model/json/real.hpp | 30 -- src/storage/model/json/string.hpp | 31 -- src/storage/record_accessor.cpp | 24 -- src/storage/{model => }/typed_value.cpp | 2 +- src/storage/{model => }/typed_value_store.cpp | 2 +- src/storage/vertex_accessor.cpp | 95 ++---- src/storage/vertices.cpp | 56 ---- .../integration/_hardcoded_query/includes.hpp | 4 +- tests/integration/queries.cpp | 2 +- 99 files changed, 491 insertions(+), 3332 deletions(-) create mode 100644 include/database/creation_exception.hpp delete mode 100644 include/database/db.hpp create mode 100644 include/database/graph_db.hpp create mode 100644 include/database/graph_db_accessor.hpp delete mode 100644 include/storage/common.hpp delete mode 100644 include/storage/edge_record.hpp delete mode 100644 include/storage/edge_type/edge_type.hpp delete mode 100644 include/storage/edge_type/edge_type_store.hpp delete mode 100644 include/storage/edge_x_vertex.hpp delete mode 100644 include/storage/edges.hpp delete mode 100644 include/storage/indexes/impl/nonunique_unordered_index.hpp delete mode 100644 include/storage/indexes/impl/unique_ordered_index.hpp delete mode 100644 include/storage/indexes/index_base.hpp delete mode 100644 include/storage/indexes/index_definition.hpp delete mode 100644 include/storage/indexes/index_holder.hpp delete mode 100644 include/storage/indexes/index_record.hpp delete mode 100644 include/storage/indexes/index_update.hpp delete mode 100644 include/storage/indexes/indexes.hpp delete mode 100644 include/storage/indexes/keys/index_key.hpp delete mode 100644 include/storage/indexes/keys/non_unique_key.hpp delete mode 100644 include/storage/indexes/keys/unique_key.hpp delete mode 100644 include/storage/iterator/graph_composable.hpp delete mode 100644 include/storage/iterator/graph_filter.hpp delete mode 100644 include/storage/label/label.hpp delete mode 100644 include/storage/label/label_collection.hpp delete mode 100644 include/storage/label/label_store.hpp delete mode 100644 include/storage/label/labels_writer.hpp delete mode 100644 include/storage/model/edge_list.hpp delete mode 100644 include/storage/model/edge_map.hpp delete mode 100644 include/storage/model/edge_model.hpp delete mode 100644 include/storage/model/property_model.hpp delete mode 100644 include/storage/model/vertex_model.hpp delete mode 100644 include/storage/type_group_edge.hpp delete mode 100644 include/storage/type_group_vertex.hpp rename include/storage/{model => }/typed_value.hpp (100%) rename include/storage/{model => }/typed_value_store.hpp (100%) rename include/storage/{model => }/typed_value_utils.h (96%) delete mode 100644 include/storage/vertex_record.hpp delete mode 100644 include/storage/vertices.hpp create mode 100644 include/utils/pass_key.hpp delete mode 100644 src/database/db.cpp create mode 100644 src/database/graph_db.cpp delete mode 100644 src/storage/edge_type/edge_type.cpp delete mode 100644 src/storage/edge_type/edge_type_store.cpp delete mode 100644 src/storage/edges.cpp delete mode 100644 src/storage/indexes/impl/nonunique_unordered_index.cpp delete mode 100644 src/storage/indexes/impl/unique_ordered_index.cpp delete mode 100644 src/storage/indexes/index_base.cpp delete mode 100644 src/storage/indexes/index_holder.cpp delete mode 100644 src/storage/indexes/index_record.cpp delete mode 100644 src/storage/indexes/index_update.cpp delete mode 100644 src/storage/indexes/indexes.cpp delete mode 100644 src/storage/label/label.cpp delete mode 100644 src/storage/label/label_collection.cpp delete mode 100644 src/storage/label/label_store.cpp delete mode 100644 src/storage/label/labels_writer.cpp delete mode 100644 src/storage/model/json/all.hpp delete mode 100644 src/storage/model/json/array.hpp delete mode 100644 src/storage/model/json/bool.hpp delete mode 100644 src/storage/model/json/integral.hpp delete mode 100644 src/storage/model/json/json.hpp delete mode 100644 src/storage/model/json/null.hpp delete mode 100644 src/storage/model/json/object.hpp delete mode 100644 src/storage/model/json/primitive.hpp delete mode 100644 src/storage/model/json/real.hpp delete mode 100644 src/storage/model/json/string.hpp delete mode 100644 src/storage/record_accessor.cpp rename src/storage/{model => }/typed_value.cpp (99%) rename src/storage/{model => }/typed_value_store.cpp (97%) delete mode 100644 src/storage/vertices.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 789f7b5df..8fbb08da1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -303,33 +303,8 @@ set(memgraph_src_files ${src_dir}/snapshot/snapshot_decoder.cpp ${src_dir}/storage/vertices.cpp ${src_dir}/storage/edges.cpp - ${src_dir}/storage/label/label.cpp - ${src_dir}/storage/label/label_collection.cpp - ${src_dir}/storage/label/label_store.cpp - ${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/typed_value.cpp - ${src_dir}/storage/model/typed_value_store.cpp - ${src_dir}/storage/model/properties/null.cpp - ${src_dir}/storage/model/properties/bool.cpp - ${src_dir}/storage/model/properties/int32.cpp - ${src_dir}/storage/model/properties/int64.cpp - ${src_dir}/storage/model/properties/float.cpp - ${src_dir}/storage/model/properties/double.cpp - ${src_dir}/storage/model/properties/string.cpp - ${src_dir}/storage/model/properties/array.cpp - ${src_dir}/storage/model/properties/property.cpp - ${src_dir}/storage/model/properties/properties.cpp - ${src_dir}/storage/model/properties/stored_property.cpp - ${src_dir}/storage/model/properties/property_family.cpp - ${src_dir}/storage/indexes/indexes.cpp - ${src_dir}/storage/indexes/index_base.cpp - ${src_dir}/storage/indexes/index_record.cpp - ${src_dir}/storage/indexes/index_update.cpp - ${src_dir}/storage/indexes/index_holder.cpp - ${src_dir}/storage/indexes/impl/unique_ordered_index.cpp - ${src_dir}/storage/indexes/impl/nonunique_unordered_index.cpp + ${src_dir}/storage/typed_value.cpp + ${src_dir}/storage/typed_value_store.cpp ${src_dir}/storage/locking/record_lock.cpp ${src_dir}/storage/garbage/garbage.cpp ${src_dir}/storage/vertex_accessor.cpp diff --git a/cmake/copy_includes.cmake b/cmake/copy_includes.cmake index 5508be6cd..d4564c21f 100644 --- a/cmake/copy_includes.cmake +++ b/cmake/copy_includes.cmake @@ -6,29 +6,16 @@ FILE(COPY ${include_dir}/database/db.hpp DESTINATION ${build_include_dir}/databa 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}/storage/edge_x_vertex.hpp DESTINATION ${build_include_dir}/storage) FILE(COPY ${include_dir}/query/util.hpp DESTINATION ${build_include_dir}/query) @@ -71,42 +58,9 @@ FILE(COPY ${include_dir}/transactions/engine.hpp DESTINATION ${build_include_dir 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/typed_value.hpp DESTINATION ${build_include_dir}/storage/model) +FILE(COPY ${include_dir}/storage/typed_value_store.hpp DESTINATION ${build_include_dir}/storage/model) +FILE(COPY ${include_dir}/storage/typed_value_utils.hpp DESTINATION ${build_include_dir}/storage/model) 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) diff --git a/include/data_structures/concurrent/concurrent_set.hpp b/include/data_structures/concurrent/concurrent_set.hpp index dc5bb69cc..b748eb4f9 100644 --- a/include/data_structures/concurrent/concurrent_set.hpp +++ b/include/data_structures/concurrent/concurrent_set.hpp @@ -5,73 +5,65 @@ // Multi thread safe set based on skiplist. // T - type of data. -template -class ConcurrentSet -{ - typedef SkipList list; - typedef typename SkipList::Iterator list_it; - typedef typename SkipList::ConstIterator list_it_con; +template +class ConcurrentSet { + typedef SkipList list; + typedef typename SkipList::Iterator list_it; + typedef typename SkipList::ConstIterator list_it_con; public: - ConcurrentSet() {} + ConcurrentSet() {} - class Accessor : public AccessorBase - { - friend class ConcurrentSet; + class Accessor : public AccessorBase { + friend class ConcurrentSet; - using AccessorBase::AccessorBase; + using AccessorBase::AccessorBase; - private: - using AccessorBase::accessor; + private: + using AccessorBase::accessor; - public: - std::pair insert(const T &item) - { - return accessor.insert(item); - } + public: + std::pair insert(const T &item) { + return accessor.insert(item); + } - std::pair insert(T &&item) - { - return accessor.insert(std::move(item)); - } + std::pair insert(T &&item) { + return accessor.insert(std::move(item)); + } - list_it_con find(const T &item) const { return accessor.find(item); } + list_it_con find(const T &item) const { return accessor.find(item); } - list_it find(const T &item) { return accessor.find(item); } + list_it find(const T &item) { return accessor.find(item); } - // Returns iterator to item or first larger if it doesn't exist. - template - list_it_con find_or_larger(const K &item) const - { - return accessor.find_or_larger(item); - } + // Returns iterator to item or first larger if it doesn't exist. + template + list_it_con find_or_larger(const K &item) const { + return accessor.find_or_larger(item); + } - // Returns iterator to item or first larger if it doesn't exist. - template - list_it find_or_larger(const K &item) - { - return accessor.find_or_larger(item); - } + // Returns iterator to item or first larger if it doesn't exist. + template + list_it find_or_larger(const K &item) { + return accessor.find_or_larger(item); + } - // Returns iterator to item or first larger if it doesn't exist. - template - list_it_con cfind_or_larger(const K &item) - { - return accessor.template find_or_larger(item); - } + // Returns iterator to item or first larger if it doesn't exist. + template + list_it_con cfind_or_larger(const K &item) { + return accessor.template find_or_larger(item); + } - bool contains(const T &item) const - { - return this->find(item) != this->end(); - } + bool contains(const T &item) const { + return this->find(item) != this->end(); + } - bool remove(const T &item) { return accessor.remove(item); } - }; + bool remove(const T &item) { return accessor.remove(item); } + }; - Accessor access() { return Accessor(&skiplist); } + Accessor access() { return Accessor(&skiplist); } - const Accessor access() const { return Accessor(&skiplist); } + const Accessor access() const { return Accessor(&skiplist); } private: - list skiplist; + list skiplist; }; diff --git a/include/database/creation_exception.hpp b/include/database/creation_exception.hpp new file mode 100644 index 000000000..d10a39627 --- /dev/null +++ b/include/database/creation_exception.hpp @@ -0,0 +1,17 @@ +// +// Copyright 2017 Memgraph +// Created by Florijan Stamenkovic on 03.02.17. +// + +#pragma once + +#include "utils/exceptions/basic_exception.hpp" + + +class CreationException : public BasicException { +public: + using BasicException::BasicException; +}; + + + diff --git a/include/database/db.hpp b/include/database/db.hpp deleted file mode 100644 index e5d46b3cc..000000000 --- a/include/database/db.hpp +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include "storage/type_group_edge.hpp" -#include "storage/type_group_vertex.hpp" - -#include "snapshot/snapshot_engine.hpp" -#include "storage/garbage/garbage.hpp" -#include "storage/graph.hpp" -#include "transactions/engine.hpp" - -class Indexes; - -// TODO: Maybe split this in another layer between Db and Dbms. Where the new -// layer would hold SnapshotEngine and his kind of concept objects. Some -// guidelines would be: retain objects which are necessary to implement querys -// in Db, the rest can be moved to the new layer. - -/** - * Main class which represents Database concept in code. - */ -class Db { -public: - using sptr = std::shared_ptr; - - /** - * This constructor will create a database with the name "default" - * - * NOTE: explicit is here to prevent compiler from evaluating const char * - * into a bool. - * - * @param import_snapshot will in constructor import latest snapshot - * into the db. - */ - explicit Db(bool import_snapshot = true); - - /** - * Construct database with a custom name. - * - * @param name database name - * @param import_snapshot will in constructor import latest snapshot - * into the db. - */ - Db(const char *name, bool import_snapshot = true); - - /** - * Construct database with a custom name. - * - * @param name database name - * @param import_snapshot will in constructor import latest snapshot - * into the db. - */ - Db(const std::string &name, bool import_snapshot = true); - - /** - * Database object can't be copied. - */ - Db(const Db &db) = delete; - -private: - /** database name */ - const std::string name_; - -public: - /** transaction engine related to this database */ - tx::Engine tx_engine; - - /** graph related to this database */ - Graph graph; - - /** garbage collector related to this database*/ - Garbage garbage = {tx_engine}; - - /** - * snapshot engine related to this database - * - * \b IMPORTANT: has to be initialized after name - * */ - SnapshotEngine snap_engine = {*this}; - - /** - * Creates Indexes for this database. - */ - Indexes indexes(); - // TODO: Indexes should be created only once somwhere Like Db or layer - // between Db and Dbms. - - /** - * Returns a name of the database. - * - * @return database name - */ - std::string const &name() const; -}; diff --git a/include/database/db_accessor.hpp b/include/database/db_accessor.hpp index a8fc3c0df..77f38ea94 100644 --- a/include/database/db_accessor.hpp +++ b/include/database/db_accessor.hpp @@ -1,6 +1,6 @@ #pragma once -#include "database/db.hpp" +#include "database/graph_db.hpp" #include "database/db_transaction.hpp" #include "utils/border.hpp" #include "utils/iterator/iterator.hpp" diff --git a/include/database/graph_db.hpp b/include/database/graph_db.hpp new file mode 100644 index 000000000..f33e6c8be --- /dev/null +++ b/include/database/graph_db.hpp @@ -0,0 +1,112 @@ +#pragma once + +#include "data_structures/concurrent/skiplist.hpp" +#include "database/db_transaction.hpp" +#include "snapshot/snapshot_engine.hpp" +#include "storage/garbage/garbage.hpp" +#include "transactions/engine.hpp" +#include "mvcc/version_list.hpp" +#include "utils/pass_key.hpp" + +// forward declaring Edge and Vertex because they use +// GraphDb::Label etc., and therefore include this header +class Vertex; +class VertexAccessor; +class Edge; +class EdgeAccessor; + +// TODO: Maybe split this in another layer between Db and Dbms. Where the new +// layer would hold SnapshotEngine and his kind of concept objects. Some +// guidelines would be: retain objects which are necessary to implement querys +// in Db, the rest can be moved to the new layer. + +/** + * Main class which represents Database concept in code. + */ +class GraphDb { +public: + using sptr = std::shared_ptr; + + // definitions for what data types are used for a Label, Property, EdgeType + using Label = uint32_t; + using EdgeType = uint32_t; + using Property = uint32_t; + + /** + * This constructor will create a database with the name "default" + * + * NOTE: explicit is here to prevent compiler from evaluating const char * + * into a bool. + * + * @param import_snapshot will in constructor import latest snapshot + * into the db. + */ + explicit GraphDb(bool import_snapshot = true); + + /** + * Construct database with a custom name. + * + * @param name database name + * @param import_snapshot will in constructor import latest snapshot + * into the db. + */ + GraphDb(const char *name, bool import_snapshot = true); + + /** + * Construct database with a custom name. + * + * @param name database name + * @param import_snapshot will in constructor import latest snapshot + * into the db. + */ + GraphDb(const std::string &name, bool import_snapshot = true); + + /** + * Database object can't be copied. + */ + GraphDb(const GraphDb &db) = delete; + + /** + * Creates a new Vertex and returns an accessor to it. + * + * @param db_trans The transaction that is creating a vertex. + * @return See above. + */ + VertexAccesor insert_vertex(DbTransaction& db_trans); + + /** + * Creates a new Edge and returns an accessor to it. + * + * @param db_trans The transaction that is creating an Edge. + * @param from The 'from' vertex. + * @param to The 'to' vertex' + * @param type Edge type. + * @return An accessor to the edge. + */ + EdgeAccessor insert_edge(DbTransaction& db_trans, VertexAccessor& from, + VertexAccessor& to, EdgeType type); + + + /** transaction engine related to this database */ + tx::Engine tx_engine; + + + /** garbage collector related to this database*/ +// TODO bring back garbage collection +// Garbage garbage = {tx_engine}; + +// TODO bring back shapshot engine +// SnapshotEngine snap_engine = {*this}; + + // database name + const std::string name_; + +private: + // main storage for the graph + SkipList*> edges_; + SkipList*> vertices_; + + // utility stuff + const PassKey pass_key; +}; + diff --git a/include/database/graph_db_accessor.hpp b/include/database/graph_db_accessor.hpp new file mode 100644 index 000000000..589f5d756 --- /dev/null +++ b/include/database/graph_db_accessor.hpp @@ -0,0 +1,24 @@ +// +// Copyright 2017 Memgraph +// Created by Florijan Stamenkovic on 03.02.17. +// + +#pragma + +#include "graph_db.hpp" +#include "transactions/transaction.hpp" + + +class GraphDbAccessor { + +public: + tx::Transaction transaction_; + +private: + + + +}; + + + diff --git a/include/dbms/cleaner.hpp b/include/dbms/cleaner.hpp index 47303339e..c5dd88f6f 100644 --- a/include/dbms/cleaner.hpp +++ b/include/dbms/cleaner.hpp @@ -1,6 +1,6 @@ #pragma once -#include "database/db.hpp" +#include "database/graph_db.hpp" #include "threading/thread.hpp" class Thread; diff --git a/include/dbms/dbms.hpp b/include/dbms/dbms.hpp index 9612d1aad..af503c287 100644 --- a/include/dbms/dbms.hpp +++ b/include/dbms/dbms.hpp @@ -2,7 +2,7 @@ #include "config/config.hpp" #include "data_structures/concurrent/concurrent_map.hpp" -#include "database/db.hpp" +#include "database/graph_db.hpp" #include "dbms/cleaner.hpp" #include "snapshot/snapshoter.hpp" diff --git a/include/mvcc/version_list.hpp b/include/mvcc/version_list.hpp index 35b05ade7..da0c19b72 100644 --- a/include/mvcc/version_list.hpp +++ b/include/mvcc/version_list.hpp @@ -17,7 +17,7 @@ namespace mvcc { using uptr = std::unique_ptr>; using item_t = T; - VersionList(Id id) : id(id) {} + VersionList() = default; VersionList(const VersionList &) = delete; @@ -179,8 +179,6 @@ namespace mvcc { record->mark_deleted(t); } - const Id id; - private: void lock_and_validate(T *record, tx::Transaction &t) { assert(record != nullptr); diff --git a/include/query/engine.hpp b/include/query/engine.hpp index c506f4c7e..bdc6026c5 100644 --- a/include/query/engine.hpp +++ b/include/query/engine.hpp @@ -2,7 +2,7 @@ #include -#include "database/db.hpp" +#include "database/graph_db.hpp" #include "logging/default.hpp" #include "query/exception/query_engine.hpp" #include "query/plan/program.hpp" diff --git a/include/query/i_plan_cpu.hpp b/include/query/i_plan_cpu.hpp index 0e2fbfa9e..a8790f730 100644 --- a/include/query/i_plan_cpu.hpp +++ b/include/query/i_plan_cpu.hpp @@ -1,7 +1,7 @@ #pragma once #include "communication/communication.hpp" -#include "database/db.hpp" +#include "database/graph_db.hpp" #include "database/db_accessor.hpp" #include "query/strip/stripped.hpp" diff --git a/include/query/plan/program_executor.hpp b/include/query/plan/program_executor.hpp index 38537afc4..0e85d3556 100644 --- a/include/query/plan/program_executor.hpp +++ b/include/query/plan/program_executor.hpp @@ -2,7 +2,7 @@ #include -#include "database/db.hpp" +#include "database/graph_db.hpp" #include "query/exception/query_engine.hpp" #include "query/exception/plan_execution.hpp" #include "query/plan/program.hpp" diff --git a/include/snapshot/snapshoter.hpp b/include/snapshot/snapshoter.hpp index 5c72980b4..7b110c381 100644 --- a/include/snapshot/snapshoter.hpp +++ b/include/snapshot/snapshoter.hpp @@ -2,7 +2,7 @@ #include -#include "database/db.hpp" +#include "database/graph_db.hpp" #include "logging/default.hpp" #include "threading/thread.hpp" diff --git a/include/storage/common.hpp b/include/storage/common.hpp deleted file mode 100644 index 8e29ab91e..000000000 --- a/include/storage/common.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "data_structures/concurrent/concurrent_map.hpp" -#include "mvcc/version_list.hpp" -#include "transactions/transaction.hpp" -#include "utils/counters/atomic_counter.hpp" diff --git a/include/storage/edge.hpp b/include/storage/edge.hpp index 5bff367d1..8525ee355 100644 --- a/include/storage/edge.hpp +++ b/include/storage/edge.hpp @@ -1,38 +1,17 @@ #pragma once +#include "database/graph_db.hpp" #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" +#include "mvcc/version_list.hpp" +#include "storage/typed_value_store.hpp" -class Edge : public mvcc::Record -{ - using buffer_t = utils::StringBuffer; - using props_writer_t = JsonWriter; +// forward declare Vertex because there is a circular usage Edge <-> Vertex +class Vertex; +class Edge : public mvcc::Record { public: - class Accessor; - - Edge() = default; - Edge(const EdgeModel &data) : data(data) {} - Edge(EdgeModel &&data) : data(std::move(data)) {} - - Edge(const Edge &) = delete; - Edge(Edge &&) = delete; - - Edge &operator=(const Edge &) = delete; - 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() << ")"; - } + mvcc::VersionList* from_; + mvcc::VersionList* to_; + GraphDb::EdgeType edge_type_; + TypedValueStore properties_; }; diff --git a/include/storage/edge_accessor.hpp b/include/storage/edge_accessor.hpp index 40e0eee24..3eb54ba4f 100644 --- a/include/storage/edge_accessor.hpp +++ b/include/storage/edge_accessor.hpp @@ -1,55 +1,24 @@ #pragma once #include "storage/edge.hpp" -#include "storage/edge_record.hpp" #include "storage/record_accessor.hpp" -#include "storage/vertex_accessor.hpp" #include "utils/assert.hpp" #include "utils/reference_wrapper.hpp" +#include "database/graph_db.hpp" -class EdgeType; -using edge_type_ref_t = ReferenceWrapper; - -class Edges; - -// There exists circular dependecy with VertexAccessor. -class EdgeAccessor : public RecordAccessor -{ - friend VertexAccessor; +class VertexAccessor; +class EdgeAccessor : public RecordAccessor { public: - using RecordAccessor::RecordAccessor; + using RecordAccessor::RecordAccessor; - using record_t = Edge; - using record_list_t = EdgeRecord; + void set_edge_type(GraphDb::EdgeType edge_type); - // Removes self and disconects vertices from it. - void remove() const; + EdgeType edge_type() const; - void edge_type(EdgeType const &edge_type); + VertexAccessor from() const; - const EdgeType &edge_type() const; + VertexAccessor to() const; - // EdgeAccessor doesnt need to be filled - VertexAccessor from() const; - - // 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'; - } + void remove() const; }; diff --git a/include/storage/edge_record.hpp b/include/storage/edge_record.hpp deleted file mode 100644 index 50ce0a42d..000000000 --- a/include/storage/edge_record.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "mvcc/version_list.hpp" -#include "storage/edge.hpp" - -class VertexRecord; - -class EdgeRecord : public mvcc::VersionList -{ -public: - EdgeRecord(Id id, VertexRecord *from, VertexRecord *to) - : from_v(from), to_v(to), VersionList(id) - { - } - EdgeRecord(const VersionList &) = delete; - - /* @brief Move constructs the version list - * Note: use only at the beginning of the "other's" lifecycle since this - * constructor doesn't move the RecordLock, but only the head pointer - */ - EdgeRecord(EdgeRecord &&other) - : from_v(other.from_v), to_v(other.to_v), VersionList(std::move(other)) - { - } - - VertexRecord *&get_key() { return this->from_v; } - - auto from() const { return this->from_v; } - - auto to() const { return this->to_v; } - -protected: - VertexRecord *from_v; - VertexRecord *to_v; -}; diff --git a/include/storage/edge_type/edge_type.hpp b/include/storage/edge_type/edge_type.hpp deleted file mode 100644 index 8838c42d8..000000000 --- a/include/storage/edge_type/edge_type.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include -#include - -#include "storage/edge.hpp" -#include "storage/edge_accessor.hpp" -#include "storage/indexes/impl/nonunique_unordered_index.hpp" -#include "storage/type_group_edge.hpp" -#include "utils/char_str.hpp" -#include "utils/reference_wrapper.hpp" -#include "utils/total_ordering.hpp" - -using EdgeTypeIndexRecord = IndexRecord; - -class EdgeType : public TotalOrdering -{ -public: - using type_index_t = NonUniqueUnorderedIndex; - - EdgeType() = delete; - - EdgeType(const std::string &id); - EdgeType(const char *id); - EdgeType(std::string &&id); - - EdgeType(const EdgeType &) = delete; - EdgeType(EdgeType &&other) = default; - - friend bool operator<(const EdgeType &lhs, const EdgeType &rhs); - - friend bool operator==(const EdgeType &lhs, const EdgeType &rhs); - - friend std::ostream &operator<<(std::ostream &stream, const EdgeType &type); - - operator const std::string &() const; - - std::string const &str() const { return id; } - - CharStr char_str() { return CharStr(&id[0]); } - - // Index of esges which have this type. - type_index_t &index() const; - -private: - std::string id; - std::unique_ptr index_v; -}; - -using edge_type_ref_t = ReferenceWrapper; diff --git a/include/storage/edge_type/edge_type_store.hpp b/include/storage/edge_type/edge_type_store.hpp deleted file mode 100644 index ac30176b0..000000000 --- a/include/storage/edge_type/edge_type_store.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include - -#include "data_structures/concurrent/concurrent_map.hpp" -#include "storage/edge_type/edge_type.hpp" -#include "utils/char_str.hpp" - -class EdgeTypeStore -{ -public: - using store_t = ConcurrentMap>; - - store_t::Accessor access(); - - const EdgeType &find_or_create(const char *name); - - bool contains(const char *name); // TODO: const - - // TODO: implement find method - // return { EdgeType, is_found } - - // TODO: find by reference if it is possible (should be faster) - // figure out the fastest way to store and find types - // do the same for labels - - // TODO: EdgeTypeStore and LabelStore are almost the same - // templetize the two of them - -private: - store_t edge_types; -}; diff --git a/include/storage/edge_x_vertex.hpp b/include/storage/edge_x_vertex.hpp deleted file mode 100644 index 382fe4a0c..000000000 --- a/include/storage/edge_x_vertex.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -// There exists circular dependecy with EdgeAccessor. This file serves to break -// that circularity. -#include "storage/edge_accessor.hpp" -#include "storage/vertex_accessor.hpp" - -auto VertexAccessor::out() const -{ - DbTransaction &t = this->db; - return iter::make_map(iter::make_iter_ref(record->data.out), - [&](auto e) -> auto { return EdgeAccessor(*e, t); }); -} - -auto VertexAccessor::in() const -{ - DbTransaction &t = this->db; - return iter::make_map(iter::make_iter_ref(record->data.in), - [&](auto e) -> auto { return EdgeAccessor(e, t); }); -} diff --git a/include/storage/edges.hpp b/include/storage/edges.hpp deleted file mode 100644 index de6b6ef99..000000000 --- a/include/storage/edges.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include - -#include "data_structures/concurrent/concurrent_map.hpp" -#include "utils/counters/atomic_counter.hpp" -#include "utils/option.hpp" - -#include "storage/edge_record.hpp" -#include "storage/model/properties/property_family.hpp" - -class EdgeAccessor; -class DbTransaction; - -using EdgePropertyFamily = PropertyFamily; -template -using EdgeIndexBase = IndexBase; - -class Edges -{ - using prop_familys_t = ConcurrentMap; - using store_t = ConcurrentMap; - -public: - store_t::Accessor access(); - - Option find(DbTransaction &t, const Id &id); - - // Creates new Edge and returns filled EdgeAccessor. - EdgeAccessor insert(DbTransaction &t, VertexRecord *from, VertexRecord *to); - - prop_familys_t::Accessor property_family_access(); - - EdgePropertyFamily &property_family_find_or_create(const std::string &name); - -private: - // TODO: Because familys wont be removed this could be done with more - // efficent - // data structure. - prop_familys_t prop_familys; - - // NOTE: this must be before prop_familys field to be destroyed before them. - // Because there are property_family references in vertices. - store_t edges; - - AtomicCounter counter; -}; diff --git a/include/storage/indexes/impl/nonunique_unordered_index.hpp b/include/storage/indexes/impl/nonunique_unordered_index.hpp deleted file mode 100644 index 8a551c081..000000000 --- a/include/storage/indexes/impl/nonunique_unordered_index.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "storage/indexes/index_base.hpp" -// #include "storage/indexes/index_record.hpp" - -#include "data_structures/concurrent/concurrent_list.hpp" - -template -class NonUniqueUnorderedIndex : public IndexBase -{ -public: - using store_t = ConcurrentList>; - // typedef T value_type; - // typedef K key_type; - - // Created with the database - NonUniqueUnorderedIndex(IndexLocation &&loc); - - NonUniqueUnorderedIndex(IndexLocation &&loc, tx::Transaction const &t); - - // Insert's value. - // nonunique => always succeds. - bool insert(IndexRecord &&value) final; - - // Returns iterator which returns valid records in range. - // ordered==None => doesn't guarantee any order of submitting records. - iter::Virtual - for_range(DbAccessor &t, Border from = Border(), - Border to = Border()) final; - - // Same as for_range just whit known returned iterator. - auto for_range_exact(DbAccessor &t, Border from = Border(), - Border to = Border()); - - // Removes for all transactions obsolete Records. - // Cleaner has to call this method when he decideds that it is time for - // cleaning. Id must be id of oldest active transaction. - void clean(const Id &id) final; - -private: - store_t list; -}; diff --git a/include/storage/indexes/impl/unique_ordered_index.hpp b/include/storage/indexes/impl/unique_ordered_index.hpp deleted file mode 100644 index 09a9b22bf..000000000 --- a/include/storage/indexes/impl/unique_ordered_index.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "storage/indexes/index_base.hpp" - -#include "data_structures/concurrent/concurrent_set.hpp" - -// TODO: T shoud be TG (TypeGroup) -template -class UniqueOrderedIndex : public IndexBase -{ -public: - // typedef T value_type; - // typedef K key_type; - - // Created with the database - UniqueOrderedIndex(IndexLocation loc, Order order); - - UniqueOrderedIndex(IndexLocation loc, Order order, - tx::Transaction const &t); - - // Insert's value. - // nonunique => always succeds. - bool insert(IndexRecord &&value) final; - - // Returns iterator which returns valid records in range. - // ordered==None => doesn't guarantee any order of submitting records. - iter::Virtual - for_range(DbAccessor &t, Border from = Border(), - Border to = Border()) final; - - // Same as for_range just whith known returned iterator. - auto for_range_exact(DbAccessor &t, Border from = Border(), - Border to = Border()); - - // Removes for all transactions obsolete Records. - // Cleaner has to call this method when he decideds that it is time for - // cleaning. Id must be id of oldest active transaction. - void clean(const Id &id) final; - -private: - ConcurrentSet> set; -}; diff --git a/include/storage/indexes/index_base.hpp b/include/storage/indexes/index_base.hpp deleted file mode 100644 index 9ce62918b..000000000 --- a/include/storage/indexes/index_base.hpp +++ /dev/null @@ -1,84 +0,0 @@ - -#pragma once - -#include -#include -#include -#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" -#include "utils/iterator/virtual_iter.hpp" - -template -class IndexRecord; - -class DbTransaction; -class DbAccessor; -namespace tx -{ -class Transaction; -} - -// Interface for all indexes. -// TG type group -// K type of key on which records are ordered -template -class IndexBase : public DeleteSensitive, public Loggable -{ -public: - // Created with the database - IndexBase(IndexDefinition &&it, std::string &&logger_name = "IndexBase"); - - IndexBase(IndexDefinition &&it, const tx::Transaction &t, - std::string &&logger_name = "IndexBase"); - - virtual ~IndexBase(){}; - - // Insert's value. - // unique => returns false if there is already valid equal value. - // nonunique => always succeds. - virtual bool insert(IndexRecord &&value) = 0; - - // Returns iterator which returns valid filled records in range. - // order==noe => doesn't guarantee any order of returned records. - // order==Ascending => guarantees order of returnd records will be from - // smallest to largest. - // order==Descending => guarantees order of returned records will be from - // largest to smallest. - // Range must be from<=to - virtual iter::Virtual - for_range(DbAccessor &, Border from = Border(), - Border to = Border()) = 0; - - // Removes for all transactions obsolete Records. - // Cleaner has to call this method when he decideds that it is time for - // cleaning. Id must be id of oldest active transaction. - virtual void clean(const Id &id) = 0; - - // Activates index for readers. - void activate(); - - // True if index is ready for reading. - bool can_read(); - - // True if transaction is obliged to insert T into index. - bool is_obliged_to_insert(const tx::Transaction &t); - - IndexType type() const { return it.type; } - - const IndexDefinition &definition() const { return it; } - -protected: - Logger logger; - -private: - const IndexDefinition it; - // Id of transaction which created this index. - const Id created; - // Active state - std::atomic_bool active = {false}; -}; diff --git a/include/storage/indexes/index_definition.hpp b/include/storage/indexes/index_definition.hpp deleted file mode 100644 index e99705d1b..000000000 --- a/include/storage/indexes/index_definition.hpp +++ /dev/null @@ -1,104 +0,0 @@ -#pragma once - -#include "utils/option.hpp" -#include "utils/order.hpp" -#include "utils/underlying_cast.hpp" - -enum DbSide : uint8_t -{ - EdgeSide = 0, - VertexSide = 1, -}; - -struct IndexType -{ -public: - // Are the records unique - const bool unique; - // Ordering of the records. - const Order order; -}; - -// Defines location of index in a sense of what is necessary to be present in -// Edge/Vertex for it to be in index. -struct IndexLocation -{ -public: - // Returns code for location. - size_t location_code() const - { - return (property_name.is_present() ? 1 : 0) | - (label_name.is_present() ? 2 : 0) | - (edge_type_name.is_present() ? 4 : 0); - } - - IndexLocation clone() const - { - return IndexLocation{side, property_name, label_name, edge_type_name}; - } - - const DbSide side; - const Option property_name; - const Option label_name; - const Option edge_type_name; -}; - -// Fully answers: -// Index on what? -// What kind of index? -struct IndexDefinition -{ -public: - // Serializes self which can be deserialized. - template - void serialize(E &encoder) const - { - std::string empty; - encoder.write_integer(underlying_cast(loc.side)); - encoder.write_string(loc.property_name.get_or(empty)); - encoder.write_string(loc.label_name.get_or(empty)); - encoder.write_string(loc.edge_type_name.get_or(empty)); - encoder.write_bool(type.unique); - encoder.write_integer(underlying_cast(type.order)); - } - - // Deserializes self. - template - static IndexDefinition deserialize(D &decoder) - { - auto side = decoder.integer() == 0 ? EdgeSide : VertexSide; - - std::string property_name_s; - decoder.string(property_name_s); - auto property_name = - property_name_s.empty() - ? Option() - : Option(std::move(property_name_s)); - - std::string label_name_s; - decoder.string(label_name_s); - auto label_name = label_name_s.empty() - ? Option() - : Option(std::move(label_name_s)); - - std::string edge_type_name_s; - decoder.string(edge_type_name_s); - auto edge_type_name = - edge_type_name_s.empty() - ? Option() - : Option(std::move(edge_type_name_s)); - - bool unique = decoder.read_bool(); - - auto order_v = decoder.integer(); - auto order = - order_v == 0 ? None : (order_v == 1 ? Ascending : Descending); - - return IndexDefinition{ - IndexLocation{side, property_name, label_name, edge_type_name}, - IndexType{unique, order}}; - } - - const IndexLocation loc; - const IndexType type; -}; diff --git a/include/storage/indexes/index_holder.hpp b/include/storage/indexes/index_holder.hpp deleted file mode 100644 index 28626b489..000000000 --- a/include/storage/indexes/index_holder.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -#include "storage/indexes/index_base.hpp" -#include "utils/option.hpp" -#include "utils/option_ptr.hpp" - -namespace tx -{ -class Transaction; -} - -// Holds one index which can be changed. Convinient class. -// TG - type group -// K - key of index_records -template -class IndexHolder -{ - -public: - IndexHolder() = default; - - IndexHolder(IndexHolder const &) = delete; - - IndexHolder(IndexHolder &&) = default; - - // Sets index for this property family. returns false if index is already - // present. - bool set_index(std::unique_ptr> inx); - - // Returns index for read only if it is present and it's valid for read. - OptionPtr> get_read() const; - - // Returns index for write only if it's present and transaction is - // responsibly for updating it. - OptionPtr> get_write(const tx::Transaction &t) const; - - // Removes index if it is given index. Caller is now responsable of - // disposing index in a safe way. - Option>> - remove_index(IndexBase *index); - - // Caller is now responsable of disposing index in a safe way. - Option>> remove_index(); - -private: - std::atomic *> index = {nullptr}; -}; diff --git a/include/storage/indexes/index_record.hpp b/include/storage/indexes/index_record.hpp deleted file mode 100644 index 4c54c376a..000000000 --- a/include/storage/indexes/index_record.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -#include "mvcc/id.hpp" -#include "utils/border.hpp" -#include "utils/total_ordering.hpp" - -namespace tx -{ -class Transaction; -} -class DbTransaction; - -// TG type group -// K key on which record is ordered. -template -class IndexRecord : public TotalOrdering>, - public TotalOrdering, IndexRecord> -{ -public: - IndexRecord() = default; - - IndexRecord(K key, typename TG::record_t *record, - typename TG::vlist_t *vlist); - - friend bool operator<(const IndexRecord &lhs, const IndexRecord &rhs) - { - return (lhs.key < rhs.key || - (lhs.key == rhs.key && lhs.vlist == rhs.vlist && - lhs.record < rhs.record)) ^ - lhs.descending; - } - - friend bool operator==(const IndexRecord &lhs, const IndexRecord &rhs) - { - return lhs.key == rhs.key && - (lhs.vlist != rhs.vlist || lhs.record == rhs.record); - } - - friend bool operator<(const Border &lhs, const IndexRecord &rhs) - { - return lhs < rhs.key; - } - - friend bool operator==(const Border &lhs, const IndexRecord &rhs) - { - return lhs == rhs.key; - } - - // Will change ordering of record to descending. - void set_descending(); - - // true if record is nullptr. - bool empty() const; - - // True if this index record i valid for given Transaction. - bool is_valid(tx::Transaction &t) const; - - // True if it can be removed. - bool to_clean(const Id &oldest_active) const; - - // This method is valid only if is_valid is true. - const auto access(DbTransaction &db) const; - - const K key; - -private: - bool descending = false; // TODO: this can be passed as template argument. - typename TG::record_t *const record{nullptr}; - typename TG::vlist_t *const vlist{nullptr}; -}; diff --git a/include/storage/indexes/index_update.hpp b/include/storage/indexes/index_update.hpp deleted file mode 100644 index 899eff11f..000000000 --- a/include/storage/indexes/index_update.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include "storage/indexes/index_record.hpp" -#include "storage/type_group_edge.hpp" -#include "storage/type_group_vertex.hpp" - -// Record for updating indexes of edge -struct IndexUpdateEdge -{ - EdgeRecord *vlist; - Edge *record; -}; - -// Record for updatin indexes of vertex -struct IndexUpdateVertex -{ - VertexRecord *vlist; - Vertex *record; -}; - -// based of IndexUpdate objects IndexRecords are created -// at the end of transaction (inside commit called on DbAccessor) -struct IndexUpdate -{ - enum - { - EDGE, - VERTEX - } tag; - - union - { - IndexUpdateEdge e; - IndexUpdateVertex v; - }; -}; - -template -IndexUpdate make_index_update(V *vlist, T *record); - -template <> -IndexUpdate make_index_update(EdgeRecord *vlist, Edge *record); - -template <> -IndexUpdate make_index_update(VertexRecord *vlist, Vertex *record); diff --git a/include/storage/indexes/indexes.hpp b/include/storage/indexes/indexes.hpp deleted file mode 100644 index 677d21fea..000000000 --- a/include/storage/indexes/indexes.hpp +++ /dev/null @@ -1,308 +0,0 @@ -#pragma once - -#include "database/db.hpp" -#include "storage/garbage/garbage.hpp" -#include "storage/graph.hpp" -#include "storage/indexes/impl/nonunique_unordered_index.hpp" -#include "storage/indexes/impl/unique_ordered_index.hpp" -#include "storage/indexes/index_definition.hpp" -#include "transactions/engine.hpp" -#include "utils/exceptions/non_exaustive_switch.hpp" -#include "utils/exceptions/not_yet_implemented.hpp" - -// Operation on indexes in the This should be the only place which knows how -// to get all indexes in database. -// TODO: This class should be updated accordingly when adding new place for -// index. -class Indexes -{ -public: - Indexes(Db &d) : db(d) {} - - // Adds index defined in given definition. Returns true if successfull. - bool add_index(IndexDefinition id); - - // currently caller has to get index through object that contains - // the index - - // TODO: redesign - // - // this was a nice try - // // Returns index from location. - // template - // Option> get_index(IndexLocation loc) - // { - // size_t code = loc.location_code(); - // - // switch (code) { - // case 0: // Illegal location - // return Option>(); - // - // case 1: - // switch (loc.side) { - // case EdgeSide: { - // return make_option( - // db.graph.edges - // .property_family_find_or_create(loc.property_name.get()) - // .index); - // } - // case VertexSide: { - // return make_option( - // db.graph.vertices - // .property_family_find_or_create(loc.property_name.get()) - // .index); - // } - // default: - // throw new NonExhaustiveSwitch("Unkown side: " + - // std::to_string(loc.side)); - // }; - // - // case 2: // Can't be removed - // return Option>(); - // - // case 3: // Not yet implemented - // throw new NotYetImplemented("Getting index over label and " - // "property isn't yet implemented"); - // case 4: // Can't be removed - // return Option>(); - // - // case 5: // Not yet implemented - // throw new NotYetImplemented("Getting index over edge_type and " - // "property isn't yet implemented"); - // case 6: // Not yet implemented - // throw new NotYetImplemented("Getting index over edge_type and " - // "label isn't yet implemented"); - // case 7: // Not yet implemented - // throw new NotYetImplemented("Getting index over label, edge_type - // " - // "and property isn't yet - // implemented"); - // default: - // throw new NonExhaustiveSwitch("Unkown index location code: " + - // std::to_string(code)); - // } - // } - - // Removes index from given location. Returns true if successfull or if no - // index was present. False if index location is illegal. - bool remove_index(IndexLocation loc) - { - size_t code = loc.location_code(); - - switch (code) { - case 0: // Illegal location - return false; - - case 1: - switch (loc.side) { - case EdgeSide: { - return remove_index( - db.graph.edges - .property_family_find_or_create(loc.property_name.get()) - .index); - } - case VertexSide: { - return remove_index( - db.graph.vertices - .property_family_find_or_create(loc.property_name.get()) - .index); - } - default: - throw new NonExhaustiveSwitch("Unkown side: " + - std::to_string(loc.side)); - }; - - case 2: // Can't be removed - return false; - - case 3: // Not yet implemented - throw new NotYetImplemented("Remove of index over label and " - "property isn't yet implemented"); - case 4: // Can't be removed - return false; - - case 5: // Not yet implemented - throw new NotYetImplemented("Remove of index over edge_type and " - "property isn't yet implemented"); - case 6: // Not yet implemented - throw new NotYetImplemented("Remove of index over edge_type and " - "label isn't yet implemented"); - case 7: // Not yet implemented - throw new NotYetImplemented("Remove of index over label, edge_type " - "and property isn't yet implemented"); - default: - throw new NonExhaustiveSwitch("Unkown index location code: " + - std::to_string(code)); - } - } - - // Calls F over all vertex indexes in the database which are readable. - template - void vertex_indexes(F &&f) - { - for (auto &l : db.graph.label_store.access()) { - f(l.second.get()->index()); - } - - for_all_property_indexes_read( - db.graph.vertices.property_family_access(), f); - } - - // Calls F over all edge indexes in the database which are readable. - template - void edge_indexes(F &&f) - { - for (auto &l : db.graph.edge_type_store.access()) { - f(l.second.get()->index()); - } - - for_all_property_indexes_read(db.graph.edges.property_family_access(), - f); - } - - // Updates property indexes for given TypeGroup TG and IU index_update - template - bool update_property_indexes(IU &iu, const tx::Transaction &t) - { - for (auto kp : iu.record->data.props) { - - // FamilyProperty index - auto opi = kp.key.get_family().index.get_write(t); - if (opi.is_present()) { - if (!opi.get()->insert(IndexRecord( - std::nullptr_t(), iu.record, iu.vlist))) { - return false; - } - } - - // TODO: other property indexes - } - - return true; - } - -private: - // Calls F for all * property indexes which are readable. - template - void for_all_property_indexes_read(A &&acc, F &f) - { - for (auto &family : acc) { - auto oi = family.second->index.get_read(); - if (oi.is_present()) { - f(*oi.get()); - } - } - - // TODO: Code for reaching other property indexes which are not yet - // coded into the database. - } - - // Creates type of index specified ind index definition. - // TG - type group vertex/edge - // K - key of index - template - std::unique_ptr> create_index(IndexDefinition id, - tx::Transaction const &t) - { - // Determine which index is needed - if (id.type.unique) { - switch (id.type.order) { - case None: { - // TODO: Implement this version of index. - throw NotYetImplemented( - "Missing implementation for Unique Unordered Index"); - } - case Ascending: - case Descending: { - return std::make_unique>( - id.loc.clone(), id.type.order, t); - } - default: - throw new NonExhaustiveSwitch("Unknown order: " + - std::to_string(id.type.order)); - }; - - } else { - switch (id.type.order) { - case None: { - return std::make_unique>( - id.loc.clone(), t); - } - case Ascending: - case Descending: { - // TODO: Implement this version of index. - throw NotYetImplemented( - "Missing implementation for Nonunique Ordered Index"); - } - default: - throw new NonExhaustiveSwitch("Unknown order: " + - std::to_string(id.type.order)); - }; - } - } - - // Fills index with returned elements. Return true if successfully filled. - // Iterator must return std::pair - template - bool fill_index(DbTransaction &t, IndexHolder &holder, I &&iter) - { - // Wait for all other active transactions to finish so that this - // transaction can see there changes so that they can be added into - // index. - t.trans.wait_for_active(); - - auto oindex = holder.get_write(t.trans); - if (oindex.is_present()) { - // Inexed to which whe must insert is present. This wouldn't be the - // case if someone removed it. - auto index = oindex.get(); - - // Iterate over all elements and add them into index. Fail if - // some insert failed. - bool res = iter.all([&](auto elem) { - // Try to insert record. - if (!index->insert(elem.first.create_index_record( - std::move(elem.second)))) { - // Index is probably unique. - - // Index wasn't successfully filled so whe should remove it - // an safely dispose of it. - auto owned_maybe = holder.remove_index(index); - if (owned_maybe.is_present()) { - db.garbage.dispose(db.tx_engine.snapshot(), - owned_maybe.get().release()); - } - - return false; - } - return true; - }); - if (res) { - // Index has been updated accordingly and whe can activate it - // for read. - index->activate(); - return true; - } - } - - return false; - } - - // Removes index from index holder - template - bool remove_index(IndexHolder &ih) - { - auto owned_maybe = ih.remove_index(); - if (owned_maybe.is_present()) { - // Index was successfully removed so whe are responsible for - // dispoising it safely. - db.garbage.dispose(db.tx_engine.snapshot(), - owned_maybe.get().release()); - return true; - } - - return false; - } - - Db &db; -}; diff --git a/include/storage/indexes/keys/index_key.hpp b/include/storage/indexes/keys/index_key.hpp deleted file mode 100644 index 0dd847153..000000000 --- a/include/storage/indexes/keys/index_key.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -// TODO: DEPRICATED - -#include "utils/total_ordering.hpp" - -#include "storage/model/properties/properties.hpp" -#include "storage/model/properties/property.hpp" - -template -class UniqueIndexKey -{ -public: -}; - -template -class IndexKey -{ -public: -}; diff --git a/include/storage/indexes/keys/non_unique_key.hpp b/include/storage/indexes/keys/non_unique_key.hpp deleted file mode 100644 index d64227258..000000000 --- a/include/storage/indexes/keys/non_unique_key.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -// TODO: DEPRICATED - -#include "unique_key.hpp" - -template -class NonUniqueKey -{ -public: - NonUniqueKey(const K& key, const T&) - { - - } - -private: - intptr_t x; -}; diff --git a/include/storage/indexes/keys/unique_key.hpp b/include/storage/indexes/keys/unique_key.hpp deleted file mode 100644 index 6c415795c..000000000 --- a/include/storage/indexes/keys/unique_key.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -// TODO: DEPRICATED - -#include "utils/total_ordering.hpp" - -#include "storage/indexes/sort_order.hpp" -#include "storage/model/properties/properties.hpp" -#include "storage/model/properties/property.hpp" - -template -class UniqueKey : public TotalOrdering> -{ -public: - using type = UniqueKey; - using key_t = K; - - UniqueKey(const K& key) : key(key) {} - - friend constexpr bool operator<(const type& lhs, const type& rhs) - { - return sort_order(lhs.key, rhs.key); - } - - friend constexpr bool operator==(const type& lhs, const type& rhs) - { - return lhs.key == rhs.key; - } - - operator const K&() const { return key; } - -private: - static constexpr SortOrder sort_order = SortOrder(); - const K& key; -}; - -template -constexpr SortOrder UniqueKey::sort_order; - -template -using UniqueKeyAsc = UniqueKey>; - -template -using UniqueKeyDesc = UniqueKey>; - diff --git a/include/storage/iterator/graph_composable.hpp b/include/storage/iterator/graph_composable.hpp deleted file mode 100644 index 37093d967..000000000 --- a/include/storage/iterator/graph_composable.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" - -// Class for creating easy composable iterators for querying. -// -// This class contains graph specific methods. -// -// Derived - type of derived class -// T - return type -template -class GraphComposable : public Composable> -{ - // TODO: various filters - // from filter - // to filter - // match filter -}; - - diff --git a/include/storage/iterator/graph_filter.hpp b/include/storage/iterator/graph_filter.hpp deleted file mode 100644 index 6a26f2acf..000000000 --- a/include/storage/iterator/graph_filter.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "utils/iterator/filter.hpp" -#include "storage/iterator/graph_composable.hpp" - -template -class GraphFilter : public Filter, - public GraphComposable -{ - using Filter::Filter; -}; - -template -auto make_graph_filter(I &&iter, OP &&op) -{ - // Compiler cant deduce type T. decltype is here to help with it. - return GraphFilter(std::move(iter), - std::move(op)); -} diff --git a/include/storage/label/label.hpp b/include/storage/label/label.hpp deleted file mode 100644 index f3bdfb63f..000000000 --- a/include/storage/label/label.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include -#include - -#include "storage/indexes/impl/nonunique_unordered_index.hpp" -#include "storage/type_group_vertex.hpp" -#include "storage/vertex.hpp" -#include "storage/vertex_accessor.hpp" -#include "utils/char_str.hpp" -#include "utils/reference_wrapper.hpp" -#include "utils/total_ordering.hpp" - -using LabelIndexRecord = IndexRecord; - -class Label : public TotalOrdering