forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDumpEdgesTool.cpp
71 lines (64 loc) · 2.14 KB
/
DumpEdgesTool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Copyright (c) 2019 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#include "utils/NebulaKeyUtils.h"
#include <rocksdb/db.h>
DEFINE_string(path, "", "rocksdb instance path");
DEFINE_int64(vertex_id, 0, "Specify the vertex id");
DEFINE_int64(parts_num, 100, "Specify the parts number");
namespace nebula {
class DumpEdges {
public:
static void scan(const char* path) {
LOG(INFO) << "open rocksdb on " << path;
rocksdb::DB* db = nullptr;
rocksdb::Options options;
auto status = rocksdb::DB::OpenForReadOnly(options, path, &db);
CHECK(status.ok()) << status.ToString();
rocksdb::ReadOptions roptions;
rocksdb::Iterator* iter = db->NewIterator(roptions);
if (!iter) {
LOG(FATAL) << "null iterator!";
}
if (FLAGS_vertex_id != 0) {
auto partId = FLAGS_vertex_id % FLAGS_parts_num + 1;
auto prefix = NebulaKeyUtils::edgePrefix(partId, FLAGS_vertex_id);
iter->Seek(prefix);
} else {
iter->SeekToFirst();
}
size_t count = 0;
while (iter->Valid()) {
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
if (NebulaKeyUtils::isEdge(key)) {
LOG(INFO) << NebulaKeyUtils::getSrcId(key) << "," << NebulaKeyUtils::getDstId(key);
count++;
}
iter->Next();
}
LOG(INFO) << "Total edges:" << count;
if (iter) {
delete iter;
}
if (db) {
db->Close();
delete db;
}
}
};
} // namespace nebula
int main(int argc, char *argv[]) {
folly::init(&argc, &argv, true);
google::SetStderrLogging(google::INFO);
LOG(INFO) << "path:" << FLAGS_path
<< ", vertex_id:" << FLAGS_vertex_id
<< ", parts_num:" << FLAGS_parts_num;
if (FLAGS_path.empty()) {
LOG(INFO) << "Specify the path!";
return -1;
}
nebula::DumpEdges::scan(FLAGS_path.c_str());
return 0;
}