Skip to content

Commit

Permalink
feat(storagenode): add --storage-trim-rate to set throttling rate of …
Browse files Browse the repository at this point in the history
…Trim

This change adds a new flat --storage-trim-rate to the storage node. It sets the deletion throttling
rate for Trim operation. If the value is zero, Trim removes the log entries without throttling.
  • Loading branch information
ijsong committed Jul 28, 2023
1 parent eaad260 commit 0087e3d
Show file tree
Hide file tree
Showing 5 changed files with 23 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 @@ -74,6 +74,7 @@ func newStartCommand() *cli.Command {
flagStorageMetricsLogInterval,
flagStorageVerbose.BoolFlag(),
flagStorageTrimDelay,
flagStorageTrimRate,

// 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 @@ -200,6 +200,11 @@ var (
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.",
}
flagStorageTrimRate = &cli.StringFlag{
Name: "storage-trim-rate",
EnvVars: []string{"STORAGE_TRIM_RATE"},
Usage: "Trim deletion throttling rate in bytes per second. If zero, no throttling is applied.",
}

// flags for telemetry.
flagExporterType = flags.FlagDesc{

Check failure on line 210 in cmd/varlogsn/flags.go

View workflow job for this annotation

GitHub Actions / lint

var `flagExporterType` is unused (unused)
Expand Down
7 changes: 7 additions & 0 deletions cmd/varlogsn/varlogsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ func parseStorageOptions(c *cli.Context) (opts []storage.Option, err error) {
if name := flagStorageTrimDelay.Name; c.IsSet(name) {
opts = append(opts, storage.WithTrimDelay(c.Duration(name)))
}
if name := flagStorageTrimRate.Name; c.IsSet(name) {
rate, err := units.FromByteSizeString(c.String(name))
if err != nil {
return nil, err
}
opts = append(opts, storage.WithTrimRateByte(int(rate)))
}
return opts, nil
}

Expand Down
9 changes: 9 additions & 0 deletions internal/storage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ type config struct {
verbose bool
metricsLogInterval time.Duration
trimDelay time.Duration
trimRateByte int
logger *zap.Logger
readOnly bool
}
Expand Down Expand Up @@ -256,6 +257,14 @@ func WithTrimDelay(trimDelay time.Duration) Option {
})
}

// WithTrimRateByte is the Trim deletion speed in bytes per second. If the
// value is zero, Trim removes the log entries without throttling.
func WithTrimRateByte(trimRateByte int) Option {
return newFuncOption(func(cfg *config) {
cfg.trimRateByte = trimRateByte
})
}

// 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 @@ -113,6 +113,7 @@ func (s *Storage) newDB(path string, cfg *dbConfig) (*pebble.DB, error) {
Levels: make([]pebble.LevelOptions, 7),
ErrorIfExists: false,
FlushDelayDeleteRange: s.trimDelay,
TargetByteDeletionRate: s.trimRateByte,
}
pebbleOpts.Levels[0].TargetFileSize = cfg.l0TargetFileSize
for i := 0; i < len(pebbleOpts.Levels); i++ {
Expand Down

0 comments on commit 0087e3d

Please sign in to comment.