*** pgsql/src/backend/access/transam/twophase.c 2009/09/01 04:15:45 1.55 --- pgsql/src/backend/access/transam/twophase.c 2009/11/23 09:58:36 1.56 *************** *** 7,13 **** * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.54 2009/06/25 19:05:52 heikki Exp $ * * NOTES * Each global transaction is associated with a global transaction --- 7,13 ---- * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.55 2009/09/01 04:15:45 tgl Exp $ * * NOTES * Each global transaction is associated with a global transaction *************** int max_prepared_xacts = 0; *** 109,114 **** --- 109,115 ---- typedef struct GlobalTransactionData { PGPROC proc; /* dummy proc */ + BackendId dummyBackendId; /* similar to backend id for backends */ TimestampTz prepared_at; /* time of preparation */ XLogRecPtr prepare_lsn; /* XLOG offset of prepare record */ Oid owner; /* ID of user that executed the xact */ *************** TwoPhaseShmemInit(void) *** 200,205 **** --- 201,220 ---- { gxacts[i].proc.links.next = (SHM_QUEUE *) TwoPhaseState->freeGXacts; TwoPhaseState->freeGXacts = &gxacts[i]; + + /* + * Assign a unique ID for each dummy proc, so that the range of + * dummy backend IDs immediately follows the range of normal + * backend IDs. We don't dare to assign a real backend ID to + * dummy procs, because prepared transactions don't take part in + * cache invalidation like a real backend ID would imply, but + * having a unique ID for them is nevertheless handy. This + * arrangement allows you to allocate an array of size + * (MaxBackends + max_prepared_xacts + 1), and have a slot for + * every backend and prepared transaction. Currently multixact.c + * uses that technique. + */ + gxacts[i].dummyBackendId = MaxBackends + 1 + i; } } else *************** pg_prepared_xact(PG_FUNCTION_ARGS) *** 648,653 **** --- 663,684 ---- } /* + * TwoPhaseGetDummyProc + * Get the dummy backend ID for prepared transaction specified by XID + * + * Dummy backend IDs are similar to real backend IDs of real backends. + * They start at MaxBackends + 1, and are unique across all currently active + * real backends and prepared transactions. + */ + BackendId + TwoPhaseGetDummyBackendId(TransactionId xid) + { + PGPROC *proc = TwoPhaseGetDummyProc(xid); + + return ((GlobalTransaction) proc)->dummyBackendId; + } + + /* * TwoPhaseGetDummyProc * Get the PGPROC that represents a prepared transaction specified by XID */