Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cangfengzhs committed Mar 7, 2022
1 parent 8e5a30a commit 17b38e6
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 152 deletions.
9 changes: 6 additions & 3 deletions src/storage/exec/MultiTagNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
namespace nebula {
namespace storage {

// MultiTagNode is a replacement of HashJoinNode
// in execution of "go over"
// if Graph don't pass any Edge prop
/**
* @brief MultiTagNode is a replacement of HashJoinNode in execution of "go over" if Graph don't
* pass any Edge prop
*
* @see IterateNode
*/
class MultiTagNode : public IterateNode<VertexID> {
public:
using RelNode::doExecute;
Expand Down
45 changes: 38 additions & 7 deletions src/storage/exec/QueryUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ class QueryUtils final {
kDst,
kOther,
};

/**
* @brief Get return col type by name
*
* @param name
* @return ReturnColType
* @see ReturnColType
*/
static ReturnColType toReturnColType(const std::string& name) {
if (name == kVid) {
return ReturnColType::kVid;
Expand All @@ -49,7 +55,14 @@ class QueryUtils final {
return ReturnColType::kOther;
}
}

/**
* @brief Get value with propName from reader
*
* @param reader Value set
* @param propName Filed name
* @param field Field definition
* @return StatusOr<nebula::Value>
*/
static StatusOr<nebula::Value> readValue(RowReader* reader,
const std::string& propName,
const meta::SchemaProviderIf::Field* field) {
Expand Down Expand Up @@ -84,9 +97,15 @@ class QueryUtils final {
return value;
}

// read prop value, If the RowReader contains this field,
// read from the rowreader, otherwise read the default value
// or null value from the latest schema
/**
* @brief read prop value, If the RowReader contains this field, read from the rowreader,
* otherwise read the default value or null value from the latest schema
*
* @param reader
* @param propName
* @param schema
* @return StatusOr<nebula::Value>
*/
static StatusOr<nebula::Value> readValue(RowReader* reader,
const std::string& propName,
const meta::NebulaSchemaProvider* schema) {
Expand Down Expand Up @@ -215,7 +234,13 @@ class QueryUtils final {
return Status::OK();
}

// return none if no valid ttl, else return the ttl property name and time
/**
* @brief Get the Edge TTL Info object
*
* @param edgeContext
* @param edgeType
* @return return none if no valid ttl, else return the ttl property name and time
*/
static folly::Optional<std::pair<std::string, int64_t>> getEdgeTTLInfo(EdgeContext* edgeContext,
EdgeType edgeType) {
folly::Optional<std::pair<std::string, int64_t>> ret;
Expand All @@ -226,7 +251,13 @@ class QueryUtils final {
return ret;
}

// return none if no valid ttl, else return the ttl property name and time
/**
* @brief Get the Tag TTL Info object
*
* @param tagContext
* @param tagId
* @return return none if no valid ttl, else return the ttl property name and time
*/
static folly::Optional<std::pair<std::string, int64_t>> getTagTTLInfo(TagContext* tagContext,
TagID tagId) {
folly::Optional<std::pair<std::string, int64_t>> ret;
Expand Down
13 changes: 11 additions & 2 deletions src/storage/exec/RelNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ using PropHandler = std::function<nebula::cpp2::ErrorCode(
template <typename T>
class StoragePlan;

// RelNode is shortcut for relational algebra node, each RelNode has an execute
// method, which will be invoked in dag when all its dependencies have finished
/**
* @brief RelNode is shortcut for relational algebra node, each RelNode has an execute method, which
* will be invoked in dag when all its dependencies have finished
*
* @tparam T is input data type of plan
*/
template <typename T>
class RelNode {
friend class StoragePlan<T>;

public:
/**
* @brief start execution with `input` and `partId`
*
*
*/
virtual nebula::cpp2::ErrorCode execute(PartitionID partId, const T& input) {
duration_.resume();
auto ret = doExecute(partId, input);
Expand Down
16 changes: 15 additions & 1 deletion src/storage/exec/ScanNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@ namespace storage {

using Cursor = std::string;

// Node to scan vertices of one partition
/**
* @brief Node to scan vertices of one partition
*/
class ScanVertexPropNode : public QueryNode<Cursor> {
public:
using RelNode<Cursor>::doExecute;

/**
* @brief Construct a new Scan Vertex Prop Node object
*
* @param context
* @param tagNodes
* @param enableReadFollower
* @param limit
* @param cursors
* @param resultDataSet
* @param expCtx
* @param filter
*/
ScanVertexPropNode(RuntimeContext* context,
std::vector<std::unique_ptr<TagNode>> tagNodes,
bool enableReadFollower,
Expand Down
148 changes: 55 additions & 93 deletions src/storage/exec/StorageIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,67 @@
namespace nebula {
namespace storage {

/**
* @brief Storage iterate Interface
*
*/
class StorageIterator {
public:
virtual ~StorageIterator() = default;

/**
* @brief check if there is any data
*
* @return true if there is still data to be accessed
* @return false if there is no data to be accessed
*/
virtual bool valid() const = 0;

// next will skip invalid data, until it points to a valid data or it is
// invalid
/**
* @brief next will skip invalid data, until it points to a valid data or it is invalid
*
*/
virtual void next() = 0;

/**
* @brief Return the key of current data.
*
* All data is iterated in key-value format.
*
* @return folly::StringPiece
*/
virtual folly::StringPiece key() const = 0;

/**
* @brief Return the value of current data.
*
*/
virtual folly::StringPiece val() const = 0;

/**
* @brief Returns the encapsulation of key-value data
*
* @see RowReader
*/
virtual RowReader* reader() const = 0;
};

// Iterator of single specified type
/**
* @brief Iterator of single specified type
*
*/
class SingleEdgeIterator : public StorageIterator {
public:
SingleEdgeIterator() = default;
/**
* @brief Construct a new Single Edge Iterator object
*
* @param context
* @param iter Kvstore's iterator.
* @param edgeType EdgeType to be read.
* @param schemas EdgeType's all version schemas.
* @param ttl
*/
SingleEdgeIterator(RuntimeContext* context,
std::unique_ptr<kvstore::KVIterator> iter,
EdgeType edgeType,
Expand Down Expand Up @@ -83,7 +123,9 @@ class SingleEdgeIterator : public StorageIterator {
}

protected:
// return true when the value iter to a valid edge value
/**
* @brief return true when the value iter to a valid edge value
*/
bool check() {
reader_.reset(*schemas_, iter_->val());
if (!reader_) {
Expand Down Expand Up @@ -113,11 +155,14 @@ class SingleEdgeIterator : public StorageIterator {
VertexID lastDstId_ = "";
};

// Iterator of multiple SingleEdgeIterator, it will iterate over edges of
// different types
/**
* @brief Iterator of multiple SingleEdgeIterator, it will iterate over edges of different types
*/
class MultiEdgeIterator : public StorageIterator {
public:
// will move to a valid SingleEdgeIterator if there is one
/**
* @brief will move to a valid SingleEdgeIterator if there is one
*/
explicit MultiEdgeIterator(std::vector<SingleEdgeIterator*> iters) : iters_(std::move(iters)) {
moveToNextValidIterator();
}
Expand Down Expand Up @@ -149,7 +194,9 @@ class MultiEdgeIterator : public StorageIterator {
return iters_[curIter_]->edgeType();
}

// return the index of multiple iterators
/**
* @brief return the index of multiple iterators
*/
size_t getIdx() const {
return curIter_;
}
Expand All @@ -168,91 +215,6 @@ class MultiEdgeIterator : public StorageIterator {
std::vector<SingleEdgeIterator*> iters_;
size_t curIter_ = 0;
};

class IndexIterator : public StorageIterator {
public:
explicit IndexIterator(std::unique_ptr<kvstore::KVIterator> iter) : iter_(std::move(iter)) {}

virtual IndexID indexId() const = 0;

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

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

folly::StringPiece key() const override {
return iter_->key();
}

folly::StringPiece val() const override {
return iter_->val();
}

protected:
std::unique_ptr<kvstore::KVIterator> iter_;
};

class VertexIndexIterator : public IndexIterator {
public:
VertexIndexIterator(std::unique_ptr<kvstore::KVIterator> iter, size_t vIdLen)
: IndexIterator(std::move(iter)), vIdLen_(vIdLen) {}

RowReader* reader() const override {
return nullptr;
}

IndexID indexId() const override {
return IndexKeyUtils::getIndexId(iter_->key());
}

VertexID vId() const {
return IndexKeyUtils::getIndexVertexID(vIdLen_, iter_->key()).str();
}

folly::StringPiece val() const override {
return iter_->val();
}

protected:
size_t vIdLen_;
};

class EdgeIndexIterator : public IndexIterator {
public:
EdgeIndexIterator(std::unique_ptr<kvstore::KVIterator> iter, size_t vIdLen)
: IndexIterator(std::move(iter)), vIdLen_(vIdLen) {}

RowReader* reader() const override {
return nullptr;
}

IndexID indexId() const override {
return IndexKeyUtils::getIndexId(iter_->key());
}

VertexID srcId() const {
return IndexKeyUtils::getIndexSrcId(vIdLen_, iter_->key()).str();
}

VertexID dstId() const {
return IndexKeyUtils::getIndexDstId(vIdLen_, iter_->key()).str();
}

EdgeRanking ranking() const {
return IndexKeyUtils::getIndexRank(vIdLen_, iter_->key());
}

folly::StringPiece val() const override {
return iter_->val();
}

protected:
size_t vIdLen_;
};

} // namespace storage
} // namespace nebula

Expand Down
38 changes: 19 additions & 19 deletions src/storage/exec/StoragePlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
namespace nebula {
namespace storage {

/*
Originated from folly::FutureDAG, not thread-safe.
The StoragePlan contains a set of RelNode, all you need to do is define a
RelNode, add it to plan by calling addNode, which will return the index of the
RelNode in this plan. The dependencies between different nodes is defined by
calling addDependency in RelNode.
To run the plan, call the go method, you could get the final result.
For simplicity, StoragePlan has not detect if has cycle in it for now, user must
make sure no cycle dependency in it.
For this version, if there are more than one node depends on the same node, that
node will be executed **more than once**. If you want to make sure each node
would be executed exactly once, StoragePlan would be inappropriate. In that
case, please refer to the previous implement, FutureDAG in
StorageDAGBenchmark.cpp
*/
/**
* @brief Storage query plan
*
* The StoragePlan contains a set of RelNode, all you need to do is define a RelNode, add it to plan
* by calling addNode, which will return the index of the RelNode in this plan. The dependencies
* between different nodes is defined by calling addDependency in RelNode.
*
* To run the plan, call the go method, you could get the final result.
*
* For simplicity, StoragePlan has not detect if has cycle in it for now, user must make sure no
* cycle dependency in it.
*
* For this version, if there are more than one node depends on the same node, that node will be
* executed **more than once**. If you want to make sure each node would be executed exactly once,
* StoragePlan would be inappropriate. In that case, please refer to the previous implement,
* FutureDAG in StorageDAGBenchmark.cpp
*
* @tparam T Iterated data type
*/
template <typename T>
class StoragePlan {
public:
Expand Down
Loading

0 comments on commit 17b38e6

Please sign in to comment.