Skip to content

Commit

Permalink
chore(redshift): retry schema does not exist errors in list schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
atzoum committed Oct 11, 2024
1 parent f11118d commit 6d60284
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sqlconnect/internal/redshift/schemaadmin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package redshift

import (
"context"
"regexp"

"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())
}
schemas, err := db.DB.ListSchemas(ctx)
if err != nil && retryableError(err) {
return db.ListSchemas(ctx)
}
return schemas, err
}
11 changes: 11 additions & 0 deletions sqlconnect/internal/redshift/schemaadmin_test.go
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`))
}

0 comments on commit 6d60284

Please sign in to comment.