Skip to content

Commit 8bb7919

Browse files
craig[bot]kev-cao
andcommitted
Merge #153369
153369: backup: use ioctx.ReadAll when reading index metadata r=msbutler a=kev-cao We currently use `io.Reader`'s `Read` to read the index metadata file. However, `Read` behavior w.r.t to returning an EOF after reading the entire file is not consistent --- S3's implementation returns EOF even if bytes are read, whereas GCS's implementation returns EOF only if a read is attempted after reading the file. The correct solution is to use `ioctx.ReadAll` whenever performing reads. Fixes: #153215 Fixes: #153214 Fixes: #153213 Fixes: #153212 Release note: None Co-authored-by: Kevin Cao <[email protected]>
2 parents 5154683 + 2de31f5 commit 8bb7919

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pkg/backup/backupdest/backup_index.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/cockroachdb/cockroach/pkg/sql"
2626
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
2727
"github.com/cockroachdb/cockroach/pkg/util/hlc"
28+
"github.com/cockroachdb/cockroach/pkg/util/ioctx"
2829
"github.com/cockroachdb/cockroach/pkg/util/metamorphic"
2930
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
3031
"github.com/cockroachdb/cockroach/pkg/util/tracing"
@@ -239,17 +240,17 @@ func GetBackupTreeIndexMetadata(
239240
if err != nil {
240241
return err
241242
}
242-
reader, size, err := store.ReadFile(
243+
reader, _, err := store.ReadFile(
243244
ctx, path.Join(indexDir, basename), cloud.ReadOptions{},
244245
)
245246
if err != nil {
246247
return errors.Wrapf(err, "reading index file %s", basename)
247248
}
248249
defer reader.Close(ctx)
249250

250-
bytes := make([]byte, size)
251-
if _, err := reader.Read(ctx, bytes); err != nil {
252-
return errors.Wrapf(err, "reading index file %s bytes", basename)
251+
bytes, err := ioctx.ReadAll(ctx, reader)
252+
if err != nil {
253+
return errors.Wrapf(err, "reading index file %s", basename)
253254
}
254255

255256
index := backuppb.BackupIndexMetadata{}

0 commit comments

Comments
 (0)