2018-01-12 22:17:04 +08:00
|
|
|
#pragma once
|
|
|
|
|
2018-02-01 19:17:08 +08:00
|
|
|
#include <experimental/filesystem>
|
|
|
|
|
2018-01-12 22:17:04 +08:00
|
|
|
#include "data_structures/concurrent/concurrent_map.hpp"
|
|
|
|
#include "data_structures/concurrent/concurrent_set.hpp"
|
|
|
|
#include "database/indexes/key_index.hpp"
|
|
|
|
#include "database/indexes/label_property_index.hpp"
|
|
|
|
#include "mvcc/version_list.hpp"
|
|
|
|
#include "storage/edge.hpp"
|
2018-01-16 17:09:15 +08:00
|
|
|
#include "storage/types.hpp"
|
2018-01-12 22:17:04 +08:00
|
|
|
#include "storage/vertex.hpp"
|
|
|
|
|
2018-01-26 00:19:33 +08:00
|
|
|
namespace distributed {
|
|
|
|
class IndexRpcServer;
|
|
|
|
};
|
|
|
|
|
2018-02-01 19:17:08 +08:00
|
|
|
namespace database {
|
|
|
|
class GraphDb;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace durability {
|
|
|
|
bool Recover(const std::experimental::filesystem::path &, database::GraphDb &);
|
|
|
|
};
|
|
|
|
|
2018-01-12 22:17:04 +08:00
|
|
|
namespace database {
|
|
|
|
|
|
|
|
/** A data structure containing the main data members of a graph database. */
|
|
|
|
class Storage {
|
|
|
|
public:
|
|
|
|
explicit Storage(int worker_id)
|
|
|
|
: vertex_generator_{worker_id}, edge_generator_{worker_id} {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
~Storage() {
|
|
|
|
// Delete vertices and edges which weren't collected before, also deletes
|
|
|
|
// records inside version list
|
|
|
|
for (auto &id_vlist : vertices_.access()) delete id_vlist.second;
|
|
|
|
for (auto &id_vlist : edges_.access()) delete id_vlist.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
Storage(const Storage &) = delete;
|
|
|
|
Storage(Storage &&) = delete;
|
|
|
|
Storage &operator=(const Storage &) = delete;
|
|
|
|
Storage &operator=(Storage &&) = delete;
|
|
|
|
|
|
|
|
gid::Generator &VertexGenerator() { return vertex_generator_; }
|
|
|
|
gid::Generator &EdgeGenerator() { return edge_generator_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class GraphDbAccessor;
|
|
|
|
friend class StorageGc;
|
2018-01-26 00:19:33 +08:00
|
|
|
friend class distributed::IndexRpcServer;
|
2018-02-01 19:17:08 +08:00
|
|
|
friend bool durability::Recover(const std::experimental::filesystem::path &,
|
|
|
|
database::GraphDb &);
|
2018-01-12 22:17:04 +08:00
|
|
|
|
|
|
|
gid::Generator vertex_generator_;
|
|
|
|
gid::Generator edge_generator_;
|
|
|
|
|
|
|
|
// main storage for the graph
|
|
|
|
ConcurrentMap<gid::Gid, mvcc::VersionList<Vertex> *> vertices_;
|
|
|
|
ConcurrentMap<gid::Gid, mvcc::VersionList<Edge> *> edges_;
|
|
|
|
|
|
|
|
// indexes
|
2018-01-16 17:09:15 +08:00
|
|
|
KeyIndex<storage::Label, Vertex> labels_index_;
|
2018-01-12 22:17:04 +08:00
|
|
|
LabelPropertyIndex label_property_index_;
|
|
|
|
|
|
|
|
// Set of transactions ids which are building indexes currently
|
|
|
|
ConcurrentSet<tx::transaction_id_t> index_build_tx_in_progress_;
|
|
|
|
};
|
|
|
|
} // namespace database
|