Skip to content

Commit

Permalink
Retry on firestore index create 409 with 'cross-transaction contentio…
Browse files Browse the repository at this point in the history
…n' (#9515)
  • Loading branch information
raz-amir authored Nov 28, 2023
1 parent f0d74c6 commit 0126c3d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mmv1/products/firestore/Index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ name: 'Index'
base_url: projects/{{project}}/databases/{{database}}/collectionGroups/{{collection}}/indexes
self_link: '{{name}}'
immutable: true
error_retry_predicates:
["transport_tpg.FirestoreIndex409CrossTransactionContetion"]
description: |
Cloud Firestore indexes enable simple and complex queries against documents in a database.
This resource manages composite indexes and not single
Expand Down
10 changes: 10 additions & 0 deletions mmv1/third_party/terraform/transport/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ func FirestoreField409RetryUnderlyingDataChanged(err error) (bool, string) {
return false, ""
}

// relevant for firestore in datastore mode
func FirestoreIndex409CrossTransactionContetion(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok {
if gerr.Code == 409 && strings.Contains(gerr.Body, "Aborted due to cross-transaction contention") {
return true, "aborted due to cross-transaction contention - retrying"
}
}
return false, ""
}

func IapClient409Operation(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok {
if gerr.Code == 409 && strings.Contains(strings.ToLower(gerr.Body), "operation was aborted") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,14 @@ func TestFirestoreField409_retryUnderlyingDataChanged(t *testing.T) {
t.Errorf("Error not detected as retryable")
}
}

func TestFirestoreIndex409_crossTransactionContetion(t *testing.T) {
err := googleapi.Error{
Code: 409,
Body: "Aborted due to cross-transaction contention",
}
isRetryable, _ := FirestoreIndex409CrossTransactionContetion(&err)
if !isRetryable {
t.Errorf("Error not detected as retryable")
}
}

0 comments on commit 0126c3d

Please sign in to comment.