Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions arangod/Graph/PathManagement/PathValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@
#endif

#include "Basics/Exceptions.h"
#include "Basics/Result.h"
#include "Basics/ResultT.h"

namespace {
[[nodiscard]] arangodb::ResultT<std::pair<std::string, size_t>>
extractCollectionName(arangodb::velocypack::HashedStringRef const& idHashed) {
size_t pos = idHashed.find('/');
if (pos == std::string::npos) {
// Invalid input. If we get here somehow we managed to store invalid
// _from/_to values or the traverser did a let an illegal start through
TRI_ASSERT(false);
return arangodb::Result{
TRI_ERROR_GRAPH_INVALID_EDGE,
"edge contains invalid value " + idHashed.toString()};
}

std::string colName = idHashed.substr(0, pos).toString();
return std::make_pair(std::move(colName), pos);
}

} // namespace

namespace arangodb::graph {

Expand Down Expand Up @@ -86,7 +107,7 @@ auto PathValidator<ProviderType, PathStore, vertexUniqueness, edgeUniqueness>::
bool success = _store.visitReversePath(
step, [&](typename PathStore::Step const& step) -> bool {
auto const& [unusedV, addedVertex] =
_uniqueVertices.emplace(step.getVertexIdentifier());
_uniqueVertices.emplace(step.getVertex().getID());

// If this add fails, we need to exclude this path
return addedVertex;
Expand All @@ -101,7 +122,7 @@ auto PathValidator<ProviderType, PathStore, vertexUniqueness, edgeUniqueness>::
// In case we have VertexUniquenessLevel::GLOBAL, we do not have to take
// care about the EdgeUniquenessLevel.
auto const& [unusedV, addedVertex] =
_uniqueVertices.emplace(step.getVertexIdentifier());
_uniqueVertices.emplace(step.getVertex().getID());
// If this add fails, we need to exclude this path
if (!addedVertex) {
return ValidationResult::Type::FILTER_AND_PRUNE;
Expand All @@ -119,7 +140,7 @@ auto PathValidator<ProviderType, PathStore, vertexUniqueness, edgeUniqueness>::
}

auto const& [unusedE, addedEdge] =
_uniqueEdges.emplace(step.getEdgeIdentifier());
_uniqueEdges.emplace(step.getEdge().getID());
// If this add fails, we need to exclude this path
return addedEdge;
});
Expand Down Expand Up @@ -186,7 +207,7 @@ auto PathValidator<ProviderType, PathStore, vertexUniqueness, edgeUniqueness>::
// If otherUniqueVertices has our step, we will return false and
// abort. Otherwise we'll return true here. This guarantees we have no
// vertex on both sides of the path twice.
return otherUniqueVertices.find(innerStep.getVertexIdentifier()) ==
return otherUniqueVertices.find(innerStep.getVertex().getID()) ==
otherUniqueVertices.end();
});
if (!success) {
Expand Down Expand Up @@ -256,7 +277,12 @@ auto PathValidator<ProviderType, PathStore, vertexUniqueness, edgeUniqueness>::
return true;
}

auto collectionName = step.getCollectionName();
auto collectionNameResult = extractCollectionName(step.getVertex().getID());
if (collectionNameResult.fail()) {
THROW_ARANGO_EXCEPTION(collectionNameResult.result());
}
auto collectionName = collectionNameResult.get().first;

if (std::find(allowedCollections.begin(), allowedCollections.end(),
collectionName) != allowedCollections.end()) {
// found in allowed collections => allowed
Expand Down
23 changes: 2 additions & 21 deletions arangod/Graph/Providers/BaseStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
#pragma once

#include <velocypack/HashedStringRef.h>
#include "Basics/ResultT.h"

#include <numeric>

namespace arangodb {

namespace graph {
namespace arangodb::graph {

class BaseStep {
public:
Expand All @@ -56,25 +53,9 @@ class BaseStep {

double getWeight() const { return _weight; }

[[nodiscard]] ResultT<std::pair<std::string, size_t>> extractCollectionName(
arangodb::velocypack::HashedStringRef const& idHashed) const {
size_t pos = idHashed.find('/');
if (pos == std::string::npos) {
// Invalid input. If we get here somehow we managed to store invalid
// _from/_to values or the traverser did a let an illegal start through
TRI_ASSERT(false);
return Result{TRI_ERROR_GRAPH_INVALID_EDGE,
"edge contains invalid value " + idHashed.toString()};
}

std::string colName = idHashed.substr(0, pos).toString();
return std::make_pair(std::move(colName), pos);
}

private:
size_t _previous;
size_t _depth;
double _weight;
};
} // namespace graph
} // namespace arangodb
} // namespace arangodb::graph
4 changes: 2 additions & 2 deletions arangod/Graph/Providers/ClusterProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,9 @@ auto ClusterProvider<StepImpl>::fetchVertices(
// in that case we do not have to fetch the actual vertex data

for (auto& lE : looseEnds) {
if (!_opts.getCache()->isVertexCached(lE->getVertexIdentifier())) {
if (!_opts.getCache()->isVertexCached(lE->getVertex().getID())) {
// we'll only cache the vertex id, we do not need the data
_opts.getCache()->cacheVertex(lE->getVertexIdentifier(),
_opts.getCache()->cacheVertex(lE->getVertex().getID(),
VPackSlice::nullSlice());
}
result.emplace_back(lE);
Expand Down
7 changes: 3 additions & 4 deletions arangod/Graph/Providers/SingleServerProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ auto SingleServerProvider<Step>::expand(

EdgeDocumentToken edgeToken{neighbour.eid};
callback(Step{id, std::move(edgeToken), previous, step.getDepth() + 1,
_opts.weightEdge(step.getWeight(), edge),
neighbour.cursorId});
_opts.weightEdge(step.getWeight(), edge)});
// TODO [GraphRefactor]: Why is cursorID set, but never used?
// Note: There is one implementation that used, it, but there is a high
// probability we do not need it anymore after refactoring is complete.
Expand Down Expand Up @@ -190,13 +189,13 @@ auto SingleServerProvider<Step>::clear() -> void {

template<class Step>
void SingleServerProvider<Step>::insertEdgeIntoResult(
EdgeDocumentToken edge, arangodb::velocypack::Builder& builder) {
typename Step::EdgeType edge, arangodb::velocypack::Builder& builder) {
_edgeLookup.insertEdgeIntoResult(edge, builder);
}

template<class Step>
void SingleServerProvider<Step>::insertEdgeIdIntoResult(
EdgeDocumentToken edge, arangodb::velocypack::Builder& builder) {
typename Step::EdgeType edge, arangodb::velocypack::Builder& builder) {
_edgeLookup.insertEdgeIdIntoResult(edge, builder);
}

Expand Down
4 changes: 2 additions & 2 deletions arangod/Graph/Providers/SingleServerProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class SingleServerProvider {
std::function<void(Step)> const& callback) -> void; // index
auto clear() -> void;

void insertEdgeIntoResult(EdgeDocumentToken edge,
void insertEdgeIntoResult(typename Step::EdgeType edge,
arangodb::velocypack::Builder& builder);
void insertEdgeIdIntoResult(EdgeDocumentToken edge,
void insertEdgeIdIntoResult(typename Step::EdgeType edge,
arangodb::velocypack::Builder& builder);

std::string getEdgeId(typename Step::Edge const& edge);
Expand Down
16 changes: 0 additions & 16 deletions arangod/Graph/Steps/ClusterProviderStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,6 @@ class ClusterProviderStep : public arangodb::graph::BaseStep {
}
bool isUnknown() const noexcept { return _validationStatus.isUnknown(); }

// beware: returns a *copy* of the vertex id
[[nodiscard]] VertexType getVertexIdentifier() const {
return _vertex.getID();
}

// beware: returns a *copy* of the edge id
[[nodiscard]] EdgeType getEdgeIdentifier() const { return _edge.getID(); }

[[nodiscard]] std::string getCollectionName() const {
auto collectionNameResult = extractCollectionName(_vertex.getID());
if (collectionNameResult.fail()) {
THROW_ARANGO_EXCEPTION(collectionNameResult.result());
}
return collectionNameResult.get().first;
}

friend auto operator<<(std::ostream& out, ClusterProviderStep const& step)
-> std::ostream&;

Expand Down
14 changes: 3 additions & 11 deletions arangod/Graph/Steps/SingleServerProviderStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ SingleServerProviderStep::SingleServerProviderStep(VertexType v, size_t depth,
_vertex(v),
_edge() {}

SingleServerProviderStep::SingleServerProviderStep(VertexType v,
EdgeDocumentToken edge,
SingleServerProviderStep::SingleServerProviderStep(VertexType v, EdgeType edge,
size_t prev)
: BaseStep(prev), _vertex(v), _edge(std::move(edge)) {}

SingleServerProviderStep::SingleServerProviderStep(VertexType v,
EdgeDocumentToken edge,
SingleServerProviderStep::SingleServerProviderStep(VertexType v, EdgeType edge,
size_t prev, size_t depth,
double weight, size_t)
double weight)
: BaseStep(prev, depth, weight), _vertex(v), _edge(std::move(edge)) {}

SingleServerProviderStep::~SingleServerProviderStep() = default;
Expand All @@ -73,9 +71,3 @@ SingleServerProviderStep::Edge::getID() const noexcept {
bool SingleServerProviderStep::Edge::isValid() const noexcept {
return getID().isValid();
}

void SingleServerProviderStep::Edge::addToBuilder(
SingleServerProvider<SingleServerProviderStep>& provider,
arangodb::velocypack::Builder& builder) const {
provider.insertEdgeIntoResult(getID(), builder);
}
47 changes: 12 additions & 35 deletions arangod/Graph/Steps/SingleServerProviderStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
/// @author Heiko Kernbach
////////////////////////////////////////////////////////////////////////////////

#include "Transaction/Methods.h"
#pragma once

#include <velocypack/HashedStringRef.h>
#include "Graph/EdgeDocumentToken.h"
#include "Graph/Providers/BaseStep.h"
#include "Graph/Providers/TypeAliases.h"

#pragma once
#include "Graph/EdgeDocumentToken.h"

namespace arangodb {
namespace graph {
namespace arangodb::graph {

template<class EdgeType>
class SingleServerProvider;
Expand Down Expand Up @@ -61,22 +60,20 @@ class SingleServerProviderStep : public arangodb::graph::BaseStep {

class Edge {
public:
explicit Edge(EdgeDocumentToken tkn) noexcept : _token(std::move(tkn)) {}
explicit Edge(EdgeType tkn) noexcept : _token(std::move(tkn)) {}
Edge() noexcept : _token() {}

void addToBuilder(SingleServerProvider<SingleServerProviderStep>& provider,
arangodb::velocypack::Builder& builder) const;
EdgeType const& getID() const noexcept;
bool isValid() const noexcept;

private:
EdgeDocumentToken _token;
EdgeType _token;
};

SingleServerProviderStep(VertexType v);
SingleServerProviderStep(VertexType v, EdgeDocumentToken edge, size_t prev);
SingleServerProviderStep(VertexType v, EdgeDocumentToken edge, size_t prev,
size_t depth, double weight, size_t);
SingleServerProviderStep(VertexType v, EdgeType edge, size_t prev);
SingleServerProviderStep(VertexType v, EdgeType edge, size_t prev,
size_t depth, double weight);
SingleServerProviderStep(VertexType v, size_t depth, double weight = 0.0);
~SingleServerProviderStep();

Expand All @@ -89,31 +86,12 @@ class SingleServerProviderStep : public arangodb::graph::BaseStep {

std::string toString() const {
return "<Step><Vertex>: " + _vertex.getID().toString() +
", <Edge>: " + std::to_string(_edge.getID().localDocumentId().id());
", <Edge>: " + _edge.getID().toString();
}
bool isProcessable() const { return !isLooseEnd(); }
bool isLooseEnd() const { return false; }
bool isUnknown() const { return false; }

// beware: will return a *copy* of the vertex id
VertexType getVertexIdentifier() const { return _vertex.getID(); }

// beware: will return a *copy* of the edge id
EdgeType getEdgeIdentifier() const { return _edge.getID(); }

std::string getCollectionName() const {
/*
* Future optimization: When re-implementing the documentFastPathLocal
* method to support string refs or either string views, we can improve this
* section here as well.
*/
auto collectionNameResult = extractCollectionName(_vertex.getID());
if (collectionNameResult.fail()) {
THROW_ARANGO_EXCEPTION(collectionNameResult.result());
}
return collectionNameResult.get().first;
};

friend auto operator<<(std::ostream& out,
SingleServerProviderStep const& step) -> std::ostream&;

Expand All @@ -125,5 +103,4 @@ class SingleServerProviderStep : public arangodb::graph::BaseStep {
Vertex _vertex;
Edge _edge;
};
} // namespace graph
} // namespace arangodb
} // namespace arangodb::graph
Loading