Skip to content

Commit a8bf021

Browse files
committed
Add subcommand to compact the database
1 parent 0570f9e commit a8bf021

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

scripts/gethimport.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@ def read_trinity(location):
507507
logger.info(f'canonical_head={canonical_head}')
508508

509509

510+
def compact(chain):
511+
logger.info('this might take a while')
512+
leveldb = chain.headerdb.db.db # what law of demeter?
513+
leveldb.compact_range()
514+
515+
510516
if __name__ == "__main__":
511517
logging.basicConfig(
512518
level=logging.DEBUG,
@@ -594,6 +600,12 @@ def read_trinity(location):
594600
)
595601
read_geth_parser.add_argument('-gethdb', type=str, required=True)
596602

603+
compact_parser = subparsers.add_parser(
604+
"compact",
605+
help="Runs a compaction over the database, do this after importing state!",
606+
)
607+
compact_parser.add_argument('-destdb', type=str, required=True)
608+
597609
args = parser.parse_args()
598610

599611
if args.command == 'import_body_range':
@@ -620,5 +632,8 @@ def read_trinity(location):
620632
gethdb = open_gethdb(args.gethdb)
621633
chain = open_trinitydb(args.destdb)
622634
sweep_state(gethdb, chain.headerdb.db)
635+
elif args.command == 'compact':
636+
chain = open_trinitydb(args.destdb)
637+
compact(chain)
623638
else:
624639
logger.error(f'unrecognized command. command={args.command}')

0 commit comments

Comments
 (0)