71
71
"if set, kvserver will compute an accurate stats diff for every addsstable request" ,
72
72
metamorphic .ConstantWithTestBool ("computeStatsDiffInStreamBatcher" , true ),
73
73
)
74
+
75
+ sstBatcherElasticCPUControlEnabled = settings .RegisterBoolSetting (
76
+ settings .ApplicationLevel ,
77
+ "bulkio.ingest.sst_batcher_elastic_control.enabled" ,
78
+ "determines whether the sst batcher integrates with elastic CPU control" ,
79
+ false , // TODO(dt): enable this by default.
80
+ )
74
81
)
75
82
76
83
// MakeAndRegisterConcurrencyLimiter makes a concurrency limiter and registers it
@@ -212,6 +219,9 @@ type SSTBatcher struct {
212
219
// disallowShadowingBelow is described on kvpb.AddSSTableRequest.
213
220
disallowShadowingBelow hlc.Timestamp
214
221
222
+ // pacer for admission control during SST ingestion
223
+ pacer CPUPacer
224
+
215
225
// skips duplicate keys (iff they are buffered together). This is true when
216
226
// used to backfill an inverted index. An array in JSONB with multiple values
217
227
// which are the same, will all correspond to the same kv in the inverted
@@ -313,6 +323,7 @@ func MakeSSTBatcher(
313
323
mem : mem ,
314
324
limiter : sendLimiter ,
315
325
rc : rc ,
326
+ pacer : NewCPUPacer (ctx , db , sstBatcherElasticCPUControlEnabled ),
316
327
}
317
328
b .mu .lastFlush = timeutil .Now ()
318
329
b .mu .tracingSpan = tracing .SpanFromContext (ctx )
@@ -352,6 +363,7 @@ func MakeStreamSSTBatcher(
352
363
// does not however make sense to scatter that range as the RHS maybe
353
364
// non-empty.
354
365
disableScatters : true ,
366
+ pacer : NewCPUPacer (ctx , db , sstBatcherElasticCPUControlEnabled ),
355
367
}
356
368
b .mu .lastFlush = timeutil .Now ()
357
369
b .mu .tracingSpan = tracing .SpanFromContext (ctx )
@@ -379,6 +391,7 @@ func MakeTestingSSTBatcher(
379
391
ingestAll : ingestAll ,
380
392
mem : mem ,
381
393
limiter : sendLimiter ,
394
+ pacer : NewCPUPacer (ctx , db , sstBatcherElasticCPUControlEnabled ),
382
395
}
383
396
b .init (ctx )
384
397
return b , nil
@@ -394,7 +407,6 @@ func (b *SSTBatcher) SetOnFlush(onFlush func(summary kvpb.BulkOpSummary)) {
394
407
func (b * SSTBatcher ) AddMVCCKeyWithImportEpoch (
395
408
ctx context.Context , key storage.MVCCKey , value []byte , importEpoch uint32 ,
396
409
) error {
397
-
398
410
mvccVal , err := storage .DecodeMVCCValue (value )
399
411
if err != nil {
400
412
return err
@@ -411,7 +423,6 @@ func (b *SSTBatcher) AddMVCCKeyWithImportEpoch(
411
423
}
412
424
413
425
func (b * SSTBatcher ) AddMVCCKeyLDR (ctx context.Context , key storage.MVCCKey , value []byte ) error {
414
-
415
426
mvccVal , err := storage .DecodeMVCCValue (value )
416
427
if err != nil {
417
428
return err
@@ -432,6 +443,9 @@ func (b *SSTBatcher) AddMVCCKeyLDR(ctx context.Context, key storage.MVCCKey, val
432
443
// keys -- like RESTORE where we want the restored data to look like the backup.
433
444
// Keys must be added in order.
434
445
func (b * SSTBatcher ) AddMVCCKey (ctx context.Context , key storage.MVCCKey , value []byte ) error {
446
+ // Pace based on admission control before adding the key.
447
+ b .pacer .Pace (ctx )
448
+
435
449
if len (b .batch .endKey ) > 0 && bytes .Equal (b .batch .endKey , key .Key ) {
436
450
if b .ingestAll && key .Timestamp .Equal (b .batch .endTimestamp ) {
437
451
if bytes .Equal (b .batch .endValue , value ) {
@@ -924,6 +938,7 @@ func (b *SSTBatcher) Close(ctx context.Context) {
924
938
if err := b .syncFlush (); err != nil {
925
939
log .Warningf (ctx , "closing with flushes in-progress encountered an error: %v" , err )
926
940
}
941
+ b .pacer .Close ()
927
942
b .mem .Close (ctx )
928
943
}
929
944
0 commit comments