@@ -105,6 +105,8 @@ type ServiceDiscovery interface {
105105 GetAllServiceClients () []ServiceClient
106106 // GetOrCreateGRPCConn returns the corresponding grpc client connection of the given url.
107107 GetOrCreateGRPCConn (url string ) (* grpc.ClientConn , error )
108+ // RemoveClientConn removes and closes the gRPC connection of the given url.
109+ RemoveClientConn (url string )
108110 // ScheduleCheckMemberChanged is used to trigger a check to see if there is any membership change
109111 // among the leader/followers in a quorum-based cluster or among the primary/secondaries in a
110112 // primary/secondary configured cluster.
@@ -1129,6 +1131,17 @@ func (c *pdServiceDiscovery) GetOrCreateGRPCConn(url string) (*grpc.ClientConn,
11291131 return grpcutil .GetOrCreateGRPCConn (c .ctx , & c .clientConns , url , c .tlsCfg , c .option .gRPCDialOptions ... )
11301132}
11311133
1134+ // RemoveClientConn removes and closes the grpc client connection of the given URL.
1135+ func (c * pdServiceDiscovery ) RemoveClientConn (url string ) {
1136+ cc , ok := c .clientConns .Load (url )
1137+ if ! ok {
1138+ return
1139+ }
1140+ if err := cc .(* grpc.ClientConn ).Close (); err != nil {
1141+ log .Error ("[pd] failed to close grpc clientConn" , errs .ZapError (errs .ErrCloseGRPCConn , err ))
1142+ }
1143+ }
1144+
11321145func addrsToURLs (addrs []string , tlsCfg * tls.Config ) []string {
11331146 // Add default schema "http://" to addrs.
11341147 urls := make ([]string , 0 , len (addrs ))
0 commit comments