Move gid::Gid to storage/common/types

Summary:
It never made sense that a global ID is its own namespace in the storage
directory tree.

Reviewers: mferencevic, ipaljak

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2346
This commit is contained in:
Teon Banek 2019-09-03 10:47:55 +02:00
parent 58be850d5c
commit cdfaf0d4a6
32 changed files with 185 additions and 256 deletions

View File

@ -93,7 +93,7 @@ bool GraphDbAccessor::should_abort() const {
durability::WriteAheadLog &GraphDbAccessor::wal() { return db_->wal(); } durability::WriteAheadLog &GraphDbAccessor::wal() { return db_->wal(); }
VertexAccessor GraphDbAccessor::InsertVertex( VertexAccessor GraphDbAccessor::InsertVertex(
std::optional<gid::Gid> requested_gid) { std::optional<storage::Gid> requested_gid) {
DCHECK(!commited_ && !aborted_) << "Accessor committed or aborted"; DCHECK(!commited_ && !aborted_) << "Accessor committed or aborted";
auto gid = db_->storage().vertex_generator_.Next(requested_gid); auto gid = db_->storage().vertex_generator_.Next(requested_gid);
@ -110,7 +110,7 @@ VertexAccessor GraphDbAccessor::InsertVertex(
} }
std::optional<VertexAccessor> GraphDbAccessor::FindVertexOptional( std::optional<VertexAccessor> GraphDbAccessor::FindVertexOptional(
gid::Gid gid, bool current_state) { storage::Gid gid, bool current_state) {
VertexAccessor record_accessor(db_->storage().LocalAddress<Vertex>(gid), VertexAccessor record_accessor(db_->storage().LocalAddress<Vertex>(gid),
*this); *this);
if (!record_accessor.Visible(transaction(), current_state)) if (!record_accessor.Visible(transaction(), current_state))
@ -118,21 +118,22 @@ std::optional<VertexAccessor> GraphDbAccessor::FindVertexOptional(
return record_accessor; return record_accessor;
} }
VertexAccessor GraphDbAccessor::FindVertex(gid::Gid gid, bool current_state) { VertexAccessor GraphDbAccessor::FindVertex(storage::Gid gid,
bool current_state) {
auto found = FindVertexOptional(gid, current_state); auto found = FindVertexOptional(gid, current_state);
CHECK(found) << "Unable to find vertex for id: " << gid; CHECK(found) << "Unable to find vertex for id: " << gid;
return *found; return *found;
} }
std::optional<EdgeAccessor> GraphDbAccessor::FindEdgeOptional( std::optional<EdgeAccessor> GraphDbAccessor::FindEdgeOptional(
gid::Gid gid, bool current_state) { storage::Gid gid, bool current_state) {
EdgeAccessor record_accessor(db_->storage().LocalAddress<Edge>(gid), *this); EdgeAccessor record_accessor(db_->storage().LocalAddress<Edge>(gid), *this);
if (!record_accessor.Visible(transaction(), current_state)) if (!record_accessor.Visible(transaction(), current_state))
return std::nullopt; return std::nullopt;
return record_accessor; return record_accessor;
} }
EdgeAccessor GraphDbAccessor::FindEdge(gid::Gid gid, bool current_state) { EdgeAccessor GraphDbAccessor::FindEdge(storage::Gid gid, bool current_state) {
auto found = FindEdgeOptional(gid, current_state); auto found = FindEdgeOptional(gid, current_state);
CHECK(found) << "Unable to find edge for id: " << gid; CHECK(found) << "Unable to find edge for id: " << gid;
return *found; return *found;
@ -450,7 +451,7 @@ void GraphDbAccessor::DetachRemoveVertex(VertexAccessor &vertex_accessor) {
EdgeAccessor GraphDbAccessor::InsertEdge( EdgeAccessor GraphDbAccessor::InsertEdge(
VertexAccessor &from, VertexAccessor &to, storage::EdgeType edge_type, VertexAccessor &from, VertexAccessor &to, storage::EdgeType edge_type,
std::optional<gid::Gid> requested_gid) { std::optional<storage::Gid> requested_gid) {
DCHECK(!commited_ && !aborted_) << "Accessor committed or aborted"; DCHECK(!commited_ && !aborted_) << "Accessor committed or aborted";
auto gid = db_->storage().edge_generator_.Next(requested_gid); auto gid = db_->storage().edge_generator_.Next(requested_gid);
auto edge_vlist = new mvcc::VersionList<Edge>( auto edge_vlist = new mvcc::VersionList<Edge>(

View File

@ -77,7 +77,7 @@ class GraphDbAccessor {
* @return See above. * @return See above.
*/ */
VertexAccessor InsertVertex( VertexAccessor InsertVertex(
std::optional<gid::Gid> requested_gid = std::nullopt); std::optional<storage::Gid> requested_gid = std::nullopt);
/** /**
* Removes the vertex of the given accessor. If the vertex has any outgoing or * Removes the vertex of the given accessor. If the vertex has any outgoing or
@ -118,7 +118,7 @@ class GraphDbAccessor {
* deletions performed in the current transaction+command are not * deletions performed in the current transaction+command are not
* ignored). * ignored).
*/ */
std::optional<VertexAccessor> FindVertexOptional(gid::Gid gid, std::optional<VertexAccessor> FindVertexOptional(storage::Gid gid,
bool current_state); bool current_state);
/** /**
@ -132,7 +132,7 @@ class GraphDbAccessor {
* deletions performed in the current transaction+command are not * deletions performed in the current transaction+command are not
* ignored). * ignored).
*/ */
VertexAccessor FindVertex(gid::Gid gid, bool current_state); VertexAccessor FindVertex(storage::Gid gid, bool current_state);
/** /**
* Returns iterable over accessors to all the vertices in the graph * Returns iterable over accessors to all the vertices in the graph
@ -303,9 +303,9 @@ class GraphDbAccessor {
* @throw utils::LockTimeoutException * @throw utils::LockTimeoutException
* @throw SerializationError * @throw SerializationError
*/ */
EdgeAccessor InsertEdge(VertexAccessor &from, VertexAccessor &to, EdgeAccessor InsertEdge(
storage::EdgeType type, VertexAccessor &from, VertexAccessor &to, storage::EdgeType type,
std::optional<gid::Gid> requested_gid = std::nullopt); std::optional<storage::Gid> requested_gid = std::nullopt);
/** /**
* Removes an edge from the graph. Parameters can indicate if the edge should * Removes an edge from the graph. Parameters can indicate if the edge should
@ -336,7 +336,7 @@ class GraphDbAccessor {
* deletions performed in the current transaction+command are not * deletions performed in the current transaction+command are not
* ignored). * ignored).
*/ */
std::optional<EdgeAccessor> FindEdgeOptional(gid::Gid gid, std::optional<EdgeAccessor> FindEdgeOptional(storage::Gid gid,
bool current_state); bool current_state);
/** /**
@ -350,7 +350,7 @@ class GraphDbAccessor {
* deletions performed in the current transaction+command are not * deletions performed in the current transaction+command are not
* ignored). * ignored).
*/ */
EdgeAccessor FindEdge(gid::Gid gid, bool current_state); EdgeAccessor FindEdge(storage::Gid gid, bool current_state);
/** /**
* Returns iterable over accessors to all the edges in the graph * Returns iterable over accessors to all the edges in the graph

View File

@ -93,7 +93,7 @@ bool GraphDbAccessor::should_abort() const {
raft::RaftInterface *GraphDbAccessor::raft() { return db_->raft(); } raft::RaftInterface *GraphDbAccessor::raft() { return db_->raft(); }
VertexAccessor GraphDbAccessor::InsertVertex( VertexAccessor GraphDbAccessor::InsertVertex(
std::optional<gid::Gid> requested_gid) { std::optional<storage::Gid> requested_gid) {
DCHECK(!commited_ && !aborted_) << "Accessor committed or aborted"; DCHECK(!commited_ && !aborted_) << "Accessor committed or aborted";
auto gid = db_->storage().vertex_generator_.Next(requested_gid); auto gid = db_->storage().vertex_generator_.Next(requested_gid);
@ -110,7 +110,7 @@ VertexAccessor GraphDbAccessor::InsertVertex(
} }
std::optional<VertexAccessor> GraphDbAccessor::FindVertexOptional( std::optional<VertexAccessor> GraphDbAccessor::FindVertexOptional(
gid::Gid gid, bool current_state) { storage::Gid gid, bool current_state) {
VertexAccessor record_accessor(db_->storage().LocalAddress<Vertex>(gid), VertexAccessor record_accessor(db_->storage().LocalAddress<Vertex>(gid),
*this); *this);
if (!record_accessor.Visible(transaction(), current_state)) if (!record_accessor.Visible(transaction(), current_state))
@ -118,21 +118,22 @@ std::optional<VertexAccessor> GraphDbAccessor::FindVertexOptional(
return record_accessor; return record_accessor;
} }
VertexAccessor GraphDbAccessor::FindVertex(gid::Gid gid, bool current_state) { VertexAccessor GraphDbAccessor::FindVertex(storage::Gid gid,
bool current_state) {
auto found = FindVertexOptional(gid, current_state); auto found = FindVertexOptional(gid, current_state);
CHECK(found) << "Unable to find vertex for id: " << gid; CHECK(found) << "Unable to find vertex for id: " << gid;
return *found; return *found;
} }
std::optional<EdgeAccessor> GraphDbAccessor::FindEdgeOptional( std::optional<EdgeAccessor> GraphDbAccessor::FindEdgeOptional(
gid::Gid gid, bool current_state) { storage::Gid gid, bool current_state) {
EdgeAccessor record_accessor(db_->storage().LocalAddress<Edge>(gid), *this); EdgeAccessor record_accessor(db_->storage().LocalAddress<Edge>(gid), *this);
if (!record_accessor.Visible(transaction(), current_state)) if (!record_accessor.Visible(transaction(), current_state))
return std::nullopt; return std::nullopt;
return record_accessor; return record_accessor;
} }
EdgeAccessor GraphDbAccessor::FindEdge(gid::Gid gid, bool current_state) { EdgeAccessor GraphDbAccessor::FindEdge(storage::Gid gid, bool current_state) {
auto found = FindEdgeOptional(gid, current_state); auto found = FindEdgeOptional(gid, current_state);
CHECK(found) << "Unable to find edge for id: " << gid; CHECK(found) << "Unable to find edge for id: " << gid;
return *found; return *found;
@ -444,7 +445,7 @@ void GraphDbAccessor::DetachRemoveVertex(VertexAccessor &vertex_accessor) {
EdgeAccessor GraphDbAccessor::InsertEdge( EdgeAccessor GraphDbAccessor::InsertEdge(
VertexAccessor &from, VertexAccessor &to, storage::EdgeType edge_type, VertexAccessor &from, VertexAccessor &to, storage::EdgeType edge_type,
std::optional<gid::Gid> requested_gid) { std::optional<storage::Gid> requested_gid) {
DCHECK(!commited_ && !aborted_) << "Accessor committed or aborted"; DCHECK(!commited_ && !aborted_) << "Accessor committed or aborted";
auto gid = db_->storage().edge_generator_.Next(requested_gid); auto gid = db_->storage().edge_generator_.Next(requested_gid);
auto edge_vlist = new mvcc::VersionList<Edge>( auto edge_vlist = new mvcc::VersionList<Edge>(

View File

@ -95,7 +95,7 @@ class GraphDbAccessor {
* @return See above. * @return See above.
*/ */
VertexAccessor InsertVertex( VertexAccessor InsertVertex(
std::optional<gid::Gid> requested_gid = std::nullopt); std::optional<storage::Gid> requested_gid = std::nullopt);
/** /**
* Removes the vertex of the given accessor. If the vertex has any outgoing or * Removes the vertex of the given accessor. If the vertex has any outgoing or
@ -131,7 +131,7 @@ class GraphDbAccessor {
* deletions performed in the current transaction+command are not * deletions performed in the current transaction+command are not
* ignored). * ignored).
*/ */
std::optional<VertexAccessor> FindVertexOptional(gid::Gid gid, std::optional<VertexAccessor> FindVertexOptional(storage::Gid gid,
bool current_state); bool current_state);
/** /**
@ -145,7 +145,7 @@ class GraphDbAccessor {
* deletions performed in the current transaction+command are not * deletions performed in the current transaction+command are not
* ignored). * ignored).
*/ */
VertexAccessor FindVertex(gid::Gid gid, bool current_state); VertexAccessor FindVertex(storage::Gid gid, bool current_state);
/** /**
* Returns iterable over accessors to all the vertices in the graph * Returns iterable over accessors to all the vertices in the graph
@ -305,9 +305,9 @@ class GraphDbAccessor {
* *
* @return An accessor to the edge. * @return An accessor to the edge.
*/ */
EdgeAccessor InsertEdge(VertexAccessor &from, VertexAccessor &to, EdgeAccessor InsertEdge(
storage::EdgeType type, VertexAccessor & from, VertexAccessor & to, storage::EdgeType type,
std::optional<gid::Gid> requested_gid = std::nullopt); std::optional<storage::Gid> requested_gid = std::nullopt);
/** /**
* Removes an edge from the graph. Parameters can indicate if the edge should * Removes an edge from the graph. Parameters can indicate if the edge should
@ -335,7 +335,7 @@ class GraphDbAccessor {
* deletions performed in the current transaction+command are not * deletions performed in the current transaction+command are not
* ignored). * ignored).
*/ */
std::optional<EdgeAccessor> FindEdgeOptional(gid::Gid gid, std::optional<EdgeAccessor> FindEdgeOptional(storage::Gid gid,
bool current_state); bool current_state);
/** /**
@ -349,7 +349,7 @@ class GraphDbAccessor {
* deletions performed in the current transaction+command are not * deletions performed in the current transaction+command are not
* ignored). * ignored).
*/ */
EdgeAccessor FindEdge(gid::Gid gid, bool current_state); EdgeAccessor FindEdge(storage::Gid gid, bool current_state);
/** /**
* Returns iterable over accessors to all the edges in the graph * Returns iterable over accessors to all the edges in the graph

View File

@ -21,15 +21,15 @@ StateDelta StateDelta::TxAbort(tx::TransactionId tx_id) {
} }
StateDelta StateDelta::CreateVertex(tx::TransactionId tx_id, StateDelta StateDelta::CreateVertex(tx::TransactionId tx_id,
gid::Gid vertex_id) { storage::Gid vertex_id) {
StateDelta op(StateDelta::Type::CREATE_VERTEX, tx_id); StateDelta op(StateDelta::Type::CREATE_VERTEX, tx_id);
op.vertex_id = vertex_id; op.vertex_id = vertex_id;
return op; return op;
} }
StateDelta StateDelta::CreateEdge(tx::TransactionId tx_id, gid::Gid edge_id, StateDelta StateDelta::CreateEdge(tx::TransactionId tx_id, storage::Gid edge_id,
gid::Gid vertex_from_id, storage::Gid vertex_from_id,
gid::Gid vertex_to_id, storage::Gid vertex_to_id,
storage::EdgeType edge_type, storage::EdgeType edge_type,
const std::string &edge_type_name) { const std::string &edge_type_name) {
StateDelta op(StateDelta::Type::CREATE_EDGE, tx_id); StateDelta op(StateDelta::Type::CREATE_EDGE, tx_id);
@ -42,7 +42,7 @@ StateDelta StateDelta::CreateEdge(tx::TransactionId tx_id, gid::Gid edge_id,
} }
StateDelta StateDelta::PropsSetVertex(tx::TransactionId tx_id, StateDelta StateDelta::PropsSetVertex(tx::TransactionId tx_id,
gid::Gid vertex_id, storage::Gid vertex_id,
storage::Property property, storage::Property property,
const std::string &property_name, const std::string &property_name,
const PropertyValue &value) { const PropertyValue &value) {
@ -54,7 +54,8 @@ StateDelta StateDelta::PropsSetVertex(tx::TransactionId tx_id,
return op; return op;
} }
StateDelta StateDelta::PropsSetEdge(tx::TransactionId tx_id, gid::Gid edge_id, StateDelta StateDelta::PropsSetEdge(tx::TransactionId tx_id,
storage::Gid edge_id,
storage::Property property, storage::Property property,
const std::string &property_name, const std::string &property_name,
const PropertyValue &value) { const PropertyValue &value) {
@ -66,7 +67,7 @@ StateDelta StateDelta::PropsSetEdge(tx::TransactionId tx_id, gid::Gid edge_id,
return op; return op;
} }
StateDelta StateDelta::AddLabel(tx::TransactionId tx_id, gid::Gid vertex_id, StateDelta StateDelta::AddLabel(tx::TransactionId tx_id, storage::Gid vertex_id,
storage::Label label, storage::Label label,
const std::string &label_name) { const std::string &label_name) {
StateDelta op(StateDelta::Type::ADD_LABEL, tx_id); StateDelta op(StateDelta::Type::ADD_LABEL, tx_id);
@ -76,8 +77,8 @@ StateDelta StateDelta::AddLabel(tx::TransactionId tx_id, gid::Gid vertex_id,
return op; return op;
} }
StateDelta StateDelta::RemoveLabel(tx::TransactionId tx_id, gid::Gid vertex_id, StateDelta StateDelta::RemoveLabel(tx::TransactionId tx_id,
storage::Label label, storage::Gid vertex_id, storage::Label label,
const std::string &label_name) { const std::string &label_name) {
StateDelta op(StateDelta::Type::REMOVE_LABEL, tx_id); StateDelta op(StateDelta::Type::REMOVE_LABEL, tx_id);
op.vertex_id = vertex_id; op.vertex_id = vertex_id;
@ -86,15 +87,16 @@ StateDelta StateDelta::RemoveLabel(tx::TransactionId tx_id, gid::Gid vertex_id,
return op; return op;
} }
StateDelta StateDelta::RemoveVertex(tx::TransactionId tx_id, gid::Gid vertex_id, StateDelta StateDelta::RemoveVertex(tx::TransactionId tx_id,
bool check_empty) { storage::Gid vertex_id, bool check_empty) {
StateDelta op(StateDelta::Type::REMOVE_VERTEX, tx_id); StateDelta op(StateDelta::Type::REMOVE_VERTEX, tx_id);
op.vertex_id = vertex_id; op.vertex_id = vertex_id;
op.check_empty = check_empty; op.check_empty = check_empty;
return op; return op;
} }
StateDelta StateDelta::RemoveEdge(tx::TransactionId tx_id, gid::Gid edge_id) { StateDelta StateDelta::RemoveEdge(tx::TransactionId tx_id,
storage::Gid edge_id) {
StateDelta op(StateDelta::Type::REMOVE_EDGE, tx_id); StateDelta op(StateDelta::Type::REMOVE_EDGE, tx_id);
op.edge_id = edge_id; op.edge_id = edge_id;
return op; return op;

View File

@ -8,7 +8,6 @@
#include "storage/single_node/mvcc/version_list.hpp" #include "storage/single_node/mvcc/version_list.hpp"
#include "storage/common/types/property_value.hpp" #include "storage/common/types/property_value.hpp"
#include "storage/common/types/types.hpp" #include "storage/common/types/types.hpp"
#include "storage/single_node/gid.hpp"
#include "utils/typeinfo.hpp" #include "utils/typeinfo.hpp"
class Vertex; class Vertex;
@ -29,12 +28,12 @@ cpp<#
;; Members valid only for some deltas, see StateDelta::Type comments above. ;; Members valid only for some deltas, see StateDelta::Type comments above.
;; TODO: when preparing the WAL for distributed, most likely remove Gids and ;; TODO: when preparing the WAL for distributed, most likely remove Gids and
;; only keep addresses. ;; only keep addresses.
(vertex-id "::gid::Gid") (vertex-id "::storage::Gid")
(edge-id "::gid::Gid") (edge-id "::storage::Gid")
(edge-address "::mvcc::VersionList<Edge> *") (edge-address "::mvcc::VersionList<Edge> *")
(vertex-from-id "::gid::Gid") (vertex-from-id "::storage::Gid")
(vertex-from-address "::mvcc::VersionList<Vertex> *") (vertex-from-address "::mvcc::VersionList<Vertex> *")
(vertex-to-id "::gid::Gid") (vertex-to-id "::storage::Gid")
(vertex-to-address "::mvcc::VersionList<Vertex> *") (vertex-to-address "::mvcc::VersionList<Vertex> *")
(edge-type "::storage::EdgeType") (edge-type "::storage::EdgeType")
(edge-type-name "std::string") (edge-type-name "std::string")
@ -100,30 +99,30 @@ omitted in the comment."))
static StateDelta TxCommit(tx::TransactionId tx_id); static StateDelta TxCommit(tx::TransactionId tx_id);
static StateDelta TxAbort(tx::TransactionId tx_id); static StateDelta TxAbort(tx::TransactionId tx_id);
static StateDelta CreateVertex(tx::TransactionId tx_id, static StateDelta CreateVertex(tx::TransactionId tx_id,
gid::Gid vertex_id); storage::Gid vertex_id);
static StateDelta CreateEdge(tx::TransactionId tx_id, gid::Gid edge_id, static StateDelta CreateEdge(tx::TransactionId tx_id, storage::Gid edge_id,
gid::Gid vertex_from_id, storage::Gid vertex_from_id,
gid::Gid vertex_to_id, storage::Gid vertex_to_id,
storage::EdgeType edge_type, storage::EdgeType edge_type,
const std::string &edge_type_name); const std::string &edge_type_name);
static StateDelta PropsSetVertex(tx::TransactionId tx_id, static StateDelta PropsSetVertex(tx::TransactionId tx_id,
gid::Gid vertex_id, storage::Gid vertex_id,
storage::Property property, storage::Property property,
const std::string &property_name, const std::string &property_name,
const PropertyValue &value); const PropertyValue &value);
static StateDelta PropsSetEdge(tx::TransactionId tx_id, gid::Gid edge_id, static StateDelta PropsSetEdge(tx::TransactionId tx_id, storage::Gid edge_id,
storage::Property property, storage::Property property,
const std::string &property_name, const std::string &property_name,
const PropertyValue &value); const PropertyValue &value);
static StateDelta AddLabel(tx::TransactionId tx_id, gid::Gid vertex_id, static StateDelta AddLabel(tx::TransactionId tx_id, storage::Gid vertex_id,
storage::Label label, storage::Label label,
const std::string &label_name); const std::string &label_name);
static StateDelta RemoveLabel(tx::TransactionId tx_id, gid::Gid vertex_id, static StateDelta RemoveLabel(tx::TransactionId tx_id, storage::Gid vertex_id,
storage::Label label, storage::Label label,
const std::string &label_name); const std::string &label_name);
static StateDelta RemoveVertex(tx::TransactionId tx_id, gid::Gid vertex_id, static StateDelta RemoveVertex(tx::TransactionId tx_id, storage::Gid vertex_id,
bool check_empty); bool check_empty);
static StateDelta RemoveEdge(tx::TransactionId tx_id, gid::Gid edge_id); static StateDelta RemoveEdge(tx::TransactionId tx_id, storage::Gid edge_id);
static StateDelta BuildIndex(tx::TransactionId tx_id, storage::Label label, static StateDelta BuildIndex(tx::TransactionId tx_id, storage::Label label,
const std::string &label_name, const std::string &label_name,
storage::Property property, storage::Property property,

View File

@ -12,7 +12,6 @@
#include "durability/single_node/state_delta.hpp" #include "durability/single_node/state_delta.hpp"
#include "storage/common/types/property_value.hpp" #include "storage/common/types/property_value.hpp"
#include "storage/common/types/types.hpp" #include "storage/common/types/types.hpp"
#include "storage/single_node/gid.hpp"
#include "transactions/type.hpp" #include "transactions/type.hpp"
#include "utils/scheduler.hpp" #include "utils/scheduler.hpp"

View File

@ -21,15 +21,15 @@ StateDelta StateDelta::TxAbort(tx::TransactionId tx_id) {
} }
StateDelta StateDelta::CreateVertex(tx::TransactionId tx_id, StateDelta StateDelta::CreateVertex(tx::TransactionId tx_id,
gid::Gid vertex_id) { storage::Gid vertex_id) {
StateDelta op(StateDelta::Type::CREATE_VERTEX, tx_id); StateDelta op(StateDelta::Type::CREATE_VERTEX, tx_id);
op.vertex_id = vertex_id; op.vertex_id = vertex_id;
return op; return op;
} }
StateDelta StateDelta::CreateEdge(tx::TransactionId tx_id, gid::Gid edge_id, StateDelta StateDelta::CreateEdge(tx::TransactionId tx_id, storage::Gid edge_id,
gid::Gid vertex_from_id, storage::Gid vertex_from_id,
gid::Gid vertex_to_id, storage::Gid vertex_to_id,
storage::EdgeType edge_type, storage::EdgeType edge_type,
const std::string &edge_type_name) { const std::string &edge_type_name) {
StateDelta op(StateDelta::Type::CREATE_EDGE, tx_id); StateDelta op(StateDelta::Type::CREATE_EDGE, tx_id);
@ -42,7 +42,7 @@ StateDelta StateDelta::CreateEdge(tx::TransactionId tx_id, gid::Gid edge_id,
} }
StateDelta StateDelta::PropsSetVertex(tx::TransactionId tx_id, StateDelta StateDelta::PropsSetVertex(tx::TransactionId tx_id,
gid::Gid vertex_id, storage::Gid vertex_id,
storage::Property property, storage::Property property,
const std::string &property_name, const std::string &property_name,
const PropertyValue &value) { const PropertyValue &value) {
@ -54,7 +54,8 @@ StateDelta StateDelta::PropsSetVertex(tx::TransactionId tx_id,
return op; return op;
} }
StateDelta StateDelta::PropsSetEdge(tx::TransactionId tx_id, gid::Gid edge_id, StateDelta StateDelta::PropsSetEdge(tx::TransactionId tx_id,
storage::Gid edge_id,
storage::Property property, storage::Property property,
const std::string &property_name, const std::string &property_name,
const PropertyValue &value) { const PropertyValue &value) {
@ -66,7 +67,7 @@ StateDelta StateDelta::PropsSetEdge(tx::TransactionId tx_id, gid::Gid edge_id,
return op; return op;
} }
StateDelta StateDelta::AddLabel(tx::TransactionId tx_id, gid::Gid vertex_id, StateDelta StateDelta::AddLabel(tx::TransactionId tx_id, storage::Gid vertex_id,
storage::Label label, storage::Label label,
const std::string &label_name) { const std::string &label_name) {
StateDelta op(StateDelta::Type::ADD_LABEL, tx_id); StateDelta op(StateDelta::Type::ADD_LABEL, tx_id);
@ -76,8 +77,8 @@ StateDelta StateDelta::AddLabel(tx::TransactionId tx_id, gid::Gid vertex_id,
return op; return op;
} }
StateDelta StateDelta::RemoveLabel(tx::TransactionId tx_id, gid::Gid vertex_id, StateDelta StateDelta::RemoveLabel(tx::TransactionId tx_id,
storage::Label label, storage::Gid vertex_id, storage::Label label,
const std::string &label_name) { const std::string &label_name) {
StateDelta op(StateDelta::Type::REMOVE_LABEL, tx_id); StateDelta op(StateDelta::Type::REMOVE_LABEL, tx_id);
op.vertex_id = vertex_id; op.vertex_id = vertex_id;
@ -86,15 +87,16 @@ StateDelta StateDelta::RemoveLabel(tx::TransactionId tx_id, gid::Gid vertex_id,
return op; return op;
} }
StateDelta StateDelta::RemoveVertex(tx::TransactionId tx_id, gid::Gid vertex_id, StateDelta StateDelta::RemoveVertex(tx::TransactionId tx_id,
bool check_empty) { storage::Gid vertex_id, bool check_empty) {
StateDelta op(StateDelta::Type::REMOVE_VERTEX, tx_id); StateDelta op(StateDelta::Type::REMOVE_VERTEX, tx_id);
op.vertex_id = vertex_id; op.vertex_id = vertex_id;
op.check_empty = check_empty; op.check_empty = check_empty;
return op; return op;
} }
StateDelta StateDelta::RemoveEdge(tx::TransactionId tx_id, gid::Gid edge_id) { StateDelta StateDelta::RemoveEdge(tx::TransactionId tx_id,
storage::Gid edge_id) {
StateDelta op(StateDelta::Type::REMOVE_EDGE, tx_id); StateDelta op(StateDelta::Type::REMOVE_EDGE, tx_id);
op.edge_id = edge_id; op.edge_id = edge_id;
return op; return op;

View File

@ -8,7 +8,6 @@
#include "storage/single_node_ha/mvcc/version_list.hpp" #include "storage/single_node_ha/mvcc/version_list.hpp"
#include "storage/common/types/property_value.hpp" #include "storage/common/types/property_value.hpp"
#include "storage/common/types/types.hpp" #include "storage/common/types/types.hpp"
#include "storage/single_node_ha/gid.hpp"
#include "utils/typeinfo.hpp" #include "utils/typeinfo.hpp"
class Vertex; class Vertex;
@ -27,10 +26,10 @@ cpp<#
(type "Type") (type "Type")
(transaction-id "::tx::TransactionId") (transaction-id "::tx::TransactionId")
;; Members valid only for some deltas, see StateDelta::Type comments above. ;; Members valid only for some deltas, see StateDelta::Type comments above.
(vertex-id "::gid::Gid") (vertex-id "::storage::Gid")
(edge-id "::gid::Gid") (edge-id "::storage::Gid")
(vertex-from-id "::gid::Gid") (vertex-from-id "::storage::Gid")
(vertex-to-id "::gid::Gid") (vertex-to-id "::storage::Gid")
(edge-type "::storage::EdgeType") (edge-type "::storage::EdgeType")
(edge-type-name "std::string") (edge-type-name "std::string")
(property "::storage::Property") (property "::storage::Property")
@ -98,30 +97,30 @@ omitted in the comment.")
static StateDelta TxCommit(tx::TransactionId tx_id); static StateDelta TxCommit(tx::TransactionId tx_id);
static StateDelta TxAbort(tx::TransactionId tx_id); static StateDelta TxAbort(tx::TransactionId tx_id);
static StateDelta CreateVertex(tx::TransactionId tx_id, static StateDelta CreateVertex(tx::TransactionId tx_id,
gid::Gid vertex_id); storage::Gid vertex_id);
static StateDelta CreateEdge(tx::TransactionId tx_id, gid::Gid edge_id, static StateDelta CreateEdge(tx::TransactionId tx_id, storage::Gid edge_id,
gid::Gid vertex_from_id, storage::Gid vertex_from_id,
gid::Gid vertex_to_id, storage::Gid vertex_to_id,
storage::EdgeType edge_type, storage::EdgeType edge_type,
const std::string &edge_type_name); const std::string &edge_type_name);
static StateDelta PropsSetVertex(tx::TransactionId tx_id, static StateDelta PropsSetVertex(tx::TransactionId tx_id,
gid::Gid vertex_id, storage::Gid vertex_id,
storage::Property property, storage::Property property,
const std::string &property_name, const std::string &property_name,
const PropertyValue &value); const PropertyValue &value);
static StateDelta PropsSetEdge(tx::TransactionId tx_id, gid::Gid edge_id, static StateDelta PropsSetEdge(tx::TransactionId tx_id, storage::Gid edge_id,
storage::Property property, storage::Property property,
const std::string &property_name, const std::string &property_name,
const PropertyValue &value); const PropertyValue &value);
static StateDelta AddLabel(tx::TransactionId tx_id, gid::Gid vertex_id, static StateDelta AddLabel(tx::TransactionId tx_id, storage::Gid vertex_id,
storage::Label label, storage::Label label,
const std::string &label_name); const std::string &label_name);
static StateDelta RemoveLabel(tx::TransactionId tx_id, gid::Gid vertex_id, static StateDelta RemoveLabel(tx::TransactionId tx_id, storage::Gid vertex_id,
storage::Label label, storage::Label label,
const std::string &label_name); const std::string &label_name);
static StateDelta RemoveVertex(tx::TransactionId tx_id, gid::Gid vertex_id, static StateDelta RemoveVertex(tx::TransactionId tx_id, storage::Gid vertex_id,
bool check_empty); bool check_empty);
static StateDelta RemoveEdge(tx::TransactionId tx_id, gid::Gid edge_id); static StateDelta RemoveEdge(tx::TransactionId tx_id, storage::Gid edge_id);
static StateDelta BuildIndex(tx::TransactionId tx_id, storage::Label label, static StateDelta BuildIndex(tx::TransactionId tx_id, storage::Label label,
const std::string &label_name, const std::string &label_name,
storage::Property property, storage::Property property,

View File

@ -6,10 +6,10 @@
#include "transactions/transaction.hpp" #include "transactions/transaction.hpp"
namespace storage::constraints::impl { namespace storage::constraints::impl {
Record::Record(gid::Gid gid, const tx::Transaction &t) Record::Record(storage::Gid gid, const tx::Transaction &t)
: curr_gid(gid), tx_id_cre(t.id_) {} : curr_gid(gid), tx_id_cre(t.id_) {}
void Record::Insert(gid::Gid gid, const tx::Transaction &t) { void Record::Insert(storage::Gid gid, const tx::Transaction &t) {
// Insert // Insert
// - delete before or in this transaction and not aborted // - delete before or in this transaction and not aborted
// - insert before and aborted // - insert before and aborted
@ -40,7 +40,7 @@ void Record::Insert(gid::Gid gid, const tx::Transaction &t) {
tx_id_exp = 0; tx_id_exp = 0;
} }
void Record::Remove(gid::Gid gid, const tx::Transaction &t) { void Record::Remove(storage::Gid gid, const tx::Transaction &t) {
// Remove // Remove
// - insert before or in this transaction and not aborted // - insert before or in this transaction and not aborted
// - remove before and aborted // - remove before and aborted

View File

@ -3,7 +3,7 @@
#pragma once #pragma once
#include "storage/common/locking/record_lock.hpp" #include "storage/common/locking/record_lock.hpp"
#include "storage/gid.hpp" #include "storage/common/types/types.hpp"
#include "transactions/type.hpp" #include "transactions/type.hpp"
namespace tx { namespace tx {
@ -13,11 +13,11 @@ class Transaction;
namespace storage::constraints::impl { namespace storage::constraints::impl {
/// Contains records of creation and deletion of entry in a constraint. /// Contains records of creation and deletion of entry in a constraint.
struct Record { struct Record {
Record(gid::Gid gid, const tx::Transaction &t); Record(storage::Gid gid, const tx::Transaction &t);
void Insert(gid::Gid gid, const tx::Transaction &t); void Insert(storage::Gid gid, const tx::Transaction &t);
void Remove(gid::Gid gid, const tx::Transaction &t); void Remove(storage::Gid gid, const tx::Transaction &t);
gid::Gid curr_gid; storage::Gid curr_gid;
tx::TransactionId tx_id_cre; tx::TransactionId tx_id_cre;
tx::TransactionId tx_id_exp{0}; tx::TransactionId tx_id_exp{0};
RecordLock lock_; RecordLock lock_;

View File

@ -21,7 +21,7 @@ class RecordAccessor;
namespace storage::constraints { namespace storage::constraints {
namespace impl { namespace impl {
struct LabelPropertyPair { struct LabelPropertyPair {
LabelPropertyPair(gid::Gid gid, const std::vector<PropertyValue> &v, LabelPropertyPair(storage::Gid gid, const std::vector<PropertyValue> &v,
const tx::Transaction &t) const tx::Transaction &t)
: values(v), record(gid, t) {} : values(v), record(gid, t) {}

View File

@ -1,11 +1,15 @@
#pragma once #pragma once
#include <atomic>
#include <cstdint> #include <cstdint>
#include <functional> #include <functional>
#include <limits> #include <limits>
#include <optional>
#include <glog/logging.h> #include <glog/logging.h>
#include "utils/atomic.hpp"
namespace storage { namespace storage {
using IdT = uint16_t; using IdT = uint16_t;
@ -146,6 +150,31 @@ class Property final {
IdT id_{0}; IdT id_{0};
}; };
/** Global ID of a record in the database. */
using Gid = uint64_t;
/** Threadsafe generation of new global IDs. */
class GidGenerator {
public:
/**
* Returns a globally unique identifier.
*
* @param requested_gid - The desired gid. If given, it will be returned and
* this generator's state updated accordingly.
*/
Gid Next(std::optional<Gid> requested_gid = std::nullopt) {
if (requested_gid) {
utils::EnsureAtomicGe(next_local_id_, *requested_gid + 1);
return *requested_gid;
} else {
return next_local_id_++;
}
}
private:
std::atomic<uint64_t> next_local_id_{0};
};
} // namespace storage } // namespace storage
namespace std { namespace std {

View File

@ -1,9 +0,0 @@
#pragma once
#ifdef MG_SINGLE_NODE
#include "storage/single_node/gid.hpp"
#endif
#ifdef MG_SINGLE_NODE_HA
#include "storage/single_node_ha/gid.hpp"
#endif

View File

@ -1,47 +0,0 @@
#pragma once
#include <atomic>
#include <cstdint>
#include <optional>
#include "glog/logging.h"
#include "utils/atomic.hpp"
namespace gid {
/**
* Global ids are created by taking both the `local` object id, and `worker` id.
* A global ID has 64 bits. The lower kWorkerIdSize bits contain the worker ID.
* All the other (upper) bits contain the local ID.
*/
using Gid = uint64_t;
/**
* Threadsafe generation of new global ids which belong to the
* worker_id machine. Never call SetId after calling Next without an Id you are
* sure is going to be used for gid, i.e. SetId should only be called before
* first Next call. We want to make sure that every id that we generate is
* larger than the id set by SetId, we can ensure that by not allowing calls to
* SetId after Next which generated new id (incremented internal id counter).
*/
class Generator {
public:
/**
* Returns a globally unique identifier.
*
* @param requested_gid - The desired gid. If given, it will be returned and
* this generator's state updated accordingly.
*/
gid::Gid Next(std::optional<gid::Gid> requested_gid = std::nullopt) {
if (requested_gid) {
utils::EnsureAtomicGe(next_local_id_, *requested_gid + 1);
return *requested_gid;
} else {
return next_local_id_++;
}
}
private:
std::atomic<uint64_t> next_local_id_{0};
};
} // namespace gid

View File

@ -2,7 +2,7 @@
#include "storage/common/locking/record_lock.hpp" #include "storage/common/locking/record_lock.hpp"
#include "storage/common/mvcc/exceptions.hpp" #include "storage/common/mvcc/exceptions.hpp"
#include "storage/single_node/gid.hpp" #include "storage/common/types/types.hpp"
#include "transactions/transaction.hpp" #include "transactions/transaction.hpp"
#include "utils/cast.hpp" #include "utils/cast.hpp"
#include "utils/exceptions.hpp" #include "utils/exceptions.hpp"
@ -22,7 +22,7 @@ class VersionList {
* creating the first Record (Version) in this VersionList. * creating the first Record (Version) in this VersionList.
*/ */
template <typename... Args> template <typename... Args>
VersionList(const tx::Transaction &t, gid::Gid gid, Args &&... args) VersionList(const tx::Transaction &t, storage::Gid gid, Args &&... args)
: gid_(gid) { : gid_(gid) {
// TODO replace 'new' with something better // TODO replace 'new' with something better
auto *v1 = new T(std::forward<Args>(args)...); auto *v1 = new T(std::forward<Args>(args)...);
@ -221,7 +221,7 @@ class VersionList {
record->mark_expired(t); record->mark_expired(t);
} }
const gid::Gid gid_; const storage::Gid gid_;
int64_t cypher_id() { return utils::MemcpyCast<int64_t>(gid_); } int64_t cypher_id() { return utils::MemcpyCast<int64_t>(gid_); }

View File

@ -91,7 +91,7 @@ database::GraphDbAccessor &RecordAccessor<TRecord>::db_accessor() const {
} }
template <typename TRecord> template <typename TRecord>
gid::Gid RecordAccessor<TRecord>::gid() const { storage::Gid RecordAccessor<TRecord>::gid() const {
return address_->gid_; return address_->gid_;
} }

View File

@ -7,7 +7,6 @@
#include "storage/common/types/property_value.hpp" #include "storage/common/types/property_value.hpp"
#include "storage/common/types/property_value_store.hpp" #include "storage/common/types/property_value_store.hpp"
#include "storage/common/types/types.hpp" #include "storage/common/types/types.hpp"
#include "storage/single_node/gid.hpp"
namespace database { namespace database {
class GraphDbAccessor; class GraphDbAccessor;
@ -94,7 +93,7 @@ class RecordAccessor {
* and edges have separate ID domains, there can be a vertex with ID X and an * and edges have separate ID domains, there can be a vertex with ID X and an
* edge with the same id. * edge with the same id.
*/ */
gid::Gid gid() const; storage::Gid gid() const;
mvcc::VersionList<TRecord> *address() const; mvcc::VersionList<TRecord> *address() const;

View File

@ -39,13 +39,13 @@ class Storage {
Storage &operator=(const Storage &) = delete; Storage &operator=(const Storage &) = delete;
Storage &operator=(Storage &&) = delete; Storage &operator=(Storage &&) = delete;
gid::Generator &VertexGenerator() { return vertex_generator_; } storage::GidGenerator &VertexGenerator() { return vertex_generator_; }
gid::Generator &EdgeGenerator() { return edge_generator_; } storage::GidGenerator &EdgeGenerator() { return edge_generator_; }
LabelPropertyIndex &label_property_index() { return label_property_index_; } LabelPropertyIndex &label_property_index() { return label_property_index_; }
/// Gets the local address for the given gid. Fails if not present. /// Gets the local address for the given gid. Fails if not present.
template <typename TRecord> template <typename TRecord>
mvcc::VersionList<TRecord> *LocalAddress(gid::Gid gid) const { mvcc::VersionList<TRecord> *LocalAddress(storage::Gid gid) const {
const auto &map = GetMap<TRecord>(); const auto &map = GetMap<TRecord>();
auto access = map.access(); auto access = map.access();
auto found = access.find(gid); auto found = access.find(gid);
@ -65,35 +65,36 @@ class Storage {
friend class GraphDb; friend class GraphDb;
friend class StorageGc; friend class StorageGc;
gid::Generator vertex_generator_; storage::GidGenerator vertex_generator_;
gid::Generator edge_generator_; storage::GidGenerator edge_generator_;
// main storage for the graph // main storage for the graph
ConcurrentMap<gid::Gid, mvcc::VersionList<Vertex> *> vertices_; ConcurrentMap<storage::Gid, mvcc::VersionList<Vertex> *> vertices_;
ConcurrentMap<gid::Gid, mvcc::VersionList<Edge> *> edges_; ConcurrentMap<storage::Gid, mvcc::VersionList<Edge> *> edges_;
// indexes // indexes
KeyIndex<storage::Label, Vertex> labels_index_; KeyIndex<storage::Label, Vertex> labels_index_;
LabelPropertyIndex label_property_index_; LabelPropertyIndex label_property_index_;
// unique constraints // unique constraints
storage::constraints::UniqueConstraints unique_constraints_; storage::constraints::UniqueConstraints unique_constraints_;
std::vector<std::string> properties_on_disk_; std::vector<std::string> properties_on_disk_;
/// Gets the Vertex/Edge main storage map. /// Gets the Vertex/Edge main storage map.
template <typename TRecord> template <typename TRecord>
const ConcurrentMap<gid::Gid, mvcc::VersionList<TRecord> *> &GetMap() const; const ConcurrentMap<storage::Gid, mvcc::VersionList<TRecord> *> &GetMap()
const;
}; };
template <> template <>
inline const ConcurrentMap<gid::Gid, mvcc::VersionList<Vertex> *> inline const ConcurrentMap<storage::Gid, mvcc::VersionList<Vertex> *>
&Storage::GetMap() const { &Storage::GetMap() const {
return vertices_; return vertices_;
} }
template <> template <>
inline const ConcurrentMap<gid::Gid, mvcc::VersionList<Edge> *> inline const ConcurrentMap<storage::Gid, mvcc::VersionList<Edge> *>
&Storage::GetMap() const { &Storage::GetMap() const {
return edges_; return edges_;
} }

View File

@ -4,10 +4,10 @@
#include <queue> #include <queue>
#include "data_structures/concurrent/concurrent_map.hpp" #include "data_structures/concurrent/concurrent_map.hpp"
#include "storage/common/types/types.hpp"
#include "storage/single_node/deferred_deleter.hpp" #include "storage/single_node/deferred_deleter.hpp"
#include "storage/single_node/edge.hpp" #include "storage/single_node/edge.hpp"
#include "storage/single_node/garbage_collector.hpp" #include "storage/single_node/garbage_collector.hpp"
#include "storage/single_node/gid.hpp"
#include "storage/single_node/mvcc/version_list.hpp" #include "storage/single_node/mvcc/version_list.hpp"
#include "storage/single_node/storage.hpp" #include "storage/single_node/storage.hpp"
#include "storage/single_node/vertex.hpp" #include "storage/single_node/vertex.hpp"
@ -29,11 +29,11 @@ class StorageGc {
using VlistT = mvcc::VersionList<TRecord>; using VlistT = mvcc::VersionList<TRecord>;
public: public:
explicit MvccDeleter(ConcurrentMap<gid::Gid, VlistT *> &collection) explicit MvccDeleter(ConcurrentMap<storage::Gid, VlistT *> &collection)
: gc_(collection, record_deleter_, version_list_deleter_) {} : gc_(collection, record_deleter_, version_list_deleter_) {}
DeferredDeleter<TRecord> record_deleter_; DeferredDeleter<TRecord> record_deleter_;
DeferredDeleter<mvcc::VersionList<TRecord>> version_list_deleter_; DeferredDeleter<mvcc::VersionList<TRecord>> version_list_deleter_;
GarbageCollector<ConcurrentMap<gid::Gid, VlistT *>, TRecord> gc_; GarbageCollector<ConcurrentMap<storage::Gid, VlistT *>, TRecord> gc_;
}; };
public: public:

View File

@ -1,47 +0,0 @@
#pragma once
#include <atomic>
#include <cstdint>
#include <optional>
#include "glog/logging.h"
#include "utils/atomic.hpp"
namespace gid {
/**
* Global ids are created by taking both the `local` object id, and `worker` id.
* A global ID has 64 bits. The lower kWorkerIdSize bits contain the worker ID.
* All the other (upper) bits contain the local ID.
*/
using Gid = uint64_t;
/**
* Threadsafe generation of new global ids which belong to the
* worker_id machine. Never call SetId after calling Next without an Id you are
* sure is going to be used for gid, i.e. SetId should only be called before
* first Next call. We want to make sure that every id that we generate is
* larger than the id set by SetId, we can ensure that by not allowing calls to
* SetId after Next which generated new id (incremented internal id counter).
*/
class Generator {
public:
/**
* Returns a globally unique identifier.
*
* @param requested_gid - The desired gid. If given, it will be returned and
* this generator's state updated accordingly.
*/
gid::Gid Next(std::optional<gid::Gid> requested_gid = std::nullopt) {
if (requested_gid) {
utils::EnsureAtomicGe(next_local_id_, *requested_gid + 1);
return *requested_gid;
} else {
return next_local_id_++;
}
}
private:
std::atomic<uint64_t> next_local_id_{0};
};
} // namespace gid

View File

@ -2,7 +2,7 @@
#include "storage/common/locking/record_lock.hpp" #include "storage/common/locking/record_lock.hpp"
#include "storage/common/mvcc/exceptions.hpp" #include "storage/common/mvcc/exceptions.hpp"
#include "storage/single_node_ha/gid.hpp" #include "storage/common/types/types.hpp"
#include "transactions/transaction.hpp" #include "transactions/transaction.hpp"
#include "utils/cast.hpp" #include "utils/cast.hpp"
#include "utils/exceptions.hpp" #include "utils/exceptions.hpp"
@ -22,7 +22,7 @@ class VersionList {
* creating the first Record (Version) in this VersionList. * creating the first Record (Version) in this VersionList.
*/ */
template <typename... Args> template <typename... Args>
VersionList(const tx::Transaction &t, gid::Gid gid, Args &&... args) VersionList(const tx::Transaction &t, storage::Gid gid, Args &&... args)
: gid_(gid) { : gid_(gid) {
// TODO replace 'new' with something better // TODO replace 'new' with something better
auto *v1 = new T(std::forward<Args>(args)...); auto *v1 = new T(std::forward<Args>(args)...);
@ -215,7 +215,7 @@ class VersionList {
record->mark_expired(t); record->mark_expired(t);
} }
const gid::Gid gid_; const storage::Gid gid_;
int64_t cypher_id() { return utils::MemcpyCast<int64_t>(gid_); } int64_t cypher_id() { return utils::MemcpyCast<int64_t>(gid_); }

View File

@ -91,7 +91,7 @@ database::GraphDbAccessor &RecordAccessor<TRecord>::db_accessor() const {
} }
template <typename TRecord> template <typename TRecord>
gid::Gid RecordAccessor<TRecord>::gid() const { storage::Gid RecordAccessor<TRecord>::gid() const {
return address_->gid_; return address_->gid_;
} }

View File

@ -7,7 +7,6 @@
#include "storage/common/types/property_value.hpp" #include "storage/common/types/property_value.hpp"
#include "storage/common/types/property_value_store.hpp" #include "storage/common/types/property_value_store.hpp"
#include "storage/common/types/types.hpp" #include "storage/common/types/types.hpp"
#include "storage/single_node_ha/gid.hpp"
namespace database { namespace database {
class GraphDbAccessor; class GraphDbAccessor;
@ -80,7 +79,7 @@ class RecordAccessor {
* and edges have separate ID domains, there can be a vertex with ID X and an * and edges have separate ID domains, there can be a vertex with ID X and an
* edge with the same id. * edge with the same id.
*/ */
gid::Gid gid() const; storage::Gid gid() const;
mvcc::VersionList<TRecord> *address() const; mvcc::VersionList<TRecord> *address() const;

View File

@ -39,13 +39,13 @@ class Storage {
Storage &operator=(const Storage &) = delete; Storage &operator=(const Storage &) = delete;
Storage &operator=(Storage &&) = delete; Storage &operator=(Storage &&) = delete;
gid::Generator &VertexGenerator() { return vertex_generator_; } storage::GidGenerator &VertexGenerator() { return vertex_generator_; }
gid::Generator &EdgeGenerator() { return edge_generator_; } storage::GidGenerator &EdgeGenerator() { return edge_generator_; }
LabelPropertyIndex &label_property_index() { return label_property_index_; } LabelPropertyIndex &label_property_index() { return label_property_index_; }
/// Gets the local address for the given gid. Fails if not present. /// Gets the local address for the given gid. Fails if not present.
template <typename TRecord> template <typename TRecord>
mvcc::VersionList<TRecord> *LocalAddress(gid::Gid gid) const { mvcc::VersionList<TRecord> *LocalAddress(storage::Gid gid) const {
const auto &map = GetMap<TRecord>(); const auto &map = GetMap<TRecord>();
auto access = map.access(); auto access = map.access();
auto found = access.find(gid); auto found = access.find(gid);
@ -65,35 +65,36 @@ class Storage {
friend class GraphDb; friend class GraphDb;
friend class StorageGc; friend class StorageGc;
gid::Generator vertex_generator_; storage::GidGenerator vertex_generator_;
gid::Generator edge_generator_; storage::GidGenerator edge_generator_;
// main storage for the graph // main storage for the graph
ConcurrentMap<gid::Gid, mvcc::VersionList<Vertex> *> vertices_; ConcurrentMap<storage::Gid, mvcc::VersionList<Vertex> *> vertices_;
ConcurrentMap<gid::Gid, mvcc::VersionList<Edge> *> edges_; ConcurrentMap<storage::Gid, mvcc::VersionList<Edge> *> edges_;
// indexes // indexes
KeyIndex<storage::Label, Vertex> labels_index_; KeyIndex<storage::Label, Vertex> labels_index_;
LabelPropertyIndex label_property_index_; LabelPropertyIndex label_property_index_;
// unique constraints // unique constraints
storage::constraints::UniqueConstraints unique_constraints_; storage::constraints::UniqueConstraints unique_constraints_;
std::vector<std::string> properties_on_disk_; std::vector<std::string> properties_on_disk_;
/// Gets the Vertex/Edge main storage map. /// Gets the Vertex/Edge main storage map.
template <typename TRecord> template <typename TRecord>
const ConcurrentMap<gid::Gid, mvcc::VersionList<TRecord> *> &GetMap() const; const ConcurrentMap<storage::Gid, mvcc::VersionList<TRecord> *> &GetMap()
const;
}; };
template <> template <>
inline const ConcurrentMap<gid::Gid, mvcc::VersionList<Vertex> *> inline const ConcurrentMap<storage::Gid, mvcc::VersionList<Vertex> *>
&Storage::GetMap() const { &Storage::GetMap() const {
return vertices_; return vertices_;
} }
template <> template <>
inline const ConcurrentMap<gid::Gid, mvcc::VersionList<Edge> *> inline const ConcurrentMap<storage::Gid, mvcc::VersionList<Edge> *>
&Storage::GetMap() const { &Storage::GetMap() const {
return edges_; return edges_;
} }

View File

@ -5,10 +5,10 @@
#include "data_structures/concurrent/concurrent_map.hpp" #include "data_structures/concurrent/concurrent_map.hpp"
#include "raft/raft_server.hpp" #include "raft/raft_server.hpp"
#include "storage/common/types/types.hpp"
#include "storage/single_node_ha/deferred_deleter.hpp" #include "storage/single_node_ha/deferred_deleter.hpp"
#include "storage/single_node_ha/edge.hpp" #include "storage/single_node_ha/edge.hpp"
#include "storage/single_node_ha/garbage_collector.hpp" #include "storage/single_node_ha/garbage_collector.hpp"
#include "storage/single_node_ha/gid.hpp"
#include "storage/single_node_ha/mvcc/version_list.hpp" #include "storage/single_node_ha/mvcc/version_list.hpp"
#include "storage/single_node_ha/storage.hpp" #include "storage/single_node_ha/storage.hpp"
#include "storage/single_node_ha/vertex.hpp" #include "storage/single_node_ha/vertex.hpp"
@ -30,11 +30,11 @@ class StorageGc {
using VlistT = mvcc::VersionList<TRecord>; using VlistT = mvcc::VersionList<TRecord>;
public: public:
explicit MvccDeleter(ConcurrentMap<gid::Gid, VlistT *> &collection) explicit MvccDeleter(ConcurrentMap<storage::Gid, VlistT *> &collection)
: gc_(collection, record_deleter_, version_list_deleter_) {} : gc_(collection, record_deleter_, version_list_deleter_) {}
DeferredDeleter<TRecord> record_deleter_; DeferredDeleter<TRecord> record_deleter_;
DeferredDeleter<mvcc::VersionList<TRecord>> version_list_deleter_; DeferredDeleter<mvcc::VersionList<TRecord>> version_list_deleter_;
GarbageCollector<ConcurrentMap<gid::Gid, VlistT *>, TRecord> gc_; GarbageCollector<ConcurrentMap<storage::Gid, VlistT *>, TRecord> gc_;
}; };
public: public:

View File

@ -126,7 +126,7 @@ class DatabaseEnvironment {
DatabaseState GetState() { DatabaseState GetState() {
// Capture all vertices // Capture all vertices
std::map<gid::Gid, int64_t> gid_mapping; std::map<storage::Gid, int64_t> gid_mapping;
std::set<DatabaseState::Vertex> vertices; std::set<DatabaseState::Vertex> vertices;
auto dba = db_.Access(); auto dba = db_.Access();
for (const auto &vertex : dba.Vertices(false)) { for (const auto &vertex : dba.Vertices(false)) {

View File

@ -357,7 +357,7 @@ class Durability : public ::testing::Test {
// Tests wal encoder to encode correctly non-CRUD deltas, and that all deltas // Tests wal encoder to encode correctly non-CRUD deltas, and that all deltas
// are written in the correct order // are written in the correct order
TEST_F(Durability, WalEncoding) { TEST_F(Durability, WalEncoding) {
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
auto gid1 = generator.Next(); auto gid1 = generator.Next();
{ {
@ -444,7 +444,7 @@ TEST_F(Durability, WalEncoding) {
} }
TEST_F(Durability, SnapshotEncoding) { TEST_F(Durability, SnapshotEncoding) {
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
auto gid1 = generator.Next(); auto gid1 = generator.Next();
auto gid2 = generator.Next(); auto gid2 = generator.Next();
@ -511,7 +511,7 @@ TEST_F(Durability, SnapshotEncoding) {
ASSERT_TRUE(dv.IsList()); ASSERT_TRUE(dv.IsList());
ASSERT_EQ(dv.ValueList().size(), 0); ASSERT_EQ(dv.ValueList().size(), 0);
std::map<gid::Gid, communication::bolt::Vertex> decoded_vertices; std::map<storage::Gid, communication::bolt::Vertex> decoded_vertices;
// Decode vertices. // Decode vertices.
for (int i = 0; i < vertex_count; ++i) { for (int i = 0; i < vertex_count; ++i) {
@ -530,7 +530,7 @@ TEST_F(Durability, SnapshotEncoding) {
EXPECT_EQ(decoded_vertices[gid2].labels.size(), 0); EXPECT_EQ(decoded_vertices[gid2].labels.size(), 0);
EXPECT_EQ(decoded_vertices[gid2].properties.size(), 2); EXPECT_EQ(decoded_vertices[gid2].properties.size(), 2);
std::map<gid::Gid, communication::bolt::Edge> decoded_edges; std::map<storage::Gid, communication::bolt::Edge> decoded_edges;
// Decode edges. // Decode edges.
for (int i = 0; i < edge_count; ++i) { for (int i = 0; i < edge_count; ++i) {

View File

@ -19,7 +19,7 @@ auto Count(TIterable iterable) {
TEST(GraphDbAccessorTest, InsertVertex) { TEST(GraphDbAccessorTest, InsertVertex) {
GraphDb db; GraphDb db;
auto accessor = db.Access(); auto accessor = db.Access();
gid::Generator generator; storage::GidGenerator generator;
EXPECT_EQ(Count(accessor.Vertices(false)), 0); EXPECT_EQ(Count(accessor.Vertices(false)), 0);

View File

@ -6,7 +6,7 @@
TEST(StateDelta, CreateVertex) { TEST(StateDelta, CreateVertex) {
database::GraphDb db; database::GraphDb db;
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
{ {
auto dba = db.Access(); auto dba = db.Access();
@ -25,7 +25,7 @@ TEST(StateDelta, CreateVertex) {
TEST(StateDelta, RemoveVertex) { TEST(StateDelta, RemoveVertex) {
database::GraphDb db; database::GraphDb db;
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
{ {
auto dba = db.Access(); auto dba = db.Access();
@ -48,7 +48,7 @@ TEST(StateDelta, RemoveVertex) {
TEST(StateDelta, CreateEdge) { TEST(StateDelta, CreateEdge) {
database::GraphDb db; database::GraphDb db;
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
auto gid1 = generator.Next(); auto gid1 = generator.Next();
auto gid2 = generator.Next(); auto gid2 = generator.Next();
@ -75,7 +75,7 @@ TEST(StateDelta, CreateEdge) {
TEST(StateDelta, RemoveEdge) { TEST(StateDelta, RemoveEdge) {
database::GraphDb db; database::GraphDb db;
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
auto gid1 = generator.Next(); auto gid1 = generator.Next();
auto gid2 = generator.Next(); auto gid2 = generator.Next();
@ -101,7 +101,7 @@ TEST(StateDelta, RemoveEdge) {
TEST(StateDelta, AddLabel) { TEST(StateDelta, AddLabel) {
database::GraphDb db; database::GraphDb db;
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
{ {
auto dba = db.Access(); auto dba = db.Access();
@ -127,7 +127,7 @@ TEST(StateDelta, AddLabel) {
TEST(StateDelta, RemoveLabel) { TEST(StateDelta, RemoveLabel) {
database::GraphDb db; database::GraphDb db;
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
{ {
auto dba = db.Access(); auto dba = db.Access();
@ -153,7 +153,7 @@ TEST(StateDelta, RemoveLabel) {
TEST(StateDelta, SetPropertyVertex) { TEST(StateDelta, SetPropertyVertex) {
database::GraphDb db; database::GraphDb db;
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
{ {
auto dba = db.Access(); auto dba = db.Access();
@ -179,7 +179,7 @@ TEST(StateDelta, SetPropertyVertex) {
TEST(StateDelta, SetPropertyEdge) { TEST(StateDelta, SetPropertyEdge) {
database::GraphDb db; database::GraphDb db;
gid::Generator generator; storage::GidGenerator generator;
auto gid0 = generator.Next(); auto gid0 = generator.Next();
auto gid1 = generator.Next(); auto gid1 = generator.Next();
auto gid2 = generator.Next(); auto gid2 = generator.Next();

View File

@ -154,7 +154,7 @@ TEST_F(UniqueConstraintsTest, InsertAbortInsert) {
// NOLINTNEXTLINE(hicpp-special-member-functions) // NOLINTNEXTLINE(hicpp-special-member-functions)
TEST_F(UniqueConstraintsTest, InsertRemoveAbortInsert) { TEST_F(UniqueConstraintsTest, InsertRemoveAbortInsert) {
gid::Gid gid = 0; storage::Gid gid = 0;
{ {
auto dba = db_.Access(); auto dba = db_.Access();
auto v = dba.InsertVertex(); auto v = dba.InsertVertex();
@ -224,7 +224,7 @@ TEST_F(UniqueConstraintsTest, InsertInsertReversed) {
// NOLINTNEXTLINE(hicpp-special-member-functions) // NOLINTNEXTLINE(hicpp-special-member-functions)
TEST_F(UniqueConstraintsTest, InsertRemoveInsert) { TEST_F(UniqueConstraintsTest, InsertRemoveInsert) {
gid::Gid gid = 0; storage::Gid gid = 0;
{ {
auto dba = db_.Access(); auto dba = db_.Access();
auto v = dba.InsertVertex(); auto v = dba.InsertVertex();

View File

@ -158,7 +158,7 @@ class MemgraphNodeIdMap {
} }
private: private:
gid::Generator generator_; storage::GidGenerator generator_;
std::unordered_map<NodeId, int64_t> node_id_to_mg_; std::unordered_map<NodeId, int64_t> node_id_to_mg_;
}; };
@ -274,7 +274,7 @@ void WriteNodeRow(
const std::vector<Field> &fields, const std::vector<std::string> &row, const std::vector<Field> &fields, const std::vector<std::string> &row,
const std::vector<std::string> &additional_labels, const std::vector<std::string> &additional_labels,
MemgraphNodeIdMap &node_id_map) { MemgraphNodeIdMap &node_id_map) {
std::optional<gid::Gid> id; std::optional<storage::Gid> id;
std::vector<std::string> labels; std::vector<std::string> labels;
std::map<std::string, communication::bolt::Value> properties; std::map<std::string, communication::bolt::Value> properties;
for (int i = 0; i < row.size(); ++i) { for (int i = 0; i < row.size(); ++i) {
@ -333,7 +333,7 @@ auto PassNodes(
void WriteRelationshipsRow( void WriteRelationshipsRow(
communication::bolt::BaseEncoder<HashedFileWriter> *encoder, communication::bolt::BaseEncoder<HashedFileWriter> *encoder,
const std::vector<Field> &fields, const std::vector<std::string> &row, const std::vector<Field> &fields, const std::vector<std::string> &row,
const MemgraphNodeIdMap &node_id_map, gid::Gid relationship_id) { const MemgraphNodeIdMap &node_id_map, storage::Gid relationship_id) {
std::optional<int64_t> start_id; std::optional<int64_t> start_id;
std::optional<int64_t> end_id; std::optional<int64_t> end_id;
std::optional<std::string> relationship_type; std::optional<std::string> relationship_type;
@ -379,7 +379,7 @@ void WriteRelationshipsRow(
int PassRelationships( int PassRelationships(
communication::bolt::BaseEncoder<HashedFileWriter> *encoder, communication::bolt::BaseEncoder<HashedFileWriter> *encoder,
const std::string &relationships_path, const MemgraphNodeIdMap &node_id_map, const std::string &relationships_path, const MemgraphNodeIdMap &node_id_map,
gid::Generator &relationship_id_generator) { storage::GidGenerator &relationship_id_generator) {
std::ifstream relationships_file(relationships_path); std::ifstream relationships_file(relationships_path);
CHECK(relationships_file) CHECK(relationships_file)
<< fmt::format("Unable to open '{}'", relationships_path); << fmt::format("Unable to open '{}'", relationships_path);
@ -406,7 +406,7 @@ void Convert(const std::vector<std::string> &nodes,
communication::bolt::BaseEncoder<HashedFileWriter> encoder(buffer); communication::bolt::BaseEncoder<HashedFileWriter> encoder(buffer);
int64_t node_count = 0; int64_t node_count = 0;
int64_t edge_count = 0; int64_t edge_count = 0;
gid::Generator relationship_id_generator; storage::GidGenerator relationship_id_generator;
MemgraphNodeIdMap node_id_map; MemgraphNodeIdMap node_id_map;
// Snapshot file has the following contents in order: // Snapshot file has the following contents in order:
// 1) Magic number. // 1) Magic number.