Skip to content

Commit 1be9cc9

Browse files
committed
creating IsOneOfTheExpectedErrors func
Signed-off-by: Alan Protasio <[email protected]>
1 parent 1828dcd commit 1be9cc9

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

pkg/storage/tsdb/bucketindex/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func ReadIndex(ctx context.Context, bkt objstore.Bucket, userID string, cfgProvi
2727
userBkt := bucket.NewUserBucketClient(userID, bkt, cfgProvider)
2828

2929
// Get the bucket index.
30-
reader, err := userBkt.WithExpectedErrs(tsdb.IsObjNotFoundOrCustomerManagedKeyErr(userBkt)).Get(ctx, IndexCompressedFilename)
30+
reader, err := userBkt.WithExpectedErrs(tsdb.IsOneOfTheExpectedErrors(userBkt.IsCustomerManagedKeyError, userBkt.IsObjNotFoundErr)).Get(ctx, IndexCompressedFilename)
3131
if err != nil {
3232
if userBkt.IsObjNotFoundErr(err) {
3333
return nil, ErrIndexNotFound

pkg/storage/tsdb/bucketindex/updater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (w *Updater) updateBlockIndexEntry(ctx context.Context, id ulid.ULID) (*Blo
132132
metaFile := path.Join(id.String(), block.MetaFilename)
133133

134134
// Get the block's meta.json file.
135-
r, err := w.bkt.ReaderWithExpectedErrs(tsdb.IsObjNotFoundOrCustomerManagedKeyErr(w.bkt)).Get(ctx, metaFile)
135+
r, err := w.bkt.ReaderWithExpectedErrs(tsdb.IsOneOfTheExpectedErrors(w.bkt.IsObjNotFoundErr, w.bkt.IsCustomerManagedKeyError)).Get(ctx, metaFile)
136136
if w.bkt.IsObjNotFoundErr(err) {
137137
return nil, ErrBlockMetaNotFound
138138
}

pkg/storage/tsdb/util.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ func HashBlockID(id ulid.ULID) uint32 {
1717
return h
1818
}
1919

20-
func IsObjNotFoundOrCustomerManagedKeyErr(bkt objstore.Bucket) objstore.IsOpFailureExpectedFunc {
20+
func IsOneOfTheExpectedErrors(f ...objstore.IsOpFailureExpectedFunc) objstore.IsOpFailureExpectedFunc {
2121
return func(err error) bool {
22-
return bkt.IsObjNotFoundErr(err) || bkt.IsCustomerManagedKeyError(err)
22+
for _, f := range f {
23+
if f(err) {
24+
return true
25+
}
26+
}
27+
return false
2328
}
2429
}

0 commit comments

Comments
 (0)