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 14, 2023
1 parent f3a79a0 commit 45691a0
Show file tree
Hide file tree
Showing 5 changed files with 20 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 @@ -75,6 +75,7 @@ func newStartCommand() *cli.Command {
flagStorageMaxConcurrentCompaction,
flagStorageMetricsLogInterval,
flagStorageVerbose.BoolFlag(),
flagStorageTrimDelay,

// logger options
flags.LogDir,
Expand Down
5 changes: 5 additions & 0 deletions cmd/varlogsn/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ 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{
Expand Down
3 changes: 3 additions & 0 deletions cmd/varlogsn/varlogsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,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 45691a0

Please sign in to comment.