Skip to content

Commit 6ba68c9

Browse files
ashish-goswamiIbrahim Jarif
authored andcommitted
Add read-only and truncate options in info tool (#1037)
(cherry picked from commit ef1e8e4)
1 parent 584e147 commit 6ba68c9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

badger/cmd/info.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type flagOptions struct {
4646
itemMeta bool
4747
keyHistory bool
4848
showInternal bool
49+
readOnly bool
50+
truncate bool
4951
}
5052

5153
var (
@@ -67,6 +69,11 @@ func init() {
6769
infoCmd.Flags().BoolVar(
6870
&opt.showInternal, "show-internal", false, "Show internal keys along with other keys."+
6971
" This option should be used along with --show-key option")
72+
infoCmd.Flags().BoolVar(&opt.readOnly, "read-only", true, "If set to true, DB will be opened "+
73+
"in read only mode. If DB has not been closed properly, this option can be set to false "+
74+
"to open DB.")
75+
infoCmd.Flags().BoolVar(&opt.truncate, "truncate", false, "If set to true, it allows "+
76+
"truncation of value log files if they have corrupt data.")
7077
}
7178

7279
var infoCmd = &cobra.Command{
@@ -89,7 +96,8 @@ func handleInfo(cmd *cobra.Command, args []string) error {
8996
// Open DB
9097
db, err := badger.Open(badger.DefaultOptions(sstDir).
9198
WithValueDir(vlogDir).
92-
WithReadOnly(true).
99+
WithReadOnly(opt.readOnly).
100+
WithTruncate(opt.truncate).
93101
WithTableLoadingMode(options.MemoryMap))
94102
if err != nil {
95103
return errors.Wrap(err, "failed to open database")

0 commit comments

Comments
 (0)