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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
use cached grpc client
Chris Luc789b496d82b
diff --git a/weed/replication/sink/filersink/fetch_write.go b/weed/replication/sink/filersink/fetch_write.goindex 0f3473ff20..d24770e3d1 100644--- a/weed/replication/sink/filersink/fetch_write.go+++ b/weed/replication/sink/filersink/fetch_write.go@@ -3,6 +3,7 @@ package filersinkimport ("context""fmt"+ "google.golang.org/grpc""strings""sync"@@ -105,15 +106,11 @@ func (fs *FilerSink) fetchAndWrite(ctx context.Context, sourceChunk *filer_pb.Fifunc (fs *FilerSink) withFilerClient(ctx context.Context, fn func(filer_pb.SeaweedFilerClient) error) error {- grpcConnection, err := util.GrpcDial(ctx, fs.grpcAddress, fs.grpcDialOption)- if err != nil {- return fmt.Errorf("fail to dial %s: %v", fs.grpcAddress, err)- }- defer grpcConnection.Close()-- client := filer_pb.NewSeaweedFilerClient(grpcConnection)+ return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {+ client := filer_pb.NewSeaweedFilerClient(grpcConnection)+ return fn(client)+ }, fs.grpcAddress, fs.grpcDialOption)- return fn(client)}func volumeId(fileId string) string {diff --git a/weed/replication/source/filer_source.go b/weed/replication/source/filer_source.goindex 3ab6c72611..d7b5ebc4d7 100644--- a/weed/replication/source/filer_source.go+++ b/weed/replication/source/filer_source.go@@ -91,15 +91,11 @@ func (fs *FilerSource) ReadPart(ctx context.Context, part string) (filename strifunc (fs *FilerSource) withFilerClient(ctx context.Context, grpcDialOption grpc.DialOption, fn func(filer_pb.SeaweedFilerClient) error) error {- grpcConnection, err := util.GrpcDial(ctx, fs.grpcAddress, grpcDialOption)- if err != nil {- return fmt.Errorf("fail to dial %s: %v", fs.grpcAddress, err)- }- defer grpcConnection.Close()-- client := filer_pb.NewSeaweedFilerClient(grpcConnection)+ return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {+ client := filer_pb.NewSeaweedFilerClient(grpcConnection)+ return fn(client)+ }, fs.grpcAddress, fs.grpcDialOption)- return fn(client)}func volumeId(fileId string) string {diff --git a/weed/s3api/s3api_handlers.go b/weed/s3api/s3api_handlers.goindex 5a63648ca7..127be07e32 100644--- a/weed/s3api/s3api_handlers.go+++ b/weed/s3api/s3api_handlers.go@@ -9,6 +9,7 @@ import ("github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/pb/filer_pb""github.com/chrislusf/seaweedfs/weed/util"+ "google.golang.org/grpc""net/http""net/url""time"@@ -38,15 +39,11 @@ func encodeResponse(response interface{}) []byte {func (s3a *S3ApiServer) withFilerClient(ctx context.Context, fn func(filer_pb.SeaweedFilerClient) error) error {- grpcConnection, err := util.GrpcDial(ctx, s3a.option.FilerGrpcAddress, s3a.option.GrpcDialOption)- if err != nil {- return fmt.Errorf("fail to dial %s: %v", s3a.option.FilerGrpcAddress, err)- }- defer grpcConnection.Close()-- client := filer_pb.NewSeaweedFilerClient(grpcConnection)+ return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {+ client := filer_pb.NewSeaweedFilerClient(grpcConnection)+ return fn(client)+ }, s3a.option.FilerGrpcAddress, s3a.option.GrpcDialOption)- return fn(client)}// If none of the http routes match respond with MethodNotAllowed