diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-04-22 18:26:24 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-04-22 18:26:24 -0700 |
| commit | aebe39a80388e699ca9b210929159d9d9d552b29 (patch) | |
| tree | f559e02c8870fc8b310885c421a1edd69b561242 | |
| parent | 5d0e1d8d741b93c8f77b6ff709b5079580c7dda6 (diff) | |
| download | seaweedfs-aebe39a80388e699ca9b210929159d9d9d552b29.tar.xz seaweedfs-aebe39a80388e699ca9b210929159d9d9d552b29.zip | |
avoid repeated grpc connection creation
fix https://github.com/chrislusf/seaweedfs/issues/1277
| -rw-r--r-- | weed/pb/grpc_client_server.go | 11 | ||||
| -rw-r--r-- | weed/wdclient/masterclient.go | 3 |
2 files changed, 10 insertions, 4 deletions
diff --git a/weed/pb/grpc_client_server.go b/weed/pb/grpc_client_server.go index c4e35618f..ef22aeded 100644 --- a/weed/pb/grpc_client_server.go +++ b/weed/pb/grpc_client_server.go @@ -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 diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index f73853c78..4f8e0d5ef 100644 --- a/weed/wdclient/masterclient.go +++ b/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 { + for mc.currentMaster == "" { + time.Sleep(3 * time.Second) + } return pb.WithMasterClient(mc.currentMaster, mc.grpcDialOption, func(client master_pb.SeaweedClient) error { return fn(client) }) |
