Skip to content

Commit 9c7f5f7

Browse files
authored
Merge pull request brainly#118 from mmichaelb/fix-serverless-errors
fix quota check for serverless redshift
2 parents 87369e6 + d0fd712 commit 9c7f5f7

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

redshift/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Config struct {
2525
SSLMode string
2626
MaxConns int
2727

28+
serverlessCheckMutex *sync.Mutex
2829
isServerless bool
2930
checkedForServerless bool
3031
}
@@ -52,6 +53,11 @@ func (c *Config) NewClient(database string) *Client {
5253
}
5354

5455
func (c *Config) IsServerless(db *DBConnection) (bool, error) {
56+
if c.serverlessCheckMutex == nil {
57+
c.serverlessCheckMutex = &sync.Mutex{}
58+
}
59+
c.serverlessCheckMutex.Lock()
60+
defer c.serverlessCheckMutex.Unlock()
5561
if c.checkedForServerless {
5662
return c.isServerless, nil
5763
}

redshift/resource_redshift_schema.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,16 +455,23 @@ func resourceRedshiftSchemaReadLocal(db *DBConnection, d *schema.ResourceData) e
455455
return err
456456
}
457457

458-
if !isServerless {
459-
err := db.QueryRow(`
458+
if isServerless {
459+
err = db.QueryRow(`
460+
SELECT COALESCE(quota, 0)
461+
FROM svv_redshift_schema_quota
462+
WHERE database_name = $1
463+
AND schema_name = $2
464+
`, db.client.databaseName, d.Get(schemaNameAttr)).Scan(&schemaQuota)
465+
} else {
466+
err = db.QueryRow(`
460467
SELECT
461468
COALESCE(quota, 0)
462469
FROM svv_schema_quota_state
463470
WHERE schema_id = $1
464471
`, d.Id()).Scan(&schemaQuota)
465-
if err != nil && err != sql.ErrNoRows {
466-
return err
467-
}
472+
}
473+
if err != nil && err != sql.ErrNoRows {
474+
return err
468475
}
469476
d.Set(schemaQuotaAttr, schemaQuota)
470477
d.Set(schemaExternalSchemaAttr, nil)

0 commit comments

Comments
 (0)