2005-06-18 00:32:51 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* twophase.h
|
|
|
|
* Two-phase-commit related declarations.
|
|
|
|
*
|
|
|
|
*
|
2014-01-07 22:05:30 +01:00
|
|
|
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
|
2005-06-18 00:32:51 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/access/twophase.h
|
2005-06-18 00:32:51 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef TWOPHASE_H
|
|
|
|
#define TWOPHASE_H
|
|
|
|
|
2012-06-25 23:45:15 +02:00
|
|
|
#include "access/xlogdefs.h"
|
|
|
|
#include "datatype/timestamp.h"
|
|
|
|
#include "storage/lock.h"
|
2005-06-18 00:32:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GlobalTransactionData is defined in twophase.c; other places have no
|
|
|
|
* business knowing the internal definition.
|
|
|
|
*/
|
|
|
|
typedef struct GlobalTransactionData *GlobalTransaction;
|
|
|
|
|
|
|
|
/* GUC variable */
|
2005-10-15 04:49:52 +02:00
|
|
|
extern int max_prepared_xacts;
|
2005-06-18 00:32:51 +02:00
|
|
|
|
2005-08-21 01:26:37 +02:00
|
|
|
extern Size TwoPhaseShmemSize(void);
|
2005-06-18 00:32:51 +02:00
|
|
|
extern void TwoPhaseShmemInit(void);
|
|
|
|
|
Fix race condition in preparing a transaction for two-phase commit.
To lock a prepared transaction's shared memory entry, we used to mark it
with the XID of the backend. When the XID was no longer active according
to the proc array, the entry was implicitly considered as not locked
anymore. However, when preparing a transaction, the backend's proc array
entry was cleared before transfering the locks (and some other state) to
the prepared transaction's dummy PGPROC entry, so there was a window where
another backend could finish the transaction before it was in fact fully
prepared.
To fix, rewrite the locking mechanism of global transaction entries. Instead
of an XID, just have simple locked-or-not flag in each entry (we store the
locking backend's backend id rather than a simple boolean, but that's just
for debugging purposes). The backend is responsible for explicitly unlocking
the entry, and to make sure that that happens, install a callback to unlock
it on abort or process exit.
Backpatch to all supported versions.
2014-05-15 15:37:50 +02:00
|
|
|
extern void AtAbort_Twophase(void);
|
|
|
|
extern void PostPrepare_Twophase(void);
|
|
|
|
|
2005-06-18 00:32:51 +02:00
|
|
|
extern PGPROC *TwoPhaseGetDummyProc(TransactionId xid);
|
2009-11-23 10:58:36 +01:00
|
|
|
extern BackendId TwoPhaseGetDummyBackendId(TransactionId xid);
|
2005-06-18 00:32:51 +02:00
|
|
|
|
2005-06-18 21:33:42 +02:00
|
|
|
extern GlobalTransaction MarkAsPreparing(TransactionId xid, const char *gid,
|
2005-10-15 04:49:52 +02:00
|
|
|
TimestampTz prepared_at,
|
|
|
|
Oid owner, Oid databaseid);
|
2005-06-18 00:32:51 +02:00
|
|
|
|
|
|
|
extern void StartPrepare(GlobalTransaction gxact);
|
|
|
|
extern void EndPrepare(GlobalTransaction gxact);
|
Allow read only connections during recovery, known as Hot Standby.
Enabled by recovery_connections = on (default) and forcing archive recovery using a recovery.conf. Recovery processing now emulates the original transactions as they are replayed, providing full locking and MVCC behaviour for read only queries. Recovery must enter consistent state before connections are allowed, so there is a delay, typically short, before connections succeed. Replay of recovering transactions can conflict and in some cases deadlock with queries during recovery; these result in query cancellation after max_standby_delay seconds have expired. Infrastructure changes have minor effects on normal running, though introduce four new types of WAL record.
New test mode "make standbycheck" allows regression tests of static command behaviour on a standby server while in recovery. Typical and extreme dynamic behaviours have been checked via code inspection and manual testing. Few port specific behaviours have been utilised, though primary testing has been on Linux only so far.
This commit is the basic patch. Additional changes will follow in this release to enhance some aspects of behaviour, notably improved handling of conflicts, deadlock detection and query cancellation. Changes to VACUUM FULL are also required.
Simon Riggs, with significant and lengthy review by Heikki Linnakangas, including streamlined redesign of snapshot creation and two-phase commit.
Important contributions from Florian Pflug, Mark Kirkwood, Merlin Moncure, Greg Stark, Gianni Ciolli, Gabriele Bartolini, Hannu Krosing, Robert Haas, Tatsuo Ishii, Hiroyuki Yamada plus support and feedback from many other community members.
2009-12-19 02:32:45 +01:00
|
|
|
extern bool StandbyTransactionIdIsPrepared(TransactionId xid);
|
2005-06-18 00:32:51 +02:00
|
|
|
|
Allow read only connections during recovery, known as Hot Standby.
Enabled by recovery_connections = on (default) and forcing archive recovery using a recovery.conf. Recovery processing now emulates the original transactions as they are replayed, providing full locking and MVCC behaviour for read only queries. Recovery must enter consistent state before connections are allowed, so there is a delay, typically short, before connections succeed. Replay of recovering transactions can conflict and in some cases deadlock with queries during recovery; these result in query cancellation after max_standby_delay seconds have expired. Infrastructure changes have minor effects on normal running, though introduce four new types of WAL record.
New test mode "make standbycheck" allows regression tests of static command behaviour on a standby server while in recovery. Typical and extreme dynamic behaviours have been checked via code inspection and manual testing. Few port specific behaviours have been utilised, though primary testing has been on Linux only so far.
This commit is the basic patch. Additional changes will follow in this release to enhance some aspects of behaviour, notably improved handling of conflicts, deadlock detection and query cancellation. Changes to VACUUM FULL are also required.
Simon Riggs, with significant and lengthy review by Heikki Linnakangas, including streamlined redesign of snapshot creation and two-phase commit.
Important contributions from Florian Pflug, Mark Kirkwood, Merlin Moncure, Greg Stark, Gianni Ciolli, Gabriele Bartolini, Hannu Krosing, Robert Haas, Tatsuo Ishii, Hiroyuki Yamada plus support and feedback from many other community members.
2009-12-19 02:32:45 +01:00
|
|
|
extern TransactionId PrescanPreparedTransactions(TransactionId **xids_p,
|
|
|
|
int *nxids_p);
|
2010-04-13 16:17:46 +02:00
|
|
|
extern void StandbyRecoverPreparedTransactions(bool overwriteOK);
|
2005-06-18 00:32:51 +02:00
|
|
|
extern void RecoverPreparedTransactions(void);
|
|
|
|
|
|
|
|
extern void RecreateTwoPhaseFile(TransactionId xid, void *content, int len);
|
|
|
|
extern void RemoveTwoPhaseFile(TransactionId xid, bool giveWarning);
|
|
|
|
|
2005-06-19 22:00:39 +02:00
|
|
|
extern void CheckPointTwoPhase(XLogRecPtr redo_horizon);
|
|
|
|
|
2005-06-18 21:33:42 +02:00
|
|
|
extern void FinishPreparedTransaction(const char *gid, bool isCommit);
|
2005-06-18 00:32:51 +02:00
|
|
|
|
|
|
|
#endif /* TWOPHASE_H */
|