Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

use cached grpc client

Chris Lu5808caa2f55b
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go
index 794471f7b1..7a0bc9181e 100644
--- a/weed/wdclient/masterclient.go
+++ b/weed/wdclient/masterclient.go
@@ -106,15 +106,11 @@ func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.Di
return fmt.Errorf("failed to parse master grpc %v", master)
}
- grpcConnection, err := util.GrpcDial(ctx, masterGrpcAddress, grpcDialOption)
- if err != nil {
- return fmt.Errorf("fail to dial %s: %v", master, err)
- }
- defer grpcConnection.Close()
-
- client := master_pb.NewSeaweedClient(grpcConnection)
+ return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {
+ client := master_pb.NewSeaweedClient(grpcConnection)
+ return fn(ctx, client)
+ }, masterGrpcAddress, grpcDialOption)
- return fn(ctx, client)
}
func (mc *MasterClient) WithClient(ctx context.Context, fn func(client master_pb.SeaweedClient) error) error {