Skip to content

DoBatch preference to 4xx if error #4783

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

Merged
merged 2 commits into from
Jul 26, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
## master / unreleased
* [FEATURE] Compactor: Added `-compactor.block-files-concurrency` allowing to configure number of go routines for download/upload block files during compaction. #4784
* [ENHANCEMENT] Querier/Ruler: Retry store-gateway in case of unexpected failure, instead of failing the query. #4532
* [ENHANCEMENT] Ring: DoBatch prioritize 4xx errors when failing. #4783
* [FEATURE] Compactor: Added -compactor.blocks-fetch-concurrency` allowing to configure number of go routines for blocks during compaction. #4787

## 1.13.0 2022-07-14

* [CHANGE] Changed default for `-ingester.min-ready-duration` from 1 minute to 15 seconds. #4539
* [CHANGE] query-frontend: Do not print anything in the logs of `query-frontend` if a in-progress query has been canceled (context canceled) to avoid spam. #4562
* [CHANGE] Compactor block deletion mark migration, needed when upgrading from v1.7, is now disabled by default. #4597
Expand Down
2 changes: 1 addition & 1 deletion pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func TestPush_QuorumError(t *testing.T) {
_, err := d.Push(ctx, request)
status, ok := status.FromError(err)
require.True(t, ok)
require.True(t, status.Code() == 429 || status.Code() == 500)
require.Equal(t, codes.Code(429), status.Code())
}

// Simulating 1 error -> Should return 2xx
Expand Down
21 changes: 16 additions & 5 deletions pkg/ring/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@ type itemTracker struct {
failed4xx atomic.Int32
failed5xx atomic.Int32
remaining atomic.Int32
err atomic.Error
err4xx atomic.Error
err5xx atomic.Error
}

func (i *itemTracker) recordError(err error) int32 {
i.err.Store(err)

if status, ok := status.FromError(err); ok && status.Code()/100 == 4 {
i.err4xx.Store(err)
return i.failed4xx.Inc()
}

i.err5xx.Store(err)
return i.failed5xx.Inc()
}

func (i *itemTracker) getError() error {
if i.failed5xx.Load() > i.failed4xx.Load() {
return i.err5xx.Load()
}

return i.err4xx.Load()
Comment on lines +49 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about fetching the two values into local variables, so you don't make 4x atomic calls?

Copy link
Contributor Author

@danielblando danielblando Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bryan, i am not sure i get your idea. They are 4 different variables. 2 for amount of erros and 2 for the actual error. Current we can only return the last known error, the change is basically to hold one error for each family type.

}

// DoBatch request against a set of keys in the ring, handling replication and
// failures. For example if we want to write N items where they may all
// hit different instances, and we want them all replicated R ways with
Expand Down Expand Up @@ -142,12 +152,13 @@ func (b *batchTracker) record(sampleTrackers []*itemTracker, err error) {
errCount := sampleTrackers[i].recordError(err)
// We should return an error if we reach the maxFailure (quorum) on a given error family OR
// we dont have any remaining ingesters to try
// Ex: 2xx, 4xx, 5xx -> return 5xx
// Ex: 2xx, 4xx, 5xx -> return 4xx
// Ex: 2xx, 5xx, 4xx -> return 4xx
// Ex: 4xx, 4xx, _ -> return 4xx
// Ex: 5xx, _, 5xx -> return 5xx
if errCount > int32(sampleTrackers[i].maxFailures) || sampleTrackers[i].remaining.Dec() == 0 {
if b.rpcsFailed.Inc() == 1 {
b.err <- err
b.err <- sampleTrackers[i].getError()
}
}
} else {
Expand All @@ -165,7 +176,7 @@ func (b *batchTracker) record(sampleTrackers []*itemTracker, err error) {
// Ex: 4xx, 5xx, 2xx
if sampleTrackers[i].remaining.Dec() == 0 {
if b.rpcsFailed.Inc() == 1 {
b.err <- sampleTrackers[i].err.Load()
b.err <- sampleTrackers[i].getError()
}
}
}
Expand Down