Skip to content

Commit dcea072

Browse files
committed
executor: skip analyze flush broadcast in test binaries
`make bench-daily` (CI job `gobench4`) fails on `BenchmarkNonPartitionPointGetPlanCacheOn`: `analyze table t` hits `context deadline exceeded` after 10s. PR #67939 added `flushStatsDeltaForAnalyze`, which broadcasts FLUSH STATS_DELTA CLUSTER via a TiDB-type cop request before each ANALYZE. The local-dump fallback was gated on `intest.InTest`, but that variable is only set under the `intest` build tag. `make bench-daily` runs `go test` without the tag, so the broadcast hits the mockstore session's empty `:10080` and hangs. Replace the gate with a `runningUnderGoTest` helper backed by `testing.Testing()`, which the linker sets to true for any binary produced by `go test` (covering both unit tests and bench-daily) and leaves false for `go build` of cmd/tidb-server. The gate is therefore a no-op in production regardless of TOML host configuration, and no longer depends on the `intest` build tag. Issue Number: close #68416
1 parent f4369ec commit dcea072

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

pkg/executor/analyze.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"slices"
2525
"strconv"
2626
"strings"
27+
"testing"
2728
"time"
2829

2930
"github.com/pingcap/errors"
@@ -89,6 +90,17 @@ const (
8990
idxTask
9091
)
9192

93+
// runningUnderGoTest reports whether the current process is a Go test binary
94+
// (`go test`, including `make bench-daily`) rather than a real tidb-server
95+
// produced by `go build` of cmd/tidb-server. Test binaries register in-process
96+
// TiDB domains without binding a TiDB RPC listener, so a FLUSH STATS_DELTA
97+
// CLUSTER broadcast would hit a mock ":10080" and burn the TiKV RPC backoff
98+
// budget before analyze starts. testing.Testing() is set by the linker only
99+
// for binaries built via `go test`, so the gate is a no-op in production.
100+
func runningUnderGoTest() bool {
101+
return testing.Testing()
102+
}
103+
92104
// flushStatsDeltaForAnalyze flushes pending stats deltas for the tables whose column-analyze
93105
// tasks will capture base count / modify_count from mysql.stats_meta. Without this, a stale
94106
// pre-analyze delta can be applied later and double count rows or modifications.
@@ -101,12 +113,7 @@ func flushStatsDeltaForAnalyze(ctx context.Context, sctx sessionctx.Context, pla
101113
return err
102114
}
103115

104-
// HACK: Some tests register in-process TiDB domains but do not start TiDB RPC
105-
// endpoints. Broadcasting FLUSH STATS_DELTA CLUSTER to those mock endpoints can
106-
// spend the TiKV RPC backoff budget before analyze really starts. When the test
107-
// topology cannot receive TiDB broadcast requests, dumping local deltas is the
108-
// only viable approximation.
109-
if intest.InTest {
116+
if runningUnderGoTest() {
110117
flushedLocally, err := flushAnalyzeStatsDeltaForTest(ctx, sctx, plan)
111118
if err != nil {
112119
return err

0 commit comments

Comments
 (0)