forked from syndtr/goleveldb
-
Notifications
You must be signed in to change notification settings - Fork 6
/
parse_db.py
79 lines (61 loc) · 1.75 KB
/
parse_db.py
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
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import optparse
import os
import logging.handlers
from db.db import (
Journal,
SessionRecord,
Manifest
)
from db.db import SStTableMeta
from db.util import show_table
def main(options):
mani = Manifest(options.path)
sessions = mani.recover_journals()
session_header = SessionRecord().header()
session_rows = []
sst_header = ["op"] + SStTableMeta(0, 0).header()
sst_rows = []
sst_alives_rows = []
sst_adds = {}
sst_dels = {}
for sess in sessions:
row = sess.generate_row()
session_rows.append(row)
for t in sess.added_tables:
row = ["Add"] + t.generate_row()
sst_rows.append(row)
sst_adds[t.num] = t
for t in sess.delete_tables:
row = ["Del"] + t.generate_row()
sst_rows.append(row)
sst_dels[t.num] = t
# alives
alives_nums = set(sst_adds.keys()) - set(sst_dels.keys())
for num, t in sst_adds.items():
if num not in alives_nums:
continue
row = ["Live"] + t.generate_row()
sst_alives_rows.append(row)
print("===== Session Records ====")
show_table(session_header, session_rows)
print()
print()
print("==== sst tables ====")
show_table(sst_header, sst_rows)
print()
print()
print("==== alive sst tables ====")
show_table(sst_header, sst_alives_rows)
print()
print()
if __name__ == "__main__":
usage = "usage: %prog [options] arg"
parser = optparse.OptionParser(usage)
# 互斥模式
parser.add_option("-f", "--file", type=str, dest="path",
help="manifest file path")
args = parser.parse_args()
options = args[0]
main(options)