@@ -13,8 +13,6 @@ import (
1313 "github.com/cockroachdb/cockroach/pkg/keys"
1414 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock"
1515 "github.com/cockroachdb/cockroach/pkg/roachpb"
16- "github.com/cockroachdb/cockroach/pkg/settings"
17- "github.com/cockroachdb/cockroach/pkg/settings/cluster"
1816 "github.com/cockroachdb/cockroach/pkg/storage/enginepb"
1917 "github.com/cockroachdb/cockroach/pkg/storage/fs"
2018 "github.com/cockroachdb/cockroach/pkg/storage/pebbleiter"
@@ -1053,10 +1051,6 @@ type Engine interface {
10531051 // modified or deleted by the Engine doing the ingestion.
10541052 IngestExternalFiles (ctx context.Context , external []pebble.ExternalFile ) (pebble.IngestOperationStats , error )
10551053
1056- // PreIngestDelay offers an engine the chance to backpressure ingestions.
1057- // When called, it may choose to block if the engine determines that it is in
1058- // or approaching a state where further ingestions may risk its health.
1059- PreIngestDelay (ctx context.Context )
10601054 // ApproximateDiskBytes returns an approximation of the on-disk size and file
10611055 // counts for the given key span, along with how many of those bytes are on
10621056 // remote, as well as specifically external remote, storage.
@@ -1718,79 +1712,6 @@ func ClearRangeWithHeuristic(
17181712 return nil
17191713}
17201714
1721- var ingestDelayL0Threshold = settings .RegisterIntSetting (
1722- settings .ApplicationLevel ,
1723- "rocksdb.ingest_backpressure.l0_file_count_threshold" ,
1724- "number of L0 files after which to backpressure SST ingestions" ,
1725- 20 ,
1726- )
1727-
1728- var ingestDelayTime = settings .RegisterDurationSetting (
1729- settings .ApplicationLevel ,
1730- "rocksdb.ingest_backpressure.max_delay" ,
1731- "maximum amount of time to backpressure a single SST ingestion" ,
1732- time .Second * 5 ,
1733- )
1734-
1735- var preIngestDelayEnabled = settings .RegisterBoolSetting (
1736- settings .SystemOnly ,
1737- "pebble.pre_ingest_delay.enabled" ,
1738- "controls whether the pre-ingest delay mechanism is active" ,
1739- false ,
1740- )
1741-
1742- // PreIngestDelay may choose to block for some duration if L0 has an excessive
1743- // number of files in it or if PendingCompactionBytesEstimate is elevated. This
1744- // it is intended to be called before ingesting a new SST, since we'd rather
1745- // backpressure the bulk operation adding SSTs than slow down the whole RocksDB
1746- // instance and impact all foreground traffic by adding too many files to it.
1747- // After the number of L0 files exceeds the configured limit, it gradually
1748- // begins delaying more for each additional file in L0 over the limit until
1749- // hitting its configured (via settings) maximum delay. If the pending
1750- // compaction limit is exceeded, it waits for the maximum delay.
1751- func preIngestDelay (ctx context.Context , eng Engine , settings * cluster.Settings ) {
1752- if settings == nil {
1753- return
1754- }
1755- if ! preIngestDelayEnabled .Get (& settings .SV ) {
1756- return
1757- }
1758- metrics := eng .GetMetrics ()
1759- targetDelay := calculatePreIngestDelay (settings , metrics .Metrics )
1760-
1761- if targetDelay == 0 {
1762- return
1763- }
1764- log .VEventf (ctx , 2 , "delaying SST ingestion %s. %d L0 files, %d L0 Sublevels" ,
1765- targetDelay , metrics .Levels [0 ].Tables .Count , metrics .Levels [0 ].Sublevels )
1766-
1767- select {
1768- case <- time .After (targetDelay ):
1769- case <- ctx .Done ():
1770- }
1771- }
1772-
1773- func calculatePreIngestDelay (settings * cluster.Settings , metrics * pebble.Metrics ) time.Duration {
1774- maxDelay := ingestDelayTime .Get (& settings .SV )
1775- l0ReadAmpLimit := ingestDelayL0Threshold .Get (& settings .SV )
1776-
1777- const ramp = 10
1778- l0ReadAmp := int64 (metrics .Levels [0 ].Tables .Count )
1779- if metrics .Levels [0 ].Sublevels >= 0 {
1780- l0ReadAmp = int64 (metrics .Levels [0 ].Sublevels )
1781- }
1782-
1783- if l0ReadAmp > l0ReadAmpLimit {
1784- delayPerFile := maxDelay / time .Duration (ramp )
1785- targetDelay := time .Duration (l0ReadAmp - l0ReadAmpLimit ) * delayPerFile
1786- if targetDelay > maxDelay {
1787- return maxDelay
1788- }
1789- return targetDelay
1790- }
1791- return 0
1792- }
1793-
17941715// Helper function to implement Reader.MVCCIterate().
17951716func iterateOnReader (
17961717 ctx context.Context ,
0 commit comments