Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dumpling: GCS client always retry and also retry for 401 error. (#58198) #59553

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions br/pkg/storage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ go_library(
"@com_github_pingcap_log//:log",
"@com_github_spf13_pflag//:pflag",
"@com_google_cloud_go_storage//:storage",
"@org_golang_google_api//googleapi",
"@org_golang_google_api//iterator",
"@org_golang_google_api//option",
"@org_golang_x_oauth2//google",
Expand Down
21 changes: 21 additions & 0 deletions br/pkg/storage/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import (
"context"
goerrors "errors"
"io"
"os"
"path"
Expand All @@ -12,9 +13,12 @@
"cloud.google.com/go/storage"
"github.com/pingcap/errors"
backuppb "github.com/pingcap/kvproto/pkg/brpb"
"github.com/pingcap/log"
berrors "github.com/pingcap/tidb/br/pkg/errors"
"github.com/spf13/pflag"
"go.uber.org/zap"
"golang.org/x/oauth2/google"
"google.golang.org/api/googleapi"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
)
Expand Down Expand Up @@ -296,6 +300,7 @@
if err != nil {
return nil, errors.Trace(err)
}
client.SetRetry(storage.WithErrorFunc(shouldRetry), storage.WithPolicy(storage.RetryAlways))

if !opts.SendCredentials {
// Clear the credentials if exists so that they will not be sent to TiKV
Expand All @@ -306,6 +311,22 @@
return &GCSStorage{gcs: gcs, bucket: bucket}, nil
}

func shouldRetry(err error) bool {
if storage.ShouldRetry(err) {
return true
}

Check warning on line 317 in br/pkg/storage/gcs.go

View check run for this annotation

Codecov / codecov/patch

br/pkg/storage/gcs.go#L316-L317

Added lines #L316 - L317 were not covered by tests

// workaround for https://github.com/googleapis/google-cloud-go/issues/9262
if e := (&googleapi.Error{}); goerrors.As(err, &e) {
if e.Code == 401 && strings.Contains(e.Message, "Authentication required.") {
log.Warn("retrying gcs request due to internal authentication error", zap.Error(err))
return true
}

Check warning on line 324 in br/pkg/storage/gcs.go

View check run for this annotation

Codecov / codecov/patch

br/pkg/storage/gcs.go#L322-L324

Added lines #L322 - L324 were not covered by tests
}

return false
}

// gcsObjectReader wrap storage.Reader and add the `Seek` method.
type gcsObjectReader struct {
storage *GCSStorage
Expand Down