Skip to content

Commit

Permalink
*: force_init_stats doesn't block http api's startup (#50853) (#51039)
Browse files Browse the repository at this point in the history
close #50854
  • Loading branch information
ti-chi-bot authored Feb 22, 2024
1 parent 23052ef commit 0b8d947
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion br/pkg/mock/mock_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (mock *Cluster) Start() error {
}
mock.Server = svr
go func() {
if err1 := svr.Run(); err1 != nil {
if err1 := svr.Run(nil); err1 != nil {
panic(err1)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion server/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestExtractHandler(t *testing.T) {
client.port = getPortFromTCPAddr(server.listener.Addr())
client.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
client.waitUntilServerOnline()
Expand Down
2 changes: 1 addition & 1 deletion server/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (ts *basicHTTPHandlerTestSuite) startServer(t *testing.T) {
ts.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
ts.server = server
go func() {
err := server.Run()
err := server.Run(ts.domain)
require.NoError(t, err)
}()
ts.waitUntilServerOnline()
Expand Down
2 changes: 1 addition & 1 deletion server/optimize_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestDumpOptimizeTraceAPI(t *testing.T) {
client.port = getPortFromTCPAddr(server.listener.Addr())
client.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
client.waitUntilServerOnline()
Expand Down
2 changes: 1 addition & 1 deletion server/plan_replayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestDumpPlanReplayerAPI(t *testing.T) {
client.port = getPortFromTCPAddr(server.listener.Addr())
client.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
client.waitUntilServerOnline()
Expand Down
5 changes: 4 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,17 @@ func (s *Server) reportConfig() {
}

// Run runs the server.
func (s *Server) Run() error {
func (s *Server) Run(dom *domain.Domain) error {
metrics.ServerEventCounter.WithLabelValues(metrics.EventStart).Inc()
s.reportConfig()

// Start HTTP API to report tidb info such as TPS.
if s.cfg.Status.ReportStatus {
s.startStatusHTTP()
}
if config.GetGlobalConfig().Performance.ForceInitStats && dom != nil {
<-dom.StatsHandle().InitStatsDone
}
// If error should be reported and exit the server it can be sent on this
// channel. Otherwise, end with sending a nil error to signal "done"
errChan := make(chan error, 2)
Expand Down
2 changes: 1 addition & 1 deletion server/statistics_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestDumpStatsAPI(t *testing.T) {
client.port = getPortFromTCPAddr(server.listener.Addr())
client.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
client.waitUntilServerOnline()
Expand Down
10 changes: 5 additions & 5 deletions server/tidb_serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestTLSAuto(t *testing.T) {
require.NoError(t, err)
cli.port = getPortFromTCPAddr(server.listener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestTLSBasic(t *testing.T) {
require.NoError(t, err)
cli.port = getPortFromTCPAddr(server.listener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestTLSVerify(t *testing.T) {
defer server.Close()
cli.port = getPortFromTCPAddr(server.listener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestErrorNoRollback(t *testing.T) {
require.NoError(t, err)
cli.port = getPortFromTCPAddr(server.listener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
defer server.Close()
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestReloadTLS(t *testing.T) {
require.NoError(t, err)
cli.port = getPortFromTCPAddr(server.listener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down
22 changes: 11 additions & 11 deletions server/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func createTidbTestSuiteWithCfg(t *testing.T, cfg *config.Config) *tidbTestSuite
ts.server.InitGlobalConnID(ts.domain.ServerID)
ts.domain.InfoSyncer().SetSessionManager(ts.server)
go func() {
err := ts.server.Run()
err := ts.server.Run(nil)
require.NoError(t, err)
}()
ts.waitUntilServerOnline()
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestStatusAPIWithTLS(t *testing.T) {
cli.port = getPortFromTCPAddr(server.listener.Addr())
cli.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestStatusAPIWithTLSCNCheck(t *testing.T) {
cli.port = getPortFromTCPAddr(server.listener.Addr())
cli.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
defer server.Close()
Expand Down Expand Up @@ -400,7 +400,7 @@ func TestSocketForwarding(t *testing.T) {
require.NoError(t, err)
cli.port = getPortFromTCPAddr(server.listener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -431,7 +431,7 @@ func TestSocket(t *testing.T) {
server, err := NewServer(cfg, ts.tidbdrv)
require.NoError(t, err)
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestSocketAndIp(t *testing.T) {
require.NoError(t, err)
cli.port = getPortFromTCPAddr(server.listener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
cli.waitUntilServerCanConnect()
Expand Down Expand Up @@ -629,7 +629,7 @@ func TestOnlySocket(t *testing.T) {
server, err := NewServer(cfg, ts.tidbdrv)
require.NoError(t, err)
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -1239,7 +1239,7 @@ func TestGracefulShutdown(t *testing.T) {
cli.port = getPortFromTCPAddr(server.listener.Addr())
cli.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -2511,7 +2511,7 @@ func TestLocalhostClientMapping(t *testing.T) {
require.NoError(t, err)
cli.port = getPortFromTCPAddr(server.listener.Addr())
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
defer server.Close()
Expand Down Expand Up @@ -3127,7 +3127,7 @@ func TestProxyProtocolWithIpFallbackable(t *testing.T) {
server, err := NewServer(cfg, ts.tidbdrv)
require.NoError(t, err)
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 100)
Expand Down Expand Up @@ -3191,7 +3191,7 @@ func TestProxyProtocolWithIpNoFallbackable(t *testing.T) {
server, err := NewServer(cfg, ts.tidbdrv)
require.NoError(t, err)
go func() {
err := server.Run()
err := server.Run(nil)
require.NoError(t, err)
}()
time.Sleep(time.Millisecond * 1000)
Expand Down
6 changes: 2 additions & 4 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,8 @@ func main() {
close(exited)
})
topsql.SetupTopSQL()
if config.GetGlobalConfig().Performance.ForceInitStats {
<-dom.StatsHandle().InitStatsDone
}
terror.MustNil(svr.Run())

terror.MustNil(svr.Run(dom))
<-exited
syncLog()
}
Expand Down

0 comments on commit 0b8d947

Please sign in to comment.