From: Pavan Deolasee Date: Mon, 11 Jan 2016 16:05:28 +0000 (+0530) Subject: Send XID assigned on a datanode back to the coordinator. X-Git-Tag: XL9_5_R1BETA1~106 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=79714a871e0e1d7ad18abe623b4987458befead1;p=postgres-xl.git Send XID assigned on a datanode back to the coordinator. We'd missed out a case where XIDs are assigned on a datanode, but the same is not sent back to the coordinator. We now also avoid running a 2PC for transactions which do not have XID assigned to them since such transactions must not have made any database changes --- diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index 7e564fb655..4a6d3f6152 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -241,6 +241,7 @@ GetNewTransactionId(bool isSubXact) xid = (TransactionId) BeginTranGTM(timestamp, global_session); if (TransactionIdIsValid(xid)) { + elog(DEBUG2, "Received new XID from GTM: %s:%d", global_session, xid); /* * Let the coordinator know about GXID assigned to this * transaction @@ -264,6 +265,19 @@ GetNewTransactionId(bool isSubXact) */ sprintf(global_session, "%s_%d", PGXCNodeName, MyProcPid); xid = (TransactionId) BeginTranGTM(timestamp, global_session); + if (TransactionIdIsValid(xid)) + { + /* + * Let the coordinator know about GXID assigned to this + * transaction + */ + if (whereToSendOutput == DestRemote && + !IS_PGXC_LOCAL_COORDINATOR) + { + pq_putmessage('x', (const char *) &xid, sizeof (GlobalTransactionId)); + IsXidFromGTM = false; + } + } } } else diff --git a/src/backend/pgxc/pool/execRemote.c b/src/backend/pgxc/pool/execRemote.c index 4bf405992c..46fc336e89 100644 --- a/src/backend/pgxc/pool/execRemote.c +++ b/src/backend/pgxc/pool/execRemote.c @@ -4064,6 +4064,13 @@ IsTwoPhaseCommitRequired(bool localWrite) return false; } + /* + * If no XID assigned, no need to run 2PC since neither coordinator nor any + * remote nodes did write operation + */ + if (!TransactionIdIsValid(GetTopTransactionIdIfAny())) + return false; + handles = get_current_handles(); for (i = 0; i < handles->dn_conn_count; i++) {