-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(redshift): retry schema does not exist errors in list schemas
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package redshift | ||
|
||
import ( | ||
"context" | ||
"regexp" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff/v4" | ||
|
||
"github.com/rudderlabs/sqlconnect-go/sqlconnect" | ||
) | ||
|
||
var schemaDoesNotExistRegex = regexp.MustCompile(`schema "(.*)" does not exist`) | ||
|
||
func (db *DB) ListSchemas(ctx context.Context) ([]sqlconnect.SchemaRef, error) { | ||
// If the list schemas query is executed while a schema is being deleted, the query will fail with a schema does not exist error. | ||
retryableError := func(err error) bool { | ||
return schemaDoesNotExistRegex.MatchString(err.Error()) | ||
} | ||
return retryOperationWithData(ctx, func() ([]sqlconnect.SchemaRef, error) { | ||
schemas, err := db.DB.ListSchemas(ctx) | ||
if err != nil && !retryableError(err) { | ||
return nil, backoff.Permanent(err) | ||
} | ||
return schemas, err | ||
}) | ||
} | ||
|
||
// retryOperationWithData retries the given operation with a constant backoff policy of 100ms for 10 times. | ||
func retryOperationWithData[T any](ctx context.Context, o backoff.OperationWithData[T]) (T, error) { | ||
return backoff.RetryWithData(o, backoff.WithMaxRetries(backoff.WithContext(backoff.NewConstantBackOff(100*time.Millisecond), ctx), 10)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package redshift | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSchemaDoesNotExistRegex(t *testing.T) { | ||
require.True(t, schemaDoesNotExistRegex.MatchString(`ERROR: schema "tsqlcon_zvtquuiqulpz_1728651180" does not exist`)) | ||
} |