1
0
Fork 0

Add isQueryKilled callback to ShortestPathOptions and use it (#8739)

* Add isQueryKilled callback to ShortestPathOptions

* Use isQueryKilledCallback

in
 * ConstantWeightShortestPathFinder
 * AttributeWeightShortestPathFinder
 * ShortestPathExecutor
This commit is contained in:
Markus Pfeiffer 2019-04-12 09:39:01 +01:00 committed by Michael Hackstein
parent e5ce10cd60
commit b3224eed1d
10 changed files with 27 additions and 26 deletions

View File

@ -205,11 +205,7 @@ bool ShortestPathExecutor::fetchPath() {
TRI_ASSERT(start.isString());
TRI_ASSERT(end.isString());
_path->clear();
} while (!_finder.shortestPath(start, end, *_path, [this]() {
if (_finder.options().query()->killed()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_KILLED);
}
}));
} while (!_finder.shortestPath(start, end, *_path));
_posInPath = 0;
return true;
}

View File

@ -160,9 +160,9 @@ AttributeWeightShortestPathFinder::AttributeWeightShortestPathFinder(ShortestPat
AttributeWeightShortestPathFinder::~AttributeWeightShortestPathFinder() {}
bool AttributeWeightShortestPathFinder::shortestPath(
arangodb::velocypack::Slice const& st, arangodb::velocypack::Slice const& ta,
ShortestPathResult& result, std::function<void()> const& callback) {
bool AttributeWeightShortestPathFinder::shortestPath(arangodb::velocypack::Slice const& st,
arangodb::velocypack::Slice const& ta,
ShortestPathResult& result) {
// For the result:
result.clear();
_highscoreSet = false;
@ -205,7 +205,7 @@ bool AttributeWeightShortestPathFinder::shortestPath(
if (++counter == 10) {
// check for abortion
callback();
options().isQueryKilledCallback();
counter = 0;
}
}

View File

@ -208,8 +208,7 @@ class AttributeWeightShortestPathFinder : public ShortestPathFinder {
// path
bool shortestPath(arangodb::velocypack::Slice const& start,
arangodb::velocypack::Slice const& target,
arangodb::graph::ShortestPathResult& result,
std::function<void()> const& callback) override;
arangodb::graph::ShortestPathResult& result) override;
void inserter(std::unordered_map<arangodb::velocypack::StringRef, size_t>& candidates,
std::vector<Step*>& result, arangodb::velocypack::StringRef const& s,

View File

@ -54,7 +54,7 @@ ConstantWeightShortestPathFinder::~ConstantWeightShortestPathFinder() {
bool ConstantWeightShortestPathFinder::shortestPath(
arangodb::velocypack::Slice const& s, arangodb::velocypack::Slice const& e,
arangodb::graph::ShortestPathResult& result, std::function<void()> const& callback) {
arangodb::graph::ShortestPathResult& result) {
result.clear();
TRI_ASSERT(s.isString());
TRI_ASSERT(e.isString());
@ -81,7 +81,7 @@ bool ConstantWeightShortestPathFinder::shortestPath(
arangodb::velocypack::StringRef n;
while (!_leftClosure.empty() && !_rightClosure.empty()) {
callback();
options().isQueryKilledCallback();
if (_leftClosure.size() < _rightClosure.size()) {
if (expandClosure(_leftClosure, _leftFound, _rightFound, false, n)) {

View File

@ -59,8 +59,7 @@ class ConstantWeightShortestPathFinder : public ShortestPathFinder {
bool shortestPath(arangodb::velocypack::Slice const& start,
arangodb::velocypack::Slice const& end,
arangodb::graph::ShortestPathResult& result,
std::function<void()> const& callback) override;
arangodb::graph::ShortestPathResult& result) override;
private:
void expandVertex(bool backward, arangodb::velocypack::StringRef vertex);

View File

@ -42,8 +42,7 @@ class ShortestPathFinder {
virtual bool shortestPath(arangodb::velocypack::Slice const& start,
arangodb::velocypack::Slice const& target,
arangodb::graph::ShortestPathResult& result,
std::function<void()> const& callback) = 0;
arangodb::graph::ShortestPathResult& result) = 0;
void destroyEngines();

View File

@ -203,7 +203,8 @@ EdgeCursor* ShortestPathOptions::nextReverseCursorCoordinator(arangodb::velocypa
return cursor.release();
}
void ShortestPathOptions::fetchVerticesCoordinator(std::deque<arangodb::velocypack::StringRef> const& vertexIds) {
void ShortestPathOptions::fetchVerticesCoordinator(
std::deque<arangodb::velocypack::StringRef> const& vertexIds) {
// TRI_ASSERT(arangodb::ServerState::instance()->isCoordinator());
if (!arangodb::ServerState::instance()->isCoordinator()) {
return;
@ -229,3 +230,9 @@ void ShortestPathOptions::fetchVerticesCoordinator(std::deque<arangodb::velocypa
cache, ch->datalake(), *(leased.get()));
}
}
void ShortestPathOptions::isQueryKilledCallback() const {
if (query()->killed()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_KILLED);
}
}

View File

@ -97,6 +97,8 @@ struct ShortestPathOptions : public BaseOptions {
void fetchVerticesCoordinator(std::deque<arangodb::velocypack::StringRef> const& vertexIds);
void isQueryKilledCallback() const;
private:
EdgeCursor* nextCursorCoordinator(arangodb::velocypack::StringRef vid);
EdgeCursor* nextReverseCursorCoordinator(arangodb::velocypack::StringRef vid);

View File

@ -121,8 +121,7 @@ class FakePathFinder : public ShortestPathFinder {
}
bool shortestPath(VPackSlice const& source, VPackSlice const& target,
arangodb::graph::ShortestPathResult& result,
std::function<void()> const& callback) override {
arangodb::graph::ShortestPathResult& result) override {
REQUIRE(source.isString());
REQUIRE(target.isString());
_calledWith.emplace_back(std::make_pair(source.copyString(), target.copyString()));

View File

@ -350,7 +350,7 @@ TEST_CASE("ConstantWeightShortestPathFinder", "[graph]") {
auto end = velocypack::Parser::fromJson("\"v/0\"");
ShortestPathResult result;
REQUIRE(true == finder->shortestPath(start->slice(), end->slice(), result, []() {}));
REQUIRE(true == finder->shortestPath(start->slice(), end->slice(), result));
}
SECTION("no path exists") {
@ -358,7 +358,7 @@ TEST_CASE("ConstantWeightShortestPathFinder", "[graph]") {
auto end = velocypack::Parser::fromJson("\"v/1\"");
ShortestPathResult result;
REQUIRE(false == finder->shortestPath(start->slice(), end->slice(), result, []() {}));
REQUIRE(false == finder->shortestPath(start->slice(), end->slice(), result));
CHECK(result.length() == 0);
}
@ -367,7 +367,7 @@ TEST_CASE("ConstantWeightShortestPathFinder", "[graph]") {
auto end = velocypack::Parser::fromJson("\"v/2\"");
ShortestPathResult result;
auto rr = finder->shortestPath(start->slice(), end->slice(), result, []() {});
auto rr = finder->shortestPath(start->slice(), end->slice(), result);
REQUIRE(rr);
REQUIRE(checkPath(result, {"1", "2"}, {{}, {"v/1", "v/2"}}));
}
@ -377,7 +377,7 @@ TEST_CASE("ConstantWeightShortestPathFinder", "[graph]") {
auto end = velocypack::Parser::fromJson("\"v/4\"");
ShortestPathResult result;
auto rr = finder->shortestPath(start->slice(), end->slice(), result, []() {});
auto rr = finder->shortestPath(start->slice(), end->slice(), result);
REQUIRE(rr);
REQUIRE(checkPath(result, {"1", "2", "3", "4"},
{{}, {"v/1", "v/2"}, {"v/2", "v/3"}, {"v/3", "v/4"}}));
@ -390,7 +390,7 @@ TEST_CASE("ConstantWeightShortestPathFinder", "[graph]") {
ShortestPathResult result;
{
auto rr = finder->shortestPath(start->slice(), end->slice(), result, []() {});
auto rr = finder->shortestPath(start->slice(), end->slice(), result);
REQUIRE(rr);
// One of the two has to be returned
@ -410,7 +410,7 @@ TEST_CASE("ConstantWeightShortestPathFinder", "[graph]") {
}
{
auto rr = finder->shortestPath(end->slice(), start->slice(), result, []() {});
auto rr = finder->shortestPath(end->slice(), start->slice(), result);
REQUIRE(!rr);
}