Skip to content

Commit 513e207

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

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scripts/gethimport.py

+19
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,16 @@ 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+
description="""
607+
If the database is not compacted it will compact itself at an
608+
unconvenient time, freezing your process for uncomfortably long.
609+
"""
610+
)
611+
compact_parser.add_argument('-destdb', type=str, required=True)
612+
597613
args = parser.parse_args()
598614

599615
if args.command == 'import_body_range':
@@ -620,5 +636,8 @@ def read_trinity(location):
620636
gethdb = open_gethdb(args.gethdb)
621637
chain = open_trinitydb(args.destdb)
622638
sweep_state(gethdb, chain.headerdb.db)
639+
elif args.command == 'compact':
640+
chain = open_trinitydb(args.destdb)
641+
compact(chain)
623642
else:
624643
logger.error(f'unrecognized command. command={args.command}')

0 commit comments

Comments
 (0)