From 134525851bbe551b55a50f3689eb2deb1f9fe2da Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Wed, 31 Jul 2019 14:43:45 +0200 Subject: [PATCH] Expose Id mappings from accessor-less Storage Reviewers: mtomic, mferencevic Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2285 --- src/storage/v2/name_id_mapper.hpp | 2 +- src/storage/v2/storage.cpp | 48 +++++++++++++++++++++++++------ src/storage/v2/storage.hpp | 14 +++++++-- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/storage/v2/name_id_mapper.hpp b/src/storage/v2/name_id_mapper.hpp index e447213ef..eb49bd200 100644 --- a/src/storage/v2/name_id_mapper.hpp +++ b/src/storage/v2/name_id_mapper.hpp @@ -65,7 +65,7 @@ class NameIdMapper final { // Currently, we never delete anything from the `utils::SkipList` so the // references will always be valid. If you change this class to remove unused // names, be sure to change the signature of this function. - const std::string &IdToName(uint64_t id) { + const std::string &IdToName(uint64_t id) const { auto id_to_name_acc = id_to_name_.access(); auto result = id_to_name_acc.find(id); CHECK(result != id_to_name_acc.end()) diff --git a/src/storage/v2/storage.cpp b/src/storage/v2/storage.cpp index 4196a0b2b..377ff1453 100644 --- a/src/storage/v2/storage.cpp +++ b/src/storage/v2/storage.cpp @@ -556,24 +556,30 @@ Result Storage::Accessor::DeleteEdge(EdgeAccessor *edge) { return Result{true}; } -const std::string &Storage::Accessor::LabelToName(LabelId label) { - return storage_->name_id_mapper_.IdToName(label.AsUint()); +const std::string &Storage::Accessor::LabelToName(LabelId label) const { + return storage_->LabelToName(label); } -const std::string &Storage::Accessor::PropertyToName(PropertyId property) { - return storage_->name_id_mapper_.IdToName(property.AsUint()); + +const std::string &Storage::Accessor::PropertyToName( + PropertyId property) const { + return storage_->PropertyToName(property); } -const std::string &Storage::Accessor::EdgeTypeToName(EdgeTypeId edge_type) { - return storage_->name_id_mapper_.IdToName(edge_type.AsUint()); + +const std::string &Storage::Accessor::EdgeTypeToName( + EdgeTypeId edge_type) const { + return storage_->EdgeTypeToName(edge_type); } LabelId Storage::Accessor::NameToLabel(const std::string &name) { - return LabelId::FromUint(storage_->name_id_mapper_.NameToId(name)); + return storage_->NameToLabel(name); } + PropertyId Storage::Accessor::NameToProperty(const std::string &name) { - return PropertyId::FromUint(storage_->name_id_mapper_.NameToId(name)); + return storage_->NameToProperty(name); } + EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string &name) { - return EdgeTypeId::FromUint(storage_->name_id_mapper_.NameToId(name)); + return storage_->NameToEdgeType(name); } void Storage::Accessor::AdvanceCommand() { ++transaction_.command_id; } @@ -832,6 +838,30 @@ Storage::Accessor Storage::Access() { return Accessor{this, transaction_id, start_timestamp}; } +const std::string &Storage::LabelToName(LabelId label) const { + return name_id_mapper_.IdToName(label.AsUint()); +} + +const std::string &Storage::PropertyToName(PropertyId property) const { + return name_id_mapper_.IdToName(property.AsUint()); +} + +const std::string &Storage::EdgeTypeToName(EdgeTypeId edge_type) const { + return name_id_mapper_.IdToName(edge_type.AsUint()); +} + +LabelId Storage::NameToLabel(const std::string &name) { + return LabelId::FromUint(name_id_mapper_.NameToId(name)); +} + +PropertyId Storage::NameToProperty(const std::string &name) { + return PropertyId::FromUint(name_id_mapper_.NameToId(name)); +} + +EdgeTypeId Storage::NameToEdgeType(const std::string &name) { + return EdgeTypeId::FromUint(name_id_mapper_.NameToId(name)); +} + VerticesIterable Storage::Accessor::Vertices(LabelId label, View view) { return VerticesIterable( storage_->indices_.label_index.Vertices(label, view, &transaction_)); diff --git a/src/storage/v2/storage.hpp b/src/storage/v2/storage.hpp index 063a98323..79b43518c 100644 --- a/src/storage/v2/storage.hpp +++ b/src/storage/v2/storage.hpp @@ -205,9 +205,9 @@ class Storage final { Result DeleteEdge(EdgeAccessor *edge); - const std::string &LabelToName(LabelId label); - const std::string &PropertyToName(PropertyId property); - const std::string &EdgeTypeToName(EdgeTypeId edge_type); + const std::string &LabelToName(LabelId label) const; + const std::string &PropertyToName(PropertyId property) const; + const std::string &EdgeTypeToName(EdgeTypeId edge_type) const; LabelId NameToLabel(const std::string &name); PropertyId NameToProperty(const std::string &name); @@ -230,6 +230,14 @@ class Storage final { Accessor Access(); + const std::string &LabelToName(LabelId label) const; + const std::string &PropertyToName(PropertyId property) const; + const std::string &EdgeTypeToName(EdgeTypeId edge_type) const; + + LabelId NameToLabel(const std::string &name); + PropertyId NameToProperty(const std::string &name); + EdgeTypeId NameToEdgeType(const std::string &name); + bool CreateIndex(LabelId label, PropertyId property) { std::unique_lock storage_guard(main_lock_); return indices_.label_property_index.CreateIndex(label, property,