Skip to content

Commit 3d105f2

Browse files
add more table in meta dump (#3870)
* add more table in meta dump * add some prefix func * add meta version Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
1 parent 8e5a30a commit 3d105f2

File tree

3 files changed

+143
-17
lines changed

3 files changed

+143
-17
lines changed

src/common/utils/MetaKeyUtils.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@ std::string MetaKeyUtils::schemaEdgesPrefix(GraphSpaceID spaceId) {
524524
return key;
525525
}
526526

527+
const std::string& MetaKeyUtils::schemaEdgesPrefix() {
528+
return kEdgesTable;
529+
}
530+
527531
std::string MetaKeyUtils::schemaEdgeKey(GraphSpaceID spaceId,
528532
EdgeType edgeType,
529533
SchemaVer version) {
@@ -590,6 +594,10 @@ std::string MetaKeyUtils::schemaTagPrefix(GraphSpaceID spaceId, TagID tagId) {
590594
return key;
591595
}
592596

597+
const std::string& MetaKeyUtils::schemaTagsPrefix() {
598+
return kTagsTable;
599+
}
600+
593601
std::string MetaKeyUtils::schemaTagsPrefix(GraphSpaceID spaceId) {
594602
std::string key;
595603
key.reserve(kTagsTable.size() + sizeof(GraphSpaceID));
@@ -625,6 +633,10 @@ std::string MetaKeyUtils::indexVal(const nebula::meta::cpp2::IndexItem& item) {
625633
return value;
626634
}
627635

636+
const std::string& MetaKeyUtils::indexPrefix() {
637+
return kIndexesTable;
638+
}
639+
628640
std::string MetaKeyUtils::indexPrefix(GraphSpaceID spaceId) {
629641
std::string key;
630642
key.reserve(kIndexesTable.size() + sizeof(GraphSpaceID));
@@ -1237,7 +1249,10 @@ GraphSpaceID MetaKeyUtils::parseLocalIdSpace(folly::StringPiece rawData) {
12371249
}
12381250

12391251
/**
1240-
* diskPartsKey = kDiskPartsTable + len(serialized(hostAddr)) + serialized(hostAddr) + path
1252+
* diskPartsKey = kDiskPartsTable +
1253+
* len(serialized(hostAddr)) + serialized(hostAddr) +
1254+
* space id +
1255+
* disk path
12411256
*/
12421257

12431258
HostAddr MetaKeyUtils::parseDiskPartsHost(const folly::StringPiece& rawData) {

src/common/utils/MetaKeyUtils.h

+6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class MetaKeyUtils final {
182182

183183
static std::string schemaEdgesPrefix(GraphSpaceID spaceId);
184184

185+
static const std::string& schemaEdgesPrefix();
186+
185187
static std::string schemaEdgeKey(GraphSpaceID spaceId, EdgeType edgeType, SchemaVer version);
186188

187189
static EdgeType parseEdgeType(folly::StringPiece key);
@@ -198,6 +200,8 @@ class MetaKeyUtils final {
198200

199201
static std::string schemaTagsPrefix(GraphSpaceID spaceId);
200202

203+
static const std::string& schemaTagsPrefix();
204+
201205
static meta::cpp2::Schema parseSchema(folly::StringPiece rawData);
202206

203207
static std::string indexKey(GraphSpaceID spaceId, IndexID indexID);
@@ -206,6 +210,8 @@ class MetaKeyUtils final {
206210

207211
static std::string indexPrefix(GraphSpaceID spaceId);
208212

213+
static const std::string& indexPrefix();
214+
209215
static IndexID parseIndexesKeyIndexID(folly::StringPiece key);
210216

211217
static meta::cpp2::IndexItem parseIndex(const folly::StringPiece& rawData);

src/tools/meta-dump/MetaDumpTool.cpp

+121-16
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,49 @@ class MetaDumper {
3131
if (!iter) {
3232
return Status::Error("Init iterator failed");
3333
}
34+
3435
std::string prefix;
3536
{
36-
LOG(INFO) << "Space info";
37-
prefix = "__spaces__";
37+
LOG(INFO) << "------------------------------------------\n\n";
38+
LOG(INFO) << "Meta version:";
39+
enum class MetaVersion {
40+
UNKNOWN = 0,
41+
V1 = 1,
42+
V2 = 2,
43+
V3 = 3,
44+
};
45+
46+
prefix = "__meta_version__";
47+
iter->Seek(rocksdb::Slice(prefix));
48+
bool found = false;
49+
while (iter->Valid() && iter->key().starts_with(prefix)) {
50+
auto version = *reinterpret_cast<const MetaVersion*>(iter->value().data());
51+
found = true;
52+
LOG(INFO) << "Meta version=" << static_cast<int>(version);
53+
break;
54+
}
55+
56+
if (!found) {
57+
prefix = MetaKeyUtils::hostPrefix();
58+
iter->Seek(rocksdb::Slice(prefix));
59+
while (iter->Valid() && iter->key().starts_with(prefix)) {
60+
found = true;
61+
auto v1KeySize = prefix.size() + sizeof(int64_t);
62+
auto version = (iter->key().size() == v1KeySize) ? MetaVersion::V1 : MetaVersion::V3;
63+
LOG(INFO) << "Meta version=" << static_cast<int>(version);
64+
iter->Next();
65+
break;
66+
}
67+
68+
if (!found) {
69+
LOG(INFO) << "Meta version= Unkown";
70+
}
71+
}
72+
}
73+
{
74+
LOG(INFO) << "------------------------------------------\n\n";
75+
LOG(INFO) << "Space info:";
76+
prefix = MetaKeyUtils::spacePrefix();
3877
iter->Seek(rocksdb::Slice(prefix));
3978
while (iter->Valid() && iter->key().starts_with(prefix)) {
4079
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
@@ -52,8 +91,9 @@ class MetaDumper {
5291
}
5392
}
5493
{
55-
LOG(INFO) << "Partition info";
56-
prefix = "__parts__";
94+
LOG(INFO) << "------------------------------------------\n\n";
95+
LOG(INFO) << "Partition info::";
96+
prefix = MetaKeyUtils::partPrefix();
5797
iter->Seek(rocksdb::Slice(prefix));
5898
while (iter->Valid() && iter->key().starts_with(prefix)) {
5999
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
@@ -71,8 +111,21 @@ class MetaDumper {
71111
}
72112
}
73113
{
74-
LOG(INFO) << "Host info";
75-
prefix = "__hosts__";
114+
LOG(INFO) << "------------------------------------------\n\n";
115+
LOG(INFO) << "Registered machine info:";
116+
prefix = MetaKeyUtils::machinePrefix();
117+
iter->Seek(rocksdb::Slice(prefix));
118+
while (iter->Valid() && iter->key().starts_with(prefix)) {
119+
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
120+
auto machine = MetaKeyUtils::parseMachineKey(key);
121+
LOG(INFO) << folly::sformat("registered machine: {}", machine.toString());
122+
iter->Next();
123+
}
124+
}
125+
{
126+
LOG(INFO) << "------------------------------------------\n\n";
127+
LOG(INFO) << "Host info:";
128+
prefix = MetaKeyUtils::hostPrefix();
76129
iter->Seek(rocksdb::Slice(prefix));
77130
while (iter->Valid() && iter->key().starts_with(prefix)) {
78131
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
@@ -87,8 +140,56 @@ class MetaDumper {
87140
}
88141
}
89142
{
90-
LOG(INFO) << "Tag info";
91-
prefix = "__tags__";
143+
LOG(INFO) << "------------------------------------------\n\n";
144+
LOG(INFO) << "Host directories info:";
145+
prefix = MetaKeyUtils::hostDirPrefix();
146+
iter->Seek(rocksdb::Slice(prefix));
147+
while (iter->Valid() && iter->key().starts_with(prefix)) {
148+
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
149+
auto val = folly::StringPiece(iter->value().data(), iter->value().size());
150+
auto addr = MetaKeyUtils::parseHostDirKey(key);
151+
auto dir = MetaKeyUtils::parseHostDir(val);
152+
153+
std::string dataDirs = "";
154+
for (auto d : dir.get_data()) {
155+
dataDirs += d + ", ";
156+
}
157+
LOG(INFO) << folly::sformat("host addr: {}, data dirs: {}, root dir: {}",
158+
addr.toString(),
159+
dataDirs,
160+
dir.get_root());
161+
iter->Next();
162+
}
163+
}
164+
{
165+
LOG(INFO) << "------------------------------------------\n\n";
166+
LOG(INFO) << "Disk partitions info:";
167+
prefix = MetaKeyUtils::diskPartsPrefix();
168+
iter->Seek(rocksdb::Slice(prefix));
169+
while (iter->Valid() && iter->key().starts_with(prefix)) {
170+
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
171+
auto val = folly::StringPiece(iter->value().data(), iter->value().size());
172+
auto addr = MetaKeyUtils::parseDiskPartsHost(key);
173+
auto spaceId = MetaKeyUtils::parseDiskPartsSpace(key);
174+
auto diskPath = MetaKeyUtils::parseDiskPartsPath(key);
175+
auto parts = MetaKeyUtils::parseDiskPartsVal(val);
176+
177+
std::string partsStr = "";
178+
for (auto p : parts.get_part_list()) {
179+
partsStr += (std::to_string(p) + ", ");
180+
}
181+
LOG(INFO) << folly::sformat("host addr: {}, data dir: {}, space id: {}, parts: {}",
182+
addr.toString(),
183+
diskPath,
184+
spaceId,
185+
partsStr);
186+
iter->Next();
187+
}
188+
}
189+
{
190+
LOG(INFO) << "------------------------------------------\n\n";
191+
LOG(INFO) << "Tag info:";
192+
prefix = MetaKeyUtils::schemaTagsPrefix();
92193
iter->Seek(rocksdb::Slice(prefix));
93194
while (iter->Valid() && iter->key().starts_with(prefix)) {
94195
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
@@ -100,8 +201,9 @@ class MetaDumper {
100201
}
101202
}
102203
{
103-
LOG(INFO) << "Edge info";
104-
prefix = "__edges__";
204+
LOG(INFO) << "------------------------------------------\n\n";
205+
LOG(INFO) << "Edge info:";
206+
prefix = MetaKeyUtils::schemaEdgesPrefix();
105207
iter->Seek(rocksdb::Slice(prefix));
106208
while (iter->Valid() && iter->key().starts_with(prefix)) {
107209
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
@@ -113,8 +215,9 @@ class MetaDumper {
113215
}
114216
}
115217
{
116-
LOG(INFO) << "Index info";
117-
prefix = "__indexes__";
218+
LOG(INFO) << "------------------------------------------\n\n";
219+
LOG(INFO) << "Index info:";
220+
prefix = MetaKeyUtils::indexPrefix();
118221
iter->Seek(rocksdb::Slice(prefix));
119222
while (iter->Valid() && iter->key().starts_with(prefix)) {
120223
auto key = folly::StringPiece(iter->key().data(), iter->key().size());
@@ -125,8 +228,9 @@ class MetaDumper {
125228
}
126229
}
127230
{
128-
LOG(INFO) << "Leader info";
129-
prefix = "__leader_terms__";
231+
LOG(INFO) << "------------------------------------------\n\n";
232+
LOG(INFO) << "Leader info:";
233+
prefix = MetaKeyUtils::leaderPrefix();
130234
HostAddr host;
131235
TermID term;
132236
nebula::cpp2::ErrorCode code;
@@ -152,8 +256,9 @@ class MetaDumper {
152256
}
153257
}
154258
{
155-
LOG(INFO) << "Zone info";
156-
prefix = "__zones__";
259+
LOG(INFO) << "------------------------------------------\n\n";
260+
LOG(INFO) << "Zone info:";
261+
prefix = MetaKeyUtils::zonePrefix();
157262
iter->Seek(rocksdb::Slice(prefix));
158263
while (iter->Valid() && iter->key().starts_with(prefix)) {
159264
auto key = folly::StringPiece(iter->key().data(), iter->key().size());

0 commit comments

Comments
 (0)