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

feat(storagenode): add --storage-trim-delay to set a delay before the deletion of log entries #529

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
5 changes: 5 additions & 0 deletions cmd/varlogsn/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,9 @@ 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.",
}
)
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