MCPcopy Create free account
hub / github.com/e2wugui/zeze / DumpRocksDb

Class DumpRocksDb

ZezeJava/ZezeJava/src/main/java/Zeze/Util/DumpRocksDb.java:40–506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38二者都整理log文件到sst中, 后者还会把0级文件整理合并到1级文件
39*/
40public final class DumpRocksDb {
41 public static void main(String[] args) throws Exception {
42 int argCount = args.length;
43 for (; argCount > 0; argCount--) {
44 var arg = args[argCount - 1];
45 if (!arg.startsWith("-") || arg.length() <= 1)
46 break;
47 int p = arg.indexOf('=', 1);
48 if (p >= 0)
49 System.setProperty(arg.substring(1, p), arg.substring(p + 1));
50 else
51 System.setProperty(arg.substring(1), "true");
52 }
53 if (argCount < 1) {
54 System.err.println("usage: java -cp ... " + DumpRocksDb.class.getName() +
55 " inputDbPath [[columnFamilyName] outputTxtFile] [options]");
56 System.err.println("options: -meta list database meta data");
57 System.err.println(" -compact compact database files");
58 System.err.println(" -compact1 compact level-0 files to level-1");
59 System.err.println(" -key=long decode key as long");
60 System.err.println(" string decode key as string");
61 System.err.println(" nstring decode key as len-prefix string");
62 System.err.println(" bean decode key as bean");
63 System.err.println(" -value=bean decode value as bean");
64 System.err.println(" raftLog decode value as raft logs for global server");
65 return;
66 }
67 var inputDbPath = args[0];
68 var columnFamilyName = argCount > 2 ? args[1] : null;
69 var outputTxtFile = argCount == 1 ? null : argCount == 2 ? args[1] : args[2];
70 var columnFamilies = new ArrayList<ColumnFamilyDescriptor>();
71 var cfOptions = new ColumnFamilyOptions();
72 var dbOptions = new DBOptions();
73 for (var cf : RocksDB.listColumnFamilies(new Options(), inputDbPath))
74 columnFamilies.add(new ColumnFamilyDescriptor(cf, cfOptions));
75 if (columnFamilies.isEmpty())
76 columnFamilies.add(new ColumnFamilyDescriptor("default".getBytes(UTF_8), cfOptions));
77
78 if ("true".equalsIgnoreCase(System.getProperty("meta"))) {
79 var outHandles = new ArrayList<ColumnFamilyHandle>(columnFamilies.size());
80 var levelCount = new int[8];
81 var levelSize = new long[8];
82 long totalCount = 0, totalSize = 0;
83 try (var rocksDb = RocksDB.openReadOnly(dbOptions, inputDbPath, columnFamilies, outHandles)) {
84 System.out.println("lvl fileName size seqNumMin seqNumMax reads entry delete columnFamilyName");
85 System.out.println("-------------------------------------------------------------------------------");
86 var metaList = rocksDb.getLiveFilesMetaData();
87 metaList.sort(
88 Comparator.comparingInt(LiveFileMetaData::level).thenComparing(SstFileMetaData::fileName));
89 for (var meta : metaList) {
90 var fileName = meta.fileName();
91 if (fileName.startsWith("/"))
92 fileName = fileName.substring(1);
93 System.out.format("%d %10s%9d %10d %10d %5d %5d %6d %s\n", meta.level(), fileName, meta.size(),
94 meta.smallestSeqno(), meta.largestSeqno(), meta.numReadsSampled(), meta.numEntries(),
95 meta.numDeletions(), new String(meta.columnFamilyName(), UTF_8));
96 levelCount[meta.level()]++;
97 levelSize[meta.level()] += meta.size();

Callers

nothing calls this directly

Calls 15

dumpMethod · 0.95
toStrMethod · 0.95
hash32Method · 0.80
putMethod · 0.65
ReadBoolMethod · 0.65
ReadLongMethod · 0.65
ReadFloatMethod · 0.65
ReadDoubleMethod · 0.65
ReadStringMethod · 0.65
ReadBytesMethod · 0.65
writeMethod · 0.65
ReadUIntMethod · 0.65

Tested by

no test coverage detected