@@ -442,7 +442,6 @@ Range MetaCodec::GetFsStatsRange(uint32_t fs_id) {
442
442
}
443
443
444
444
// lock format: ${prefix} kTableMeta kMetaLock {name}
445
-
446
445
static const uint32_t kLockKeyHeaderSize = kPrefixSize + 2 ; // prefix + table id + meta type
447
446
448
447
bool MetaCodec::IsLockKey (const std::string& key) {
@@ -1103,5 +1102,265 @@ FsStatsDataEntry MetaCodec::DecodeFsStatsValue(const std::string& value) {
1103
1102
return std::move (stats);
1104
1103
}
1105
1104
1105
+ bool MetaCodec::IsMetaTableKey (const std::string& key) {
1106
+ if (key.size () <= kPrefixSize + 1 ) {
1107
+ return false ;
1108
+ }
1109
+
1110
+ if (key.substr (0 , kPrefixSize ) != kPrefix || key.at (kPrefixSize ) != kTableMeta ) {
1111
+ return false ;
1112
+ }
1113
+
1114
+ return true ;
1115
+ }
1116
+
1117
+ bool MetaCodec::IsFsStatsTableKey (const std::string& key) {
1118
+ if (key.size () <= kPrefixSize + 1 ) {
1119
+ return false ;
1120
+ }
1121
+
1122
+ if (key.substr (0 , kPrefixSize ) != kPrefix || key.at (kPrefixSize ) != kTableFsStats ) {
1123
+ return false ;
1124
+ }
1125
+
1126
+ return true ;
1127
+ }
1128
+
1129
+ bool MetaCodec::IsFsMetaTableKey (const std::string& key) {
1130
+ if (key.size () <= kPrefixSize + 1 ) {
1131
+ return false ;
1132
+ }
1133
+
1134
+ if (key.substr (0 , kPrefixSize ) != kPrefix || key.at (kPrefixSize ) != kTableFsMeta ) {
1135
+ return false ;
1136
+ }
1137
+
1138
+ return true ;
1139
+ }
1140
+
1141
+ std::pair<std::string, std::string> MetaCodec::ParseMetaTableKey (const std::string& key, const std::string& value) {
1142
+ std::string key_desc, value_desc;
1143
+
1144
+ MetaType meta_type = static_cast <MetaType>(key.at (kPrefixSize + 1 ));
1145
+ switch (meta_type) {
1146
+ case kMetaLock : {
1147
+ std::string name;
1148
+ DecodeLockKey (key, name);
1149
+
1150
+ key_desc = fmt::format (" {} kTableMeta kMetaLock {}" , kPrefix , name);
1151
+
1152
+ int64_t mds_id;
1153
+ uint64_t epoch;
1154
+ uint64_t expire_time_ms;
1155
+ DecodeLockValue (value, mds_id, epoch, expire_time_ms);
1156
+
1157
+ value_desc = fmt::format (" {} {} {}" , mds_id, epoch, expire_time_ms);
1158
+ } break ;
1159
+
1160
+ case kMetaAutoIncrement : {
1161
+ std::string name;
1162
+ DecodeAutoIncrementIDKey (key, name);
1163
+
1164
+ key_desc = fmt::format (" {} kTableMeta kMetaAutoIncrement {}" , kPrefix , name);
1165
+
1166
+ uint64_t next_id;
1167
+ DecodeAutoIncrementIDValue (value, next_id);
1168
+
1169
+ value_desc = fmt::format (" {} {}" , next_id);
1170
+ } break ;
1171
+
1172
+ case kMetaHeartbeat : {
1173
+ pb::mdsv2::Role role = static_cast <pb::mdsv2::Role>(key.at (kPrefixSize + 2 ));
1174
+ if (role == pb::mdsv2::ROLE_MDS) {
1175
+ int64_t mds_id;
1176
+ DecodeHeartbeatKey (key, mds_id);
1177
+
1178
+ key_desc = fmt::format (" {} kTableMeta kMetaHeartbeat kRoleMds {}" , kPrefix , mds_id);
1179
+
1180
+ auto mds_info = DecodeHeartbeatMdsValue (value);
1181
+ value_desc = mds_info.ShortDebugString ();
1182
+
1183
+ } else if (role == pb::mdsv2::ROLE_CLIENT) {
1184
+ std::string client_id;
1185
+ DecodeHeartbeatKey (key, client_id);
1186
+
1187
+ key_desc = fmt::format (" {} kTableMeta kMetaHeartbeat kRoleClient {}" , kPrefix , client_id);
1188
+
1189
+ auto client_info = DecodeHeartbeatClientValue (value);
1190
+ value_desc = client_info.ShortDebugString ();
1191
+ }
1192
+
1193
+ } break ;
1194
+
1195
+ case kMetaFs : {
1196
+ std::string name;
1197
+ DecodeFsKey (key, name);
1198
+ key_desc = fmt::format (" {} kTableMeta kMetaFs {}" , kPrefix , name);
1199
+
1200
+ auto fs_info = DecodeFsValue (value);
1201
+ value_desc = fs_info.ShortDebugString ();
1202
+
1203
+ } break ;
1204
+
1205
+ case kMetaFsQuota : {
1206
+ uint32_t fs_id;
1207
+ DecodeFsQuotaKey (key, fs_id);
1208
+ key_desc = fmt::format (" {} kTableMeta kMetaFsQuota {}" , kPrefix , fs_id);
1209
+
1210
+ auto quota = DecodeFsQuotaValue (value);
1211
+ value_desc = quota.ShortDebugString ();
1212
+
1213
+ } break ;
1214
+
1215
+ default :
1216
+ CHECK (false ) << fmt::format (" invalid meta type({}) key({})." , static_cast <int >(meta_type),
1217
+ Helper::StringToHex (key));
1218
+ }
1219
+
1220
+ return std::make_pair (std::move (key_desc), std::move (value_desc));
1221
+ }
1222
+
1223
+ std::pair<std::string, std::string> MetaCodec::ParseFsStatsTableKey (const std::string& key, const std::string& value) {
1224
+ CHECK (IsFsStatsKey (key)) << fmt::format (" invalid fs stats key({})." , Helper::StringToHex (key));
1225
+
1226
+ std::string key_desc, value_desc;
1227
+
1228
+ uint32_t fs_id;
1229
+ uint64_t time_ns;
1230
+ DecodeFsStatsKey (key, fs_id, time_ns);
1231
+ key_desc = fmt::format (" {} kTableFsStats kMetaFsStats {} {}" , kPrefix , fs_id, time_ns);
1232
+
1233
+ auto fs_stats = DecodeFsStatsValue (value);
1234
+ value_desc = fs_stats.ShortDebugString ();
1235
+
1236
+ return std::make_pair (std::move (key_desc), std::move (value_desc));
1237
+ }
1238
+
1239
+ std::pair<std::string, std::string> MetaCodec::ParseFsMetaTableKey (const std::string& key, const std::string& value) {
1240
+ CHECK (IsFsMetaTableKey (key)) << fmt::format (" invalid fs meta key({})." , Helper::StringToHex (key));
1241
+
1242
+ std::string key_desc, value_desc;
1243
+
1244
+ MetaType meta_type = static_cast <MetaType>(key.at (kPrefixSize + 1 + 4 ));
1245
+ switch (meta_type) {
1246
+ case kMetaFsInode : {
1247
+ FsInodeType inode_type = static_cast <FsInodeType>(key.at (kPrefixSize + 1 + 4 + 1 + 8 ));
1248
+ switch (inode_type) {
1249
+ case kFsInodeAttr : {
1250
+ uint32_t fs_id;
1251
+ Ino ino;
1252
+ DecodeInodeKey (key, fs_id, ino);
1253
+
1254
+ key_desc = fmt::format (" {} kTableFsMeta {} kMetaFsInode {} kFsInodeAttr" , kPrefix , fs_id, ino);
1255
+
1256
+ auto attr = DecodeInodeValue (value);
1257
+ value_desc = attr.ShortDebugString ();
1258
+ } break ;
1259
+
1260
+ case kFsInodeDentry : {
1261
+ uint32_t fs_id;
1262
+ Ino ino;
1263
+ std::string name;
1264
+ DecodeDentryKey (key, fs_id, ino, name);
1265
+
1266
+ key_desc = fmt::format (" {} kTableFsMeta {} kMetaFsInode {} kFsInodeDentry {}" , kPrefix , fs_id, ino, name);
1267
+
1268
+ auto dentry = DecodeDentryValue (value);
1269
+ value_desc = dentry.ShortDebugString ();
1270
+ } break ;
1271
+
1272
+ case kFsInodeChunk : {
1273
+ uint32_t fs_id;
1274
+ Ino ino;
1275
+ uint64_t chunk_index;
1276
+ DecodeChunkKey (key, fs_id, ino, chunk_index);
1277
+
1278
+ key_desc =
1279
+ fmt::format (" {} kTableFsMeta {} kMetaFsInode {} kFsInodeChunk {}" , kPrefix , fs_id, ino, chunk_index);
1280
+
1281
+ auto chunk = DecodeChunkValue (value);
1282
+ value_desc = chunk.ShortDebugString ();
1283
+ } break ;
1284
+
1285
+ default :
1286
+ CHECK (false ) << fmt::format (" invalid inode type({}) key({})." , static_cast <int >(inode_type),
1287
+ Helper::StringToHex (key));
1288
+ }
1289
+ } break ;
1290
+
1291
+ case kMetaFsFileSession : {
1292
+ uint32_t fs_id;
1293
+ Ino ino;
1294
+ std::string session_id;
1295
+ DecodeFileSessionKey (key, fs_id, ino, session_id);
1296
+
1297
+ key_desc = fmt::format (" {} kTableFsMeta {} kMetaFsFileSession {} {}" , kPrefix , fs_id, ino, session_id);
1298
+
1299
+ auto file_session = DecodeFileSessionValue (value);
1300
+ value_desc = file_session.ShortDebugString ();
1301
+ } break ;
1302
+
1303
+ case kMetaFsDirQuota : {
1304
+ uint32_t fs_id;
1305
+ Ino ino;
1306
+ DecodeDirQuotaKey (key, fs_id, ino);
1307
+
1308
+ key_desc = fmt::format (" {} kTableFsMeta {} kMetaFsDirQuota {}" , kPrefix , fs_id, ino);
1309
+
1310
+ auto dir_quota = DecodeDirQuotaValue (value);
1311
+ value_desc = dir_quota.ShortDebugString ();
1312
+
1313
+ } break ;
1314
+ case kMetaFsDelSlice : {
1315
+ uint32_t fs_id;
1316
+ Ino ino;
1317
+ uint64_t chunk_index;
1318
+ uint64_t time_ns;
1319
+ DecodeDelSliceKey (key, fs_id, ino, chunk_index, time_ns);
1320
+
1321
+ key_desc = fmt::format (" {} kTableFsMeta {} kMetaFsDelSlice {} {} {}" , kPrefix , fs_id, ino, chunk_index, time_ns);
1322
+
1323
+ auto del_slice = DecodeDelSliceValue (value);
1324
+ value_desc = del_slice.ShortDebugString ();
1325
+ } break ;
1326
+
1327
+ case kMetaFsDelFile : {
1328
+ uint32_t fs_id;
1329
+ Ino ino;
1330
+ DecodeDelFileKey (key, fs_id, ino);
1331
+
1332
+ key_desc = fmt::format (" {} kTableFsMeta {} kMetaFsDelFile {} {}" , kPrefix , fs_id, ino);
1333
+
1334
+ auto del_file = DecodeDelFileValue (value);
1335
+ value_desc = del_file.ShortDebugString ();
1336
+ } break ;
1337
+
1338
+ default :
1339
+ CHECK (false ) << fmt::format (" invalid meta type({}) key({})." , static_cast <int >(meta_type),
1340
+ Helper::StringToHex (key));
1341
+ }
1342
+
1343
+ return std::make_pair (std::move (key_desc), std::move (value_desc));
1344
+ }
1345
+
1346
+ std::pair<std::string, std::string> MetaCodec::ParseKey (const std::string& key, const std::string& value) {
1347
+ TableID table_id = static_cast <TableID>(key.at (kPrefixSize ));
1348
+ switch (table_id) {
1349
+ case kTableMeta :
1350
+ return ParseMetaTableKey (key, value);
1351
+ case kTableFsStats :
1352
+
1353
+ return ParseFsStatsTableKey (key, value);
1354
+ case kTableFsMeta :
1355
+ return ParseFsMetaTableKey (key, value);
1356
+
1357
+ default :
1358
+ CHECK (false ) << fmt::format (" invalid table id({}) key({})." , static_cast <int >(table_id),
1359
+ Helper::StringToHex (key));
1360
+ }
1361
+
1362
+ return {};
1363
+ }
1364
+
1106
1365
} // namespace mdsv2
1107
1366
} // namespace dingofs
0 commit comments