From 12e4309b008aee28646612ddff65cce904400e5a Mon Sep 17 00:00:00 2001 From: Ashish Goswami Date: Mon, 16 Sep 2019 07:58:59 +0530 Subject: [PATCH 1/3] Add read-only option in info tool --- badger/cmd/info.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/badger/cmd/info.go b/badger/cmd/info.go index 601a10ed7..8cd31aa1b 100644 --- a/badger/cmd/info.go +++ b/badger/cmd/info.go @@ -46,6 +46,7 @@ type flagOptions struct { itemMeta bool keyHistory bool showInternal bool + readOnly bool } var ( @@ -67,6 +68,9 @@ func init() { infoCmd.Flags().BoolVar( &opt.showInternal, "show-internal", false, "Show internal keys along with other keys."+ " This option should be used along with --show-key option") + infoCmd.Flags().BoolVar(&opt.readOnly, "read-only", true, "If set to true, DB will be opened "+ + "in read only mode. If DB has not been closed properly, this option can be set to false "+ + "open DB. This might result in truncation of corrupt data.") } var infoCmd = &cobra.Command{ @@ -89,7 +93,7 @@ func handleInfo(cmd *cobra.Command, args []string) error { // Open DB db, err := badger.Open(badger.DefaultOptions(sstDir). WithValueDir(vlogDir). - WithReadOnly(true). + WithReadOnly(opt.readOnly). WithTableLoadingMode(options.MemoryMap)) if err != nil { return errors.Wrap(err, "failed to open database") From 19ae6f8d690ca5ff937bbd212fc1fecdd6628193 Mon Sep 17 00:00:00 2001 From: Ashish Goswami Date: Mon, 16 Sep 2019 14:19:56 +0530 Subject: [PATCH 2/3] Minor Fix --- badger/cmd/info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/badger/cmd/info.go b/badger/cmd/info.go index 8cd31aa1b..76770d027 100644 --- a/badger/cmd/info.go +++ b/badger/cmd/info.go @@ -70,7 +70,7 @@ func init() { " This option should be used along with --show-key option") infoCmd.Flags().BoolVar(&opt.readOnly, "read-only", true, "If set to true, DB will be opened "+ "in read only mode. If DB has not been closed properly, this option can be set to false "+ - "open DB. This might result in truncation of corrupt data.") + "to open DB. This might result in truncation of corrupt data.") } var infoCmd = &cobra.Command{ From d31b3251b5903c4e161bf8b0d6aa8470dfc542f5 Mon Sep 17 00:00:00 2001 From: ashish Date: Mon, 16 Sep 2019 19:24:39 +0530 Subject: [PATCH 3/3] Add truncate flag to info command --- badger/cmd/info.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/badger/cmd/info.go b/badger/cmd/info.go index 76770d027..2fe6f8ed2 100644 --- a/badger/cmd/info.go +++ b/badger/cmd/info.go @@ -47,6 +47,7 @@ type flagOptions struct { keyHistory bool showInternal bool readOnly bool + truncate bool } var ( @@ -70,7 +71,9 @@ func init() { " This option should be used along with --show-key option") infoCmd.Flags().BoolVar(&opt.readOnly, "read-only", true, "If set to true, DB will be opened "+ "in read only mode. If DB has not been closed properly, this option can be set to false "+ - "to open DB. This might result in truncation of corrupt data.") + "to open DB.") + infoCmd.Flags().BoolVar(&opt.truncate, "truncate", false, "If set to true, it allows "+ + "truncation of value log files if they have corrupt data.") } var infoCmd = &cobra.Command{ @@ -94,6 +97,7 @@ func handleInfo(cmd *cobra.Command, args []string) error { db, err := badger.Open(badger.DefaultOptions(sstDir). WithValueDir(vlogDir). WithReadOnly(opt.readOnly). + WithTruncate(opt.truncate). WithTableLoadingMode(options.MemoryMap)) if err != nil { return errors.Wrap(err, "failed to open database")