AcquirePublishLock acquires an exclusive advisory lock for publishing a server This prevents race conditions when multiple versions are published concurrently Using pg_advisory_xact_lock which auto-releases on transaction end
(ctx context.Context, tx pgx.Tx, serverName string)
| 763 | // This prevents race conditions when multiple versions are published concurrently |
| 764 | // Using pg_advisory_xact_lock which auto-releases on transaction end |
| 765 | func (db *PostgreSQL) AcquirePublishLock(ctx context.Context, tx pgx.Tx, serverName string) error { |
| 766 | if ctx.Err() != nil { |
| 767 | return ctx.Err() |
| 768 | } |
| 769 | |
| 770 | lockID := hashServerName(serverName) |
| 771 | |
| 772 | if _, err := db.getExecutor(tx).Exec(ctx, "SELECT pg_advisory_xact_lock($1)", lockID); err != nil { |
| 773 | return fmt.Errorf("failed to acquire publish lock: %w", err) |
| 774 | } |
| 775 | |
| 776 | return nil |
| 777 | } |
| 778 | |
| 779 | // hashServerName creates a consistent hash of the server name for advisory locking |
| 780 | // We use FNV-1a hash and mask to 63 bits to fit in PostgreSQL's bigint range |
nothing calls this directly
no test coverage detected