8000 db: don't require quotes around level number in options section · cockroachdb/pebble@f81f1ed · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit f81f1ed

Browse files
committed
db: don't require quotes around level number in options section
The current format requires per-level sections to look like `[Level "1"]`. The quotes can be a pain to escape, especially when this is passed through the `--store` command line. This change makes the parsing more tolerant to allow but not require quotes, so that `[Level 1]` also works.
1 parent 0fe9656 commit f81f1ed

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

options.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bytes"
99
"fmt"
1010
"io"
11+
"regexp"
1112
"runtime"
1213
"strconv"
1314
"strings"
@@ -1792,15 +1793,11 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
17921793
return err
17931794

17941795
case strings.HasPrefix(section, "Level "):
1795-
var index int
1796-
if n, err := fmt.Sscanf(section, `Level "%d"`, &index); err != nil {
1797-
return err
1798-
} else if n != 1 {
1799-
if hooks != nil && hooks.SkipUnknown != nil && hooks.SkipUnknown(section, value) {
1800-
return nil
1801-
}
1796+
m := regexp.MustCompile(`Level\s*"?(\d+)"?\s*$`).FindStringSubmatch(section)
1797+
if m == nil {
18021798
return errors.Errorf("pebble: unknown section: %q", errors.Safe(section))
18031799
}
1800+
index, _ := strconv.Atoi(m[1])
18041801

18051802
if len(o.Levels) <= index {
18061803
newLevels := make([]LevelOptions, index+1)

options_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,36 @@ func TestOptionsParse(t *testing.T) {
306306
}
307307
}
308308

309+
func TestOptionsParseLevelNoQuotes(t *testing.T) {
310+
withQuotes := `
311+
[Options]
312+
[Level "1"]
313+
block_restart_interval=8
314+
block_size=10
315+
[Level "6"]
316+
block_restart_interval=8
317+
block_size=10
318+
`
319+
withoutQuotes := `
320+
[Options]
321+
[Level 1]
322+
block_restart_interval=8
323+
block_size=10
324+
[Level 6]
325+
block_restart_interval=8
326+
block_size=10
327+
`
328+
o1 := &Options{}
329+
require.NoError(t, o1.Parse(withQuotes, nil))
330+
o1.EnsureDefaults()
331+
332+
o2 := &Options{}
333+
require.NoError(t, o2.Parse(withoutQuotes, nil))
334+
o2.EnsureDefaults()
335+
336+
require.Equal(t, o1.String(), o2.String())
337+
}
338+
309339
func TestOptionsValidate(t *testing.T) {
310340
testCases := []struct {
311341
options string

0 commit comments

Comments
 (0)
0