Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate retries in the inner loop for errors that will not succeed. #8080

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/4334.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:bug
filestore: fail fast on quota error which cannot succeed on retry.
```
```release-note:bug
storage: refresh etag sooner on an IAM conflict error, which will make applications of multiple IAM resources much faster.
```
18 changes: 11 additions & 7 deletions google/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ func isMonitoringConcurrentEditError(err error) (bool, string) {
return false, ""
}

// Retry if filestore operation returns a 429 with a specific message for
// concurrent operations.
func isNotFilestoreQuotaError(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok {
if gerr.Code == 429 {
return false, ""
}
}
return isCommonRetryableErrorCode(err)
}

// Retry if App Engine operation returns a 409 with a specific message for
// concurrent operations.
func isAppEngineRetryableError(err error) (bool, string) {
Expand Down Expand Up @@ -260,13 +271,6 @@ func isNotFoundRetryableError(opType string) RetryErrorPredicateFunc {
}
}

func isStoragePreconditionError(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 412 {
return true, fmt.Sprintf("Retry on storage precondition not met")
}
return false, ""
}

func isDataflowJobUpdateRetryableError(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok {
if gerr.Code == 404 && strings.Contains(gerr.Body, "in RUNNING OR DRAINING state") {
Expand Down
2 changes: 1 addition & 1 deletion google/filestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (w *FilestoreOperationWaiter) QueryOp() (interface{}, error) {
// Returns the proper get.
url := fmt.Sprintf("https://file.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)

return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil, isNotFilestoreQuotaError)
}

func createFilestoreWaiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*FilestoreOperationWaiter, error) {
Expand Down
4 changes: 2 additions & 2 deletions google/iam_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (u *StorageBucketIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.
return nil, err
}

policy, err := sendRequest(u.Config, "GET", "", url, userAgent, obj, isStoragePreconditionError)
policy, err := sendRequest(u.Config, "GET", "", url, userAgent, obj)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (u *StorageBucketIamUpdater) SetResourceIamPolicy(policy *cloudresourcemana
return err
}

_, err = sendRequestWithTimeout(u.Config, "PUT", "", url, userAgent, obj, u.d.Timeout(schema.TimeoutCreate), isStoragePreconditionError)
_, err = sendRequestWithTimeout(u.Config, "PUT", "", url, userAgent, obj, u.d.Timeout(schema.TimeoutCreate))
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand Down
8 changes: 4 additions & 4 deletions google/resource_filestore_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func resourceFilestoreInstanceCreate(d *schema.ResourceData, meta interface{}) e
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate))
res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate), isNotFilestoreQuotaError)
if err != nil {
return fmt.Errorf("Error creating Instance: %s", err)
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func resourceFilestoreInstanceRead(d *schema.ResourceData, meta interface{}) err
billingProject = bp
}

res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil)
res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil, isNotFilestoreQuotaError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("FilestoreInstance %q", d.Id()))
}
Expand Down Expand Up @@ -381,7 +381,7 @@ func resourceFilestoreInstanceUpdate(d *schema.ResourceData, meta interface{}) e
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate), isNotFilestoreQuotaError)

if err != nil {
return fmt.Errorf("Error updating Instance %q: %s", d.Id(), err)
Expand Down Expand Up @@ -428,7 +428,7 @@ func resourceFilestoreInstanceDelete(d *schema.ResourceData, meta interface{}) e
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete), isNotFilestoreQuotaError)
if err != nil {
return handleNotFoundError(err, d, "Instance")
}
Expand Down
2 changes: 1 addition & 1 deletion google/resource_filestore_instance_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func testAccCheckFilestoreInstanceDestroyProducer(t *testing.T) func(s *terrafor
billingProject = config.BillingProject
}

_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, isNotFilestoreQuotaError)
if err == nil {
return fmt.Errorf("FilestoreInstance still exists at %s", url)
}
Expand Down