-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
binlog: fix show pump/drainer status #44764
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ import ( | |
"github.com/pingcap/tidb/privilege" | ||
"github.com/pingcap/tidb/privilege/privileges" | ||
"github.com/pingcap/tidb/sessionctx" | ||
"github.com/pingcap/tidb/sessionctx/binloginfo" | ||
"github.com/pingcap/tidb/sessionctx/sessionstates" | ||
"github.com/pingcap/tidb/sessionctx/stmtctx" | ||
"github.com/pingcap/tidb/sessionctx/variable" | ||
|
@@ -1876,16 +1877,18 @@ func (e *ShowExec) fetchShowWarnings(errOnly bool) error { | |
|
||
// fetchShowPumpOrDrainerStatus gets status of all pumps or drainers and fill them into e.rows. | ||
func (e *ShowExec) fetchShowPumpOrDrainerStatus(kind string) error { | ||
registry, err := createRegistry(config.GetGlobalConfig().Path) | ||
registry, needToClose, err := createRegistry(config.GetGlobalConfig().Path) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
nodes, _, err := registry.Nodes(context.Background(), node.NodePrefix[kind]) | ||
if err != nil { | ||
return errors.Trace(err) | ||
if needToClose { | ||
defer func() { | ||
_ = registry.Close() | ||
}() | ||
} | ||
err = registry.Close() | ||
|
||
nodes, _, err := registry.Nodes(context.Background(), node.NodePrefix[kind]) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
@@ -1900,18 +1903,21 @@ func (e *ShowExec) fetchShowPumpOrDrainerStatus(kind string) error { | |
return nil | ||
} | ||
|
||
// createRegistry returns an ectd registry | ||
func createRegistry(urls string) (*node.EtcdRegistry, error) { | ||
// createRegistry returns an ectd registry, need to close, and error | ||
func createRegistry(urls string) (*node.EtcdRegistry, bool, error) { | ||
if pumpClient := binloginfo.GetPumpsClient(); pumpClient != nil && pumpClient.EtcdRegistry != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need tolerate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. When TiDB doesn't enable binlog,
Yes. It's also binlog's related sql. It also have the same problem. |
||
return pumpClient.EtcdRegistry, false, nil | ||
} | ||
ectdEndpoints, err := util.ParseHostPortAddr(urls) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
return nil, false, errors.Trace(err) | ||
} | ||
cli, err := etcd.NewClientFromCfg(ectdEndpoints, etcdDialTimeout, node.DefaultRootPath, nil) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
return nil, false, errors.Trace(err) | ||
} | ||
|
||
return node.NewEtcdRegistry(cli, etcdDialTimeout), nil | ||
return node.NewEtcdRegistry(cli, etcdDialTimeout), true, nil | ||
} | ||
|
||
func (e *ShowExec) getTable() (table.Table, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to use a new function? This client, I think, is used for Pump/Drainer specifically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about changing function's name to
getOrCreateBinlogRegistry
to avoid abuse? @okJiang