cmd/blockstore/yaml: print first and last slot

This commit is contained in:
Richard Patel 2022-09-11 10:46:01 +02:00
parent 22cd485d9c
commit 3e87b452bd
1 changed files with 22 additions and 0 deletions

View File

@ -51,6 +51,7 @@ func run(c *cobra.Command, args []string) {
defer db.Close()
printRoot(db)
printMetaRange(db)
if *flagSlots == "all" {
dumpAllSlots(db)
@ -91,6 +92,27 @@ func printRoot(db *blockstore.DB) {
fmt.Println("root:", root)
}
func printMetaRange(db *blockstore.DB) {
iter := db.DB.NewIteratorCF(grocksdb.NewDefaultReadOptions(), db.CfMeta)
defer iter.Close()
iter.SeekToFirst()
if iter.Valid() {
slot, ok := blockstore.ParseSlotKey(iter.Key().Data())
if ok {
fmt.Printf("first_slot: %d\n", slot)
}
}
iter.SeekToLast()
if iter.Valid() {
slot, ok := blockstore.ParseSlotKey(iter.Key().Data())
if ok {
fmt.Printf("last_slot: %d\n", slot)
}
}
}
func dumpAllSlots(db *blockstore.DB) {
iter := db.DB.NewIteratorCF(grocksdb.NewDefaultReadOptions(), db.CfMeta)
iter.SeekToFirst()