@@ -50,6 +50,7 @@ import (
50
50
"github.com/pingcap/tidb/privilege"
51
51
"github.com/pingcap/tidb/privilege/privileges"
52
52
"github.com/pingcap/tidb/sessionctx"
53
+ "github.com/pingcap/tidb/sessionctx/binloginfo"
53
54
"github.com/pingcap/tidb/sessionctx/sessionstates"
54
55
"github.com/pingcap/tidb/sessionctx/stmtctx"
55
56
"github.com/pingcap/tidb/sessionctx/variable"
@@ -1775,16 +1776,18 @@ func (e *ShowExec) fetchShowWarnings(errOnly bool) error {
1775
1776
1776
1777
// fetchShowPumpOrDrainerStatus gets status of all pumps or drainers and fill them into e.rows.
1777
1778
func (e * ShowExec ) fetchShowPumpOrDrainerStatus (kind string ) error {
1778
- registry , err := createRegistry (config .GetGlobalConfig ().Path )
1779
+ registry , needToClose , err := getOrCreateBinlogRegistry (config .GetGlobalConfig ().Path )
1779
1780
if err != nil {
1780
1781
return errors .Trace (err )
1781
1782
}
1782
1783
1783
- nodes , _ , err := registry .Nodes (context .Background (), node .NodePrefix [kind ])
1784
- if err != nil {
1785
- return errors .Trace (err )
1784
+ if needToClose {
1785
+ defer func () {
1786
+ _ = registry .Close ()
1787
+ }()
1786
1788
}
1787
- err = registry .Close ()
1789
+
1790
+ nodes , _ , err := registry .Nodes (context .Background (), node .NodePrefix [kind ])
1788
1791
if err != nil {
1789
1792
return errors .Trace (err )
1790
1793
}
@@ -1799,18 +1802,21 @@ func (e *ShowExec) fetchShowPumpOrDrainerStatus(kind string) error {
1799
1802
return nil
1800
1803
}
1801
1804
1802
- // createRegistry returns an ectd registry
1803
- func createRegistry (urls string ) (* node.EtcdRegistry , error ) {
1805
+ // getOrCreateBinlogRegistry returns an etcd registry for binlog, need to close, and error
1806
+ func getOrCreateBinlogRegistry (urls string ) (* node.EtcdRegistry , bool , error ) {
1807
+ if pumpClient := binloginfo .GetPumpsClient (); pumpClient != nil && pumpClient .EtcdRegistry != nil {
1808
+ return pumpClient .EtcdRegistry , false , nil
1809
+ }
1804
1810
ectdEndpoints , err := util .ParseHostPortAddr (urls )
1805
1811
if err != nil {
1806
- return nil , errors .Trace (err )
1812
+ return nil , false , errors .Trace (err )
1807
1813
}
1808
1814
cli , err := etcd .NewClientFromCfg (ectdEndpoints , etcdDialTimeout , node .DefaultRootPath , nil )
1809
1815
if err != nil {
1810
- return nil , errors .Trace (err )
1816
+ return nil , false , errors .Trace (err )
1811
1817
}
1812
1818
1813
- return node .NewEtcdRegistry (cli , etcdDialTimeout ), nil
1819
+ return node .NewEtcdRegistry (cli , etcdDialTimeout ), true , nil
1814
1820
}
1815
1821
1816
1822
func (e * ShowExec ) getTable () (table.Table , error ) {
0 commit comments