From c6ccc034deea9921eaa6ad35a1afc5f9e76260a0 Mon Sep 17 00:00:00 2001 From: Ryan Orth Date: Tue, 27 Feb 2024 16:31:04 -0800 Subject: [PATCH 1/4] fix: issue with switch when err is nil --- v1/retryable_client.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/v1/retryable_client.go b/v1/retryable_client.go index 98c973c..21ac815 100644 --- a/v1/retryable_client.go +++ b/v1/retryable_client.go @@ -100,26 +100,27 @@ func (rc *RetryableClient) RetryableBulkImportRelationships(ctx context.Context, canceled, cancelErr := isCanceledError(ctx.Err(), err) unknown := !retryable && !conflict && !canceled && err != nil - switch { - case canceled: - - return cancelErr - case unknown: + if err != nil { + switch { + case canceled: - return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err) - case conflict && conflictStrategy == Skip: + return cancelErr + case unknown: - case retryable || (conflict && conflictStrategy == Touch): - err = rc.writeBatchesWithRetry(ctx, relationships) - if err != nil { - return fmt.Errorf("failed to write relationships after retry: %w", err) - } - case conflict && conflictStrategy == Fail: - return fmt.Errorf("duplicate relationships found") + return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err) + case conflict && conflictStrategy == Skip: - default: + case retryable || (conflict && conflictStrategy == Touch): + err = rc.writeBatchesWithRetry(ctx, relationships) + if err != nil { + return fmt.Errorf("failed to write relationships after retry: %w", err) + } + case conflict && conflictStrategy == Fail: + return fmt.Errorf("duplicate relationships found") - return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err) + default: + return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err) + } } return nil From 26e357f74ea9d4bf5d9939aaafe6c156a1e9ad80 Mon Sep 17 00:00:00 2001 From: Ryan Orth Date: Tue, 27 Feb 2024 19:39:00 -0800 Subject: [PATCH 2/4] chore: moved nil check up --- v1/retryable_client.go | 43 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/v1/retryable_client.go b/v1/retryable_client.go index 21ac815..c33c894 100644 --- a/v1/retryable_client.go +++ b/v1/retryable_client.go @@ -91,6 +91,9 @@ 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 @@ -98,32 +101,24 @@ func (rc *RetryableClient) RetryableBulkImportRelationships(ctx context.Context, retryable := isRetryableError(err) conflict := isAlreadyExistsError(err) canceled, cancelErr := isCanceledError(ctx.Err(), err) - unknown := !retryable && !conflict && !canceled && err != nil - - if 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: - - case retryable || (conflict && conflictStrategy == Touch): - err = rc.writeBatchesWithRetry(ctx, relationships) - if err != nil { - return fmt.Errorf("failed to write relationships after retry: %w", err) - } - case conflict && conflictStrategy == Fail: - return fmt.Errorf("duplicate relationships found") - - default: - return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err) + unknown := !retryable && !conflict && !canceled + + switch { + case canceled: + return cancelErr + case unknown: + return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err) + 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 { From 1387548fcbff1436b984085e77197135e27146f2 Mon Sep 17 00:00:00 2001 From: Ryan Orth Date: Wed, 28 Feb 2024 06:27:40 -0800 Subject: [PATCH 3/4] fix: remove unnecessary unknown from switch statement --- v1/retryable_client.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/v1/retryable_client.go b/v1/retryable_client.go index c33c894..2bae3ed 100644 --- a/v1/retryable_client.go +++ b/v1/retryable_client.go @@ -101,13 +101,10 @@ func (rc *RetryableClient) RetryableBulkImportRelationships(ctx context.Context, retryable := isRetryableError(err) conflict := isAlreadyExistsError(err) canceled, cancelErr := isCanceledError(ctx.Err(), err) - unknown := !retryable && !conflict && !canceled switch { case canceled: return cancelErr - case unknown: - return fmt.Errorf("error finalizing write of %d relationships: %w", len(relationships), err) case retryable || (conflict && conflictStrategy == Touch): err = rc.writeBatchesWithRetry(ctx, relationships) if err != nil { From 175e6270abde7f64cfc4dfb172a2d925cff80385 Mon Sep 17 00:00:00 2001 From: Ryan Orth Date: Thu, 29 Feb 2024 06:46:52 -0800 Subject: [PATCH 4/4] fix: add back skip conflict strategy case --- v1/retryable_client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/v1/retryable_client.go b/v1/retryable_client.go index 2bae3ed..f591283 100644 --- a/v1/retryable_client.go +++ b/v1/retryable_client.go @@ -105,6 +105,8 @@ func (rc *RetryableClient) RetryableBulkImportRelationships(ctx context.Context, switch { case canceled: return cancelErr + case conflict && conflictStrategy == Skip: + return nil case retryable || (conflict && conflictStrategy == Touch): err = rc.writeBatchesWithRetry(ctx, relationships) if err != nil {