@@ -1035,20 +1035,42 @@ type Options struct {
10351035 // changing options dynamically?
10361036 WALMinSyncInterval func () time.Duration
10371037
1038+ // The controls below manage deletion pacing, which slows down
1039+ // deletions when compactions finish or when readers close and
1040+ // obsolete files must be cleaned up. Rapid deletion of many
1041+ // files simultaneously can increase disk latency on certain
1042+ // SSDs, and this functionality helps protect against that.
1043+
10381044 // TargetByteDeletionRate is the rate (in bytes per second) at which sstable file
10391045 // deletions are limited to (under normal circumstances).
10401046 //
1041- // Deletion pacing is used to slow down deletions when compactions finish up
1042- // or readers close and newly-obsolete files need cleaning up. Deleting lots
1043- // of files at once can cause disk latency to go up on some SSDs, which this
1044- // functionality guards against.
1045- //
10461047 // This value is only a best-effort target; the effective rate can be
10471048 // higher if deletions are falling behind or disk space is running low.
10481049 //
10491050 // Setting this to 0 disables deletion pacing, which is also the default.
10501051 TargetByteDeletionRate int
10511052
1053+ // FreeSpaceThresholdBytes specifies the minimum amount of free disk space that Pebble
1054+ // attempts to maintain. If free disk space drops below this threshold, deletions
1055+ // are accelerated above TargetByteDeletionRate until the threshold is restored.
1056+ // Default is 16GB.
1057+ FreeSpaceThresholdBytes uint64
1058+
1059+ // FreeSpaceTimeframe sets the duration (in seconds) within which Pebble attempts
1060+ // to restore the free disk space back to FreeSpaceThreshold. A lower value means
1061+ // more aggressive deletions. Default is 10s.
1062+ FreeSpaceTimeframe time.Duration
1063+
1064+ // ObsoleteBytesMaxRatio specifies the maximum allowed ratio of obsolete files to
1065+ // live files. If this ratio is exceeded, Pebble speeds up deletions above the
1066+ // TargetByteDeletionRate until the ratio is restored. Default is 0.20.
1067+ ObsoleteBytesMaxRatio float64
1068+
1069+ // ObsoleteBytesTimeframe sets the duration (in seconds) within which Pebble aims
1070+ // to restore the obsolete-to-live bytes ratio below ObsoleteBytesMaxRatio. A lower
1071+ // value means more aggressive deletions. Default is 300s.
1072+ ObsoleteBytesTimeframe time.Duration
1073+
10521074 // EnableSQLRowSpillMetrics specifies whether the Pebble instance will only be used
10531075 // to temporarily persist data spilled to disk for row-oriented SQL query execution.
10541076 EnableSQLRowSpillMetrics bool
@@ -1135,6 +1157,22 @@ func (o *Options) EnsureDefaults() {
11351157 o .Cleaner = DeleteCleaner {}
11361158 }
11371159
1160+ if o .FreeSpaceThresholdBytes == 0 {
1161+ o .FreeSpaceThresholdBytes = 16 << 30 // 16 GB
1162+ }
1163+
1164+ if o .FreeSpaceTimeframe == 0 {
1165+ o .FreeSpaceTimeframe = 10 * time .Second
1166+ }
1167+
1168+ if o .ObsoleteBytesMaxRatio == 0 {
1169+ o .ObsoleteBytesMaxRatio = 0.20
1170+ }
1171+
1172+ if o .ObsoleteBytesTimeframe == 0 {
1173+ o .ObsoleteBytesTimeframe = 300 * time .Second
1174+ }
1175+
11381176 if o .Experimental .DisableIngestAsFlushable == nil {
11391177 o .Experimental .DisableIngestAsFlushable = func () bool { return false }
11401178 }
@@ -1393,6 +1431,10 @@ func (o *Options) String() string {
13931431 fmt .Fprintf (& buf , " mem_table_size=%d\n " , o .MemTableSize )
13941432 fmt .Fprintf (& buf , " mem_table_stop_writes_threshold=%d\n " , o .MemTableStopWritesThreshold )
13951433 fmt .Fprintf (& buf , " min_deletion_rate=%d\n " , o .TargetByteDeletionRate )
1434+ fmt .Fprintf (& buf , " free_space_threshold_bytes=%d\n " , o .FreeSpaceThresholdBytes )
1435+ fmt .Fprintf (& buf , " free_space_timeframe=%s\n " , o .FreeSpaceTimeframe .String ())
1436+ fmt .Fprintf (& buf , " obsolete_bytes_max_ratio=%f\n " , o .ObsoleteBytesMaxRatio )
1437+ fmt .Fprintf (& buf , " obsolete_bytes_timeframe=%s\n " , o .ObsoleteBytesTimeframe .String ())
13961438 fmt .Fprintf (& buf , " merger=%s\n " , o .Merger .Name )
13971439 if o .Experimental .MultiLevelCompactionHeuristic != nil {
13981440 fmt .Fprintf (& buf , " multilevel_compaction_heuristic=%s\n " , o .Experimental .MultiLevelCompactionHeuristic .String ())
@@ -1729,6 +1771,14 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
17291771 // may be meaningful again eventually.
17301772 case "min_deletion_rate" :
17311773 o .TargetByteDeletionRate , err = strconv .Atoi (value )
1774+ case "free_space_threshold_bytes" :
1775+ o .FreeSpaceThresholdBytes , err = strconv .ParseUint (value , 10 , 64 )
1776+ case "free_space_timeframe" :
1777+ o .FreeSpaceTimeframe , err = time .ParseDuration (value )
1778+ case "obsolete_bytes_max_ratio" :
1779+ o .ObsoleteBytesMaxRatio , err = strconv .ParseFloat (value , 64 )
1780+ case "obsolete_bytes_timeframe" :
1781+ o .ObsoleteBytesTimeframe , err = time .ParseDuration (value )
17321782 case "min_flush_rate" :
17331783 // Do nothing; option existed in older versions of pebble, and
17341784 // may be meaningful again eventually.
0 commit comments