Fix some compilation errors in query engine module

This commit is contained in:
Aidar Samerkhanov 2023-04-12 22:16:54 +00:00
parent faa3e542b6
commit 18bf1c237b
6 changed files with 130 additions and 103 deletions

View File

@ -35,6 +35,7 @@
// This cannot be avoided by simple include orderings so we
// simply undefine those macros as we're sure that libkrb5
// won't and can't be used anywhere in the query engine.
#include "storage/v2/edge_accessor.hpp"
#include "storage/v2/storage.hpp"
#undef FALSE
@ -83,9 +84,9 @@ class EdgeAccessor final {
return impl_->ClearProperties();
}
VertexAccessor To() const;
std::unique_ptr<VertexAccessor> To() const;
VertexAccessor From() const;
std::unique_ptr<VertexAccessor> From() const;
bool IsCycle() const;
@ -102,7 +103,9 @@ class VertexAccessor final {
public:
storage::VertexAccessor *impl_;
static EdgeAccessor MakeEdgeAccessor(const storage::EdgeAccessor impl) { return EdgeAccessor(impl); }
static std::unique_ptr<EdgeAccessor> MakeEdgeAccessor(const std::unique_ptr<storage::EdgeAccessor> &impl) {
return std::make_unique<EdgeAccessor>(std::move(impl));
}
public:
explicit VertexAccessor(storage::VertexAccessor *impl) : impl_(impl) {}
@ -168,7 +171,7 @@ class VertexAccessor final {
auto OutEdges(storage::View view, const std::vector<storage::EdgeTypeId> &edge_types,
const VertexAccessor &dest) const
-> storage::Result<decltype(iter::imap(MakeEdgeAccessor, *impl_.OutEdges(view)))> {
-> storage::Result<decltype(iter::imap(MakeEdgeAccessor, *impl_->OutEdges(view)))> {
auto maybe_edges = impl_->OutEdges(view, edge_types, dest.impl_);
if (maybe_edges.HasError()) return maybe_edges.GetError();
return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges));
@ -190,9 +193,13 @@ class VertexAccessor final {
bool operator!=(const VertexAccessor &v) const noexcept { return !(*this == v); }
};
inline VertexAccessor EdgeAccessor::To() const { return VertexAccessor(impl_->ToVertex()); }
inline std::unique_ptr<VertexAccessor> EdgeAccessor::To() const {
return std::make_unique<VertexAccessor>(impl_->ToVertex());
}
inline VertexAccessor EdgeAccessor::From() const { return VertexAccessor(impl_->FromVertex()); }
inline std::unique_ptr<VertexAccessor> EdgeAccessor::From() const {
return std::make_unique<VertexAccessor>(impl_->FromVertex());
}
inline bool EdgeAccessor::IsCycle() const { return To() == From(); }
@ -318,10 +325,10 @@ class DbAccessor final {
public:
explicit DbAccessor(storage::Storage::Accessor *accessor) : accessor_(accessor) {}
std::optional<VertexAccessor> FindVertex(storage::Gid gid, storage::View view) {
std::unique_ptr<VertexAccessor> FindVertex(storage::Gid gid, storage::View view) {
auto maybe_vertex = accessor_->FindVertex(gid, view);
if (maybe_vertex) return VertexAccessor(*maybe_vertex);
return std::nullopt;
if (maybe_vertex) return std::make_unique<VertexAccessor>(std::move(maybe_vertex));
return {};
}
void FinalizeTransaction() { accessor_->FinalizeTransaction(); }
@ -347,27 +354,27 @@ class DbAccessor final {
return VerticesIterable(accessor_->Vertices(label, property, lower, upper, view));
}
VertexAccessor InsertVertex() { return VertexAccessor(accessor_->CreateVertex()); }
std::unique_ptr<VertexAccessor> InsertVertex() { return std::make_unique<VertexAccessor>(accessor_->CreateVertex()); }
storage::Result<EdgeAccessor> InsertEdge(VertexAccessor *from, VertexAccessor *to,
const storage::EdgeTypeId &edge_type) {
auto maybe_edge = accessor_->CreateEdge(&from->impl_, &to->impl_, edge_type);
storage::Result<std::unique_ptr<EdgeAccessor>> InsertEdge(VertexAccessor *from, VertexAccessor *to,
const storage::EdgeTypeId &edge_type) {
auto maybe_edge = accessor_->CreateEdge(from->impl_, to->impl_, edge_type);
if (maybe_edge.HasError()) return storage::Result<EdgeAccessor>(maybe_edge.GetError());
return EdgeAccessor(*maybe_edge);
return std::make_unique<EdgeAccessor>(std::move(maybe_edge));
}
storage::Result<std::unique_ptr<EdgeAccessor>> RemoveEdge(EdgeAccessor *edge) {
auto res = accessor_->DeleteEdge(&edge->impl_);
auto res = accessor_->DeleteEdge(edge->impl_);
if (res.HasError()) {
return res.GetError();
}
const auto &value = res.GetValue();
if (!value) {
return std::optional<EdgeAccessor>{};
return storage::Result<std::unique_ptr<EdgeAccessor>>{std::unique_ptr<EdgeAccessor>()};
}
return std::make_optional<EdgeAccessor>(*value);
return std::make_unique<EdgeAccessor>(std::move(value));
}
storage::Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachRemoveVertex(

View File

@ -309,7 +309,7 @@ std::unique_ptr<VertexAccessor> InMemoryStorage::InMemoryAccessor::CreateVertex(
std::unique_ptr<VertexAccessor> InMemoryStorage::InMemoryAccessor::FindVertex(storage::Gid gid, View view) {
auto acc = storage_->vertices_.access();
auto it = acc.find(gid);
if (it == acc.end()) return std::unique_ptr<VertexAccessor>();
if (it == acc.end()) return {};
return VertexAccessor::Create(&*it, &transaction_, &storage_->indices_, &storage_->constraints_, config_, view);
}

View File

@ -79,7 +79,7 @@ class InMemoryStorage final {
~InMemoryStorage();
class InMemoryAccessor final : public Accessor {
class InMemoryAccessor final : public Storage::Accessor {
private:
friend class InMemoryStorage;

View File

@ -149,126 +149,130 @@ struct ConstraintsInfo {
std::vector<std::pair<LabelId, std::set<PropertyId>>> unique;
};
class Accessor {
class Storage {
public:
Accessor() {}
Accessor(const Accessor &) = delete;
Accessor &operator=(const Accessor &) = delete;
Accessor &operator=(Accessor &&other) = delete;
class Accessor {
public:
Accessor() {}
Accessor(const Accessor &) = delete;
Accessor &operator=(const Accessor &) = delete;
Accessor &operator=(Accessor &&other) = delete;
// NOTE: After the accessor is moved, all objects derived from it (accessors
// and iterators) are *invalid*. You have to get all derived objects again.
Accessor(Accessor &&other) noexcept;
// NOTE: After the accessor is moved, all objects derived from it (accessors
// and iterators) are *invalid*. You have to get all derived objects again.
Accessor(Accessor &&other) noexcept;
virtual ~Accessor() {}
virtual ~Accessor() {}
/// @throw std::bad_alloc
virtual std::unique_ptr<VertexAccessor> CreateVertex() = 0;
/// @throw std::bad_alloc
virtual std::unique_ptr<VertexAccessor> CreateVertex() = 0;
virtual std::unique_ptr<VertexAccessor> FindVertex(Gid gid, View view) = 0;
virtual std::unique_ptr<VertexAccessor> FindVertex(Gid gid, View view) = 0;
virtual VerticesIterable Vertices(View view) = 0;
virtual VerticesIterable Vertices(View view) = 0;
virtual VerticesIterable Vertices(LabelId label, View view) = 0;
virtual VerticesIterable Vertices(LabelId label, View view) = 0;
virtual VerticesIterable Vertices(LabelId label, PropertyId property, View view) = 0;
virtual VerticesIterable Vertices(LabelId label, PropertyId property, View view) = 0;
virtual VerticesIterable Vertices(LabelId label, PropertyId property, const PropertyValue &value, View view) = 0;
virtual VerticesIterable Vertices(LabelId label, PropertyId property, const PropertyValue &value, View view) = 0;
virtual VerticesIterable Vertices(LabelId label, PropertyId property,
const std::optional<utils::Bound<PropertyValue>> &lower_bound,
const std::optional<utils::Bound<PropertyValue>> &upper_bound, View view) = 0;
virtual VerticesIterable Vertices(LabelId label, PropertyId property,
const std::optional<utils::Bound<PropertyValue>> &lower_bound,
const std::optional<utils::Bound<PropertyValue>> &upper_bound, View view) = 0;
/// Return approximate number of all vertices in the database.
/// Note that this is always an over-estimate and never an under-estimate.
virtual int64_t ApproximateVertexCount() const = 0;
/// Return approximate number of all vertices in the database.
/// Note that this is always an over-estimate and never an under-estimate.
virtual int64_t ApproximateVertexCount() const = 0;
/// Return approximate number of vertices with the given label.
/// Note that this is always an over-estimate and never an under-estimate.
virtual int64_t ApproximateVertexCount(LabelId label) const = 0;
/// Return approximate number of vertices with the given label.
/// Note that this is always an over-estimate and never an under-estimate.
virtual int64_t ApproximateVertexCount(LabelId label) const = 0;
/// Return approximate number of vertices with the given label and property.
/// Note that this is always an over-estimate and never an under-estimate.
virtual int64_t ApproximateVertexCount(LabelId label, PropertyId property) const = 0;
/// Return approximate number of vertices with the given label and property.
/// Note that this is always an over-estimate and never an under-estimate.
virtual int64_t ApproximateVertexCount(LabelId label, PropertyId property) const = 0;
/// Return approximate number of vertices with the given label and the given
/// value for the given property. Note that this is always an over-estimate
/// and never an under-estimate.
virtual int64_t ApproximateVertexCount(LabelId label, PropertyId property, const PropertyValue &value) const = 0;
/// Return approximate number of vertices with the given label and the given
/// value for the given property. Note that this is always an over-estimate
/// and never an under-estimate.
virtual int64_t ApproximateVertexCount(LabelId label, PropertyId property, const PropertyValue &value) const = 0;
/// Return approximate number of vertices with the given label and value for
/// the given property in the range defined by provided upper and lower
/// bounds.
virtual int64_t ApproximateVertexCount(LabelId label, PropertyId property,
const std::optional<utils::Bound<PropertyValue>> &lower,
const std::optional<utils::Bound<PropertyValue>> &upper) const = 0;
/// Return approximate number of vertices with the given label and value for
/// the given property in the range defined by provided upper and lower
/// bounds.
virtual int64_t ApproximateVertexCount(LabelId label, PropertyId property,
const std::optional<utils::Bound<PropertyValue>> &lower,
const std::optional<utils::Bound<PropertyValue>> &upper) const = 0;
virtual std::optional<storage::IndexStats> GetIndexStats(const storage::LabelId &label,
const storage::PropertyId &property) const = 0;
virtual std::optional<storage::IndexStats> GetIndexStats(const storage::LabelId &label,
const storage::PropertyId &property) const = 0;
virtual std::vector<std::pair<LabelId, PropertyId>> ClearIndexStats() = 0;
virtual std::vector<std::pair<LabelId, PropertyId>> ClearIndexStats() = 0;
virtual std::vector<std::pair<LabelId, PropertyId>> DeleteIndexStatsForLabels(
const std::span<std::string> labels) = 0;
virtual std::vector<std::pair<LabelId, PropertyId>> DeleteIndexStatsForLabels(
const std::span<std::string> labels) = 0;
virtual void SetIndexStats(const storage::LabelId &label, const storage::PropertyId &property,
const IndexStats &stats) = 0;
virtual void SetIndexStats(const storage::LabelId &label, const storage::PropertyId &property,
const IndexStats &stats) = 0;
/// @return Accessor to the deleted vertex if a deletion took place, std::nullopt otherwise
/// @throw std::bad_alloc
virtual Result<std::unique_ptr<VertexAccessor>> DeleteVertex(VertexAccessor *vertex) = 0;
/// @return Accessor to the deleted vertex if a deletion took place, std::nullopt otherwise
/// @throw std::bad_alloc
virtual Result<std::unique_ptr<VertexAccessor>> DeleteVertex(VertexAccessor *vertex) = 0;
/// @return Accessor to the deleted vertex and deleted edges if a deletion took place, std::nullopt otherwise
/// @throw std::bad_alloc
virtual Result<std::optional<std::pair<std::unique_ptr<VertexAccessor>, std::vector<std::unique_ptr<EdgeAccessor>>>>>
DetachDeleteVertex(VertexAccessor *vertex) = 0;
/// @return Accessor to the deleted vertex and deleted edges if a deletion took place, std::nullopt otherwise
/// @throw std::bad_alloc
virtual Result<
std::optional<std::pair<std::unique_ptr<VertexAccessor>, std::vector<std::unique_ptr<EdgeAccessor>>>>>
DetachDeleteVertex(VertexAccessor *vertex) = 0;
/// @throw std::bad_alloc
virtual Result<std::unique_ptr<EdgeAccessor>> CreateEdge(VertexAccessor *from, VertexAccessor *to,
EdgeTypeId edge_type) = 0;
/// @throw std::bad_alloc
virtual Result<std::unique_ptr<EdgeAccessor>> CreateEdge(VertexAccessor *from, VertexAccessor *to,
EdgeTypeId edge_type) = 0;
/// Accessor to the deleted edge if a deletion took place, std::nullopt otherwise
/// @throw std::bad_alloc
virtual Result<std::unique_ptr<EdgeAccessor>> DeleteEdge(EdgeAccessor *edge) = 0;
/// Accessor to the deleted edge if a deletion took place, std::nullopt otherwise
/// @throw std::bad_alloc
virtual Result<std::unique_ptr<EdgeAccessor>> 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;
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;
/// @throw std::bad_alloc if unable to insert a new mapping
virtual LabelId NameToLabel(std::string_view name) = 0;
/// @throw std::bad_alloc if unable to insert a new mapping
virtual LabelId NameToLabel(std::string_view name) = 0;
/// @throw std::bad_alloc if unable to insert a new mapping
virtual PropertyId NameToProperty(std::string_view name) = 0;
/// @throw std::bad_alloc if unable to insert a new mapping
virtual PropertyId NameToProperty(std::string_view name) = 0;
/// @throw std::bad_alloc if unable to insert a new mapping
virtual EdgeTypeId NameToEdgeType(std::string_view name) = 0;
/// @throw std::bad_alloc if unable to insert a new mapping
virtual EdgeTypeId NameToEdgeType(std::string_view name) = 0;
virtual bool LabelIndexExists(LabelId label) const = 0;
virtual bool LabelIndexExists(LabelId label) const = 0;
virtual bool LabelPropertyIndexExists(LabelId label, PropertyId property) const = 0;
virtual bool LabelPropertyIndexExists(LabelId label, PropertyId property) const = 0;
virtual IndicesInfo ListAllIndices() const = 0;
virtual IndicesInfo ListAllIndices() const = 0;
virtual ConstraintsInfo ListAllConstraints() const = 0;
virtual ConstraintsInfo ListAllConstraints() const = 0;
virtual void AdvanceCommand() = 0;
virtual void AdvanceCommand() = 0;
/// Returns void if the transaction has been committed.
/// Returns `StorageDataManipulationError` if an error occures. Error can be:
/// * `ReplicationError`: there is at least one SYNC replica that has not confirmed receiving the transaction.
/// * `ConstraintViolation`: the changes made by this transaction violate an existence or unique constraint. In this
/// case the transaction is automatically aborted.
/// @throw std::bad_alloc
virtual utils::BasicResult<StorageDataManipulationError, void> Commit(
std::optional<uint64_t> desired_commit_timestamp = {}) = 0;
/// Returns void if the transaction has been committed.
/// Returns `StorageDataManipulationError` if an error occures. Error can be:
/// * `ReplicationError`: there is at least one SYNC replica that has not confirmed receiving the transaction.
/// * `ConstraintViolation`: the changes made by this transaction violate an existence or unique constraint. In this
/// case the transaction is automatically aborted.
/// @throw std::bad_alloc
virtual utils::BasicResult<StorageDataManipulationError, void> Commit(
std::optional<uint64_t> desired_commit_timestamp = {}) = 0;
/// @throw std::bad_alloc
virtual void Abort() = 0;
/// @throw std::bad_alloc
virtual void Abort() = 0;
virtual void FinalizeTransaction() = 0;
virtual void FinalizeTransaction() = 0;
virtual std::optional<uint64_t> GetTransactionId() const = 0;
virtual std::optional<uint64_t> GetTransactionId() const = 0;
};
};
} // namespace memgraph::storage

View File

@ -21,9 +21,20 @@ std::unique_ptr<VertexAccessor> VertexAccessor::Create(Vertex *vertex, Transacti
return InMemoryVertexAccessor::Create(vertex, transaction, indices, constraints, config, view);
}
Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::InEdges(
View view, const std::vector<EdgeTypeId> &edge_types) const {
return InEdges(view, edge_types, nullptr);
}
Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::InEdges(View view) const {
return InEdges(view, {}, nullptr);
}
Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::OutEdges(
View view, const std::vector<EdgeTypeId> &edge_types) const {
return OutEdges(view, edge_types, nullptr);
}
Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::OutEdges(View view) const {
return OutEdges(view, {}, nullptr);
}

View File

@ -85,6 +85,9 @@ class VertexAccessor {
const std::vector<EdgeTypeId> &edge_types,
const VertexAccessor *destination) const = 0;
Result<std::vector<std::unique_ptr<EdgeAccessor>>> InEdges(View view,
const std::vector<EdgeTypeId> &edge_types) const;
Result<std::vector<std::unique_ptr<EdgeAccessor>>> InEdges(View view) const;
/// @throw std::bad_alloc
@ -94,6 +97,8 @@ class VertexAccessor {
const std::vector<EdgeTypeId> &edge_types,
const VertexAccessor *destination) const = 0;
Result<std::vector<std::unique_ptr<EdgeAccessor>>> OutEdges(View view,
const std::vector<EdgeTypeId> &edge_types) const;
Result<std::vector<std::unique_ptr<EdgeAccessor>>> OutEdges(View view) const;
virtual Result<size_t> InDegree(View view) const = 0;