MCPcopy
hub / github.com/modelcontextprotocol/registry / AcquirePublishLock

Method AcquirePublishLock

internal/database/postgres.go:765–777  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

763// This prevents race conditions when multiple versions are published concurrently
764// Using pg_advisory_xact_lock which auto-releases on transaction end
765func (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

Callers

nothing calls this directly

Calls 3

getExecutorMethod · 0.95
hashServerNameFunction · 0.85
ExecMethod · 0.80

Tested by

no test coverage detected