Skip to content

Commit

Permalink
Retry on firestore field create 409 with 'underlying data changed' (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
raz-amir authored Oct 25, 2023
1 parent e5fbaca commit b2de0d5
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/Field.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ immutable: false
update_verb: :PATCH
update_mask: true
create_verb: :PATCH
error_retry_predicates:
["transport_tpg.FirestoreField409RetryUnderlyingDataChanged"]
description: |
Represents a single field in the database.
Fields are grouped by their "Collection Group", which represent all collections
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 @@ -320,6 +320,16 @@ func DatastoreIndex409Contention(err error) (bool, string) {
return false, ""
}

// relevant for firestore in datastore mode
func FirestoreField409RetryUnderlyingDataChanged(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok {
if gerr.Code == 409 && strings.Contains(gerr.Body, "Please retry, underlying data changed") {
return true, "underlying data changed - 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 @@ -170,3 +170,14 @@ func TestIsSwgAutogenRouterRetryableError_notReady(t *testing.T) {
t.Errorf("Error not detected as retryable")
}
}

func TestFirestoreField409_retryUnderlyingDataChanged(t *testing.T) {
err := googleapi.Error{
Code: 409,
Body: "Please retry, underlying data changed",
}
isRetryable, _ := FirestoreField409RetryUnderlyingDataChanged(&err)
if !isRetryable {
t.Errorf("Error not detected as retryable")
}
}

0 comments on commit b2de0d5

Please sign in to comment.