Skip to content

Commit

Permalink
[enhancement] proxy: reduce the interval time of refresh cn nodes (#1…
Browse files Browse the repository at this point in the history
…9704)

reduce the interval time of refresh cn nodes

Approved by: @daviszhen, @zhangxu19830126, @sukki37
  • Loading branch information
volgariver6 authored Nov 2, 2024
1 parent e36630f commit 1130481
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1729,11 +1729,13 @@ func doShowBackendServers(ses *Session, execCtx *ExecCtx) error {
labels["account"] = tenant
se = clusterservice.NewSelector().SelectByLabel(
filterLabels(labels), clusterservice.Contain)
moc := clusterservice.GetMOCluster(ses.GetService())
moc.ForceRefresh(true)
if isSysTenant(tenant) {
u := ses.GetTenantInfo().GetUser()
// For super use dump and root, we should list all servers.
if isSuperUser(u) {
clusterservice.GetMOCluster(ses.GetService()).GetCNService(
moc.GetCNService(
clusterservice.NewSelectAll(), func(s metadata.CNService) bool {
appendFn(&s)
return true
Expand Down
46 changes: 46 additions & 0 deletions pkg/frontend/mysql_cmd_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,52 @@ func TestMysqlCmdExecutor_HandleShowBackendServers(t *testing.T) {
require.Equal(t, "s1", row[0])
require.Equal(t, "addr1", row[1])
})

convey.Convey("filter label sys account", t, func() {
ses.mrs = &MysqlResultSet{}
cluster := clusterservice.NewMOCluster(
sid,
nil,
0,
clusterservice.WithDisableRefresh(),
clusterservice.WithServices(
[]metadata.CNService{
{
ServiceID: "s1",
SQLAddress: "addr1",
Labels: map[string]metadata.LabelList{
"account": {Labels: []string{"t1"}},
},
WorkState: metadata.WorkState_Working,
},
{
ServiceID: "s2",
SQLAddress: "addr2",
Labels: map[string]metadata.LabelList{
"account": {Labels: []string{"t2"}},
},
WorkState: metadata.WorkState_Working,
},
{
ServiceID: "s3",
SQLAddress: "addr3",
WorkState: metadata.WorkState_Working,
},
},
nil,
),
)
runtime.ServiceRuntime(sid).SetGlobalVariables(runtime.ClusterService, cluster)
ses.SetTenantInfo(&TenantInfo{Tenant: "sys", User: "dump"})
proto.connectAttrs = map[string]string{}
ec := newTestExecCtx(ctx, ctrl)

err = handleShowBackendServers(ses, ec)
require.NoError(t, err)
rs := ses.GetMysqlResultSet()
require.Equal(t, uint64(4), rs.GetColumnCount())
require.Equal(t, uint64(3), rs.GetRowCount())
})
},
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
// The default value of proxy service.
defaultListenAddress = "127.0.0.1:6009"
// The default value of refresh interval to HAKeeper.
defaultRefreshInterval = 5 * time.Second
defaultRefreshInterval = 2 * time.Second
// The default value of rebalance interval.
defaultRebalanceInterval = 10 * time.Second
// The default value of rebalnce tolerance.
Expand Down

0 comments on commit 1130481

Please sign in to comment.