-
Notifications
You must be signed in to change notification settings - Fork 814
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
Add Retries to Sync Blocks #3975
Changes from 3 commits
2e4acec
17aeb6a
5ebd50c
82f3d78
e23593f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,6 +32,7 @@ import ( | |||||
|
||||||
"github.com/cortexproject/cortex/pkg/storage/bucket" | ||||||
"github.com/cortexproject/cortex/pkg/storage/tsdb" | ||||||
"github.com/cortexproject/cortex/pkg/util" | ||||||
util_log "github.com/cortexproject/cortex/pkg/util/log" | ||||||
"github.com/cortexproject/cortex/pkg/util/spanlogger" | ||||||
"github.com/cortexproject/cortex/pkg/util/validation" | ||||||
|
@@ -151,11 +152,30 @@ func (u *BucketStores) InitialSync(ctx context.Context) error { | |||||
|
||||||
// SyncBlocks synchronizes the stores state with the Bucket store for every user. | ||||||
func (u *BucketStores) SyncBlocks(ctx context.Context) error { | ||||||
return u.syncUsersBlocks(ctx, func(ctx context.Context, s *store.BucketStore) error { | ||||||
return u.syncUsersBlocksWithRetries(ctx, func(ctx context.Context, s *store.BucketStore) error { | ||||||
return s.SyncBlocks(ctx) | ||||||
}) | ||||||
} | ||||||
|
||||||
func (u *BucketStores) syncUsersBlocksWithRetries(ctx context.Context, f func(context.Context, *store.BucketStore) error) error { | ||||||
retries := util.NewBackoff(ctx, util.BackoffConfig{ | ||||||
MinBackoff: 100 * time.Millisecond, | ||||||
MaxBackoff: 10 * time.Second, | ||||||
MaxRetries: 3, | ||||||
}) | ||||||
|
||||||
for retries.Ongoing() { | ||||||
err := u.syncUsersBlocks(ctx, f) | ||||||
if err == nil { | ||||||
return err | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] it's the same but more clear:
Suggested change
|
||||||
} | ||||||
|
||||||
retries.Wait() | ||||||
} | ||||||
|
||||||
return retries.Err() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would suppress the actual error. I would save the last error returned by |
||||||
} | ||||||
|
||||||
func (u *BucketStores) syncUsersBlocks(ctx context.Context, f func(context.Context, *store.BucketStore) error) (returnErr error) { | ||||||
defer func(start time.Time) { | ||||||
u.syncTimes.Observe(time.Since(start).Seconds()) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Given that
maxRetries
is 3, we can never reach max backoff of 10 seconds. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok I originally stole that from here and just modified it along the way. Is a 1-second
MaxBackoff
ok?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok to keep it as is. If you choose to use 1s as MaxBackoff, that's fine too. I think it's more important to do retry here, than how much time it waits.