Skip to content

Commit

Permalink
retry on batches
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Aug 18, 2024
1 parent 07bbd78 commit e68dc38
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions io/aerospike/record_batch_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func (rw *batchRecordWriter) flushBuffer() error {
for attemptsLeft(rw.retryPolicy, attempt) {
err := rw.asc.BatchOperate(nil, rw.operationBuffer)

if err == nil || isAcceptableError(err) {
if isNilOrAcceptableError(err) {
rw.operationBuffer = rw.processAndFilterOperations()
if len(rw.operationBuffer) == 0 {
return nil // All operations succeeded
}
} else if err != nil && !shouldRetry(err) {
} else if !shouldRetry(err) {
return fmt.Errorf("non-retryable error on restore: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion io/aerospike/record_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (rw *singleRecordWriter) executeWrite(writePolicy *a.WritePolicy, record *m
return nil
}

if isAcceptableError(aerr) {
if isNilOrAcceptableError(aerr) {
switch {
case aerr.Matches(atypes.GENERATION_ERROR):
rw.stats.IncrRecordsFresher()
Expand Down
6 changes: 3 additions & 3 deletions io/aerospike/restore_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ func sleep(rc *models.RetryPolicy, attempt int) {
time.Sleep(duration)
}

func isAcceptableError(err a.Error) bool {
return err.Matches(atypes.GENERATION_ERROR, atypes.KEY_EXISTS_ERROR)
func isNilOrAcceptableError(err a.Error) bool {
return err == nil || err.Matches(atypes.GENERATION_ERROR, atypes.KEY_EXISTS_ERROR)
}

func shouldRetry(err a.Error) bool {
return err.Matches(
return err != nil && err.Matches(
atypes.NO_AVAILABLE_CONNECTIONS_TO_NODE,
atypes.TIMEOUT,
atypes.DEVICE_OVERLOAD,
Expand Down

0 comments on commit e68dc38

Please sign in to comment.