Skip to content

Commit

Permalink
stats handle the flag use_vertex_key (#4738)
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 authored and Sophie-Xie committed Oct 20, 2022
1 parent 5593627 commit f1ad49e
Showing 1 changed file with 19 additions and 1 deletion.
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

0 comments on commit f1ad49e

Please sign in to comment.