Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove redundant logic in GetDstBySrc #4902

Merged
merged 3 commits into from
Nov 18, 2022
Merged
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
19 changes: 15 additions & 4 deletions src/storage/exec/EdgeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class EdgeNode : public IterateNode<T> {
EdgeType edgeType,
const std::vector<PropContext>* props,
StorageExpressionContext* expCtx,
Expression* exp)
Expression* exp,
bool maySkipDecode = false)
: context_(context),
edgeContext_(edgeContext),
edgeType_(edgeType),
Expand All @@ -55,6 +56,9 @@ class EdgeNode : public IterateNode<T> {
schemas_ = &(schemaIter->second);
ttl_ = QueryUtils::getEdgeTTLInfo(edgeContext_, std::abs(edgeType_));
edgeName_ = edgeContext_->edgeNames_[edgeType_];
if (!ttl_.has_value() && maySkipDecode) {
skipDecode_ = true;
}
IterateNode<T>::name_ = "EdgeNode";
}

Expand All @@ -72,6 +76,8 @@ class EdgeNode : public IterateNode<T> {
const std::vector<std::shared_ptr<const meta::NebulaSchemaProvider>>* schemas_ = nullptr;
std::optional<std::pair<std::string, int64_t>> ttl_;
std::string edgeName_;
// when no ttl exists and we don't need to read property in value, skip build RowReader
bool skipDecode_{false};
};

// FetchEdgeNode is used to fetch a single edge
Expand Down Expand Up @@ -180,8 +186,9 @@ class SingleEdgeNode final : public EdgeNode<VertexID> {
EdgeType edgeType,
const std::vector<PropContext>* props,
StorageExpressionContext* expCtx = nullptr,
Expression* exp = nullptr)
: EdgeNode(context, edgeContext, edgeType, props, expCtx, exp) {
Expression* exp = nullptr,
bool maySkipDecode = false)
: EdgeNode(context, edgeContext, edgeType, props, expCtx, exp, maySkipDecode) {
name_ = "SingleEdgeNode";
}

Expand Down Expand Up @@ -221,7 +228,11 @@ class SingleEdgeNode final : public EdgeNode<VertexID> {
prefix_ = NebulaKeyUtils::edgePrefix(context_->vIdLen(), partId, vId, edgeType_);
ret = context_->env()->kvstore_->prefix(context_->spaceId(), partId, prefix_, &iter);
if (ret == nebula::cpp2::ErrorCode::SUCCEEDED && iter && iter->valid()) {
iter_.reset(new SingleEdgeIterator(context_, std::move(iter), edgeType_, schemas_, &ttl_));
if (!skipDecode_) {
iter_.reset(new SingleEdgeIterator(context_, std::move(iter), edgeType_, schemas_, &ttl_));
} else {
iter_.reset(new SingleEdgeKeyIterator(std::move(iter), edgeType_));
}
} else {
iter_.reset();
}
Expand Down
18 changes: 7 additions & 11 deletions src/storage/exec/GetDstBySrcNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,12 @@ class GetDstBySrcNode : public QueryNode<VertexID> {
setCurrentEdgeInfo(type);
}
auto key = iter_->key();
auto reader = iter_->reader();
auto props = context_->props_;
DCHECK_EQ(props->size(), 1);

nebula::List list;
// collect props need to return
if (!QueryUtils::collectEdgeProps(
key, context_->vIdLen(), context_->isIntId(), reader, props, list)
.ok()) {
return nebula::cpp2::ErrorCode::E_EDGE_PROP_NOT_FOUND;
auto dstId = NebulaKeyUtils::getDstId(context_->vIdLen(), key);
if (context_->isIntId()) {
pengweisong marked this conversation as resolved.
Show resolved Hide resolved
result_->emplace_back(*reinterpret_cast<const int64_t*>(dstId.data()));
} else {
result_->emplace_back(dstId.subpiece(0, dstId.find_first_of('\0')).toString());
}
result_->emplace_back(std::move(list.values[0]));
}
return nebula::cpp2::ErrorCode::SUCCEEDED;
}
Expand All @@ -80,6 +74,8 @@ class GetDstBySrcNode : public QueryNode<VertexID> {
context_->edgeType_ = type;
context_->edgeName_ = edgeNodes_[iter_->getIdx()]->getEdgeName();
context_->props_ = &(edgeContext_->propContexts_[idx].second);
DCHECK_EQ(context_->props_->size(), 1);
DCHECK_EQ((*context_->props_)[0].name_, kDst);
}

private:
Expand Down
24 changes: 23 additions & 1 deletion src/storage/exec/StorageIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class StorageIterator {
*/
class SingleEdgeIterator : public StorageIterator {
public:
SingleEdgeIterator() = default;
/**
* @brief Construct a new Single Edge Iterator object
*
Expand All @@ -92,6 +91,9 @@ class SingleEdgeIterator : public StorageIterator {
}
}

SingleEdgeIterator(std::unique_ptr<kvstore::KVIterator> iter, EdgeType edgeType)
: iter_(std::move(iter)), edgeType_(edgeType) {}

bool valid() const override {
return reader_ != nullptr;
}
Expand Down Expand Up @@ -155,6 +157,26 @@ class SingleEdgeIterator : public StorageIterator {
VertexID lastDstId_ = "";
};

class SingleEdgeKeyIterator : public SingleEdgeIterator {
public:
// A simplified iterator that only iterates keys, we can use this iterator when no ttl exists and
// no property need to be read from value
SingleEdgeKeyIterator(std::unique_ptr<kvstore::KVIterator> iter, EdgeType edgeType)
: SingleEdgeIterator(std::move(iter), edgeType) {}

bool valid() const override {
return iter_->valid();
}

void next() override {
iter_->next();
}

RowReader* reader() const override {
LOG(FATAL) << "This iterator should not read value";
}
};

/**
* @brief Iterator of multiple SingleEdgeIterator, it will iterate over edges of different types
*/
Expand Down
5 changes: 4 additions & 1 deletion src/storage/query/GetDstBySrcProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ StoragePlan<VertexID> GetDstBySrcProcessor::buildPlan(RuntimeContext* context,
StoragePlan<VertexID> plan;
std::vector<SingleEdgeNode*> edges;
for (const auto& ec : edgeContext_.propContexts_) {
auto edge = std::make_unique<SingleEdgeNode>(context, &edgeContext_, ec.first, &ec.second);
// Since we only return dst in this processor, some steps would be skipped when iterating
// key-values if possible, for example, decoding value
auto edge = std::make_unique<SingleEdgeNode>(
context, &edgeContext_, ec.first, &ec.second, nullptr, nullptr, true);
edges.emplace_back(edge.get());
plan.addNode(std::move(edge));
}
Expand Down