mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Two-phase commit. Original patch by Heikki Linnakangas, with additional
hacking by Alvaro Herrera and Tom Lane.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/subtrans.h,v 1.5 2004/12/31 22:03:21 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/subtrans.h,v 1.6 2005/06/17 22:32:48 tgl Exp $
|
||||
*/
|
||||
#ifndef SUBTRANS_H
|
||||
#define SUBTRANS_H
|
||||
@@ -18,7 +18,7 @@ extern TransactionId SubTransGetTopmostTransaction(TransactionId xid);
|
||||
extern int SUBTRANSShmemSize(void);
|
||||
extern void SUBTRANSShmemInit(void);
|
||||
extern void BootStrapSUBTRANS(void);
|
||||
extern void StartupSUBTRANS(void);
|
||||
extern void StartupSUBTRANS(TransactionId oldestActiveXID);
|
||||
extern void ShutdownSUBTRANS(void);
|
||||
extern void CheckPointSUBTRANS(void);
|
||||
extern void ExtendSUBTRANS(TransactionId newestXact);
|
||||
|
||||
49
src/include/access/twophase.h
Normal file
49
src/include/access/twophase.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* twophase.h
|
||||
* Two-phase-commit related declarations.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/twophase.h,v 1.1 2005/06/17 22:32:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef TWOPHASE_H
|
||||
#define TWOPHASE_H
|
||||
|
||||
#include "storage/lock.h"
|
||||
|
||||
|
||||
/*
|
||||
* GlobalTransactionData is defined in twophase.c; other places have no
|
||||
* business knowing the internal definition.
|
||||
*/
|
||||
typedef struct GlobalTransactionData *GlobalTransaction;
|
||||
|
||||
/* GUC variable */
|
||||
extern int max_prepared_xacts;
|
||||
|
||||
extern int TwoPhaseShmemSize(void);
|
||||
extern void TwoPhaseShmemInit(void);
|
||||
|
||||
extern PGPROC *TwoPhaseGetDummyProc(TransactionId xid);
|
||||
|
||||
extern GlobalTransaction MarkAsPreparing(TransactionId xid, Oid databaseid,
|
||||
char *gid, AclId owner);
|
||||
extern void MarkAsPrepared(GlobalTransaction gxact);
|
||||
|
||||
extern void StartPrepare(GlobalTransaction gxact);
|
||||
extern void EndPrepare(GlobalTransaction gxact);
|
||||
|
||||
extern TransactionId PrescanPreparedTransactions(void);
|
||||
extern void RecoverPreparedTransactions(void);
|
||||
|
||||
extern void RecreateTwoPhaseFile(TransactionId xid, void *content, int len);
|
||||
extern void RemoveTwoPhaseFile(TransactionId xid, bool giveWarning);
|
||||
|
||||
extern void FinishPreparedTransaction(char *gid, bool isCommit);
|
||||
|
||||
#endif /* TWOPHASE_H */
|
||||
39
src/include/access/twophase_rmgr.h
Normal file
39
src/include/access/twophase_rmgr.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* twophase_rmgr.h
|
||||
* Two-phase-commit resource managers definition
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/twophase_rmgr.h,v 1.1 2005/06/17 22:32:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef TWOPHASE_RMGR_H
|
||||
#define TWOPHASE_RMGR_H
|
||||
|
||||
typedef void (*TwoPhaseCallback) (TransactionId xid, uint16 info,
|
||||
void *recdata, uint32 len);
|
||||
typedef uint8 TwoPhaseRmgrId;
|
||||
|
||||
/*
|
||||
* Built-in resource managers
|
||||
*/
|
||||
#define TWOPHASE_RM_END_ID 0
|
||||
#define TWOPHASE_RM_LOCK_ID 1
|
||||
#define TWOPHASE_RM_INVAL_ID 2
|
||||
#define TWOPHASE_RM_FLATFILES_ID 3
|
||||
#define TWOPHASE_RM_NOTIFY_ID 4
|
||||
#define TWOPHASE_RM_MAX_ID TWOPHASE_RM_NOTIFY_ID
|
||||
|
||||
extern const TwoPhaseCallback twophase_recover_callbacks[];
|
||||
extern const TwoPhaseCallback twophase_postcommit_callbacks[];
|
||||
extern const TwoPhaseCallback twophase_postabort_callbacks[];
|
||||
|
||||
|
||||
extern void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info,
|
||||
const void *data, uint32 len);
|
||||
|
||||
#endif /* TWOPHASE_RMGR_H */
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/xact.h,v 1.76 2005/06/06 17:01:24 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/xact.h,v 1.77 2005/06/17 22:32:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -47,7 +47,8 @@ extern bool XactReadOnly;
|
||||
typedef enum
|
||||
{
|
||||
XACT_EVENT_COMMIT,
|
||||
XACT_EVENT_ABORT
|
||||
XACT_EVENT_ABORT,
|
||||
XACT_EVENT_PREPARE
|
||||
} XactEvent;
|
||||
|
||||
typedef void (*XactCallback) (XactEvent event, void *arg);
|
||||
@@ -72,8 +73,11 @@ typedef void (*SubXactCallback) (SubXactEvent event, SubTransactionId mySubid,
|
||||
* XLOG allows to store some information in high 4 bits of log
|
||||
* record xl_info field
|
||||
*/
|
||||
#define XLOG_XACT_COMMIT 0x00
|
||||
#define XLOG_XACT_ABORT 0x20
|
||||
#define XLOG_XACT_COMMIT 0x00
|
||||
#define XLOG_XACT_PREPARE 0x10
|
||||
#define XLOG_XACT_ABORT 0x20
|
||||
#define XLOG_XACT_COMMIT_PREPARED 0x30
|
||||
#define XLOG_XACT_ABORT_PREPARED 0x40
|
||||
|
||||
typedef struct xl_xact_commit
|
||||
{
|
||||
@@ -99,6 +103,31 @@ typedef struct xl_xact_abort
|
||||
|
||||
#define MinSizeOfXactAbort offsetof(xl_xact_abort, xnodes)
|
||||
|
||||
/*
|
||||
* COMMIT_PREPARED and ABORT_PREPARED are identical to COMMIT/ABORT records
|
||||
* except that we have to store the XID of the prepared transaction explicitly
|
||||
* --- the XID in the record header will be for the transaction doing the
|
||||
* COMMIT PREPARED or ABORT PREPARED command.
|
||||
*/
|
||||
|
||||
typedef struct xl_xact_commit_prepared
|
||||
{
|
||||
TransactionId xid; /* XID of prepared xact */
|
||||
xl_xact_commit crec; /* COMMIT record */
|
||||
/* MORE DATA FOLLOWS AT END OF STRUCT */
|
||||
} xl_xact_commit_prepared;
|
||||
|
||||
#define MinSizeOfXactCommitPrepared offsetof(xl_xact_commit_prepared, crec.xnodes)
|
||||
|
||||
typedef struct xl_xact_abort_prepared
|
||||
{
|
||||
TransactionId xid; /* XID of prepared xact */
|
||||
xl_xact_abort arec; /* ABORT record */
|
||||
/* MORE DATA FOLLOWS AT END OF STRUCT */
|
||||
} xl_xact_abort_prepared;
|
||||
|
||||
#define MinSizeOfXactAbortPrepared offsetof(xl_xact_abort_prepared, arec.xnodes)
|
||||
|
||||
|
||||
/* ----------------
|
||||
* extern definitions
|
||||
@@ -121,6 +150,7 @@ extern void CommitTransactionCommand(void);
|
||||
extern void AbortCurrentTransaction(void);
|
||||
extern void BeginTransactionBlock(void);
|
||||
extern bool EndTransactionBlock(void);
|
||||
extern bool PrepareTransactionBlock(char *gid);
|
||||
extern void UserAbortTransactionBlock(void);
|
||||
extern void ReleaseSavepoint(List *options);
|
||||
extern void DefineSavepoint(char *name);
|
||||
|
||||
Reference in New Issue
Block a user