Skip to content

Commit

Permalink
[dbnode] Emit consistencyResultError from fetchTaggedResultAccumulator
Browse files Browse the repository at this point in the history
  • Loading branch information
vpranckaitis committed Dec 15, 2020
1 parent 59843cf commit aec8152
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/dbnode/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ func IsBadRequestError(err error) bool {

// IsConsistencyResultError determines if the error is a consistency result error.
func IsConsistencyResultError(err error) bool {
_, ok := err.(consistencyResultErr)
return ok
for err != nil {
if _, ok := err.(consistencyResultErr); ok { //nolint:errorlint
return true
}
err = xerrors.InnerError(err)
}
return false
}

// NumResponded returns how many nodes responded for a given error
Expand Down Expand Up @@ -117,8 +122,8 @@ func isHostNotAvailableError(err error) bool {

type consistencyResultError interface {
error
xerrors.ContainedError

InnerError() error
numResponded() int
numSuccess() int
}
Expand Down
7 changes: 6 additions & 1 deletion src/dbnode/client/fetch_tagged_results_accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,13 @@ func (accum *fetchTaggedResultAccumulator) accumulatedResult(
doneAccumulating := true
// NB(r): Use new renamed error to keep the underlying error
// (invalid/retryable) type.
enqueued := accum.topoMap.HostsLen()
responded := enqueued
consistencyErr := newConsistencyResultError(accum.consistencyLevel, enqueued, responded,
accum.errors)
err := fmt.Errorf("unable to satisfy consistency requirements: shards=%d, err=%v",
accum.numShardsPending, accum.errors)
accum.numShardsPending, consistencyErr)
err = xerrors.NewRenamedError(consistencyErr, err)
for i := range accum.errors {
if IsBadRequestError(accum.errors[i]) {
err = xerrors.NewInvalidParamsError(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ func (tm testFetchStateWorkflow) run() fetchTaggedResultAccumulator {
}
assert.Equal(tm.t, s.expectedDone, done, fmt.Sprintf("i=%d, step=%+v", i, s))
assert.Equal(tm.t, s.expectedErr, err != nil, fmt.Sprintf("i=%d, step=%+v, err=%v", i, s, err))
if err != nil {
assert.True(tm.t, IsConsistencyResultError(err),
fmt.Sprintf("i=%d, step=%+v, expected consistency result error", i, s))
}
}
return accum
}
Expand Down

0 comments on commit aec8152

Please sign in to comment.