Skip to content

Commit

Permalink
Add retries to SQL user insert and update operations.
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
danawillow authored and modular-magician committed Nov 15, 2019
1 parent 3e20ddf commit 71ab170
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 14 additions & 4 deletions google-beta/resource_sql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ func resourceSqlUserCreate(d *schema.ResourceData, meta interface{}) error {

mutexKV.Lock(instanceMutexKey(project, instance))
defer mutexKV.Unlock(instanceMutexKey(project, instance))
op, err := config.clientSqlAdmin.Users.Insert(project, instance,
user).Do()
var op *sqladmin.Operation
insertFunc := func() error {
op, err = config.clientSqlAdmin.Users.Insert(project, instance,
user).Do()
return err
}
err = retryTimeDuration(insertFunc, d.Timeout(schema.TimeoutCreate))

if err != nil {
return fmt.Errorf("Error, failed to insert "+
Expand Down Expand Up @@ -172,8 +177,13 @@ func resourceSqlUserUpdate(d *schema.ResourceData, meta interface{}) error {

mutexKV.Lock(instanceMutexKey(project, instance))
defer mutexKV.Unlock(instanceMutexKey(project, instance))
op, err := config.clientSqlAdmin.Users.Update(project, instance, name,
user).Host(host).Do()
var op *sqladmin.Operation
updateFunc := func() error {
op, err = config.clientSqlAdmin.Users.Update(project, instance, name,
user).Host(host).Do()
return err
}
err = retryTimeDuration(updateFunc, d.Timeout(schema.TimeoutUpdate))

if err != nil {
return fmt.Errorf("Error, failed to update"+
Expand Down
8 changes: 0 additions & 8 deletions google-beta/self_link_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ func GetLocationalResourcePropertiesFromSelfLinkString(selfLink string) (string,
}

s := strings.Split(parsed.Path, "/")

// This is a pretty bad way to tell if this is a self link, but stops us
// from accessing an index out of bounds and causing a panic. generally, we
// expect bad values to be partial URIs and names, so this will catch them
if len(s) < 9 {
return "", "", "", fmt.Errorf("value %s was not a self link", selfLink)
}

return s[4], s[6], s[8], nil
}

Expand Down

0 comments on commit 71ab170

Please sign in to comment.