Skip to content

Commit

Permalink
feat(storagenode): add --storage-trim-delay to set a delay before the…
Browse files Browse the repository at this point in the history
… deletion of log entries

This change adds a new flag --storage-trim-delay to the storage node. It sets the delay before
storage removes logs. If the value is zero, Trim will delay the removal of prefix log entries until
writing additional log entries.
  • Loading branch information
ijsong committed Jul 28, 2023
1 parent 2201b10 commit eaad260
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/varlogsn/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func newStartCommand() *cli.Command {
flagStorageMaxConcurrentCompaction,
flagStorageMetricsLogInterval,
flagStorageVerbose.BoolFlag(),
flagStorageTrimDelay,

// logger options
flags.LogDir,
Expand Down
32 changes: 32 additions & 0 deletions cmd/varlogsn/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,36 @@ var (
EnvVars: []string{"STORAGE_METRICS_LOG_INTERVAL"},
Value: storage.DefaultMetricsLogInterval,
}
flagStorageTrimDelay = &cli.DurationFlag{
Name: "storage-trim-delay",
EnvVars: []string{"STORAGE_TRIM_DELAY"},
Usage: "Delay before deletion of log entries caused by Trim operation. If zero, lazy deletion waits for other log entries to be appended.",
}

// flags for telemetry.
flagExporterType = flags.FlagDesc{
Name: "exporter-type",
Usage: "exporter type: stdout, otlp or noop",
Envs: []string{"EXPORTER_TYPE"},
}
flagExporterStopTimeout = flags.FlagDesc{
Name: "expoter-stop-timeout",
Usage: "timeout for stopping exporter",
Envs: []string{"EXPORTER_STOP_TIMEOUT"},
}
flagStdoutExporterPrettyPrint = flags.FlagDesc{
Name: "exporter-pretty-print",
Usage: "pretty print when using stdout exporter",
Envs: []string{"EXPORTER_PRETTY_PRINT"},
}
flagOTLPExporterInsecure = flags.FlagDesc{
Name: "exporter-otlp-insecure",
Usage: "disable client transport security for the OTLP exporter",
Envs: []string{"EXPORTER_OTLP_INSECURE"},
}
flagOTLPExporterEndpoint = flags.FlagDesc{
Name: "exporter-otlp-endpoint",
Usage: "the endpoint that exporter connects",
Envs: []string{"EXPORTER_OTLP_ENDPOINT"},
}
)
3 changes: 3 additions & 0 deletions cmd/varlogsn/varlogsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func parseStorageOptions(c *cli.Context) (opts []storage.Option, err error) {
if c.Bool(flagStorageVerbose.Name) {
opts = append(opts, storage.WithVerboseLogging())
}
if name := flagStorageTrimDelay.Name; c.IsSet(name) {
opts = append(opts, storage.WithTrimDelay(c.Duration(name)))
}
return opts, nil
}

Expand Down
10 changes: 10 additions & 0 deletions internal/storage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type config struct {
commitDBConfig dbConfig
verbose bool
metricsLogInterval time.Duration
trimDelay time.Duration
logger *zap.Logger
readOnly bool
}
Expand Down Expand Up @@ -246,6 +247,15 @@ func WithLogger(logger *zap.Logger) Option {
})
}

// WithTrimDelay sets the delay before storage removes logs. If the value is
// zero, Trim will delay the removal of prefix log entries until writing
// additional log entries.
func WithTrimDelay(trimDelay time.Duration) Option {
return newFuncOption(func(cfg *config) {
cfg.trimDelay = trimDelay
})
}

// ReadOnly makes storage read-only. It is helpful only for testing. Usually,
// users do not have to call it.
func ReadOnly() Option {
Expand Down
1 change: 1 addition & 0 deletions internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (s *Storage) newDB(path string, cfg *dbConfig) (*pebble.DB, error) {
MaxConcurrentCompactions: func() int { return cfg.maxConcurrentCompaction },
Levels: make([]pebble.LevelOptions, 7),
ErrorIfExists: false,
FlushDelayDeleteRange: s.trimDelay,
}
pebbleOpts.Levels[0].TargetFileSize = cfg.l0TargetFileSize
for i := 0; i < len(pebbleOpts.Levels); i++ {
Expand Down

0 comments on commit eaad260

Please sign in to comment.