-
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 2 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" | ||
|
@@ -152,10 +153,31 @@ 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 s.SyncBlocks(ctx) | ||
return u.syncUsersBlocksWithRetries(ctx, s) | ||
}) | ||
} | ||
|
||
func (u *BucketStores) syncUsersBlocksWithRetries(ctx context.Context, s *store.BucketStore) error { | ||
var lastErr error | ||
|
||
retries := util.NewBackoff(ctx, util.BackoffConfig{ | ||
MinBackoff: 100 * time.Millisecond, | ||
MaxBackoff: 10 * time.Second, | ||
MaxRetries: 3, | ||
Comment on lines
+162
to
+164
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: Given that 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. Ah ok I originally stole that from here and just modified it along the way. Is a 1-second 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. 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. |
||
}) | ||
|
||
for retries.Ongoing() { | ||
lastErr = s.SyncBlocks(ctx) | ||
if lastErr != nil { | ||
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 will return error on first failure, and will not do any retry. Better version would be:
|
||
return lastErr | ||
} | ||
|
||
retries.Wait() | ||
} | ||
|
||
return nil | ||
} | ||
|
||
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.
I'm not sure about this design. We pass our own function to
u.syncUsersBlocks()
. I was expecting something like this:And then having
syncUsersBlocksWithRetries()
callingsyncUsersBlocks()
.Am I missing anything?
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.
Nope. I'll get on it!