Browse Source

avoid repeated grpc connection creation

fix https://github.com/chrislusf/seaweedfs/issues/1277
pull/1293/head
Chris Lu 5 years ago
parent
commit
aebe39a803
  1. 11
      weed/pb/grpc_client_server.go
  2. 3
      weed/wdclient/masterclient.go

11
weed/pb/grpc_client_server.go

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

3
weed/wdclient/masterclient.go

@ -121,6 +121,9 @@ func (mc *MasterClient) tryConnectToMaster(master string) (nextHintedLeader stri
} }
func (mc *MasterClient) WithClient(fn func(client master_pb.SeaweedClient) error) error { 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 pb.WithMasterClient(mc.currentMaster, mc.grpcDialOption, func(client master_pb.SeaweedClient) error {
return fn(client) return fn(client)
}) })

Loading…
Cancel
Save