Skip to content

Commit cac52f7

Browse files
feat(storage): Use ReadHandle for faster re-connect (googleapis#11510)
1 parent da9788f commit cac52f7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

storage/grpc_client.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,10 +1112,15 @@ func (c *grpcStorageClient) NewMultiRangeDownloader(ctx context.Context, params
11121112

11131113
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, contextMetadataFromBidiReadObject(req)...)
11141114

1115-
openStream := func() (*bidiReadStreamResponse, context.CancelFunc, error) {
1115+
openStream := func(readHandle ReadHandle) (*bidiReadStreamResponse, context.CancelFunc, error) {
11161116
if err := applyCondsProto("grpcStorageClient.BidiReadObject", params.gen, params.conds, r); err != nil {
11171117
return nil, nil, err
11181118
}
1119+
if readHandle != nil {
1120+
req.GetReadObjectSpec().ReadHandle = &storagepb.BidiReadHandle{
1121+
Handle: readHandle,
1122+
}
1123+
}
11191124
var stream storagepb.Storage_BidiReadObjectClient
11201125
var resp *storagepb.BidiReadObjectResponse
11211126
cc, cancel := context.WithCancel(ctx)
@@ -1158,7 +1163,7 @@ func (c *grpcStorageClient) NewMultiRangeDownloader(ctx context.Context, params
11581163
}
11591164

11601165
// For the first time open stream without adding any range.
1161-
resp, cancel, err := openStream()
1166+
resp, cancel, err := openStream(nil)
11621167
if err != nil {
11631168
return nil, err
11641169
}
@@ -1419,7 +1424,7 @@ func (r *gRPCBidiReader) reopenStream(failSpec []rangeSpec) error {
14191424
r.cancel()
14201425
}
14211426

1422-
res, cancel, err := r.reopen()
1427+
res, cancel, err := r.reopen(r.readHandle)
14231428
if err != nil {
14241429
return err
14251430
}
@@ -1894,7 +1899,7 @@ type gRPCBidiReader struct {
18941899
settings *settings
18951900
readHandle ReadHandle
18961901
readID int64
1897-
reopen func() (*bidiReadStreamResponse, context.CancelFunc, error)
1902+
reopen func(ReadHandle) (*bidiReadStreamResponse, context.CancelFunc, error)
18981903
readSpec *storagepb.BidiReadObjectSpec
18991904
data chan []rangeSpec
19001905
ctx context.Context

0 commit comments

Comments
 (0)