diff --git a/pkg/ddl/backfilling_test.go b/pkg/ddl/backfilling_test.go index 57275d962d5c6..e80b3e45359a1 100644 --- a/pkg/ddl/backfilling_test.go +++ b/pkg/ddl/backfilling_test.go @@ -404,6 +404,17 @@ func assertDistSQLCtxEqual(t *testing.T, expected *distsqlctx.DistSQLContext, ac require.Equal(t, errctx.NewContextWithLevels(expected.ErrCtx.LevelMap(), expected.WarnHandler), actual.ErrCtx) } +func TestReorgDistSQLCtxNotFillCache(t *testing.T) { + // Reorg coprocessor scans are single-pass bulk reads and must not pollute the TiKV + // block cache, so NotFillCache is always set on the reorg DistSQLContext. + ctx := newDefaultReorgDistSQLCtx(&mock.Client{}, contextutil.NewStaticWarnHandler(0)) + require.True(t, ctx.NotFillCache) + + withMeta, err := newReorgDistSQLCtxWithReorgMeta(&mock.Client{}, &model.DDLReorgMeta{}, contextutil.NewStaticWarnHandler(0)) + require.NoError(t, err) + require.True(t, withMeta.NotFillCache) +} + func TestValidateAndFillRanges(t *testing.T) { mkRange := func(start, end string) kv.KeyRange { return kv.KeyRange{StartKey: []byte(start), EndKey: []byte(end)} diff --git a/pkg/ddl/backfilling_txn_executor.go b/pkg/ddl/backfilling_txn_executor.go index f2a72e3fc1382..3622e27a13657 100644 --- a/pkg/ddl/backfilling_txn_executor.go +++ b/pkg/ddl/backfilling_txn_executor.go @@ -154,8 +154,13 @@ func newDefaultReorgDistSQLCtx(kvClient kv.Client, warnHandler contextutil.WarnA var execDetails execdetails.SyncExecDetails var cpuUsages ppcpuusage.SQLCPUUsages return &distsqlctx.DistSQLContext{ - WarnHandler: warnHandler, - Client: kvClient, + WarnHandler: warnHandler, + Client: kvClient, + // Reorg scans are single-pass bulk reads over the whole table/index range: the blocks + // they touch are never re-read by the reorg, so caching them brings no benefit and can + // evict the working set that concurrent foreground traffic relies on. Skip filling the + // block cache for all reorg coprocessor scans. + NotFillCache: true, EnableChunkRPC: true, EnabledRateLimitAction: vardef.DefTiDBEnableRateLimitAction, KVVars: tikvstore.NewVariables(&sqlKiller.Signal),