Make Gid a full on class wrapper around uint64_t

Summary:
This makes Gid the same as the one in storage/v2. Before they can be
merge into one implementation, we probably want to have a similar
transition for remaining ID types.

Depends on D2346

Reviewers: mferencevic, ipaljak

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2347
This commit is contained in:
Teon Banek 2019-09-03 14:28:28 +02:00
parent cdfaf0d4a6
commit 7213bec886
31 changed files with 210 additions and 129 deletions

View File

@ -102,7 +102,7 @@ VertexAccessor GraphDbAccessor::InsertVertex(
bool success =
db_->storage().vertices_.access().insert(gid, vertex_vlist).second;
CHECK(success) << "Attempting to insert a vertex with an existing GID: "
<< gid;
<< gid.AsUint();
wal().Emplace(
database::StateDelta::CreateVertex(transaction_->id_, vertex_vlist->gid_));
auto va = VertexAccessor(vertex_vlist, *this);
@ -121,7 +121,7 @@ std::optional<VertexAccessor> GraphDbAccessor::FindVertexOptional(
VertexAccessor GraphDbAccessor::FindVertex(storage::Gid gid,
bool 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.AsUint();
return *found;
}
@ -135,7 +135,7 @@ std::optional<EdgeAccessor> GraphDbAccessor::FindEdgeOptional(
EdgeAccessor GraphDbAccessor::FindEdge(storage::Gid gid, bool 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.AsUint();
return *found;
}
@ -461,7 +461,7 @@ EdgeAccessor GraphDbAccessor::InsertEdge(
// edges_ skiplist.
bool success = db_->storage().edges_.access().insert(gid, edge_vlist).second;
CHECK(success) << "Attempting to insert an edge with an existing GID: "
<< gid;
<< gid.AsUint();
// ensure that the "from" accessor has the latest version
from.SwitchNew();

View File

@ -102,7 +102,7 @@ VertexAccessor GraphDbAccessor::InsertVertex(
bool success =
db_->storage().vertices_.access().insert(gid, vertex_vlist).second;
CHECK(success) << "Attempting to insert a vertex with an existing GID: "
<< gid;
<< gid.AsUint();
raft()->Emplace(
database::StateDelta::CreateVertex(transaction_->id_, vertex_vlist->gid_));
auto va = VertexAccessor(vertex_vlist, *this);
@ -121,7 +121,7 @@ std::optional<VertexAccessor> GraphDbAccessor::FindVertexOptional(
VertexAccessor GraphDbAccessor::FindVertex(storage::Gid gid,
bool 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.AsUint();
return *found;
}
@ -135,7 +135,7 @@ std::optional<EdgeAccessor> GraphDbAccessor::FindEdgeOptional(
EdgeAccessor GraphDbAccessor::FindEdge(storage::Gid gid, bool 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.AsUint();
return *found;
}
@ -455,7 +455,7 @@ EdgeAccessor GraphDbAccessor::InsertEdge(
// edges_ skiplist.
bool success = db_->storage().edges_.access().insert(gid, edge_vlist).second;
CHECK(success) << "Attempting to insert an edge with an existing GID: "
<< gid;
<< gid.AsUint();
// ensure that the "from" accessor has the latest version
from.SwitchNew();

View File

@ -179,7 +179,8 @@ bool RecoverSnapshot(const fs::path &snapshot_file, database::GraphDb *db,
Value vertex_dv;
RETURN_IF_NOT(decoder.ReadValue(&vertex_dv, Value::Type::Vertex));
auto &vertex = vertex_dv.ValueVertex();
auto vertex_accessor = dba.InsertVertex(vertex.id.AsUint());
auto vertex_accessor =
dba.InsertVertex(storage::Gid::FromUint(vertex.id.AsUint()));
for (const auto &label : vertex.labels) {
vertex_accessor.add_label(dba.Label(label));
@ -199,8 +200,8 @@ bool RecoverSnapshot(const fs::path &snapshot_file, database::GraphDb *db,
auto it_to = vertices.find(edge.to.AsUint());
RETURN_IF_NOT(it_from != vertices.end() && it_to != vertices.end());
auto edge_accessor =
dba.InsertEdge(it_from->second, it_to->second,
dba.EdgeType(edge.type), edge.id.AsUint());
dba.InsertEdge(it_from->second, it_to->second, dba.EdgeType(edge.type),
storage::Gid::FromUint(edge.id.AsUint()));
for (const auto &property_pair : edge.properties)
edge_accessor.PropsSet(dba.Property(property_pair.first),

View File

@ -164,38 +164,38 @@ void StateDelta::Encode(
case Type::TRANSACTION_ABORT:
break;
case Type::CREATE_VERTEX:
encoder.WriteInt(vertex_id);
encoder.WriteInt(vertex_id.AsInt());
break;
case Type::CREATE_EDGE:
encoder.WriteInt(edge_id);
encoder.WriteInt(vertex_from_id);
encoder.WriteInt(vertex_to_id);
encoder.WriteInt(edge_id.AsInt());
encoder.WriteInt(vertex_from_id.AsInt());
encoder.WriteInt(vertex_to_id.AsInt());
encoder.WriteInt(edge_type.Id());
encoder.WriteString(edge_type_name);
break;
case Type::SET_PROPERTY_VERTEX:
encoder.WriteInt(vertex_id);
encoder.WriteInt(vertex_id.AsInt());
encoder.WriteInt(property.Id());
encoder.WriteString(property_name);
encoder.WriteValue(glue::ToBoltValue(value));
break;
case Type::SET_PROPERTY_EDGE:
encoder.WriteInt(edge_id);
encoder.WriteInt(edge_id.AsInt());
encoder.WriteInt(property.Id());
encoder.WriteString(property_name);
encoder.WriteValue(glue::ToBoltValue(value));
break;
case Type::ADD_LABEL:
case Type::REMOVE_LABEL:
encoder.WriteInt(vertex_id);
encoder.WriteInt(vertex_id.AsInt());
encoder.WriteInt(label.Id());
encoder.WriteString(label_name);
break;
case Type::REMOVE_VERTEX:
encoder.WriteInt(vertex_id);
encoder.WriteInt(vertex_id.AsInt());
break;
case Type::REMOVE_EDGE:
encoder.WriteInt(edge_id);
encoder.WriteInt(edge_id.AsInt());
break;
case Type::BUILD_INDEX:
encoder.WriteInt(label.Id());
@ -240,6 +240,10 @@ void StateDelta::Encode(
if (!decoder.ReadValue(&dv)) return nullopt; \
r_val.member = dv.value_f();
#define DECODE_GID_MEMBER(member) \
if (!decoder.ReadValue(&dv)) return nullopt; \
r_val.member = storage::Gid::FromInt(dv.ValueInt());
#define DECODE_MEMBER_CAST(member, value_f, type) \
if (!decoder.ReadValue(&dv)) return nullopt; \
r_val.member = static_cast<type>(dv.value_f());
@ -264,24 +268,24 @@ std::optional<StateDelta> StateDelta::Decode(
case Type::TRANSACTION_ABORT:
break;
case Type::CREATE_VERTEX:
DECODE_MEMBER(vertex_id, ValueInt)
DECODE_GID_MEMBER(vertex_id)
break;
case Type::CREATE_EDGE:
DECODE_MEMBER(edge_id, ValueInt)
DECODE_MEMBER(vertex_from_id, ValueInt)
DECODE_MEMBER(vertex_to_id, ValueInt)
DECODE_GID_MEMBER(edge_id)
DECODE_GID_MEMBER(vertex_from_id)
DECODE_GID_MEMBER(vertex_to_id)
DECODE_MEMBER_CAST(edge_type, ValueInt, storage::EdgeType)
DECODE_MEMBER(edge_type_name, ValueString)
break;
case Type::SET_PROPERTY_VERTEX:
DECODE_MEMBER(vertex_id, ValueInt)
DECODE_GID_MEMBER(vertex_id)
DECODE_MEMBER_CAST(property, ValueInt, storage::Property)
DECODE_MEMBER(property_name, ValueString)
if (!decoder.ReadValue(&dv)) return nullopt;
r_val.value = glue::ToPropertyValue(dv);
break;
case Type::SET_PROPERTY_EDGE:
DECODE_MEMBER(edge_id, ValueInt)
DECODE_GID_MEMBER(edge_id)
DECODE_MEMBER_CAST(property, ValueInt, storage::Property)
DECODE_MEMBER(property_name, ValueString)
if (!decoder.ReadValue(&dv)) return nullopt;
@ -289,15 +293,15 @@ std::optional<StateDelta> StateDelta::Decode(
break;
case Type::ADD_LABEL:
case Type::REMOVE_LABEL:
DECODE_MEMBER(vertex_id, ValueInt)
DECODE_GID_MEMBER(vertex_id)
DECODE_MEMBER_CAST(label, ValueInt, storage::Label)
DECODE_MEMBER(label_name, ValueString)
break;
case Type::REMOVE_VERTEX:
DECODE_MEMBER(vertex_id, ValueInt)
DECODE_GID_MEMBER(vertex_id)
break;
case Type::REMOVE_EDGE:
DECODE_MEMBER(edge_id, ValueInt)
DECODE_GID_MEMBER(edge_id)
break;
case Type::BUILD_INDEX:
DECODE_MEMBER_CAST(label, ValueInt, storage::Label)

View File

@ -83,7 +83,8 @@ bool RecoverSnapshot(const fs::path &snapshot_file, database::GraphDb *db,
Value vertex_dv;
RETURN_IF_NOT(decoder.ReadValue(&vertex_dv, Value::Type::Vertex));
auto &vertex = vertex_dv.ValueVertex();
auto vertex_accessor = dba.InsertVertex(vertex.id.AsUint());
auto vertex_accessor =
dba.InsertVertex(storage::Gid::FromUint(vertex.id.AsUint()));
for (const auto &label : vertex.labels) {
vertex_accessor.add_label(dba.Label(label));
@ -103,8 +104,8 @@ bool RecoverSnapshot(const fs::path &snapshot_file, database::GraphDb *db,
auto it_to = vertices.find(edge.to.AsUint());
RETURN_IF_NOT(it_from != vertices.end() && it_to != vertices.end());
auto edge_accessor =
dba.InsertEdge(it_from->second, it_to->second,
dba.EdgeType(edge.type), edge.id.AsUint());
dba.InsertEdge(it_from->second, it_to->second, dba.EdgeType(edge.type),
storage::Gid::FromUint(edge.id.AsUint()));
for (const auto &property_pair : edge.properties)
edge_accessor.PropsSet(dba.Property(property_pair.first),

View File

@ -170,38 +170,38 @@ void StateDelta::Encode(
case Type::NO_OP:
break;
case Type::CREATE_VERTEX:
encoder.WriteInt(vertex_id);
encoder.WriteInt(vertex_id.AsInt());
break;
case Type::CREATE_EDGE:
encoder.WriteInt(edge_id);
encoder.WriteInt(vertex_from_id);
encoder.WriteInt(vertex_to_id);
encoder.WriteInt(edge_id.AsInt());
encoder.WriteInt(vertex_from_id.AsInt());
encoder.WriteInt(vertex_to_id.AsInt());
encoder.WriteInt(edge_type.Id());
encoder.WriteString(edge_type_name);
break;
case Type::SET_PROPERTY_VERTEX:
encoder.WriteInt(vertex_id);
encoder.WriteInt(vertex_id.AsInt());
encoder.WriteInt(property.Id());
encoder.WriteString(property_name);
encoder.WriteValue(glue::ToBoltValue(value));
break;
case Type::SET_PROPERTY_EDGE:
encoder.WriteInt(edge_id);
encoder.WriteInt(edge_id.AsInt());
encoder.WriteInt(property.Id());
encoder.WriteString(property_name);
encoder.WriteValue(glue::ToBoltValue(value));
break;
case Type::ADD_LABEL:
case Type::REMOVE_LABEL:
encoder.WriteInt(vertex_id);
encoder.WriteInt(vertex_id.AsInt());
encoder.WriteInt(label.Id());
encoder.WriteString(label_name);
break;
case Type::REMOVE_VERTEX:
encoder.WriteInt(vertex_id);
encoder.WriteInt(vertex_id.AsInt());
break;
case Type::REMOVE_EDGE:
encoder.WriteInt(edge_id);
encoder.WriteInt(edge_id.AsInt());
break;
case Type::BUILD_INDEX:
encoder.WriteInt(label.Id());
@ -246,6 +246,10 @@ void StateDelta::Encode(
if (!decoder.ReadValue(&dv)) return nullopt; \
r_val.member = dv.value_f();
#define DECODE_GID_MEMBER(member) \
if (!decoder.ReadValue(&dv)) return nullopt; \
r_val.member = storage::Gid::FromInt(dv.ValueInt());
#define DECODE_MEMBER_CAST(member, value_f, type) \
if (!decoder.ReadValue(&dv)) return nullopt; \
r_val.member = static_cast<type>(dv.value_f());
@ -271,24 +275,24 @@ std::optional<StateDelta> StateDelta::Decode(
case Type::NO_OP:
break;
case Type::CREATE_VERTEX:
DECODE_MEMBER(vertex_id, ValueInt)
DECODE_GID_MEMBER(vertex_id)
break;
case Type::CREATE_EDGE:
DECODE_MEMBER(edge_id, ValueInt)
DECODE_MEMBER(vertex_from_id, ValueInt)
DECODE_MEMBER(vertex_to_id, ValueInt)
DECODE_GID_MEMBER(edge_id)
DECODE_GID_MEMBER(vertex_from_id)
DECODE_GID_MEMBER(vertex_to_id)
DECODE_MEMBER_CAST(edge_type, ValueInt, storage::EdgeType)
DECODE_MEMBER(edge_type_name, ValueString)
break;
case Type::SET_PROPERTY_VERTEX:
DECODE_MEMBER(vertex_id, ValueInt)
DECODE_GID_MEMBER(vertex_id)
DECODE_MEMBER_CAST(property, ValueInt, storage::Property)
DECODE_MEMBER(property_name, ValueString)
if (!decoder.ReadValue(&dv)) return nullopt;
r_val.value = glue::ToPropertyValue(dv);
break;
case Type::SET_PROPERTY_EDGE:
DECODE_MEMBER(edge_id, ValueInt)
DECODE_GID_MEMBER(edge_id)
DECODE_MEMBER_CAST(property, ValueInt, storage::Property)
DECODE_MEMBER(property_name, ValueString)
if (!decoder.ReadValue(&dv)) return nullopt;
@ -296,15 +300,15 @@ std::optional<StateDelta> StateDelta::Decode(
break;
case Type::ADD_LABEL:
case Type::REMOVE_LABEL:
DECODE_MEMBER(vertex_id, ValueInt)
DECODE_GID_MEMBER(vertex_id)
DECODE_MEMBER_CAST(label, ValueInt, storage::Label)
DECODE_MEMBER(label_name, ValueString)
break;
case Type::REMOVE_VERTEX:
DECODE_MEMBER(vertex_id, ValueInt)
DECODE_GID_MEMBER(vertex_id)
break;
case Type::REMOVE_EDGE:
DECODE_MEMBER(edge_id, ValueInt)
DECODE_GID_MEMBER(edge_id)
break;
case Type::BUILD_INDEX:
DECODE_MEMBER_CAST(label, ValueInt, storage::Label)

View File

@ -80,7 +80,7 @@ Value ToBoltValue(const query::TypedValue &value) {
}
communication::bolt::Vertex ToBoltVertex(const VertexAccessor &vertex) {
auto id = communication::bolt::Id::FromUint(vertex.gid());
auto id = communication::bolt::Id::FromUint(vertex.gid().AsUint());
std::vector<std::string> labels;
labels.reserve(vertex.labels().size());
for (const auto &label : vertex.labels()) {
@ -96,9 +96,9 @@ communication::bolt::Vertex ToBoltVertex(const VertexAccessor &vertex) {
}
communication::bolt::Edge ToBoltEdge(const EdgeAccessor &edge) {
auto id = communication::bolt::Id::FromUint(edge.gid());
auto from = communication::bolt::Id::FromUint(edge.from().gid());
auto to = communication::bolt::Id::FromUint(edge.to().gid());
auto id = communication::bolt::Id::FromUint(edge.gid().AsUint());
auto from = communication::bolt::Id::FromUint(edge.from().gid().AsUint());
auto to = communication::bolt::Id::FromUint(edge.to().gid().AsUint());
auto type = edge.db_accessor().EdgeTypeName(edge.EdgeType());
std::map<std::string, Value> properties;
for (const auto &prop : edge.Properties()) {

View File

@ -904,9 +904,9 @@ size_t TypedValue::Hash::operator()(const TypedValue &value) const {
return hash;
}
case TypedValue::Type::Vertex:
return value.ValueVertex().gid();
return value.ValueVertex().gid().AsUint();
case TypedValue::Type::Edge:
return value.ValueEdge().gid();
return value.ValueEdge().gid().AsUint();
case TypedValue::Type::Path: {
const auto &vertices = value.ValuePath().vertices();
const auto &edges = value.ValuePath().edges();

View File

@ -22,6 +22,7 @@ inline void Save(const storage::EdgeType &common, slk::Builder *builder) {
inline void Load(storage::EdgeType *common, slk::Reader *reader) {
slk::Load(&common->id_, reader);
}
inline void Save(const storage::Property &common, slk::Builder *builder) {
slk::Save(common.id_, builder);
}
@ -30,6 +31,16 @@ inline void Load(storage::Property *common, slk::Reader *reader) {
slk::Load(&common->id_, reader);
}
inline void Save(const storage::Gid &gid, slk::Builder *builder) {
slk::Save(gid.AsUint(), builder);
}
inline void Load(storage::Gid *gid, slk::Reader *reader) {
uint64_t id;
slk::Load(&id, reader);
*gid = storage::Gid::FromUint(id);
}
void Save(const PropertyValue &value, slk::Builder *builder);
void Load(PropertyValue *value, slk::Reader *reader);

View File

@ -9,6 +9,7 @@
#include <glog/logging.h>
#include "utils/atomic.hpp"
#include "utils/cast.hpp"
namespace storage {
@ -151,7 +152,47 @@ class Property final {
};
/** Global ID of a record in the database. */
using Gid = uint64_t;
class Gid final {
private:
explicit Gid(uint64_t id) : id_(id) {}
public:
Gid() = default;
static Gid FromUint(uint64_t id) { return Gid{id}; }
static Gid FromInt(int64_t id) {
return Gid{utils::MemcpyCast<uint64_t>(id)};
}
uint64_t AsUint() const { return id_; }
int64_t AsInt() const { return utils::MemcpyCast<int64_t>(id_); }
private:
uint64_t id_;
};
inline bool operator==(const Gid &first, const Gid &second) {
return first.AsUint() == second.AsUint();
}
inline bool operator!=(const Gid &first, const Gid &second) {
return first.AsUint() != second.AsUint();
}
inline bool operator<(const Gid &first, const Gid &second) {
return first.AsUint() < second.AsUint();
}
inline bool operator>(const Gid &first, const Gid &second) {
return first.AsUint() > second.AsUint();
}
inline bool operator<=(const Gid &first, const Gid &second) {
return first.AsUint() <= second.AsUint();
}
inline bool operator>=(const Gid &first, const Gid &second) {
return first.AsUint() >= second.AsUint();
}
/** Threadsafe generation of new global IDs. */
class GidGenerator {
@ -164,10 +205,10 @@ class GidGenerator {
*/
Gid Next(std::optional<Gid> requested_gid = std::nullopt) {
if (requested_gid) {
utils::EnsureAtomicGe(next_local_id_, *requested_gid + 1);
utils::EnsureAtomicGe(next_local_id_, requested_gid->AsUint() + 1U);
return *requested_gid;
} else {
return next_local_id_++;
return Gid::FromUint(next_local_id_++);
}
}
@ -198,4 +239,11 @@ struct hash<storage::Property> {
return hash<storage::IdT>()(k.Id());
}
};
template <>
struct hash<storage::Gid> {
size_t operator()(const storage::Gid &gid) const {
return hash<uint64_t>()(gid.AsUint());
}
};
} // namespace std

View File

@ -72,6 +72,6 @@ std::ostream &operator<<(std::ostream &, const EdgeAccessor &);
namespace std {
template <>
struct hash<EdgeAccessor> {
size_t operator()(const EdgeAccessor &e) const { return e.gid(); };
size_t operator()(const EdgeAccessor &e) const { return e.gid().AsUint(); };
};
} // namespace std

View File

@ -4,7 +4,6 @@
#include "storage/common/mvcc/exceptions.hpp"
#include "storage/common/types/types.hpp"
#include "transactions/transaction.hpp"
#include "utils/cast.hpp"
#include "utils/exceptions.hpp"
namespace mvcc {
@ -223,7 +222,7 @@ class VersionList {
const storage::Gid gid_;
int64_t cypher_id() { return utils::MemcpyCast<int64_t>(gid_); }
int64_t cypher_id() { return gid_.AsInt(); }
private:
/// @throw utils::LockTimeoutException

View File

@ -52,7 +52,7 @@ class Storage {
CHECK(found != access.end())
<< "Failed to find "
<< (std::is_same<TRecord, Vertex>::value ? "vertex" : "edge")
<< " for gid: " << gid;
<< " for gid: " << gid.AsUint();
return found->second;
}

View File

@ -172,6 +172,6 @@ std::ostream &operator<<(std::ostream &, const VertexAccessor &);
namespace std {
template <>
struct hash<VertexAccessor> {
size_t operator()(const VertexAccessor &v) const { return v.gid(); };
size_t operator()(const VertexAccessor &v) const { return v.gid().AsUint(); };
};
} // namespace std

View File

@ -72,6 +72,6 @@ std::ostream &operator<<(std::ostream &, const EdgeAccessor &);
namespace std {
template <>
struct hash<EdgeAccessor> {
size_t operator()(const EdgeAccessor &e) const { return e.gid(); };
size_t operator()(const EdgeAccessor &e) const { return e.gid().AsUint(); };
};
} // namespace std

View File

@ -4,7 +4,6 @@
#include "storage/common/mvcc/exceptions.hpp"
#include "storage/common/types/types.hpp"
#include "transactions/transaction.hpp"
#include "utils/cast.hpp"
#include "utils/exceptions.hpp"
namespace mvcc {
@ -217,7 +216,7 @@ class VersionList {
const storage::Gid gid_;
int64_t cypher_id() { return utils::MemcpyCast<int64_t>(gid_); }
int64_t cypher_id() { return gid_.AsInt(); }
private:
void lock_and_validate(T *record, const tx::Transaction &t) {

View File

@ -52,7 +52,7 @@ class Storage {
CHECK(found != access.end())
<< "Failed to find "
<< (std::is_same<TRecord, Vertex>::value ? "vertex" : "edge")
<< " for gid: " << gid;
<< " for gid: " << gid.AsUint();
return found->second;
}

View File

@ -153,6 +153,6 @@ std::ostream &operator<<(std::ostream &, const VertexAccessor &);
namespace std {
template <>
struct hash<VertexAccessor> {
size_t operator()(const VertexAccessor &v) const { return v.gid(); };
size_t operator()(const VertexAccessor &v) const { return v.gid().AsUint(); };
};
} // namespace std

View File

@ -21,7 +21,7 @@ void MvccMix(benchmark::State &state) {
state.PauseTiming();
tx::Engine engine;
auto t1 = engine.Begin();
mvcc::VersionList<Prop> version_list(*t1, 0);
mvcc::VersionList<Prop> version_list(*t1, storage::Gid::FromInt(0));
engine.Commit(*t1);
auto t2 = engine.Begin();

View File

@ -198,13 +198,13 @@ TEST(BoltEncoder, VertexAndEdge) {
// and Memgraph now encodes IDs so we need to check the output
// part by part.
CheckOutput(output, vertexedge_encoded, 5, false);
CheckInt(output, va1.gid());
CheckInt(output, va1.gid().AsInt());
CheckOutput(output, vertexedge_encoded + 6, 34, false);
CheckInt(output, va2.gid());
CheckInt(output, va2.gid().AsInt());
CheckOutput(output, vertexedge_encoded + 41, 4, false);
CheckInt(output, ea.gid());
CheckInt(output, va1.gid());
CheckInt(output, va2.gid());
CheckInt(output, ea.gid().AsInt());
CheckInt(output, va1.gid().AsInt());
CheckInt(output, va2.gid().AsInt());
CheckOutput(output, vertexedge_encoded + 48, 26);
}

View File

@ -202,7 +202,7 @@ VertexAccessor CreateVertex(GraphDbAccessor *dba,
}
if (add_property_id) {
vertex.PropsSet(dba->Property(kPropertyId),
PropertyValue(static_cast<int64_t>(vertex.gid())));
PropertyValue(vertex.gid().AsInt()));
}
return vertex;
}
@ -218,7 +218,7 @@ EdgeAccessor CreateEdge(GraphDbAccessor *dba, VertexAccessor from,
}
if (add_property_id) {
edge.PropsSet(dba->Property(kPropertyId),
PropertyValue(static_cast<int64_t>(edge.gid())));
PropertyValue(edge.gid().AsInt()));
}
return edge;
}

View File

@ -19,7 +19,7 @@ TEST(LabelsIndex, UniqueInsert) {
tx::Engine engine;
auto t1 = engine.Begin();
mvcc::VersionList<Vertex> vlist(*t1, 0);
mvcc::VersionList<Vertex> vlist(*t1, storage::Gid::FromInt(0));
engine.Commit(*t1);
auto t2 = engine.Begin();
@ -48,8 +48,8 @@ TEST(LabelsIndex, UniqueFilter) {
tx::Engine engine;
auto t1 = engine.Begin();
mvcc::VersionList<Vertex> vlist1(*t1, 0);
mvcc::VersionList<Vertex> vlist2(*t1, 1);
mvcc::VersionList<Vertex> vlist1(*t1, storage::Gid::FromInt(0));
mvcc::VersionList<Vertex> vlist2(*t1, storage::Gid::FromInt(1));
engine.Advance(t1->id_);
auto r1v1 = vlist1.find(*t1);
auto r1v2 = vlist2.find(*t1);
@ -89,8 +89,8 @@ TEST(LabelsIndex, Refresh) {
// add two vertices to database
auto t1 = engine.Begin();
mvcc::VersionList<Vertex> vlist1(*t1, 0);
mvcc::VersionList<Vertex> vlist2(*t1, 1);
mvcc::VersionList<Vertex> vlist1(*t1, storage::Gid::FromInt(0));
mvcc::VersionList<Vertex> vlist2(*t1, storage::Gid::FromInt(1));
engine.Advance(t1->id_);
auto v1r1 = vlist1.find(*t1);

View File

@ -24,7 +24,7 @@ class LabelPropertyIndexComplexTest : public ::testing::Test {
EXPECT_EQ(index.CreateIndex(*key), true);
t = engine.Begin();
vlist = new mvcc::VersionList<Vertex>(*t, 0);
vlist = new mvcc::VersionList<Vertex>(*t, storage::Gid::FromInt(0));
engine.Advance(t->id_);
vertex = vlist->find(*t);

View File

@ -54,16 +54,19 @@ class DbGenerator {
}
EdgeAccessor RandomEdge(bool remove_from_ids = false) {
return dba_.FindEdge(RandomElement(edge_ids_, remove_from_ids), true);
return dba_.FindEdge(
storage::Gid::FromInt(RandomElement(edge_ids_, remove_from_ids)), true);
}
VertexAccessor RandomVertex(bool remove_from_ids = false) {
return dba_.FindVertex(RandomElement(vertex_ids_, remove_from_ids), true);
return dba_.FindVertex(
storage::Gid::FromInt(RandomElement(vertex_ids_, remove_from_ids)),
true);
}
VertexAccessor InsertVertex() {
auto vertex = dba_.InsertVertex();
vertex_ids_.emplace_back(vertex.gid());
vertex_ids_.emplace_back(vertex.gid().AsInt());
return vertex;
}
@ -76,7 +79,7 @@ class DbGenerator {
auto from = RandomVertex();
auto to = RandomVertex();
auto edge = dba_.InsertEdge(from, to, EdgeType(RandomInt(kEdgeTypeCount)));
edge_ids_.emplace_back(edge.gid());
edge_ids_.emplace_back(edge.gid().AsInt());
return edge;
}
@ -84,7 +87,7 @@ class DbGenerator {
auto vertex = RandomVertex();
auto edge =
dba_.InsertEdge(vertex, vertex, EdgeType(RandomInt(kEdgeTypeCount)));
edge_ids_.emplace_back(edge.gid());
edge_ids_.emplace_back(edge.gid().AsInt());
return edge;
}
@ -226,7 +229,7 @@ void CompareDbs(database::GraphDb &a, database::GraphDb &b) {
for (auto v_a : dba_a.Vertices(false)) {
vertices_a_count++;
auto v_b = dba_b.FindVertexOptional(v_a.gid(), false);
ASSERT_TRUE(v_b) << "Vertex not found, id: " << v_a.gid();
ASSERT_TRUE(v_b) << "Vertex not found, id: " << v_a.gid().AsUint();
ASSERT_EQ(v_a.labels().size(), v_b->labels().size());
std::vector<std::string> v_a_labels;
std::vector<std::string> v_b_labels;
@ -246,7 +249,7 @@ void CompareDbs(database::GraphDb &a, database::GraphDb &b) {
edges_a_count++;
auto e_b = dba_b.FindEdgeOptional(e_a.gid(), false);
ASSERT_TRUE(e_b);
ASSERT_TRUE(e_b) << "Edge not found, id: " << e_a.gid();
ASSERT_TRUE(e_b) << "Edge not found, id: " << e_a.gid().AsUint();
EXPECT_EQ(dba_a.EdgeTypeName(e_a.EdgeType()),
dba_b.EdgeTypeName(e_b->EdgeType()));
EXPECT_EQ(e_a.from().gid(), e_b->from().gid());
@ -518,7 +521,8 @@ TEST_F(Durability, SnapshotEncoding) {
ASSERT_TRUE(
decoder.ReadValue(&dv, communication::bolt::Value::Type::Vertex));
auto &vertex = dv.ValueVertex();
decoded_vertices.emplace(vertex.id.AsUint(), vertex);
decoded_vertices.emplace(storage::Gid::FromUint(vertex.id.AsUint()),
vertex);
}
ASSERT_EQ(decoded_vertices.size(), 3);
ASSERT_EQ(decoded_vertices[gid0].labels.size(), 1);
@ -536,15 +540,15 @@ TEST_F(Durability, SnapshotEncoding) {
for (int i = 0; i < edge_count; ++i) {
ASSERT_TRUE(decoder.ReadValue(&dv, communication::bolt::Value::Type::Edge));
auto &edge = dv.ValueEdge();
decoded_edges.emplace(edge.id.AsUint(), edge);
decoded_edges.emplace(storage::Gid::FromUint(edge.id.AsUint()), edge);
}
EXPECT_EQ(decoded_edges.size(), 2);
EXPECT_EQ(decoded_edges[gid0].from.AsUint(), gid0);
EXPECT_EQ(decoded_edges[gid0].to.AsUint(), gid1);
EXPECT_EQ(decoded_edges[gid0].from.AsUint(), gid0.AsUint());
EXPECT_EQ(decoded_edges[gid0].to.AsUint(), gid1.AsUint());
EXPECT_EQ(decoded_edges[gid0].type, "et0");
EXPECT_EQ(decoded_edges[gid0].properties.size(), 1);
EXPECT_EQ(decoded_edges[gid1].from.AsUint(), gid2);
EXPECT_EQ(decoded_edges[gid1].to.AsUint(), gid1);
EXPECT_EQ(decoded_edges[gid1].from.AsUint(), gid2.AsUint());
EXPECT_EQ(decoded_edges[gid1].to.AsUint(), gid1.AsUint());
EXPECT_EQ(decoded_edges[gid1].type, "et1");
EXPECT_EQ(decoded_edges[gid1].properties.size(), 0);
@ -812,7 +816,8 @@ TEST_F(Durability, SequentialRecovery) {
auto init_db = [](database::GraphDb &db) {
auto dba = db.Access();
for (int i = 0; i < kNumVertices; ++i) dba.InsertVertex(i);
for (int i = 0; i < kNumVertices; ++i)
dba.InsertVertex(storage::Gid::FromInt(i));
dba.Commit();
};
@ -823,7 +828,8 @@ TEST_F(Durability, SequentialRecovery) {
threads.emplace_back([&random_int, &db, &keep_running]() {
while (keep_running) {
auto dba = db.Access();
auto v = dba.FindVertex(random_int(kNumVertices), false);
auto v = dba.FindVertex(
storage::Gid::FromInt(random_int(kNumVertices)), false);
try {
v.PropsSet(dba.Property("prop"), PropertyValue(random_int(100)));
} catch (utils::LockTimeoutException &) {

View File

@ -15,31 +15,37 @@ TEST(Edges, Filtering) {
auto tx = tx_engine.Begin();
int64_t vertex_gid = 0;
mvcc::VersionList<Vertex> v0(*tx, vertex_gid++);
mvcc::VersionList<Vertex> v1(*tx, vertex_gid++);
mvcc::VersionList<Vertex> v2(*tx, vertex_gid++);
mvcc::VersionList<Vertex> v3(*tx, vertex_gid++);
mvcc::VersionList<Vertex> v0(*tx, storage::Gid::FromInt(vertex_gid++));
mvcc::VersionList<Vertex> v1(*tx, storage::Gid::FromInt(vertex_gid++));
mvcc::VersionList<Vertex> v2(*tx, storage::Gid::FromInt(vertex_gid++));
mvcc::VersionList<Vertex> v3(*tx, storage::Gid::FromInt(vertex_gid++));
storage::EdgeType t1{1};
storage::EdgeType t2{2};
int64_t edge_gid = 0;
mvcc::VersionList<Edge> e1(*tx, edge_gid++, &v0, &v1, t1);
mvcc::VersionList<Edge> e1(*tx, storage::Gid::FromInt(edge_gid++), &v0, &v1,
t1);
edges.emplace(&v1, &e1, t1);
mvcc::VersionList<Edge> e2(*tx, edge_gid++, &v0, &v2, t2);
mvcc::VersionList<Edge> e2(*tx, storage::Gid::FromInt(edge_gid++), &v0, &v2,
t2);
edges.emplace(&v2, &e2, t2);
mvcc::VersionList<Edge> e3(*tx, edge_gid++, &v0, &v3, t1);
mvcc::VersionList<Edge> e3(*tx, storage::Gid::FromInt(edge_gid++), &v0, &v3,
t1);
edges.emplace(&v3, &e3, t1);
mvcc::VersionList<Edge> e4(*tx, edge_gid++, &v0, &v1, t2);
mvcc::VersionList<Edge> e4(*tx, storage::Gid::FromInt(edge_gid++), &v0, &v1,
t2);
edges.emplace(&v1, &e4, t2);
mvcc::VersionList<Edge> e5(*tx, edge_gid++, &v0, &v2, t1);
mvcc::VersionList<Edge> e5(*tx, storage::Gid::FromInt(edge_gid++), &v0, &v2,
t1);
edges.emplace(&v2, &e5, t1);
mvcc::VersionList<Edge> e6(*tx, edge_gid++, &v0, &v3, t2);
mvcc::VersionList<Edge> e6(*tx, storage::Gid::FromInt(edge_gid++), &v0, &v3,
t2);
edges.emplace(&v3, &e6, t2);
auto edge_addresses = [edges](mvcc::VersionList<Vertex> *dest,

View File

@ -38,7 +38,7 @@ TEST(GraphDbAccessorTest, InsertVertex) {
TEST(GraphDbAccessorTest, UniqueVertexId) {
GraphDb db;
SkipList<int64_t> ids;
SkipList<storage::Gid> ids;
std::vector<std::thread> threads;
for (int i = 0; i < 50; i++) {
@ -140,7 +140,7 @@ TEST(GraphDbAccessorTest, InsertEdge) {
TEST(GraphDbAccessorTest, UniqueEdgeId) {
GraphDb db;
SkipList<int64_t> ids;
SkipList<storage::Gid> ids;
std::vector<std::thread> threads;
for (int i = 0; i < 50; i++) {

View File

@ -15,8 +15,8 @@ TEST(MVCC, Deadlock) {
tx::Engine engine;
auto t0 = engine.Begin();
mvcc::VersionList<Prop> version_list1(*t0, 0);
mvcc::VersionList<Prop> version_list2(*t0, 1);
mvcc::VersionList<Prop> version_list1(*t0, storage::Gid::FromInt(0));
mvcc::VersionList<Prop> version_list2(*t0, storage::Gid::FromInt(1));
engine.Commit(*t0);
auto t1 = engine.Begin();
@ -34,7 +34,8 @@ TEST(MVCC, UpdateDontDelete) {
{
tx::Engine engine;
auto t1 = engine.Begin();
mvcc::VersionList<DestrCountRec> version_list(*t1, 0, count);
mvcc::VersionList<DestrCountRec> version_list(*t1, storage::Gid::FromInt(0),
count);
engine.Commit(*t1);
auto t2 = engine.Begin();
@ -58,7 +59,7 @@ TEST(MVCC, UpdateDontDelete) {
TEST(MVCC, Oldest) {
tx::Engine engine;
auto t1 = engine.Begin();
mvcc::VersionList<Prop> version_list(*t1, 0);
mvcc::VersionList<Prop> version_list(*t1, storage::Gid::FromInt(0));
auto first = version_list.Oldest();
EXPECT_NE(first, nullptr);
// TODO Gleich: no need to do 10 checks of the same thing

View File

@ -60,7 +60,8 @@ class Mvcc : public ::testing::Test {
int version_list_size = 0;
tx::Engine engine;
tx::Transaction *t1 = engine.Begin();
mvcc::VersionList<TestClass> version_list{*t1, 0, version_list_size};
mvcc::VersionList<TestClass> version_list{*t1, storage::Gid::FromInt(0),
version_list_size};
TestClass *v1 = nullptr;
tx::Transaction *t2 = nullptr;
tx::TransactionId id0, id1, id2;

View File

@ -24,7 +24,7 @@ class MvccGcTest : public ::testing::Test {
protected:
std::atomic<int> record_destruction_count{0};
mvcc::VersionList<DestrCountRec> version_list{*t0, 0,
mvcc::VersionList<DestrCountRec> version_list{*t0, storage::Gid::FromInt(0),
record_destruction_count};
std::vector<tx::Transaction *> transactions{t0};
@ -124,8 +124,8 @@ TEST(GarbageCollector, GcClean) {
// create a version list in transaction t1
auto t1 = engine.Begin();
std::atomic<int> record_destruction_count{0};
auto vl =
new mvcc::VersionList<DestrCountRec>(*t1, 0, record_destruction_count);
auto vl = new mvcc::VersionList<DestrCountRec>(*t1, storage::Gid::FromInt(0),
record_destruction_count);
auto access = collection.access();
access.insert(0, vl);
engine.Commit(*t1);

View File

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

View File

@ -145,13 +145,13 @@ struct hash<NodeId> {
class MemgraphNodeIdMap {
public:
std::optional<int64_t> Get(const NodeId &node_id) const {
std::optional<storage::Gid> Get(const NodeId &node_id) const {
auto found_it = node_id_to_mg_.find(node_id);
if (found_it == node_id_to_mg_.end()) return std::nullopt;
return found_it->second;
}
uint64_t Insert(const NodeId &node_id) {
storage::Gid Insert(const NodeId &node_id) {
auto gid = generator_.Next();
node_id_to_mg_[node_id] = gid;
return gid;
@ -159,7 +159,7 @@ class MemgraphNodeIdMap {
private:
storage::GidGenerator generator_;
std::unordered_map<NodeId, int64_t> node_id_to_mg_;
std::unordered_map<NodeId, storage::Gid> node_id_to_mg_;
};
std::vector<std::string> ReadRow(std::istream &stream) {
@ -307,7 +307,7 @@ void WriteNodeRow(
additional_labels.end());
CHECK(id) << "Node ID must be specified";
encoder->WriteVertex(
{communication::bolt::Id::FromUint(*id), labels, properties});
{communication::bolt::Id::FromUint(id->AsUint()), labels, properties});
}
auto PassNodes(
@ -334,8 +334,8 @@ void WriteRelationshipsRow(
communication::bolt::BaseEncoder<HashedFileWriter> *encoder,
const std::vector<Field> &fields, const std::vector<std::string> &row,
const MemgraphNodeIdMap &node_id_map, storage::Gid relationship_id) {
std::optional<int64_t> start_id;
std::optional<int64_t> end_id;
std::optional<storage::Gid> start_id;
std::optional<storage::Gid> end_id;
std::optional<std::string> relationship_type;
std::map<std::string, communication::bolt::Value> properties;
for (int i = 0; i < row.size(); ++i) {
@ -369,9 +369,9 @@ void WriteRelationshipsRow(
CHECK(end_id) << "END_ID must be set";
CHECK(relationship_type) << "Relationship TYPE must be set";
auto bolt_id = communication::bolt::Id::FromUint(relationship_id);
auto bolt_start_id = communication::bolt::Id::FromUint(*start_id);
auto bolt_end_id = communication::bolt::Id::FromUint(*end_id);
auto bolt_id = communication::bolt::Id::FromUint(relationship_id.AsUint());
auto bolt_start_id = communication::bolt::Id::FromUint(start_id->AsUint());
auto bolt_end_id = communication::bolt::Id::FromUint(end_id->AsUint());
encoder->WriteEdge(
{bolt_id, bolt_start_id, bolt_end_id, *relationship_type, properties});
}