1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-07-08 18:16:50 +02:00

avoid repeated grpc connection creation

fix https://github.com/chrislusf/seaweedfs/issues/1277
This commit is contained in:
Chris Lu 2020-04-22 18:26:24 -07:00
parent 5d0e1d8d74
commit aebe39a803
2 changed files with 10 additions and 4 deletions

View file

@ -86,13 +86,15 @@ func WithCachedGrpcClient(fn func(*grpc.ClientConn) error, address string, opts
err := fn(existingConnection)
if err != nil {
grpcClientsLock.Lock()
delete(grpcClients, address)
// delete(grpcClients, address)
grpcClientsLock.Unlock()
existingConnection.Close()
// println("closing existing connection to", existingConnection.Target())
// existingConnection.Close()
}
return err
}
println(" dialing to", address, "...")
grpcConnection, err := GrpcDial(context.Background(), address, opts...)
if err != nil {
grpcClientsLock.Unlock()
@ -105,9 +107,10 @@ func WithCachedGrpcClient(fn func(*grpc.ClientConn) error, address string, opts
err = fn(grpcConnection)
if err != nil {
grpcClientsLock.Lock()
delete(grpcClients, address)
// delete(grpcClients, address)
grpcClientsLock.Unlock()
grpcConnection.Close()
// println("closing created new connection to", grpcConnection.Target())
// grpcConnection.Close()
}
return err

View file

@ -121,6 +121,9 @@ func (mc *MasterClient) tryConnectToMaster(master string) (nextHintedLeader stri
}
func (mc *MasterClient) WithClient(fn func(client master_pb.SeaweedClient) error) error {
for mc.currentMaster == "" {
time.Sleep(3 * time.Second)
}
return pb.WithMasterClient(mc.currentMaster, mc.grpcDialOption, func(client master_pb.SeaweedClient) error {
return fn(client)
})