Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions pkg/executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"slices"
"strconv"
"strings"
"testing"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -89,6 +90,17 @@ const (
idxTask
)

// runningUnderGoTest reports whether the current process is a Go test binary
// (`go test`, including `make bench-daily`) rather than a real tidb-server
// produced by `go build` of cmd/tidb-server. Test binaries register in-process
// TiDB domains without binding a TiDB RPC listener, so a FLUSH STATS_DELTA
// CLUSTER broadcast would hit a mock ":10080" and burn the TiKV RPC backoff
// budget before analyze starts. testing.Testing() is set by the linker only
// for binaries built via `go test`, so the gate is a no-op in production.
func runningUnderGoTest() bool {
Comment thread
mjonss marked this conversation as resolved.
return testing.Testing()
}

// flushStatsDeltaForAnalyze flushes pending stats deltas for the tables whose column-analyze
// tasks will capture base count / modify_count from mysql.stats_meta. Without this, a stale
// pre-analyze delta can be applied later and double count rows or modifications.
Expand All @@ -101,12 +113,8 @@ func flushStatsDeltaForAnalyze(ctx context.Context, sctx sessionctx.Context, pla
return err
}

// HACK: Some tests register in-process TiDB domains but do not start TiDB RPC
// endpoints. Broadcasting FLUSH STATS_DELTA CLUSTER to those mock endpoints can
// spend the TiKV RPC backoff budget before analyze really starts. When the test
// topology cannot receive TiDB broadcast requests, dumping local deltas is the
// only viable approximation.
if intest.InTest {
// HACK: test binaries have no real RPC peer to broadcast to; dump locally instead.
if runningUnderGoTest() {
flushedLocally, err := flushAnalyzeStatsDeltaForTest(ctx, sctx, plan)
if err != nil {
return err
Expand Down
Loading