diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-04-05 20:31:58 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-04-05 20:31:58 -0700 |
| commit | c789b496d82bb1ff811dd8682c7ebde3d7725a03 (patch) | |
| tree | d3c08adb87674a81fb9a3f9abdf51ec553d2ffc1 /weed/s3api/s3api_handlers.go | |
| parent | 5808caa2f55b1e9c76c5fa50576db895a499892c (diff) | |
| download | seaweedfs-c789b496d82bb1ff811dd8682c7ebde3d7725a03.tar.xz seaweedfs-c789b496d82bb1ff811dd8682c7ebde3d7725a03.zip | |
use cached grpc client
Diffstat (limited to 'weed/s3api/s3api_handlers.go')
| -rw-r--r-- | weed/s3api/s3api_handlers.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/weed/s3api/s3api_handlers.go b/weed/s3api/s3api_handlers.go index 5a63648ca..127be07e3 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 |
