Skip to content

Commit

Permalink
coprocessor: skip empty tidb nodes (#56858)
Browse files Browse the repository at this point in the history
close #36546
  • Loading branch information
Leavrth authored Nov 6, 2024
1 parent 6004c3e commit b6a817d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
9 changes: 7 additions & 2 deletions br/cmd/br/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ func runBackupCommand(command *cobra.Command, cmdName string) error {
return nil
}

// No need to cache the coproceesor result
config.GetGlobalConfig().TiKVClient.CoprCache.CapacityMB = 0
config.UpdateGlobal(func(conf *config.Config) {
// Need to be skipped when the cluster has TiDB type coprocessor tasks
conf.AdvertiseAddress = config.UnavailableIP

// No need to cache the coproceesor result
conf.TiKVClient.CoprCache.CapacityMB = 0
})

// Disable the memory limit tuner. That's because the server memory is get from TiDB node instead of BR node.
gctuner.GlobalMemoryLimitTuner.DisableAdjustMemoryLimit()
Expand Down
9 changes: 7 additions & 2 deletions br/cmd/br/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ func runRestoreCommand(command *cobra.Command, cmdName string) error {
return nil
}

// No need to cache the coproceesor result
config.GetGlobalConfig().TiKVClient.CoprCache.CapacityMB = 0
config.UpdateGlobal(func(conf *config.Config) {
// Need to be skipped when the cluster has TiDB type coprocessor tasks
conf.AdvertiseAddress = config.UnavailableIP

// No need to cache the coproceesor result
conf.TiKVClient.CoprCache.CapacityMB = 0
})

// Disable the memory limit tuner. That's because the server memory is get from TiDB node instead of BR node.
gctuner.GlobalMemoryLimitTuner.DisableAdjustMemoryLimit()
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const (
// MaxTokenLimit is the max token limit value.
MaxTokenLimit = 1024 * 1024
DefSchemaLease = 45 * time.Second
UnavailableIP = "<nil>"
)

// Valid config maps
Expand Down
13 changes: 13 additions & 0 deletions pkg/executor/infoschema_cluster_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ func (s *mockStore) StartGCWorker() error { panic("not implemented") }
func (s *mockStore) Name() string { return "mockStore" }
func (s *mockStore) Describe() string { return "" }

func TestSkipEmptyIPNodesForTiDBTypeCoprocessor(t *testing.T) {
originIP := config.GetGlobalConfig().AdvertiseAddress
config.GetGlobalConfig().AdvertiseAddress = config.UnavailableIP
defer func() { config.GetGlobalConfig().AdvertiseAddress = originIP }()
store, _ := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
rows := tk.MustQuery("select * from information_schema.cluster_slow_query").Rows()
require.Equal(t, tk.Session().GetSessionVars().StmtCtx.WarningCount(), uint16(0))
// the TiDB node is skipped because it does not has IP
require.Equal(t, 0, len(rows))
}

func TestTiDBClusterInfo(t *testing.T) {
s := createInfosSchemaClusterTableSuite(t)

Expand Down
4 changes: 4 additions & 0 deletions pkg/store/copr/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ func buildTiDBMemCopTasks(ranges *KeyRanges, req *kv.Request) ([]*copTask, error
if req.TiDBServerID > 0 && req.TiDBServerID != ser.ServerIDGetter() {
continue
}
// skip some nodes, such as BR created when backup/restore
if ser.IP == config.UnavailableIP {
continue
}

addr := net.JoinHostPort(ser.IP, strconv.FormatUint(uint64(ser.StatusPort), 10))
tasks = append(tasks, &copTask{
Expand Down

0 comments on commit b6a817d

Please sign in to comment.