diff --git a/plugin/storage/badger/factory.go b/plugin/storage/badger/factory.go index 77f8f01045f..5572ffec72b 100644 --- a/plugin/storage/badger/factory.go +++ b/plugin/storage/badger/factory.go @@ -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) diff --git a/plugin/storage/badger/options.go b/plugin/storage/badger/options.go index 8775578c431..4d9d5395304 100644 --- a/plugin/storage/badger/options.go +++ b/plugin/storage/badger/options.go @@ -39,6 +39,8 @@ type NamespaceConfig struct { SyncWrites bool MaintenanceInterval time.Duration MetricsUpdateInterval time.Duration + Truncate bool + ReadOnly bool } const ( @@ -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" @@ -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, @@ -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 @@ -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 diff --git a/plugin/storage/badger/options_test.go b/plugin/storage/badger/options_test.go index 73f5005c6d4..cd9353072cb 100644 --- a/plugin/storage/badger/options_test.go +++ b/plugin/storage/badger/options_test.go @@ -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) }