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

stats handle the flag use_vertex_key #4738

Merged
merged 1 commit into from
Oct 19, 2022
Merged
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
20 changes: 19 additions & 1 deletion src/storage/admin/StatsTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "common/base/MurmurHash2.h"
#include "common/utils/NebulaKeyUtils.h"
#include "kvstore/Common.h"
#include "storage/StorageFlags.h"

DEFINE_int32(stats_sleep_interval_ms,
0,
Expand Down Expand Up @@ -111,6 +112,8 @@ nebula::cpp2::ErrorCode StatsTask::genSubTask(GraphSpaceID spaceId,
std::unique_ptr<kvstore::KVIterator> tagIter;
auto edgePrefix = NebulaKeyUtils::edgePrefix(part);
std::unique_ptr<kvstore::KVIterator> edgeIter;
auto vertexPrefix = NebulaKeyUtils::vertexPrefix(part);
std::unique_ptr<kvstore::KVIterator> vertexIter;

// When the storage occurs leader change, continue to read data from the
// follower instead of reporting an error.
Expand All @@ -124,6 +127,13 @@ nebula::cpp2::ErrorCode StatsTask::genSubTask(GraphSpaceID spaceId,
LOG(INFO) << "Stats task failed";
return ret;
}
if (FLAGS_use_vertex_key) {
ret = env_->kvstore_->prefix(spaceId, part, vertexPrefix, &vertexIter, true);
if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(INFO) << "Stats task failed";
return ret;
}
}
std::unordered_map<TagID, int64_t> tagsVertices;
std::unordered_map<EdgeType, int64_t> edgetypeEdges;
std::unordered_map<PartitionID, int64_t> positiveRelevancy;
Expand Down Expand Up @@ -230,6 +240,14 @@ nebula::cpp2::ErrorCode StatsTask::genSubTask(GraphSpaceID spaceId,
edgeIter->next();
sleepIfScannedSomeRecord(++countToSleep);
}
int64_t verticesCountByVertexKey = 0;
if (FLAGS_use_vertex_key) {
while (vertexIter && vertexIter->valid()) {
verticesCountByVertexKey++;
vertexIter->next();
sleepIfScannedSomeRecord(++countToSleep);
}
}
nebula::meta::cpp2::StatsItem statsItem;

// convert tagId/edgeType to tagName/edgeName
Expand All @@ -246,7 +264,7 @@ nebula::cpp2::ErrorCode StatsTask::genSubTask(GraphSpaceID spaceId,
}
}

statsItem.space_vertices_ref() = spaceVertices;
statsItem.space_vertices_ref() = FLAGS_use_vertex_key ? verticesCountByVertexKey : spaceVertices;
statsItem.space_edges_ref() = spaceEdges;
using Correlativities = std::vector<nebula::meta::cpp2::Correlativity>;
Correlativities positiveCorrelativity;
Expand Down