Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Truncate and ReadOnly options for badger #1842

Merged
merged 2 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugin/storage/badger/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
opts.SyncWrites = f.Options.primary.SyncWrites
opts.Dir = f.Options.primary.KeyDirectory
opts.ValueDir = f.Options.primary.ValueDirectory

// These options make no sense with ephemeral data
opts.Truncate = f.Options.primary.Truncate
opts.ReadOnly = f.Options.primary.ReadOnly
}

store, err := badger.Open(opts)
Expand Down
18 changes: 17 additions & 1 deletion plugin/storage/badger/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type NamespaceConfig struct {
SyncWrites bool
MaintenanceInterval time.Duration
MetricsUpdateInterval time.Duration
Truncate bool
ReadOnly bool
}

const (
Expand All @@ -55,6 +57,8 @@ const (
suffixSyncWrite = ".consistency"
suffixMaintenanceInterval = ".maintenance-interval"
suffixMetricsInterval = ".metrics-update-interval" // Intended only for testing purposes
suffixTruncate = ".truncate"
suffixReadOnly = ".read-only"
defaultDataDir = string(os.PathSeparator) + "data"
defaultValueDir = defaultDataDir + string(os.PathSeparator) + "values"
defaultKeysDir = defaultDataDir + string(os.PathSeparator) + "keys"
Expand Down Expand Up @@ -116,7 +120,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *NamespaceConfig) {
flagSet.Bool(
nsConfig.namespace+suffixSyncWrite,
nsConfig.SyncWrites,
"If all writes should be synced immediately. This can impact write performance.",
"If all writes should be synced immediately to physical disk. This will impact write performance.",
)
flagSet.Duration(
nsConfig.namespace+suffixMaintenanceInterval,
Expand All @@ -128,6 +132,16 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *NamespaceConfig) {
nsConfig.MetricsUpdateInterval,
"How often the badger metrics are collected by Jaeger. Format is time.Duration (https://golang.org/pkg/time/#Duration)",
)
flagSet.Bool(
nsConfig.namespace+suffixTruncate,
nsConfig.Truncate,
"If write-ahead-log should be truncated on restart. this will cause data loss.",
)
flagSet.Bool(
nsConfig.namespace+suffixReadOnly,
nsConfig.ReadOnly,
"Allows to open badger database in read only mode. Multiple instances can open same database in read-only mode. Values still in the write-ahead-log must be replayed before opening.",
)
}

// InitFromViper initializes Options with properties from viper
Expand All @@ -143,6 +157,8 @@ func initFromViper(cfg *NamespaceConfig, v *viper.Viper) {
cfg.SpanStoreTTL = v.GetDuration(cfg.namespace + suffixSpanstoreTTL)
cfg.MaintenanceInterval = v.GetDuration(cfg.namespace + suffixMaintenanceInterval)
cfg.MetricsUpdateInterval = v.GetDuration(cfg.namespace + suffixMetricsInterval)
cfg.Truncate = v.GetBool(cfg.namespace + suffixTruncate)
cfg.ReadOnly = v.GetBool(cfg.namespace + suffixReadOnly)
}

// GetPrimary returns the primary namespace configuration
Expand Down
15 changes: 15 additions & 0 deletions plugin/storage/badger/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@ func TestParseOptions(t *testing.T) {
assert.Equal(t, time.Duration(168*time.Hour), opts.GetPrimary().SpanStoreTTL)
assert.Equal(t, "/var/lib/badger", opts.GetPrimary().KeyDirectory)
assert.Equal(t, "/mnt/slow/badger", opts.GetPrimary().ValueDirectory)
assert.False(t, opts.GetPrimary().ReadOnly)
assert.False(t, opts.GetPrimary().Truncate)
}

func TestTruncateAndReadOnlyOptions(t *testing.T) {
opts := NewOptions("badger")
v, command := config.Viperize(opts.AddFlags)
command.ParseFlags([]string{
"--badger.truncate=true",
"--badger.read-only=true",
})
opts.InitFromViper(v)

assert.True(t, opts.GetPrimary().ReadOnly)
assert.True(t, opts.GetPrimary().Truncate)
}