Implement explicit types in storage v2

Reviewers: teon.banek, mtomic

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2224
This commit is contained in:
Matej Ferencevic 2019-07-22 13:35:36 +02:00
parent e83abaaa5a
commit d7d0963434
15 changed files with 1483 additions and 1003 deletions

View File

@ -4,6 +4,7 @@
#include <glog/logging.h>
#include "storage/v2/id_types.hpp"
#include "storage/v2/property_value.hpp"
namespace storage {
@ -128,49 +129,49 @@ struct Delta {
timestamp(timestamp),
command_id(command_id) {}
Delta(AddLabelTag, uint64_t label, std::atomic<uint64_t> *timestamp,
Delta(AddLabelTag, LabelId label, std::atomic<uint64_t> *timestamp,
uint64_t command_id)
: action(Action::ADD_LABEL),
timestamp(timestamp),
command_id(command_id),
label(label) {}
Delta(RemoveLabelTag, uint64_t label, std::atomic<uint64_t> *timestamp,
Delta(RemoveLabelTag, LabelId label, std::atomic<uint64_t> *timestamp,
uint64_t command_id)
: action(Action::REMOVE_LABEL),
timestamp(timestamp),
command_id(command_id),
label(label) {}
Delta(SetPropertyTag, uint64_t key, const PropertyValue &value,
Delta(SetPropertyTag, PropertyId key, const PropertyValue &value,
std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::SET_PROPERTY),
timestamp(timestamp),
command_id(command_id),
property({key, value}) {}
Delta(AddInEdgeTag, uint64_t edge_type, Vertex *vertex, Edge *edge,
Delta(AddInEdgeTag, EdgeTypeId edge_type, Vertex *vertex, Edge *edge,
std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::ADD_IN_EDGE),
timestamp(timestamp),
command_id(command_id),
vertex_edge({edge_type, vertex, edge}) {}
Delta(AddOutEdgeTag, uint64_t edge_type, Vertex *vertex, Edge *edge,
Delta(AddOutEdgeTag, EdgeTypeId edge_type, Vertex *vertex, Edge *edge,
std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::ADD_OUT_EDGE),
timestamp(timestamp),
command_id(command_id),
vertex_edge({edge_type, vertex, edge}) {}
Delta(RemoveInEdgeTag, uint64_t edge_type, Vertex *vertex, Edge *edge,
Delta(RemoveInEdgeTag, EdgeTypeId edge_type, Vertex *vertex, Edge *edge,
std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::REMOVE_IN_EDGE),
timestamp(timestamp),
command_id(command_id),
vertex_edge({edge_type, vertex, edge}) {}
Delta(RemoveOutEdgeTag, uint64_t edge_type, Vertex *vertex, Edge *edge,
Delta(RemoveOutEdgeTag, EdgeTypeId edge_type, Vertex *vertex, Edge *edge,
std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::REMOVE_OUT_EDGE),
timestamp(timestamp),
@ -223,13 +224,13 @@ struct Delta {
std::atomic<Delta *> next{nullptr};
union {
uint64_t label;
LabelId label;
struct {
uint64_t key;
PropertyId key;
storage::PropertyValue value;
} property;
struct {
uint64_t edge_type;
EdgeTypeId edge_type;
Vertex *vertex;
Edge *edge;
} vertex_edge;

View File

@ -6,7 +6,7 @@
#include "utils/spin_lock.hpp"
#include "storage/v2/delta.hpp"
#include "storage/v2/gid.hpp"
#include "storage/v2/id_types.hpp"
namespace storage {
@ -20,7 +20,7 @@ struct Edge {
Gid gid;
std::map<uint64_t, storage::PropertyValue> properties;
std::map<PropertyId, storage::PropertyValue> properties;
utils::SpinLock lock;
bool deleted;

View File

@ -15,7 +15,7 @@ VertexAccessor EdgeAccessor::ToVertex() {
return VertexAccessor{to_vertex_, transaction_};
}
Result<bool> EdgeAccessor::SetProperty(uint64_t property,
Result<bool> EdgeAccessor::SetProperty(PropertyId property,
const PropertyValue &value) {
std::lock_guard<utils::SpinLock> guard(edge_->lock);
@ -47,7 +47,8 @@ Result<bool> EdgeAccessor::SetProperty(uint64_t property,
return Result<bool>{existed};
}
Result<PropertyValue> EdgeAccessor::GetProperty(uint64_t property, View view) {
Result<PropertyValue> EdgeAccessor::GetProperty(PropertyId property,
View view) {
bool deleted = false;
PropertyValue value;
Delta *delta = nullptr;
@ -90,8 +91,9 @@ Result<PropertyValue> EdgeAccessor::GetProperty(uint64_t property, View view) {
return Result<PropertyValue>{std::move(value)};
}
Result<std::map<uint64_t, PropertyValue>> EdgeAccessor::Properties(View view) {
std::map<uint64_t, PropertyValue> properties;
Result<std::map<PropertyId, PropertyValue>> EdgeAccessor::Properties(
View view) {
std::map<PropertyId, PropertyValue> properties;
bool deleted = false;
Delta *delta = nullptr;
{
@ -136,9 +138,9 @@ Result<std::map<uint64_t, PropertyValue>> EdgeAccessor::Properties(View view) {
}
});
if (deleted) {
return Result<std::map<uint64_t, PropertyValue>>{Error::DELETED_OBJECT};
return Result<std::map<PropertyId, PropertyValue>>{Error::DELETED_OBJECT};
}
return Result<std::map<uint64_t, PropertyValue>>{std::move(properties)};
return Result<std::map<PropertyId, PropertyValue>>{std::move(properties)};
}
} // namespace storage

View File

@ -19,7 +19,7 @@ class EdgeAccessor final {
friend class Storage;
public:
EdgeAccessor(Edge *edge, uint64_t edge_type, Vertex *from_vertex,
EdgeAccessor(Edge *edge, EdgeTypeId edge_type, Vertex *from_vertex,
Vertex *to_vertex, Transaction *transaction)
: edge_(edge),
edge_type_(edge_type),
@ -31,13 +31,13 @@ class EdgeAccessor final {
VertexAccessor ToVertex();
uint64_t EdgeType() const { return edge_type_; }
EdgeTypeId EdgeType() const { return edge_type_; }
Result<bool> SetProperty(uint64_t property, const PropertyValue &value);
Result<bool> SetProperty(PropertyId property, const PropertyValue &value);
Result<PropertyValue> GetProperty(uint64_t property, View view);
Result<PropertyValue> GetProperty(PropertyId property, View view);
Result<std::map<uint64_t, PropertyValue>> Properties(View view);
Result<std::map<PropertyId, PropertyValue>> Properties(View view);
Gid Gid() const { return edge_->gid; }
@ -48,7 +48,7 @@ class EdgeAccessor final {
private:
Edge *edge_;
uint64_t edge_type_;
EdgeTypeId edge_type_;
Vertex *from_vertex_;
Vertex *to_vertex_;
Transaction *transaction_;

View File

@ -1,45 +0,0 @@
#pragma once
#include "utils/cast.hpp"
namespace storage {
class Gid final {
private:
explicit Gid(uint64_t gid) : gid_(gid) {}
public:
static Gid FromUint(uint64_t gid) { return Gid{gid}; }
static Gid FromInt(int64_t gid) {
return Gid{utils::MemcpyCast<uint64_t>(gid)};
}
uint64_t AsUint() const { return gid_; }
int64_t AsInt() const { return utils::MemcpyCast<int64_t>(gid_); }
private:
uint64_t gid_;
};
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();
}
} // namespace storage

View File

@ -0,0 +1,53 @@
#pragma once
#include <type_traits>
#include "utils/cast.hpp"
namespace storage {
#define STORAGE_DEFINE_ID_TYPE(name) \
class name final { \
private: \
explicit name(uint64_t id) : id_(id) {} \
\
public: \
static name FromUint(uint64_t id) { return name{id}; } \
static name FromInt(int64_t id) { \
return name{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_; \
}; \
static_assert(std::is_trivially_copyable<name>::value, \
"storage::" #name " must be trivially copyable!"); \
inline bool operator==(const name &first, const name &second) { \
return first.AsUint() == second.AsUint(); \
} \
inline bool operator!=(const name &first, const name &second) { \
return first.AsUint() != second.AsUint(); \
} \
inline bool operator<(const name &first, const name &second) { \
return first.AsUint() < second.AsUint(); \
} \
inline bool operator>(const name &first, const name &second) { \
return first.AsUint() > second.AsUint(); \
} \
inline bool operator<=(const name &first, const name &second) { \
return first.AsUint() <= second.AsUint(); \
} \
inline bool operator>=(const name &first, const name &second) { \
return first.AsUint() >= second.AsUint(); \
}
STORAGE_DEFINE_ID_TYPE(Gid);
STORAGE_DEFINE_ID_TYPE(LabelId);
STORAGE_DEFINE_ID_TYPE(PropertyId);
STORAGE_DEFINE_ID_TYPE(EdgeTypeId);
#undef STORAGE_DEFINE_ID_TYPE
} // namespace storage

View File

@ -91,8 +91,8 @@ Result<bool> Storage::Accessor::DetachDeleteVertex(VertexAccessor *vertex) {
"accessor when deleting a vertex!";
auto vertex_ptr = vertex->vertex_;
std::vector<std::tuple<uint64_t, Vertex *, Edge *>> in_edges;
std::vector<std::tuple<uint64_t, Vertex *, Edge *>> out_edges;
std::vector<std::tuple<EdgeTypeId, Vertex *, Edge *>> in_edges;
std::vector<std::tuple<EdgeTypeId, Vertex *, Edge *>> out_edges;
{
std::lock_guard<utils::SpinLock> guard(vertex_ptr->lock);
@ -146,7 +146,7 @@ Result<bool> Storage::Accessor::DetachDeleteVertex(VertexAccessor *vertex) {
Result<EdgeAccessor> Storage::Accessor::CreateEdge(VertexAccessor *from,
VertexAccessor *to,
uint64_t edge_type) {
EdgeTypeId edge_type) {
CHECK(from->transaction_ == to->transaction_)
<< "VertexAccessors must be from the same transaction when creating "
"an edge!";
@ -251,7 +251,8 @@ Result<bool> Storage::Accessor::DeleteEdge(EdgeAccessor *edge) {
CreateAndLinkDelta(&transaction_, from_vertex, Delta::AddOutEdgeTag(),
edge_type, to_vertex, edge_ptr);
{
std::tuple<uint64_t, Vertex *, Edge *> link{edge_type, to_vertex, edge_ptr};
std::tuple<EdgeTypeId, Vertex *, Edge *> link{edge_type, to_vertex,
edge_ptr};
auto it = std::find(from_vertex->out_edges.begin(),
from_vertex->out_edges.end(), link);
CHECK(it != from_vertex->out_edges.end()) << "Invalid database state!";
@ -262,8 +263,8 @@ Result<bool> Storage::Accessor::DeleteEdge(EdgeAccessor *edge) {
CreateAndLinkDelta(&transaction_, to_vertex, Delta::AddInEdgeTag(), edge_type,
from_vertex, edge_ptr);
{
std::tuple<uint64_t, Vertex *, Edge *> link{edge_type, from_vertex,
edge_ptr};
std::tuple<EdgeTypeId, Vertex *, Edge *> link{edge_type, from_vertex,
edge_ptr};
auto it =
std::find(to_vertex->in_edges.begin(), to_vertex->in_edges.end(), link);
CHECK(it != to_vertex->in_edges.end()) << "Invalid database state!";
@ -274,24 +275,24 @@ Result<bool> Storage::Accessor::DeleteEdge(EdgeAccessor *edge) {
return Result<bool>{true};
}
const std::string &Storage::Accessor::LabelToName(uint64_t label) {
return storage_->name_id_mapper_.IdToName(label);
const std::string &Storage::Accessor::LabelToName(LabelId label) {
return storage_->name_id_mapper_.IdToName(label.AsUint());
}
const std::string &Storage::Accessor::PropertyToName(uint64_t property) {
return storage_->name_id_mapper_.IdToName(property);
const std::string &Storage::Accessor::PropertyToName(PropertyId property) {
return storage_->name_id_mapper_.IdToName(property.AsUint());
}
const std::string &Storage::Accessor::EdgeTypeToName(uint64_t edge_type) {
return storage_->name_id_mapper_.IdToName(edge_type);
const std::string &Storage::Accessor::EdgeTypeToName(EdgeTypeId edge_type) {
return storage_->name_id_mapper_.IdToName(edge_type.AsUint());
}
uint64_t Storage::Accessor::NameToLabel(const std::string &name) {
return storage_->name_id_mapper_.NameToId(name);
LabelId Storage::Accessor::NameToLabel(const std::string &name) {
return LabelId::FromUint(storage_->name_id_mapper_.NameToId(name));
}
uint64_t Storage::Accessor::NameToProperty(const std::string &name) {
return storage_->name_id_mapper_.NameToId(name);
PropertyId Storage::Accessor::NameToProperty(const std::string &name) {
return PropertyId::FromUint(storage_->name_id_mapper_.NameToId(name));
}
uint64_t Storage::Accessor::NameToEdgeType(const std::string &name) {
return storage_->name_id_mapper_.NameToId(name);
EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string &name) {
return EdgeTypeId::FromUint(storage_->name_id_mapper_.NameToId(name));
}
void Storage::Accessor::AdvanceCommand() { ++transaction_.command_id; }
@ -392,7 +393,7 @@ void Storage::Accessor::Abort() {
break;
}
case Delta::Action::ADD_IN_EDGE: {
std::tuple<uint64_t, Vertex *, Edge *> link{
std::tuple<EdgeTypeId, Vertex *, Edge *> link{
current->vertex_edge.edge_type, current->vertex_edge.vertex,
current->vertex_edge.edge};
auto it = std::find(vertex->in_edges.begin(),
@ -402,7 +403,7 @@ void Storage::Accessor::Abort() {
break;
}
case Delta::Action::ADD_OUT_EDGE: {
std::tuple<uint64_t, Vertex *, Edge *> link{
std::tuple<EdgeTypeId, Vertex *, Edge *> link{
current->vertex_edge.edge_type, current->vertex_edge.vertex,
current->vertex_edge.edge};
auto it = std::find(vertex->out_edges.begin(),
@ -412,7 +413,7 @@ void Storage::Accessor::Abort() {
break;
}
case Delta::Action::REMOVE_IN_EDGE: {
std::tuple<uint64_t, Vertex *, Edge *> link{
std::tuple<EdgeTypeId, Vertex *, Edge *> link{
current->vertex_edge.edge_type, current->vertex_edge.vertex,
current->vertex_edge.edge};
auto it = std::find(vertex->in_edges.begin(),
@ -423,7 +424,7 @@ void Storage::Accessor::Abort() {
break;
}
case Delta::Action::REMOVE_OUT_EDGE: {
std::tuple<uint64_t, Vertex *, Edge *> link{
std::tuple<EdgeTypeId, Vertex *, Edge *> link{
current->vertex_edge.edge_type, current->vertex_edge.vertex,
current->vertex_edge.edge};
auto it = std::find(vertex->out_edges.begin(),

View File

@ -76,17 +76,17 @@ class Storage final {
Result<bool> DetachDeleteVertex(VertexAccessor *vertex);
Result<EdgeAccessor> CreateEdge(VertexAccessor *from, VertexAccessor *to,
uint64_t edge_type);
EdgeTypeId edge_type);
Result<bool> DeleteEdge(EdgeAccessor *edge);
const std::string &LabelToName(uint64_t label);
const std::string &PropertyToName(uint64_t property);
const std::string &EdgeTypeToName(uint64_t edge_type);
const std::string &LabelToName(LabelId label);
const std::string &PropertyToName(PropertyId property);
const std::string &EdgeTypeToName(EdgeTypeId edge_type);
uint64_t NameToLabel(const std::string &name);
uint64_t NameToProperty(const std::string &name);
uint64_t NameToEdgeType(const std::string &name);
LabelId NameToLabel(const std::string &name);
PropertyId NameToProperty(const std::string &name);
EdgeTypeId NameToEdgeType(const std::string &name);
void AdvanceCommand();

View File

@ -9,7 +9,7 @@
#include "storage/v2/delta.hpp"
#include "storage/v2/edge.hpp"
#include "storage/v2/gid.hpp"
#include "storage/v2/id_types.hpp"
namespace storage {
@ -21,11 +21,11 @@ struct Vertex {
Gid gid;
std::vector<uint64_t> labels;
std::map<uint64_t, storage::PropertyValue> properties;
std::vector<LabelId> labels;
std::map<PropertyId, storage::PropertyValue> properties;
std::vector<std::tuple<uint64_t, Vertex *, Edge *>> in_edges;
std::vector<std::tuple<uint64_t, Vertex *, Edge *>> out_edges;
std::vector<std::tuple<EdgeTypeId, Vertex *, Edge *>> in_edges;
std::vector<std::tuple<EdgeTypeId, Vertex *, Edge *>> out_edges;
utils::SpinLock lock;
bool deleted;

View File

@ -42,7 +42,7 @@ std::optional<VertexAccessor> VertexAccessor::Create(Vertex *vertex,
return VertexAccessor{vertex, transaction};
}
Result<bool> VertexAccessor::AddLabel(uint64_t label) {
Result<bool> VertexAccessor::AddLabel(LabelId label) {
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
if (!PrepareForWrite(transaction_, vertex_))
@ -60,7 +60,7 @@ Result<bool> VertexAccessor::AddLabel(uint64_t label) {
return Result<bool>{true};
}
Result<bool> VertexAccessor::RemoveLabel(uint64_t label) {
Result<bool> VertexAccessor::RemoveLabel(LabelId label) {
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
if (!PrepareForWrite(transaction_, vertex_))
@ -78,7 +78,7 @@ Result<bool> VertexAccessor::RemoveLabel(uint64_t label) {
return Result<bool>{true};
}
Result<bool> VertexAccessor::HasLabel(uint64_t label, View view) {
Result<bool> VertexAccessor::HasLabel(LabelId label, View view) {
bool deleted = false;
bool has_label = false;
Delta *delta = nullptr;
@ -126,9 +126,9 @@ Result<bool> VertexAccessor::HasLabel(uint64_t label, View view) {
return Result<bool>{has_label};
}
Result<std::vector<uint64_t>> VertexAccessor::Labels(View view) {
Result<std::vector<LabelId>> VertexAccessor::Labels(View view) {
bool deleted = false;
std::vector<uint64_t> labels;
std::vector<LabelId> labels;
Delta *delta = nullptr;
{
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
@ -170,11 +170,11 @@ Result<std::vector<uint64_t>> VertexAccessor::Labels(View view) {
break;
}
});
if (deleted) return Result<std::vector<uint64_t>>{Error::DELETED_OBJECT};
return Result<std::vector<uint64_t>>{std::move(labels)};
if (deleted) return Result<std::vector<LabelId>>{Error::DELETED_OBJECT};
return Result<std::vector<LabelId>>{std::move(labels)};
}
Result<bool> VertexAccessor::SetProperty(uint64_t property,
Result<bool> VertexAccessor::SetProperty(PropertyId property,
const PropertyValue &value) {
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
@ -206,7 +206,7 @@ Result<bool> VertexAccessor::SetProperty(uint64_t property,
return Result<bool>{existed};
}
Result<PropertyValue> VertexAccessor::GetProperty(uint64_t property,
Result<PropertyValue> VertexAccessor::GetProperty(PropertyId property,
View view) {
bool deleted = false;
PropertyValue value;
@ -250,9 +250,9 @@ Result<PropertyValue> VertexAccessor::GetProperty(uint64_t property,
return Result<PropertyValue>{std::move(value)};
}
Result<std::map<uint64_t, PropertyValue>> VertexAccessor::Properties(
Result<std::map<PropertyId, PropertyValue>> VertexAccessor::Properties(
View view) {
std::map<uint64_t, PropertyValue> properties;
std::map<PropertyId, PropertyValue> properties;
bool deleted = false;
Delta *delta = nullptr;
{
@ -297,14 +297,14 @@ Result<std::map<uint64_t, PropertyValue>> VertexAccessor::Properties(
}
});
if (deleted) {
return Result<std::map<uint64_t, PropertyValue>>{Error::DELETED_OBJECT};
return Result<std::map<PropertyId, PropertyValue>>{Error::DELETED_OBJECT};
}
return Result<std::map<uint64_t, PropertyValue>>{std::move(properties)};
return Result<std::map<PropertyId, PropertyValue>>{std::move(properties)};
}
Result<std::vector<EdgeAccessor>>
VertexAccessor::InEdges(const std::vector<uint64_t> &edge_types, View view) {
std::vector<std::tuple<uint64_t, Vertex *, Edge *>> in_edges;
Result<std::vector<EdgeAccessor>> VertexAccessor::InEdges(
const std::vector<EdgeTypeId> &edge_types, View view) {
std::vector<std::tuple<EdgeTypeId, Vertex *, Edge *>> in_edges;
bool deleted = false;
Delta *delta = nullptr;
{
@ -318,7 +318,7 @@ VertexAccessor::InEdges(const std::vector<uint64_t> &edge_types, View view) {
switch (delta.action) {
case Delta::Action::ADD_IN_EDGE: {
// Add the edge because we don't see the removal.
std::tuple<uint64_t, Vertex *, Edge *> link{
std::tuple<EdgeTypeId, Vertex *, Edge *> link{
delta.vertex_edge.edge_type, delta.vertex_edge.vertex,
delta.vertex_edge.edge};
auto it = std::find(in_edges.begin(), in_edges.end(), link);
@ -328,7 +328,7 @@ VertexAccessor::InEdges(const std::vector<uint64_t> &edge_types, View view) {
}
case Delta::Action::REMOVE_IN_EDGE: {
// Remove the label because we don't see the addition.
std::tuple<uint64_t, Vertex *, Edge *> link{
std::tuple<EdgeTypeId, Vertex *, Edge *> link{
delta.vertex_edge.edge_type, delta.vertex_edge.vertex,
delta.vertex_edge.edge};
auto it = std::find(in_edges.begin(), in_edges.end(), link);
@ -368,9 +368,9 @@ VertexAccessor::InEdges(const std::vector<uint64_t> &edge_types, View view) {
return Result<decltype(ret)>(std::move(ret));
}
Result<std::vector<EdgeAccessor>>
VertexAccessor::OutEdges(const std::vector<uint64_t> &edge_types, View view) {
std::vector<std::tuple<uint64_t, Vertex *, Edge *>> out_edges;
Result<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(
const std::vector<EdgeTypeId> &edge_types, View view) {
std::vector<std::tuple<EdgeTypeId, Vertex *, Edge *>> out_edges;
bool deleted = false;
Delta *delta = nullptr;
{
@ -384,7 +384,7 @@ VertexAccessor::OutEdges(const std::vector<uint64_t> &edge_types, View view) {
switch (delta.action) {
case Delta::Action::ADD_OUT_EDGE: {
// Add the edge because we don't see the removal.
std::tuple<uint64_t, Vertex *, Edge *> link{
std::tuple<EdgeTypeId, Vertex *, Edge *> link{
delta.vertex_edge.edge_type, delta.vertex_edge.vertex,
delta.vertex_edge.edge};
auto it = std::find(out_edges.begin(), out_edges.end(), link);
@ -394,7 +394,7 @@ VertexAccessor::OutEdges(const std::vector<uint64_t> &edge_types, View view) {
}
case Delta::Action::REMOVE_OUT_EDGE: {
// Remove the label because we don't see the addition.
std::tuple<uint64_t, Vertex *, Edge *> link{
std::tuple<EdgeTypeId, Vertex *, Edge *> link{
delta.vertex_edge.edge_type, delta.vertex_edge.vertex,
delta.vertex_edge.edge};
auto it = std::find(out_edges.begin(), out_edges.end(), link);

View File

@ -25,25 +25,25 @@ class VertexAccessor final {
Transaction *transaction,
View view);
Result<bool> AddLabel(uint64_t label);
Result<bool> AddLabel(LabelId label);
Result<bool> RemoveLabel(uint64_t label);
Result<bool> RemoveLabel(LabelId label);
Result<bool> HasLabel(uint64_t label, View view);
Result<bool> HasLabel(LabelId label, View view);
Result<std::vector<uint64_t>> Labels(View view);
Result<std::vector<LabelId>> Labels(View view);
Result<bool> SetProperty(uint64_t property, const PropertyValue &value);
Result<bool> SetProperty(PropertyId property, const PropertyValue &value);
Result<PropertyValue> GetProperty(uint64_t property, View view);
Result<PropertyValue> GetProperty(PropertyId property, View view);
Result<std::map<uint64_t, PropertyValue>> Properties(View view);
Result<std::map<PropertyId, PropertyValue>> Properties(View view);
Result<std::vector<EdgeAccessor>>
InEdges(const std::vector<uint64_t> &edge_types, View view);
Result<std::vector<EdgeAccessor>> InEdges(
const std::vector<EdgeTypeId> &edge_types, View view);
Result<std::vector<EdgeAccessor>>
OutEdges(const std::vector<uint64_t> &edge_types, View view);
Result<std::vector<EdgeAccessor>> OutEdges(
const std::vector<EdgeTypeId> &edge_types, View view);
Gid Gid() const { return vertex_->gid; }

View File

@ -44,7 +44,8 @@ void UpdateLabelFunc(int thread_id, storage::Storage *storage,
acc.FindVertex(gid, storage::View::OLD);
CHECK(vertex.has_value())
<< "Vertex with GID " << gid.AsUint() << " doesn't exist";
if (vertex->AddLabel(label_dist(gen)).HasValue()) {
if (vertex->AddLabel(storage::LabelId::FromUint(label_dist(gen)))
.HasValue()) {
acc.Commit();
} else {
acc.Abort();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -57,9 +57,12 @@ TEST(StorageV2Gc, Sanity) {
EXPECT_EQ(vertex.has_value(), i % 5 != 0);
if (vertex.has_value()) {
EXPECT_FALSE(vertex->AddLabel(3 * i).HasError());
EXPECT_FALSE(vertex->AddLabel(3 * i + 1).HasError());
EXPECT_FALSE(vertex->AddLabel(3 * i + 2).HasError());
EXPECT_FALSE(
vertex->AddLabel(storage::LabelId::FromUint(3 * i)).HasError());
EXPECT_FALSE(
vertex->AddLabel(storage::LabelId::FromUint(3 * i + 1)).HasError());
EXPECT_FALSE(
vertex->AddLabel(storage::LabelId::FromUint(3 * i + 2)).HasError());
}
}
@ -78,8 +81,11 @@ TEST(StorageV2Gc, Sanity) {
auto labels_new = vertex->Labels(storage::View::NEW);
EXPECT_TRUE(labels_new.HasValue());
EXPECT_THAT(labels_new.GetValue(),
UnorderedElementsAre(3 * i, 3 * i + 1, 3 * i + 2));
EXPECT_THAT(
labels_new.GetValue(),
UnorderedElementsAre(storage::LabelId::FromUint(3 * i),
storage::LabelId::FromUint(3 * i + 1),
storage::LabelId::FromUint(3 * i + 2)));
}
}
@ -97,7 +103,8 @@ TEST(StorageV2Gc, Sanity) {
EXPECT_EQ(to_vertex.has_value(), (i + 1) % 5 != 0);
if (from_vertex.has_value() && to_vertex.has_value()) {
EXPECT_FALSE(acc.CreateEdge(&from_vertex.value(), &to_vertex.value(), i)
EXPECT_FALSE(acc.CreateEdge(&from_vertex.value(), &to_vertex.value(),
storage::EdgeTypeId::FromUint(i))
.HasError());
}
}
@ -121,20 +128,19 @@ TEST(StorageV2Gc, Sanity) {
auto vertex = acc.FindVertex(vertices[i], storage::View::NEW);
EXPECT_EQ(vertex.has_value(), i % 5 != 0 && i % 3 != 0);
if (vertex.has_value()) {
auto out_edges =
vertex->OutEdges(std::vector<uint64_t>{}, storage::View::NEW);
auto out_edges = vertex->OutEdges({}, storage::View::NEW);
if (i % 5 != 4 && i % 3 != 2) {
EXPECT_EQ(out_edges.GetValue().size(), 1);
EXPECT_EQ(out_edges.GetValue().at(0).EdgeType(), i);
EXPECT_EQ(out_edges.GetValue().at(0).EdgeType().AsUint(), i);
} else {
EXPECT_TRUE(out_edges->empty());
}
auto in_edges =
vertex->InEdges(std::vector<uint64_t>{}, storage::View::NEW);
auto in_edges = vertex->InEdges({}, storage::View::NEW);
if (i % 5 != 1 && i % 3 != 1) {
EXPECT_EQ(in_edges.GetValue().size(), 1);
EXPECT_EQ(in_edges.GetValue().at(0).EdgeType(), (i + 999) % 1000);
EXPECT_EQ(in_edges.GetValue().at(0).EdgeType().AsUint(),
(i + 999) % 1000);
} else {
EXPECT_TRUE(in_edges->empty());
}