Skip to content

Commit

Permalink
fixup! chore: improve rsources service table setup procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
atzoum committed Nov 27, 2023
1 parent 00d29e7 commit 4440591
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions services/rsources/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,15 @@ func (sh *sourcesHandler) init() error {
}
}

const lockId = 100020001
const lockID = 100020001

if err := withAdvisoryLock(ctx, sh.localDB, lockId, func(tx *sql.Tx) error {
if err := withAdvisoryLock(ctx, sh.localDB, lockID, func(tx *sql.Tx) error {
sh.log.Debugf("setting up rsources tables in %s", sh.config.LocalHostname)
if err := setupTables(ctx, sh.localDB, sh.config.LocalHostname, sh.log); err != nil {
return err
}

Check warning on line 486 in services/rsources/handler.go

View check run for this annotation

Codecov / codecov/patch

services/rsources/handler.go#L485-L486

Added lines #L485 - L486 were not covered by tests
if err := migrateFailedKeysTable(ctx, tx); err != nil {
return fmt.Errorf("failed to migrate rsources_failed_keys table: %w", err)
return fmt.Errorf("migrating rsources_failed_keys table: %w", err)
}

Check warning on line 489 in services/rsources/handler.go

View check run for this annotation

Codecov / codecov/patch

services/rsources/handler.go#L488-L489

Added lines #L488 - L489 were not covered by tests
sh.log.Debugf("rsources tables setup successfully in %s", sh.config.LocalHostname)
return nil
Expand All @@ -494,7 +494,7 @@ func (sh *sourcesHandler) init() error {
}

if sh.sharedDB != nil {
if err := withAdvisoryLock(ctx, sh.sharedDB, lockId, func(_ *sql.Tx) error {
if err := withAdvisoryLock(ctx, sh.sharedDB, lockID, func(_ *sql.Tx) error {
sh.log.Debugf("setting up rsources tables for shared db %s", sh.config.SharedConn)
if err := setupTables(ctx, sh.sharedDB, "shared", sh.log); err != nil {
return err
Expand All @@ -503,7 +503,7 @@ func (sh *sourcesHandler) init() error {

sh.log.Debugf("setting up rsources logical replication in %s", sh.config.LocalHostname)
if err := sh.setupLogicalReplication(ctx); err != nil {
return fmt.Errorf("failed to setup rsources logical replication in %s: %w", sh.config.LocalHostname, err)
return fmt.Errorf("logical replication in %q: %w", sh.config.LocalHostname, err)
}
sh.log.Debugf("rsources logical replication setup successfully in %s", sh.config.LocalHostname)
return nil
Expand Down Expand Up @@ -817,7 +817,7 @@ func withAdvisoryLock(ctx context.Context, db *sql.DB, lockId int64, f func(tx *
}

Check warning on line 817 in services/rsources/handler.go

View check run for this annotation

Codecov / codecov/patch

services/rsources/handler.go#L816-L817

Added lines #L816 - L817 were not covered by tests
defer func() { _ = tx.Rollback() }()
if _, err := tx.ExecContext(ctx, `SELECT pg_advisory_xact_lock($1)`, lockId); err != nil {
return fmt.Errorf("error while acquiring advisory lock: %w", err)
return fmt.Errorf("acquiring advisory lock: %w", err)
}

Check warning on line 821 in services/rsources/handler.go

View check run for this annotation

Codecov / codecov/patch

services/rsources/handler.go#L820-L821

Added lines #L820 - L821 were not covered by tests
if err := f(tx); err != nil {
return err
Expand Down

0 comments on commit 4440591

Please sign in to comment.