Skip to content

Commit

Permalink
cmd/tools/metabase-listing-performance: handle timeout correctly
Browse files Browse the repository at this point in the history
Change-Id: Iee48bbe50cba1c74adb272d8c21d50b631f72609
  • Loading branch information
egonelbre authored and Storj Robot committed Apr 11, 2024
1 parent 7d05502 commit 8b0cb71
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cmd/tools/metabase-listing-performance/main.go
Expand Up @@ -23,7 +23,6 @@ import (
"golang.org/x/exp/slices"

_ "storj.io/common/dbutil/cockroachutil"
"storj.io/common/errs2"
"storj.io/common/uuid"
"storj.io/storj/satellite/metabase"
)
Expand Down Expand Up @@ -230,20 +229,24 @@ func Benchmark(ctx context.Context, log *zap.Logger, db *metabase.DB) (err error

if !*skipList {
err := benchmarkListObjects(ctx, slog, db, testName, opts, listFile)
err = errs2.IgnoreCanceled(err)
err = ignoreTimeoutOrCancel(err)
if err != nil {
return errs.Wrap(err)
}
_ = listFile.Sync()
}
if !*skipIterator {
err := benchmarkIterator(ctx, slog, db, testName, opts, iterateFile)
err = errs2.IgnoreCanceled(err)
err = ignoreTimeoutOrCancel(err)
if err != nil {
return errs.Wrap(err)
}
_ = iterateFile.Sync()
}

if ctx.Err() != nil {
return errs.Wrap(ctx.Err())
}
}
}
}
Expand All @@ -252,6 +255,21 @@ func Benchmark(ctx context.Context, log *zap.Logger, db *metabase.DB) (err error
return nil
}

// isCanceledOrTimeout returns true, when the error is a cancellation.
func isCanceledOrTimeout(err error) bool {
return errs.IsFunc(err, func(err error) bool {
return err == context.Canceled || err == context.DeadlineExceeded //nolint:errorlint,goerr113
})
}

// ignoreTimeoutOrCancel returns nil, when the operation was about canceling.
func ignoreTimeoutOrCancel(err error) error {
if isCanceledOrTimeout(err) {
return nil
}
return err
}

const maxTimePerBenchmark = 5 * time.Minute

func benchmarkListObjects(ctx context.Context, log *zap.Logger, db *metabase.DB, testName string, opts metabase.ListObjects, out io.Writer) error {
Expand Down

0 comments on commit 8b0cb71

Please sign in to comment.