Skip to content

Commit 20e6502

Browse files
danielblandoalexqyle
authored andcommitted
DoBatch preference to 4xx if error (cortexproject#4783)
* DoBatch preference to 4xx if error Signed-off-by: Daniel Blando <[email protected]> * Fix comment Signed-off-by: Daniel Blando <[email protected]> Signed-off-by: Alex Le <[email protected]>
1 parent 41e1f08 commit 20e6502

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
## master / unreleased
44
* [FEATURE] Compactor: Added `-compactor.block-files-concurrency` allowing to configure number of go routines for download/upload block files during compaction. #4784
55
* [ENHANCEMENT] Querier/Ruler: Retry store-gateway in case of unexpected failure, instead of failing the query. #4532
6+
* [ENHANCEMENT] Ring: DoBatch prioritize 4xx errors when failing. #4783
67
* [FEATURE] Compactor: Added -compactor.blocks-fetch-concurrency` allowing to configure number of go routines for blocks during compaction. #4787
78

89
## 1.13.0 2022-07-14
10+
911
* [CHANGE] Changed default for `-ingester.min-ready-duration` from 1 minute to 15 seconds. #4539
1012
* [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
1113
* [CHANGE] Compactor block deletion mark migration, needed when upgrading from v1.7, is now disabled by default. #4597

pkg/distributor/distributor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func TestPush_QuorumError(t *testing.T) {
554554
_, err := d.Push(ctx, request)
555555
status, ok := status.FromError(err)
556556
require.True(t, ok)
557-
require.True(t, status.Code() == 429 || status.Code() == 500)
557+
require.Equal(t, codes.Code(429), status.Code())
558558
}
559559

560560
// Simulating 1 error -> Should return 2xx

pkg/ring/batch.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,29 @@ type itemTracker struct {
3030
failed4xx atomic.Int32
3131
failed5xx atomic.Int32
3232
remaining atomic.Int32
33-
err atomic.Error
33+
err4xx atomic.Error
34+
err5xx atomic.Error
3435
}
3536

3637
func (i *itemTracker) recordError(err error) int32 {
37-
i.err.Store(err)
3838

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

44+
i.err5xx.Store(err)
4345
return i.failed5xx.Inc()
4446
}
4547

48+
func (i *itemTracker) getError() error {
49+
if i.failed5xx.Load() > i.failed4xx.Load() {
50+
return i.err5xx.Load()
51+
}
52+
53+
return i.err4xx.Load()
54+
}
55+
4656
// DoBatch request against a set of keys in the ring, handling replication and
4757
// failures. For example if we want to write N items where they may all
4858
// hit different instances, and we want them all replicated R ways with
@@ -142,12 +152,13 @@ func (b *batchTracker) record(sampleTrackers []*itemTracker, err error) {
142152
errCount := sampleTrackers[i].recordError(err)
143153
// We should return an error if we reach the maxFailure (quorum) on a given error family OR
144154
// we dont have any remaining ingesters to try
145-
// Ex: 2xx, 4xx, 5xx -> return 5xx
155+
// Ex: 2xx, 4xx, 5xx -> return 4xx
156+
// Ex: 2xx, 5xx, 4xx -> return 4xx
146157
// Ex: 4xx, 4xx, _ -> return 4xx
147158
// Ex: 5xx, _, 5xx -> return 5xx
148159
if errCount > int32(sampleTrackers[i].maxFailures) || sampleTrackers[i].remaining.Dec() == 0 {
149160
if b.rpcsFailed.Inc() == 1 {
150-
b.err <- err
161+
b.err <- sampleTrackers[i].getError()
151162
}
152163
}
153164
} else {
@@ -165,7 +176,7 @@ func (b *batchTracker) record(sampleTrackers []*itemTracker, err error) {
165176
// Ex: 4xx, 5xx, 2xx
166177
if sampleTrackers[i].remaining.Dec() == 0 {
167178
if b.rpcsFailed.Inc() == 1 {
168-
b.err <- sampleTrackers[i].err.Load()
179+
b.err <- sampleTrackers[i].getError()
169180
}
170181
}
171182
}

0 commit comments

Comments
 (0)