use cached grpc client

This commit is contained in:
Chris Lu 2019-04-05 20:26:52 -07:00
parent cd6d35aa52
commit 5808caa2f5

View File

@ -106,15 +106,11 @@ func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.Di
return fmt.Errorf("failed to parse master grpc %v", master) return fmt.Errorf("failed to parse master grpc %v", master)
} }
grpcConnection, err := util.GrpcDial(ctx, masterGrpcAddress, grpcDialOption) return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {
if err != nil { client := master_pb.NewSeaweedClient(grpcConnection)
return fmt.Errorf("fail to dial %s: %v", master, err) return fn(ctx, client)
} }, masterGrpcAddress, grpcDialOption)
defer grpcConnection.Close()
client := master_pb.NewSeaweedClient(grpcConnection)
return fn(ctx, client)
} }
func (mc *MasterClient) WithClient(ctx context.Context, fn func(client master_pb.SeaweedClient) error) error { func (mc *MasterClient) WithClient(ctx context.Context, fn func(client master_pb.SeaweedClient) error) error {