From 0773c47d05a121717e6616d8380ca37d3f2a43aa Mon Sep 17 00:00:00 2001 From: Richard Patel Date: Sun, 11 Sep 2022 09:01:29 +0200 Subject: [PATCH] cmd/blockstore/yaml: accept --slots=all Adds option to dump all slots --- cmd/radiance/blockstore/yaml/yaml.go | 43 +++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/cmd/radiance/blockstore/yaml/yaml.go b/cmd/radiance/blockstore/yaml/yaml.go index c39a70a..74c6d66 100644 --- a/cmd/radiance/blockstore/yaml/yaml.go +++ b/cmd/radiance/blockstore/yaml/yaml.go @@ -33,7 +33,13 @@ func init() { Cmd.Run = run } -func run(_ *cobra.Command, args []string) { +func run(c *cobra.Command, args []string) { + go func() { + // No need for clean shutdown, exit quickly + <-c.Context().Done() + os.Exit(0) + }() + rocksDB := args[0] printColumnFamilies(rocksDB) @@ -46,12 +52,16 @@ func run(_ *cobra.Command, args []string) { printRoot(db) - slots, ok := util.ParseInts(*flagSlots) - if !ok { - klog.Exitf("Invalid slots specifier: %s", *flagSlots) - } - if len(slots) > 0 { - dumpSlots(db, slots) + if *flagSlots == "all" { + dumpAllSlots(db) + } else { + slots, ok := util.ParseInts(*flagSlots) + if !ok { + klog.Exitf("Invalid slots specifier: %s", *flagSlots) + } + if len(slots) > 0 { + dumpSlots(db, slots) + } } if klog.Stats.Error.Lines() > 0 { @@ -81,6 +91,25 @@ func printRoot(db *blockstore.DB) { fmt.Println("root:", root) } +func dumpAllSlots(db *blockstore.DB) { + iter := db.DB.NewIteratorCF(grocksdb.NewDefaultReadOptions(), db.CfMeta) + iter.SeekToFirst() + defer iter.Close() + hasHeader := false + for iter.Valid() { + if !hasHeader { + fmt.Println("slots:") + hasHeader = true + } + slot, ok := blockstore.ParseSlotKey(iter.Key().Data()) + if !ok { + continue + } + dumpSlot(db, slot) + iter.Next() + } +} + func dumpSlots(db *blockstore.DB, slots util.Ints) { fmt.Println("slots:") slots.Iter(func(slot uint64) bool {