From 6f652fff42f0d1986bce739ae2c141f92c16da7e Mon Sep 17 00:00:00 2001 From: Andi Skrgat Date: Wed, 17 May 2023 10:59:13 +0200 Subject: [PATCH] NameIDMapper refactored --- src/storage/v2/disk/storage.cpp | 54 ----------------------------- src/storage/v2/disk/storage.hpp | 26 -------------- src/storage/v2/inmemory/storage.cpp | 48 ------------------------- src/storage/v2/inmemory/storage.hpp | 26 -------------- src/storage/v2/storage.cpp | 42 ++++++++++++++++++++++ src/storage/v2/storage.hpp | 24 ++++++------- 6 files changed, 54 insertions(+), 166 deletions(-) diff --git a/src/storage/v2/disk/storage.cpp b/src/storage/v2/disk/storage.cpp index 13002fdf4..f33789bc7 100644 --- a/src/storage/v2/disk/storage.cpp +++ b/src/storage/v2/disk/storage.cpp @@ -876,32 +876,6 @@ Result> DiskStorage::DiskAccessor::DeleteEdge(EdgeAc &disk_storage->indices_, &disk_storage->constraints_, config_, true); } -// this should be handled on an above level of abstraction -const std::string &DiskStorage::DiskAccessor::LabelToName(LabelId label) const { return storage_->LabelToName(label); } - -// this should be handled on an above level of abstraction -const std::string &DiskStorage::DiskAccessor::PropertyToName(PropertyId property) const { - return storage_->PropertyToName(property); -} - -// this should be handled on an above level of abstraction -const std::string &DiskStorage::DiskAccessor::EdgeTypeToName(EdgeTypeId edge_type) const { - return storage_->EdgeTypeToName(edge_type); -} - -// this should be handled on an above level of abstraction -LabelId DiskStorage::DiskAccessor::NameToLabel(const std::string_view name) { return storage_->NameToLabel(name); } - -// this should be handled on an above level of abstraction -PropertyId DiskStorage::DiskAccessor::NameToProperty(const std::string_view name) { - return storage_->NameToProperty(name); -} - -// this should be handled on an above level of abstraction -EdgeTypeId DiskStorage::DiskAccessor::NameToEdgeType(const std::string_view name) { - return storage_->NameToEdgeType(name); -} - // this should be handled on an above level of abstraction void DiskStorage::DiskAccessor::AdvanceCommand() { ++transaction_.command_id; } @@ -1269,34 +1243,6 @@ std::optional DiskStorage::DiskAccessor::GetTransactionId() const { return {}; } -// this should be handled on an above level of abstraction -const std::string &DiskStorage::LabelToName(LabelId label) const { return name_id_mapper_.IdToName(label.AsUint()); } - -// this should be handled on an above level of abstraction -const std::string &DiskStorage::PropertyToName(PropertyId property) const { - return name_id_mapper_.IdToName(property.AsUint()); -} - -// this should be handled on an above level of abstraction -const std::string &DiskStorage::EdgeTypeToName(EdgeTypeId edge_type) const { - return name_id_mapper_.IdToName(edge_type.AsUint()); -} - -// this should be handled on an above level of abstraction -LabelId DiskStorage::NameToLabel(const std::string_view name) { - return LabelId::FromUint(name_id_mapper_.NameToId(name)); -} - -// this should be handled on an above level of abstraction -PropertyId DiskStorage::NameToProperty(const std::string_view name) { - return PropertyId::FromUint(name_id_mapper_.NameToId(name)); -} - -// this should be handled on an above level of abstraction -EdgeTypeId DiskStorage::NameToEdgeType(const std::string_view name) { - return EdgeTypeId::FromUint(name_id_mapper_.NameToId(name)); -} - utils::BasicResult DiskStorage::CreateIndex( LabelId label, const std::optional desired_commit_timestamp) { /// TODO: (andi): Here we will probably use some lock to protect reading from and writing to the RocksDB at the diff --git a/src/storage/v2/disk/storage.hpp b/src/storage/v2/disk/storage.hpp index 9af2dea2d..ae3d3ab85 100644 --- a/src/storage/v2/disk/storage.hpp +++ b/src/storage/v2/disk/storage.hpp @@ -168,19 +168,6 @@ class DiskStorage final : public Storage { Result> DeleteEdge(EdgeAccessor *edge) override; - const std::string &LabelToName(LabelId label) const override; - const std::string &PropertyToName(PropertyId property) const override; - const std::string &EdgeTypeToName(EdgeTypeId edge_type) const override; - - /// @throw std::bad_alloc if unable to insert a new mapping - LabelId NameToLabel(std::string_view name) override; - - /// @throw std::bad_alloc if unable to insert a new mapping - PropertyId NameToProperty(std::string_view name) override; - - /// @throw std::bad_alloc if unable to insert a new mapping - EdgeTypeId NameToEdgeType(std::string_view name) override; - bool LabelIndexExists(LabelId label) const override { throw utils::NotYetImplemented("LabelIndexExists()"); } bool LabelPropertyIndexExists(LabelId label, PropertyId property) const override { @@ -254,19 +241,6 @@ class DiskStorage final : public Storage { new DiskAccessor{this, override_isolation_level.value_or(isolation_level_), storage_mode_}); } - const std::string &LabelToName(LabelId label) const override; - const std::string &PropertyToName(PropertyId property) const override; - const std::string &EdgeTypeToName(EdgeTypeId edge_type) const override; - - /// @throw std::bad_alloc if unable to insert a new mapping - LabelId NameToLabel(std::string_view name) override; - - /// @throw std::bad_alloc if unable to insert a new mapping - PropertyId NameToProperty(std::string_view name) override; - - /// @throw std::bad_alloc if unable to insert a new mapping - EdgeTypeId NameToEdgeType(std::string_view name) override; - /// Create an index. /// Returns void if the index has been created. /// Returns `StorageIndexDefinitionError` if an error occures. Error can be: diff --git a/src/storage/v2/inmemory/storage.cpp b/src/storage/v2/inmemory/storage.cpp index 4e7d0da73..6de8d9bd3 100644 --- a/src/storage/v2/inmemory/storage.cpp +++ b/src/storage/v2/inmemory/storage.cpp @@ -603,30 +603,6 @@ Result> InMemoryStorage::InMemoryAccessor::DeleteEdg &mem_storage->indices_, &mem_storage->constraints_, config_, true); } -const std::string &InMemoryStorage::InMemoryAccessor::LabelToName(LabelId label) const { - return storage_->LabelToName(label); -} - -const std::string &InMemoryStorage::InMemoryAccessor::PropertyToName(PropertyId property) const { - return storage_->PropertyToName(property); -} - -const std::string &InMemoryStorage::InMemoryAccessor::EdgeTypeToName(EdgeTypeId edge_type) const { - return storage_->EdgeTypeToName(edge_type); -} - -LabelId InMemoryStorage::InMemoryAccessor::NameToLabel(const std::string_view name) { - return storage_->NameToLabel(name); -} - -PropertyId InMemoryStorage::InMemoryAccessor::NameToProperty(const std::string_view name) { - return storage_->NameToProperty(name); -} - -EdgeTypeId InMemoryStorage::InMemoryAccessor::NameToEdgeType(const std::string_view name) { - return storage_->NameToEdgeType(name); -} - void InMemoryStorage::InMemoryAccessor::AdvanceCommand() { ++transaction_.command_id; } utils::BasicResult InMemoryStorage::InMemoryAccessor::Commit( @@ -940,30 +916,6 @@ std::optional InMemoryStorage::InMemoryAccessor::GetTransactionId() co return {}; } -const std::string &InMemoryStorage::LabelToName(LabelId label) const { - return name_id_mapper_.IdToName(label.AsUint()); -} - -const std::string &InMemoryStorage::PropertyToName(PropertyId property) const { - return name_id_mapper_.IdToName(property.AsUint()); -} - -const std::string &InMemoryStorage::EdgeTypeToName(EdgeTypeId edge_type) const { - return name_id_mapper_.IdToName(edge_type.AsUint()); -} - -LabelId InMemoryStorage::NameToLabel(const std::string_view name) { - return LabelId::FromUint(name_id_mapper_.NameToId(name)); -} - -PropertyId InMemoryStorage::NameToProperty(const std::string_view name) { - return PropertyId::FromUint(name_id_mapper_.NameToId(name)); -} - -EdgeTypeId InMemoryStorage::NameToEdgeType(const std::string_view name) { - return EdgeTypeId::FromUint(name_id_mapper_.NameToId(name)); -} - utils::BasicResult InMemoryStorage::CreateIndex( LabelId label, const std::optional desired_commit_timestamp) { std::unique_lock storage_guard(main_lock_); diff --git a/src/storage/v2/inmemory/storage.hpp b/src/storage/v2/inmemory/storage.hpp index fda079754..ea7b0dbb9 100644 --- a/src/storage/v2/inmemory/storage.hpp +++ b/src/storage/v2/inmemory/storage.hpp @@ -189,19 +189,6 @@ class InMemoryStorage final : public Storage { /// @throw std::bad_alloc Result> DeleteEdge(EdgeAccessor *edge) override; - const std::string &LabelToName(LabelId label) const override; - const std::string &PropertyToName(PropertyId property) const override; - const std::string &EdgeTypeToName(EdgeTypeId edge_type) const override; - - /// @throw std::bad_alloc if unable to insert a new mapping - LabelId NameToLabel(std::string_view name) override; - - /// @throw std::bad_alloc if unable to insert a new mapping - PropertyId NameToProperty(std::string_view name) override; - - /// @throw std::bad_alloc if unable to insert a new mapping - EdgeTypeId NameToEdgeType(std::string_view name) override; - bool LabelIndexExists(LabelId label) const override { return static_cast(storage_)->indices_.label_index.IndexExists(label); } @@ -255,19 +242,6 @@ class InMemoryStorage final : public Storage { new InMemoryAccessor{this, override_isolation_level.value_or(isolation_level_), storage_mode_}); } - const std::string &LabelToName(LabelId label) const override; - const std::string &PropertyToName(PropertyId property) const override; - const std::string &EdgeTypeToName(EdgeTypeId edge_type) const override; - - /// @throw std::bad_alloc if unable to insert a new mapping - LabelId NameToLabel(std::string_view name) override; - - /// @throw std::bad_alloc if unable to insert a new mapping - PropertyId NameToProperty(std::string_view name) override; - - /// @throw std::bad_alloc if unable to insert a new mapping - EdgeTypeId NameToEdgeType(std::string_view name) override; - /// Create an index. /// Returns void if the index has been created. /// Returns `StorageIndexDefinitionError` if an error occures. Error can be: diff --git a/src/storage/v2/storage.cpp b/src/storage/v2/storage.cpp index 9dd3e01a4..9cc8fe09d 100644 --- a/src/storage/v2/storage.cpp +++ b/src/storage/v2/storage.cpp @@ -279,4 +279,46 @@ Storage::Accessor::Accessor(Accessor &&other) noexcept other.commit_timestamp_.reset(); } +// this should be handled on an above level of abstraction +const std::string &Storage::LabelToName(LabelId label) const { return name_id_mapper_.IdToName(label.AsUint()); } + +// this should be handled on an above level of abstraction +const std::string &Storage::PropertyToName(PropertyId property) const { + return name_id_mapper_.IdToName(property.AsUint()); +} + +// this should be handled on an above level of abstraction +const std::string &Storage::EdgeTypeToName(EdgeTypeId edge_type) const { + return name_id_mapper_.IdToName(edge_type.AsUint()); +} + +// this should be handled on an above level of abstraction +LabelId Storage::NameToLabel(const std::string_view name) { return LabelId::FromUint(name_id_mapper_.NameToId(name)); } + +// this should be handled on an above level of abstraction +PropertyId Storage::NameToProperty(const std::string_view name) { + return PropertyId::FromUint(name_id_mapper_.NameToId(name)); +} + +// this should be handled on an above level of abstraction +EdgeTypeId Storage::NameToEdgeType(const std::string_view name) { + return EdgeTypeId::FromUint(name_id_mapper_.NameToId(name)); +} + +const std::string &Storage::Accessor::LabelToName(LabelId label) const { return storage_->LabelToName(label); } + +const std::string &Storage::Accessor::PropertyToName(PropertyId property) const { + return storage_->PropertyToName(property); +} + +const std::string &Storage::Accessor::EdgeTypeToName(EdgeTypeId edge_type) const { + return storage_->EdgeTypeToName(edge_type); +} + +LabelId Storage::Accessor::NameToLabel(const std::string_view name) { return storage_->NameToLabel(name); } + +PropertyId Storage::Accessor::NameToProperty(const std::string_view name) { return storage_->NameToProperty(name); } + +EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string_view name) { return storage_->NameToEdgeType(name); } + } // namespace memgraph::storage diff --git a/src/storage/v2/storage.hpp b/src/storage/v2/storage.hpp index ad288ca81..c8756deb0 100644 --- a/src/storage/v2/storage.hpp +++ b/src/storage/v2/storage.hpp @@ -272,18 +272,18 @@ class Storage { /// @throw std::bad_alloc virtual Result> DeleteEdge(EdgeAccessor *edge) = 0; - virtual const std::string &LabelToName(LabelId label) const = 0; - virtual const std::string &PropertyToName(PropertyId property) const = 0; - virtual const std::string &EdgeTypeToName(EdgeTypeId edge_type) const = 0; + const std::string &LabelToName(LabelId label) const; + const std::string &PropertyToName(PropertyId property) const; + const std::string &EdgeTypeToName(EdgeTypeId edge_type) const; /// @throw std::bad_alloc if unable to insert a new mapping - virtual LabelId NameToLabel(std::string_view name) = 0; + LabelId NameToLabel(std::string_view name); /// @throw std::bad_alloc if unable to insert a new mapping - virtual PropertyId NameToProperty(std::string_view name) = 0; + PropertyId NameToProperty(std::string_view name); /// @throw std::bad_alloc if unable to insert a new mapping - virtual EdgeTypeId NameToEdgeType(std::string_view name) = 0; + EdgeTypeId NameToEdgeType(std::string_view name); virtual bool LabelIndexExists(LabelId label) const = 0; @@ -322,18 +322,18 @@ class Storage { virtual std::unique_ptr Access(std::optional override_isolation_level) = 0; std::unique_ptr Access() { return Access(std::optional{}); } - virtual const std::string &LabelToName(LabelId label) const = 0; - virtual const std::string &PropertyToName(PropertyId property) const = 0; - virtual const std::string &EdgeTypeToName(EdgeTypeId edge_type) const = 0; + const std::string &LabelToName(LabelId label) const; + const std::string &PropertyToName(PropertyId property) const; + const std::string &EdgeTypeToName(EdgeTypeId edge_type) const; /// @throw std::bad_alloc if unable to insert a new mapping - virtual LabelId NameToLabel(std::string_view name) = 0; + LabelId NameToLabel(std::string_view name); /// @throw std::bad_alloc if unable to insert a new mapping - virtual PropertyId NameToProperty(std::string_view name) = 0; + PropertyId NameToProperty(std::string_view name); /// @throw std::bad_alloc if unable to insert a new mapping - virtual EdgeTypeId NameToEdgeType(std::string_view name) = 0; + EdgeTypeId NameToEdgeType(std::string_view name); /// Create an index. /// Returns void if the index has been created.