You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
|
Apr
(4) |
May
(28) |
Jun
(12) |
Jul
(11) |
Aug
(12) |
Sep
(5) |
Oct
(19) |
Nov
(14) |
Dec
(12) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(18) |
Feb
(30) |
Mar
(115) |
Apr
(89) |
May
(50) |
Jun
(44) |
Jul
(22) |
Aug
(13) |
Sep
(11) |
Oct
(30) |
Nov
(28) |
Dec
(39) |
2012 |
Jan
(38) |
Feb
(18) |
Mar
(43) |
Apr
(91) |
May
(108) |
Jun
(46) |
Jul
(37) |
Aug
(44) |
Sep
(33) |
Oct
(29) |
Nov
(36) |
Dec
(15) |
2013 |
Jan
(35) |
Feb
(611) |
Mar
(5) |
Apr
(55) |
May
(30) |
Jun
(28) |
Jul
(458) |
Aug
(34) |
Sep
(9) |
Oct
(39) |
Nov
(22) |
Dec
(32) |
2014 |
Jan
(16) |
Feb
(16) |
Mar
(42) |
Apr
(179) |
May
(7) |
Jun
(6) |
Jul
(9) |
Aug
|
Sep
(4) |
Oct
|
Nov
(3) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
|
1
(3) |
2
(5) |
3
|
4
(4) |
5
|
6
|
7
(7) |
8
(10) |
9
(6) |
10
(5) |
11
(1) |
12
|
13
|
14
|
15
|
16
|
17
(4) |
18
(1) |
19
|
20
|
21
(5) |
22
(15) |
23
(18) |
24
(7) |
25
(4) |
26
|
27
|
28
(3) |
29
(2) |
30
(11) |
31
(4) |
|
|
From: Michael P. <mic...@us...> - 2011-03-02 08:17:51
|
Project "Postgres-XC". The branch, merge_postgres_9_0_3 has been created at 3ba29c3723ed6a31b0faa8fea0b9a7e57ca0c25d (commit) - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- hooks/post-receive -- Postgres-XC |
From: Koichi S. <koi...@us...> - 2011-03-02 03:58:48
|
Project "Postgres-XC". The branch, ha_support has been updated via 29ea460de8f7e66093c7b38cd49e238aed2ba129 (commit) via b0075708ecefd2a5aadbc2ed6d52ea7172ce1a34 (commit) from 0cb897c8fb3c0948ab75951f33d8d105d25d0912 (commit) - Log ----------------------------------------------------------------- commit 29ea460de8f7e66093c7b38cd49e238aed2ba129 Merge: b007570 0cb897c Author: Koichi Suzuki <koi...@gm...> Date: Wed Mar 2 13:00:49 2011 +0900 Merge branch 'ha_support' of ssh://postgres-xc.git.sourceforge.net/gitroot/postgres-xc/postgres-xc into ha_support commit b0075708ecefd2a5aadbc2ed6d52ea7172ce1a34 Author: Koichi Suzuki <koi...@gm...> Date: Wed Mar 2 12:53:16 2011 +0900 This commit is to fix two issues. 1. Changed assigment of xcm_xxxx() return value so that caller can check error by testing if the returned value is negative. 2. Changed the use of random number to determine the delay time when spin lock was not acquired. Now this is based upon nrand48. The seed and internal status is stored in a separate area so it does not influence coordinator/datanode. diff --git a/src/include/pgxc/xcm/node_membership_struct.h b/src/include/pgxc/xcm/node_membership_struct.h index a39ee3d..baefa00 100644 --- a/src/include/pgxc/xcm/node_membership_struct.h +++ b/src/include/pgxc/xcm/node_membership_struct.h @@ -416,14 +416,14 @@ typedef struct xcm_fault_comps { * of such component, these calls will return XCM_ERR_STATUS. */ #define XCM_OK 0 /* Successful */ +#define XCM_OTHER_UPDATE 1 /* Shared memory updated for some reason */ #define XCM_ERR_NOT_INITIALIZED -1 /* Shared memory not built yet */ #define XCM_ERR_OUT_OF_RANGE -2 /* Specified component does not exist */ #define XCM_ERR_COMP_FAILED -3 /* Specified component is not running */ -#define XCM_OTHER_UPDATE -4 /* Shared memory updated for some reason */ -#define XCM_ERR_MISC -5 /* Other system call error */ -#define XCM_ERR_PARM -6 /* Invalid parameters specified */ -#define XCM_ERR_STATUS -7 /* Cluster status cannot accept the operation */ -#define XCM_NOT_FOUND -8 /* Indicates that the specified object not found */ +#define XCM_ERR_MISC -4 /* Other system call error */ +#define XCM_ERR_PARM -5 /* Invalid parameters specified */ +#define XCM_ERR_STATUS -6 /* Cluster status cannot accept the operation */ +#define XCM_NOT_FOUND -7 /* Indicates that the specified object not found */ /* * Misc. magic numbers/values. diff --git a/src/pgxc/xcm/node_membership.c b/src/pgxc/xcm/node_membership.c index 18a6f5f..aac05db 100644 --- a/src/pgxc/xcm/node_membership.c +++ b/src/pgxc/xcm/node_membership.c @@ -96,6 +96,7 @@ static int check_init(void); static xcm_components *init_shm(void); static xcm_connPoint *copy_connPoints(xcm_connPoint *conn, int n_conn); static xcm_fault_comps *alloc_fault_comps(int num_comps); +static void init_random(void); /* * Internal one ... comes from @@ -194,13 +195,39 @@ int xcm_destroy_shm() /* * Check if the shared memory is attached. If not, try to attach it. + * Also reinitializa the random number series used in the wait of slock + * using pid. */ + +/* + * This is just to be used in spinlock wait. + */ +unsigned short xcm_rand_seed[3]; +#define MY_MAXSHORT (int)(0x7fff) + +/* + * Setup the seed of the random number using my PID + */ +static void init_random() +{ + pid_t mypid; + mypid = getpid(); + if (sizeof(pid_t) > 4) { + mypid &= 0x7fffffff; + } + xcm_rand_seed[0] = 0; + xcm_rand_seed[1] = mypid/MY_MAXSHORT; + xcm_rand_seed[2] = mypid%MY_MAXSHORT; +} + static int check_init() { xcm_components *checkv; - if (shm_top == NULL) + if (shm_top == NULL) { + init_random(); checkv = init_shm(); + } else return(0); if (checkv == NULL) diff --git a/src/pgxc/xcm/xcm_s_lock.c b/src/pgxc/xcm/xcm_s_lock.c index 5ccf1df..eea9ab2 100644 --- a/src/pgxc/xcm/xcm_s_lock.c +++ b/src/pgxc/xcm/xcm_s_lock.c @@ -66,6 +66,12 @@ xcm_s_lock_stuck(volatile xcm_slock_t *lock, const char *file, int line) /* * xcm_s_lock(lock) - platform-independent portion of waiting for a spinlock. */ +/* + * Seed for the random number used to determine wait time. + * Defined in node_membership.c. + */ +extern unsigned short *xcm_rand_seed; + void xcm_s_lock(volatile xcm_slock_t *lock, const char *file, int line) { @@ -140,7 +146,7 @@ xcm_s_lock(volatile xcm_slock_t *lock, const char *file, int line) /* increase delay by a random fraction between 1X and 2X */ cur_delay += (int) (cur_delay * - ((double) random() / (double) MAX_RANDOM_VALUE) + 0.5); + ((double) nrand48(xcm_rand_seed) / (double) MAX_RANDOM_VALUE) + 0.5); /* wrap back to minimum delay when max is exceeded */ if (cur_delay > MAX_DELAY_MSEC) cur_delay = MIN_DELAY_MSEC; ----------------------------------------------------------------------- Summary of changes: src/include/pgxc/xcm/node_membership_struct.h | 10 ++++---- src/pgxc/xcm/node_membership.c | 29 ++++++++++++++++++++++++- src/pgxc/xcm/xcm_s_lock.c | 8 ++++++- 3 files changed, 40 insertions(+), 7 deletions(-) hooks/post-receive -- Postgres-XC |
From: Michael P. <mic...@us...> - 2011-03-02 03:01:52
|
Project "Postgres-XC". The branch, ha_support has been updated via 0cb897c8fb3c0948ab75951f33d8d105d25d0912 (commit) from c2fdec2ef8f70e118bd66d26996689190268845d (commit) - Log ----------------------------------------------------------------- commit 0cb897c8fb3c0948ab75951f33d8d105d25d0912 Author: Michael P <mic...@us...> Date: Wed Mar 2 11:59:31 2011 +0900 Support mirror numbering in 2PC Data for pg_prepared_xact() function This support was still lacking because the node list was set with the list of global IDs used on pooler. Node list is written with the following format: Dn1/Mir1,Dn1/Mir2,..,DnN/MirN Ex: 1/1,1/2,3/1 diff --git a/src/backend/pgxc/pool/execRemote.c b/src/backend/pgxc/pool/execRemote.c index 809d08f..af70052 100644 --- a/src/backend/pgxc/pool/execRemote.c +++ b/src/backend/pgxc/pool/execRemote.c @@ -4640,13 +4640,26 @@ PGXCNode_Build2PCData(bool isimplicit) datanodes = collect_pgxcnode_numbers(dn_conn_count, pgxc_handles->datanode_handles, REMOTE_CONN_DATANODE); - sprintf(buffer, "%d", datanodes[0]); - - for (i = 1; i < dn_conn_count; i++) + if (IsPGXCMirrorMode) { - sprintf(buffer, "%s,%d", buffer, datanodes[i]); + int datanode_id, mirror_id; + + datanode_id = PGXCMirror_GetMirrorIDAndDatanodeID(datanodes[0], &mirror_id); + sprintf(buffer, "%d/%d", datanode_id, mirror_id); + + for (i = 1; i < dn_conn_count; i++) + { + datanode_id = PGXCMirror_GetMirrorIDAndDatanodeID(datanodes[i], &mirror_id); + sprintf(buffer, "%s,%d/%d", buffer, datanode_id, mirror_id); + } } + else + { + sprintf(buffer, "%d", datanodes[0]); + for (i = 1; i < dn_conn_count; i++) + sprintf(buffer, "%s,%d", buffer, datanodes[i]); + } PGXC_2PCData->nodelist = (char *) malloc(strlen(buffer) + 1); memcpy(PGXC_2PCData->nodelist, buffer, strlen(buffer) + 1); } ----------------------------------------------------------------------- Summary of changes: src/backend/pgxc/pool/execRemote.c | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-) hooks/post-receive -- Postgres-XC |
From: Michael P. <mic...@us...> - 2011-03-02 00:57:30
|
Project "Postgres-XC". The branch, ha_support has been updated via c2fdec2ef8f70e118bd66d26996689190268845d (commit) via 3ba29c3723ed6a31b0faa8fea0b9a7e57ca0c25d (commit) from 482825deb075f295fc349fa3bb3fda8ca46d92df (commit) - Log ----------------------------------------------------------------- commit c2fdec2ef8f70e118bd66d26996689190268845d Merge: 482825d 3ba29c3 Author: Michael P <mic...@us...> Date: Wed Mar 2 10:02:06 2011 +0900 Merge branch 'master' into ha_support diff --cc src/backend/access/transam/xact.c index 082431c,4ef1edd..1f3c09f --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@@ -2092,11 -2083,9 +2091,11 @@@ CommitTransaction(bool contact_gtm * an application can use this special prepare. * If PrepareTransaction is called during an implicit 2PC, do not release ressources, * this is made by CommitTransaction when transaction has been committed on Nodes. + * + * In case of an explicit 2PC, 2PC Data of PGXC is set when PGXCNodePrepare is called. */ static void - PrepareTransaction(bool write_2pc_file, bool is_implicit) + PrepareTransaction(bool is_implicit) #else static void PrepareTransaction(void) diff --cc src/include/access/twophase.h index 06b219c,94df1ad..4a5e712 --- a/src/include/access/twophase.h +++ b/src/include/access/twophase.h @@@ -48,15 -37,8 +48,9 @@@ extern GlobalTransaction MarkAsPreparin extern GlobalTransaction MarkAsPreparing(TransactionId xid, const char *gid, TimestampTz prepared_at, Oid owner, Oid databaseid); +#endif - #ifdef PGXC - extern void RemoveGXactCoord(GlobalTransaction gxact); - extern void EndPrepare(GlobalTransaction gxact, bool write_2pc_file); - #else extern void EndPrepare(GlobalTransaction gxact); - #endif - extern void StartPrepare(GlobalTransaction gxact); extern TransactionId PrescanPreparedTransactions(void); ----------------------------------------------------------------------- Summary of changes: src/backend/access/transam/twophase.c | 40 ------- src/backend/access/transam/xact.c | 184 ++++++++++++++++----------------- src/backend/tcop/utility.c | 25 ++++- src/include/access/twophase.h | 6 - src/include/access/xact.h | 6 +- 5 files changed, 112 insertions(+), 149 deletions(-) hooks/post-receive -- Postgres-XC |
From: Michael P. <mic...@us...> - 2011-03-02 00:47:59
|
Project "Postgres-XC". The branch, master has been updated via 3ba29c3723ed6a31b0faa8fea0b9a7e57ca0c25d (commit) from 51cabe99e820989af4634ef7113a294563e8820c (commit) - Log ----------------------------------------------------------------- commit 3ba29c3723ed6a31b0faa8fea0b9a7e57ca0c25d Author: Michael P <mic...@us...> Date: Wed Mar 2 09:46:21 2011 +0900 Fix for bug 3134395, 3086422, 3136230: 2PC locks When a PREPARE was being made on Coordinator for a transaction not using DDL, 2PC file was bypassed so as to make a fake COMMIT on Coordinator. The problem was that locks hold at PREPARE state were not released at COMMIT PREPARED on Coordinator because lock information was obtained from 2PC, which indeed did not exist on Coordinator for non-DDL transactions. With this fix, instead of a fake PREPARE, XC does a Commit on Coordinator without contacting GTM, this permits to release correctly all the locks held by transaction. PrepareTransaction is simplified in xact.c, but CommitTransaction needs an additional parameter to decide if GTM is called at COMMIT or not. diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index af15e79..1531d44 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -892,13 +892,8 @@ StartPrepare(GlobalTransaction gxact) * * Calculates CRC and writes state file to WAL and in pg_twophase directory. */ -#ifdef PGXC -void -EndPrepare(GlobalTransaction gxact, bool write_2pc_file) -#else void EndPrepare(GlobalTransaction gxact) -#endif { TransactionId xid = gxact->proc.xid; TwoPhaseFileHeader *hdr; @@ -935,11 +930,6 @@ EndPrepare(GlobalTransaction gxact) * PANIC anyway. */ -#ifdef PGXC - /* Write 2PC state file on Coordinator side if a DDL is involved in transaction */ - if (write_2pc_file) - { -#endif TwoPhaseFilePath(path, xid); fd = BasicOpenFile(path, @@ -1012,9 +1002,6 @@ EndPrepare(GlobalTransaction gxact) * We save the PREPARE record's location in the gxact for later use by * CheckPointTwoPhase. */ -#ifdef PGXC - } -#endif START_CRIT_SECTION(); @@ -1026,15 +1013,6 @@ EndPrepare(GlobalTransaction gxact) /* If we crash now, we have prepared: WAL replay will fix things */ -#ifdef PGXC - /* - * Just write 2PC state file on Datanodes - * or on Coordinators if DDL queries are involved. - */ - if (write_2pc_file) - { -#endif - /* write correct CRC and close file */ if ((write(fd, &statefile_crc, sizeof(pg_crc32))) != sizeof(pg_crc32)) { @@ -1049,10 +1027,6 @@ EndPrepare(GlobalTransaction gxact) (errcode_for_file_access(), errmsg("could not close two-phase state file: %m"))); -#ifdef PGXC - } -#endif - /* * Mark the prepared transaction as valid. As soon as xact.c marks MyProc * as not running our XID (which it will do immediately after this @@ -1903,17 +1877,3 @@ RecordTransactionAbortPrepared(TransactionId xid, END_CRIT_SECTION(); } - - -#ifdef PGXC -/* - * Remove a gxact on a Coordinator, - * this is used to be able to prepare a commit transaction on another coordinator than the one - * who prepared the transaction, for a transaction that does not include DDLs - */ -void -RemoveGXactCoord(GlobalTransaction gxact) -{ - RemoveGXact(gxact); -} -#endif diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 0fa83fa..4ef1edd 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -112,14 +112,13 @@ typedef enum TBlockState TBLOCK_BEGIN, /* starting transaction block */ TBLOCK_INPROGRESS, /* live transaction */ TBLOCK_END, /* COMMIT received */ +#ifdef PGXC + TBLOCK_END_NOT_GTM, /* COMMIT received but do not commit on GTM */ +#endif TBLOCK_ABORT, /* failed xact, awaiting ROLLBACK */ TBLOCK_ABORT_END, /* failed xact, ROLLBACK received */ TBLOCK_ABORT_PENDING, /* live xact, ROLLBACK received */ TBLOCK_PREPARE, /* live xact, PREPARE received */ -#ifdef PGXC - TBLOCK_PREPARE_NO_2PC_FILE, /* PREPARE receive but skip 2PC file creation - * and Commit gxact */ -#endif /* subtransaction states */ TBLOCK_SUBBEGIN, /* starting a subtransaction */ TBLOCK_SUBINPROGRESS, /* live subtransaction */ @@ -287,7 +286,7 @@ static void CallSubXactCallbacks(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid); static void CleanupTransaction(void); -static void CommitTransaction(void); +static void CommitTransaction(bool contact_gtm); static TransactionId RecordTransactionAbort(bool isSubXact); static void StartTransaction(void); @@ -312,7 +311,7 @@ static const char *TransStateAsString(TransState state); #ifdef PGXC /* PGXC_COORD */ static GlobalTransactionId GetGlobalTransactionId(TransactionState s); -static void PrepareTransaction(bool write_2pc_file, bool is_implicit); +static void PrepareTransaction(bool is_implicit); /* ---------------------------------------------------------------- * PG-XC Functions @@ -1744,7 +1743,7 @@ StartTransaction(void) * NB: if you change this routine, better look at PrepareTransaction too! */ static void -CommitTransaction(void) +CommitTransaction(bool contact_gtm) { TransactionState s = CurrentTransactionState; TransactionId latestXid; @@ -1754,7 +1753,7 @@ CommitTransaction(void) char implicitgid[256]; TransactionId xid = GetCurrentTransactionId(); - if (IS_PGXC_COORDINATOR && !IsConnFromCoord()) + if (IS_PGXC_COORDINATOR && !IsConnFromCoord() && contact_gtm) PreparePGXCNodes = PGXCNodeIsImplicit2PC(&PrepareLocalCoord); if (PrepareLocalCoord || PreparePGXCNodes) @@ -1768,7 +1767,7 @@ CommitTransaction(void) * If current transaction has a DDL, and involves more than 1 Coordinator, * PREPARE first on local Coordinator. */ - PrepareTransaction(true, true); + PrepareTransaction(true); } else { @@ -1865,7 +1864,7 @@ CommitTransaction(void) * * This is called only if it is not necessary to prepare the nodes. */ - if (IS_PGXC_COORDINATOR && !IsConnFromCoord() && !PreparePGXCNodes) + if (IS_PGXC_COORDINATOR && !IsConnFromCoord() && !PreparePGXCNodes && contact_gtm) PGXCNodeCommit(); #endif @@ -1892,12 +1891,12 @@ CommitTransaction(void) * * Also do not commit a transaction that has already been prepared on Datanodes */ - if (IS_PGXC_COORDINATOR && !IsConnFromCoord() && !PreparePGXCNodes) + if (IS_PGXC_COORDINATOR && !IsConnFromCoord() && !PreparePGXCNodes && contact_gtm) { CommitTranGTM(s->globalTransactionId); latestXid = s->globalTransactionId; } - else if (IS_PGXC_DATANODE || IsConnFromCoord()) + else if ((IS_PGXC_DATANODE || IsConnFromCoord()) && contact_gtm) { /* If we are autovacuum, commit on GTM */ if ((IsAutoVacuumWorkerProcess() || GetForceXidFromGTM()) @@ -2086,7 +2085,7 @@ CommitTransaction(void) * this is made by CommitTransaction when transaction has been committed on Nodes. */ static void -PrepareTransaction(bool write_2pc_file, bool is_implicit) +PrepareTransaction(bool is_implicit) #else static void PrepareTransaction(void) @@ -2222,7 +2221,7 @@ PrepareTransaction(void) * updates, because the transaction manager might get confused if we lose * a global transaction. */ - EndPrepare(gxact, write_2pc_file); + EndPrepare(gxact); /* * Now we clean up backend-internal state and release internal resources. @@ -2273,17 +2272,6 @@ PrepareTransaction(void) #ifdef PGXC /* - * We want to be able to commit a prepared transaction from another coordinator, - * so clean up the gxact in shared memory also. - */ - if (!write_2pc_file) - { - RemoveGXactCoord(gxact); - } -#endif - -#ifdef PGXC - /* * In case of an implicit 2PC, ressources are released by CommitTransaction() */ if (!is_implicit) @@ -2665,6 +2653,9 @@ StartTransactionCommand(void) case TBLOCK_BEGIN: case TBLOCK_SUBBEGIN: case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif case TBLOCK_SUBEND: case TBLOCK_ABORT_END: case TBLOCK_SUBABORT_END: @@ -2673,9 +2664,6 @@ StartTransactionCommand(void) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif elog(ERROR, "StartTransactionCommand: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -2714,7 +2702,11 @@ CommitTransactionCommand(void) * transaction commit, and return to the idle state. */ case TBLOCK_STARTED: +#ifdef PGXC + CommitTransaction(true); +#else CommitTransaction(); +#endif s->blockState = TBLOCK_DEFAULT; break; @@ -2743,10 +2735,20 @@ CommitTransactionCommand(void) * idle state. */ case TBLOCK_END: +#ifdef PGXC + CommitTransaction(true); +#else CommitTransaction(); +#endif s->blockState = TBLOCK_DEFAULT; break; +#ifdef PGXC + case TBLOCK_END_NOT_GTM: + CommitTransaction(false); + s->blockState = TBLOCK_DEFAULT; + break; +#endif /* * Here we are in the middle of a transaction block but one of the * commands caused an abort so we do nothing but remain in the @@ -2782,20 +2784,13 @@ CommitTransactionCommand(void) * return to the idle state. */ case TBLOCK_PREPARE: - PrepareTransaction(true, false); - s->blockState = TBLOCK_DEFAULT; - break; - #ifdef PGXC - /* - * We are complieting a PREPARE TRANSACTION for a pgxc transaction - * that involved DDLs on a Coordinator. - */ - case TBLOCK_PREPARE_NO_2PC_FILE: - PrepareTransaction(false, false); + PrepareTransaction(false); +#else + PrepareTransaction(); +#endif s->blockState = TBLOCK_DEFAULT; break; -#endif /* * We were just issued a SAVEPOINT inside a transaction block. @@ -2824,23 +2819,21 @@ CommitTransactionCommand(void) if (s->blockState == TBLOCK_END) { Assert(s->parent == NULL); +#ifdef PGXC + CommitTransaction(true); +#else CommitTransaction(); +#endif s->blockState = TBLOCK_DEFAULT; } else if (s->blockState == TBLOCK_PREPARE) { Assert(s->parent == NULL); - PrepareTransaction(true, false); - s->blockState = TBLOCK_DEFAULT; - } #ifdef PGXC - else if (s->blockState == TBLOCK_PREPARE_NO_2PC_FILE) - { - Assert(s->parent == NULL); - PrepareTransaction(false, false); + PrepareTransaction(false); +#endif s->blockState = TBLOCK_DEFAULT; } -#endif else { Assert(s->blockState == TBLOCK_INPROGRESS || @@ -2998,6 +2991,9 @@ AbortCurrentTransaction(void) * the transaction). */ case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif AbortTransaction(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; @@ -3038,9 +3034,6 @@ AbortCurrentTransaction(void) * the transaction). */ case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif AbortTransaction(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; @@ -3384,6 +3377,9 @@ BeginTransactionBlock(void) case TBLOCK_BEGIN: case TBLOCK_SUBBEGIN: case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif case TBLOCK_SUBEND: case TBLOCK_ABORT_END: case TBLOCK_SUBABORT_END: @@ -3392,9 +3388,6 @@ BeginTransactionBlock(void) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif elog(FATAL, "BeginTransactionBlock: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -3413,19 +3406,18 @@ BeginTransactionBlock(void) * We do it this way because it's not convenient to change memory context, * resource owner, etc while executing inside a Portal. */ -#ifdef PGXC -bool -PrepareTransactionBlock(char *gid, bool write_2pc_file) -#else bool PrepareTransactionBlock(char *gid) -#endif { TransactionState s; bool result; /* Set up to commit the current transaction */ +#ifdef PGXC + result = EndTransactionBlock(true); +#else result = EndTransactionBlock(); +#endif /* If successful, change outer tblock state to PREPARE */ if (result) @@ -3440,16 +3432,6 @@ PrepareTransactionBlock(char *gid) /* Save GID where PrepareTransaction can find it again */ prepareGID = MemoryContextStrdup(TopTransactionContext, gid); -#ifdef PGXC - /* - * For a Postgres-XC Coordinator, prepare is done for a transaction - * if and only if a DDL was involved in the transaction. - * If not, it is enough to prepare it on Datanodes involved only. - */ - if (!write_2pc_file) - s->blockState = TBLOCK_PREPARE_NO_2PC_FILE; - else -#endif s->blockState = TBLOCK_PREPARE; } else @@ -3480,7 +3462,11 @@ PrepareTransactionBlock(char *gid) * resource owner, etc while executing inside a Portal. */ bool +#ifdef PGXC +EndTransactionBlock(bool contact_gtm) +#else EndTransactionBlock(void) +#endif { TransactionState s = CurrentTransactionState; bool result = false; @@ -3492,6 +3478,11 @@ EndTransactionBlock(void) * to COMMIT. */ case TBLOCK_INPROGRESS: +#ifdef PGXC + if (!contact_gtm) + s->blockState = TBLOCK_END_NOT_GTM; + else +#endif s->blockState = TBLOCK_END; result = true; break; @@ -3570,6 +3561,9 @@ EndTransactionBlock(void) case TBLOCK_BEGIN: case TBLOCK_SUBBEGIN: case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif case TBLOCK_SUBEND: case TBLOCK_ABORT_END: case TBLOCK_SUBABORT_END: @@ -3578,9 +3572,6 @@ EndTransactionBlock(void) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif elog(FATAL, "EndTransactionBlock: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -3665,6 +3656,9 @@ UserAbortTransactionBlock(void) case TBLOCK_BEGIN: case TBLOCK_SUBBEGIN: case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif case TBLOCK_SUBEND: case TBLOCK_ABORT_END: case TBLOCK_SUBABORT_END: @@ -3673,9 +3667,6 @@ UserAbortTransactionBlock(void) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif elog(FATAL, "UserAbortTransactionBlock: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -3713,6 +3704,9 @@ DefineSavepoint(char *name) case TBLOCK_BEGIN: case TBLOCK_SUBBEGIN: case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif case TBLOCK_SUBEND: case TBLOCK_ABORT: case TBLOCK_SUBABORT: @@ -3723,9 +3717,6 @@ DefineSavepoint(char *name) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif elog(FATAL, "DefineSavepoint: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -3772,6 +3763,9 @@ ReleaseSavepoint(List *options) case TBLOCK_BEGIN: case TBLOCK_SUBBEGIN: case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif case TBLOCK_SUBEND: case TBLOCK_ABORT: case TBLOCK_SUBABORT: @@ -3782,9 +3776,6 @@ ReleaseSavepoint(List *options) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif elog(FATAL, "ReleaseSavepoint: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -3875,6 +3866,9 @@ RollbackToSavepoint(List *options) case TBLOCK_BEGIN: case TBLOCK_SUBBEGIN: case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif case TBLOCK_SUBEND: case TBLOCK_ABORT_END: case TBLOCK_SUBABORT_END: @@ -3883,9 +3877,6 @@ RollbackToSavepoint(List *options) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif elog(FATAL, "RollbackToSavepoint: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -3968,10 +3959,10 @@ BeginInternalSubTransaction(char *name) case TBLOCK_STARTED: case TBLOCK_INPROGRESS: case TBLOCK_END: - case TBLOCK_PREPARE: #ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: + case TBLOCK_END_NOT_GTM: #endif + case TBLOCK_PREPARE: case TBLOCK_SUBINPROGRESS: /* Normal subtransaction start */ PushTransaction(); @@ -3984,7 +3975,6 @@ BeginInternalSubTransaction(char *name) if (name) s->name = MemoryContextStrdup(TopTransactionContext, name); break; - /* These cases are invalid. */ case TBLOCK_DEFAULT: case TBLOCK_BEGIN: @@ -4055,6 +4045,9 @@ RollbackAndReleaseCurrentSubTransaction(void) case TBLOCK_SUBBEGIN: case TBLOCK_INPROGRESS: case TBLOCK_END: +#ifdef PGXC + case TBLOCK_END_NOT_GTM: +#endif case TBLOCK_SUBEND: case TBLOCK_ABORT: case TBLOCK_ABORT_END: @@ -4064,9 +4057,6 @@ RollbackAndReleaseCurrentSubTransaction(void) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: -#ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: -#endif elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -4113,11 +4103,11 @@ AbortOutOfAnyTransaction(void) case TBLOCK_BEGIN: case TBLOCK_INPROGRESS: case TBLOCK_END: - case TBLOCK_ABORT_PENDING: - case TBLOCK_PREPARE: #ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: + case TBLOCK_END_NOT_GTM: #endif + case TBLOCK_ABORT_PENDING: + case TBLOCK_PREPARE: /* In a transaction, so clean up */ AbortTransaction(); CleanupTransaction(); @@ -4207,11 +4197,11 @@ TransactionBlockStatusCode(void) case TBLOCK_INPROGRESS: case TBLOCK_SUBINPROGRESS: case TBLOCK_END: - case TBLOCK_SUBEND: - case TBLOCK_PREPARE: #ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: + case TBLOCK_END_NOT_GTM: #endif + case TBLOCK_SUBEND: + case TBLOCK_PREPARE: return 'T'; /* in transaction */ case TBLOCK_ABORT: case TBLOCK_SUBABORT: @@ -4707,10 +4697,10 @@ BlockStateAsString(TBlockState blockState) return "ABORT END"; case TBLOCK_ABORT_PENDING: return "ABORT PEND"; + case TBLOCK_PREPARE: #ifdef PGXC - case TBLOCK_PREPARE_NO_2PC_FILE: + case TBLOCK_END_NOT_GTM: #endif - case TBLOCK_PREPARE: return "PREPARE"; case TBLOCK_SUBBEGIN: return "SUB BEGIN"; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 90c1f81..065d880 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -335,7 +335,11 @@ ProcessUtility(Node *parsetree, break; case TRANS_STMT_COMMIT: +#ifdef PGXC + if (!EndTransactionBlock(true)) +#else if (!EndTransactionBlock()) +#endif { /* report unsuccessful commit in completionTag */ if (completionTag) @@ -361,16 +365,31 @@ ProcessUtility(Node *parsetree, if (IsConnFromCoord()) operation_local = true; - if (!PrepareTransactionBlock(stmt->gid, operation_local)) + if (operation_local) { -#else +#endif if (!PrepareTransactionBlock(stmt->gid)) { -#endif /* report unsuccessful commit in completionTag */ if (completionTag) strcpy(completionTag, "ROLLBACK"); } +#ifdef PGXC + } + else + { + /* + * In this case commit locally to erase the transaction traces + * but do not contact GTM + */ + if (!EndTransactionBlock(false)) + { + /* report unsuccessful commit in completionTag */ + if (completionTag) + strcpy(completionTag, "ROLLBACK"); + } + } +#endif break; case TRANS_STMT_COMMIT_PREPARED: diff --git a/src/include/access/twophase.h b/src/include/access/twophase.h index 7b78a6d..94df1ad 100644 --- a/src/include/access/twophase.h +++ b/src/include/access/twophase.h @@ -38,13 +38,7 @@ extern GlobalTransaction MarkAsPreparing(TransactionId xid, const char *gid, TimestampTz prepared_at, Oid owner, Oid databaseid); -#ifdef PGXC -extern void RemoveGXactCoord(GlobalTransaction gxact); -extern void EndPrepare(GlobalTransaction gxact, bool write_2pc_file); -#else extern void EndPrepare(GlobalTransaction gxact); -#endif - extern void StartPrepare(GlobalTransaction gxact); extern TransactionId PrescanPreparedTransactions(void); diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 9b2be9f..e7f1089 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -172,12 +172,12 @@ extern void AbortCurrentTransactionOnce(void); #endif extern void AbortCurrentTransaction(void); extern void BeginTransactionBlock(void); -extern bool EndTransactionBlock(void); #ifdef PGXC -extern bool PrepareTransactionBlock(char *gid, bool write_2pc_file); +extern bool EndTransactionBlock(bool contact_gtm); #else -extern bool PrepareTransactionBlock(char *gid); +extern bool EndTransactionBlock(void); #endif +extern bool PrepareTransactionBlock(char *gid); extern void UserAbortTransactionBlock(void); extern void ReleaseSavepoint(List *options); extern void DefineSavepoint(char *name); ----------------------------------------------------------------------- Summary of changes: src/backend/access/transam/twophase.c | 40 ------- src/backend/access/transam/xact.c | 184 ++++++++++++++++----------------- src/backend/tcop/utility.c | 25 ++++- src/include/access/twophase.h | 6 - src/include/access/xact.h | 6 +- 5 files changed, 112 insertions(+), 149 deletions(-) hooks/post-receive -- Postgres-XC |