From b01fdd336884abb85a243f1e40e73cca6334dc55 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Fri, 24 Jun 2022 11:36:12 +0800 Subject: [PATCH] add lock (#4352) --- src/graph/executor/algo/BatchShortestPath.cpp | 2 +- src/graph/executor/algo/ShortestPathBase.cpp | 17 +++++++++-------- src/graph/executor/algo/ShortestPathBase.h | 11 +++-------- src/graph/executor/algo/SingleShortestPath.cpp | 5 ++++- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/graph/executor/algo/BatchShortestPath.cpp b/src/graph/executor/algo/BatchShortestPath.cpp index cf7c8591ac0..f01e0af2a6e 100644 --- a/src/graph/executor/algo/BatchShortestPath.cpp +++ b/src/graph/executor/algo/BatchShortestPath.cpp @@ -135,7 +135,7 @@ folly::Future BatchShortestPath::getNeighbors(size_t rowNum, size_t step nullptr) .via(qctx_->rctx()->runner()) .thenValue([this, rowNum, reverse, stepNum, getNbrTime](auto&& resp) { - addStats(resp, stats_, stepNum, getNbrTime.elapsedInUSec(), reverse); + addStats(resp, stepNum, getNbrTime.elapsedInUSec(), reverse); return buildPath(rowNum, std::move(resp), reverse); }); } diff --git a/src/graph/executor/algo/ShortestPathBase.cpp b/src/graph/executor/algo/ShortestPathBase.cpp index 876e52d352b..ea4b7645eff 100644 --- a/src/graph/executor/algo/ShortestPathBase.cpp +++ b/src/graph/executor/algo/ShortestPathBase.cpp @@ -38,7 +38,7 @@ folly::Future> ShortestPathBase::getMeetVidsProps( nullptr) .via(qctx_->rctx()->runner()) .thenValue([this, getPropsTime](PropRpcResponse&& resp) { - addStats(resp, stats_, getPropsTime.elapsedInUSec()); + addStats(resp, getPropsTime.elapsedInUSec()); return handlePropResp(std::move(resp)); }); } @@ -168,7 +168,6 @@ Status ShortestPathBase::handleErrorCode(nebula::cpp2::ErrorCode code, Partition } void ShortestPathBase::addStats(RpcResponse& resp, - std::unordered_map* stats, size_t stepNum, int64_t timeInUSec, bool reverse) const { @@ -193,15 +192,17 @@ void ShortestPathBase::addStats(RpcResponse& resp, } ss << "\n}"; if (reverse) { - stats->emplace(folly::sformat("reverse step {}", stepNum), ss.str()); + statsLock_.lock(); + stats_->emplace(folly::sformat("reverse step {}", stepNum), ss.str()); + statsLock_.unlock(); } else { - stats->emplace(folly::sformat("step {}", stepNum), ss.str()); + statsLock_.lock(); + stats_->emplace(folly::sformat("step {}", stepNum), ss.str()); + statsLock_.unlock(); } } -void ShortestPathBase::addStats(PropRpcResponse& resp, - std::unordered_map* stats, - int64_t timeInUSec) const { +void ShortestPathBase::addStats(PropRpcResponse& resp, int64_t timeInUSec) const { auto& hostLatency = resp.hostLatency(); std::stringstream ss; ss << "{\n"; @@ -217,7 +218,7 @@ void ShortestPathBase::addStats(PropRpcResponse& resp, ss << "\n}"; } ss << "\n}"; - stats->emplace(folly::sformat("get_prop "), ss.str()); + stats_->emplace(folly::sformat("get_prop "), ss.str()); } } // namespace graph diff --git a/src/graph/executor/algo/ShortestPathBase.h b/src/graph/executor/algo/ShortestPathBase.h index 7f80336260f..bc7ece02df2 100644 --- a/src/graph/executor/algo/ShortestPathBase.h +++ b/src/graph/executor/algo/ShortestPathBase.h @@ -43,15 +43,9 @@ class ShortestPathBase { Status handleErrorCode(nebula::cpp2::ErrorCode code, PartitionID partId) const; - void addStats(RpcResponse& resp, - std::unordered_map* stats, - size_t stepNum, - int64_t timeInUSec, - bool reverse) const; + void addStats(RpcResponse& resp, size_t stepNum, int64_t timeInUSec, bool reverse) const; - void addStats(PropRpcResponse& resp, - std::unordered_map* stats, - int64_t timeInUSec) const; + void addStats(PropRpcResponse& resp, int64_t timeInUSec) const; template StatusOr handleCompleteness(const storage::StorageRpcResponse& rpcResp, @@ -86,6 +80,7 @@ class ShortestPathBase { std::unordered_map* stats_{nullptr}; size_t maxStep_; bool singleShortest_{true}; + folly::SpinLock statsLock_; std::vector resultDs_; std::vector leftVids_; diff --git a/src/graph/executor/algo/SingleShortestPath.cpp b/src/graph/executor/algo/SingleShortestPath.cpp index eb862e7967a..379a4a358ba 100644 --- a/src/graph/executor/algo/SingleShortestPath.cpp +++ b/src/graph/executor/algo/SingleShortestPath.cpp @@ -108,7 +108,7 @@ folly::Future SingleShortestPath::getNeighbors(size_t rowNum, nullptr) .via(qctx_->rctx()->runner()) .thenValue([this, rowNum, stepNum, getNbrTime, reverse](auto&& resp) { - addStats(resp, stats_, stepNum, getNbrTime.elapsedInUSec(), reverse); + addStats(resp, stepNum, getNbrTime.elapsedInUSec(), reverse); return buildPath(rowNum, std::move(resp), reverse); }); } @@ -264,6 +264,9 @@ folly::Future SingleShortestPath::buildEvenPath(size_t rowNum, return false; } for (auto& meetVertex : vertices) { + if (!meetVertex.isVertex()) { + continue; + } auto meetVid = meetVertex.getVertex().vid; auto leftPaths = createLeftPath(rowNum, meetVid); auto rightPaths = createRightPath(rowNum, meetVid, false);