Skip to content

Commit

Permalink
Merge pull request #166 from ryaneorth/fix-switch-statement
Browse files Browse the repository at this point in the history
fix: issue with switch when err is nil
  • Loading branch information
vroldanbet authored Feb 29, 2024
2 parents 12fab70 + 175e627 commit 561fb11
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions v1/retryable_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,33 @@ func (rc *RetryableClient) RetryableBulkImportRelationships(ctx context.Context,
})

_, err = bulkImportClient.CloseAndRecv() // transaction commit happens here
if err == nil {
return nil
}

// Failure to commit transaction means the stream is closed, so it can't be reused any further
// The retry will be done using WriteRelationships instead of BulkImportRelationships
// This lets us retry with TOUCH semantics in case of failure due to duplicates
retryable := isRetryableError(err)
conflict := isAlreadyExistsError(err)
canceled, cancelErr := isCanceledError(ctx.Err(), err)
unknown := !retryable && !conflict && !canceled && err != nil

switch {
case canceled:

return cancelErr
case unknown:

return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err)
case conflict && conflictStrategy == Skip:

return nil
case retryable || (conflict && conflictStrategy == Touch):
err = rc.writeBatchesWithRetry(ctx, relationships)
if err != nil {
return fmt.Errorf("failed to write relationships after retry: %w", err)
}
return nil
case conflict && conflictStrategy == Fail:
return fmt.Errorf("duplicate relationships found")

default:

return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err)
}

return nil
}

func (rc *RetryableClient) writeBatchesWithRetry(ctx context.Context, relationships []*v1.Relationship) error {
Expand Down

0 comments on commit 561fb11

Please sign in to comment.