diff options
author | Pavan Deolasee | 2015-06-23 11:12:06 +0000 |
---|---|---|
committer | Pavan Deolasee | 2015-06-23 11:12:06 +0000 |
commit | 250b2f0e3414e6510d6c42c44eeea79a19c62639 (patch) | |
tree | a422785ac6f7304cf807f7bf02b029aeb525aefc | |
parent | 289cba11506536aa156c14e322ab09b8a8b7a21c (diff) |
Find and remember node id of the remote node as set via SET global_session
command during shared queue acquire/bind time
Current code had calls to find this out during shared queue release. Given that
shared queue release may be called during transaction abort and the fact that
we can no longer make any sys cache lookup in abort call path, it seems much
safer to note and remember this value when its used for the first time in the
session
(We could have remembered this value when SET global_session command is
processed. But that happens during backend startup time and we haven't yet
setup the datanode and coordinator node handles at that time. So we can't
really determine the node id, which an index into the array of these handles,
at that time)
-rw-r--r-- | src/backend/pgxc/squeue/squeue.c | 24 | ||||
-rw-r--r-- | src/backend/postmaster/postmaster.c | 3 | ||||
-rw-r--r-- | src/backend/tcop/postgres.c | 3 | ||||
-rw-r--r-- | src/backend/tcop/pquery.c | 10 | ||||
-rw-r--r-- | src/include/pgxc/pgxc.h | 4 |
5 files changed, 24 insertions, 20 deletions
diff --git a/src/backend/pgxc/squeue/squeue.c b/src/backend/pgxc/squeue/squeue.c index 02d11d2430..5bb1edfa40 100644 --- a/src/backend/pgxc/squeue/squeue.c +++ b/src/backend/pgxc/squeue/squeue.c @@ -352,16 +352,15 @@ tryagain: */ if (sq->sq_pid != 0) { - int selfid; /* Node Id of the parent data node */ int i; - char ntype = PGXC_NODE_DATANODE; bool old_squeue = true; - selfid = PGXCNodeGetNodeIdFromName(PGXC_PARENT_NODE, &ntype); + PGXC_PARENT_NODE_ID = PGXCNodeGetNodeIdFromName(PGXC_PARENT_NODE, + &PGXC_PARENT_NODE_TYPE); for (i = 0; i < sq->sq_nconsumers; i++) { ConsState *cstate = &(sq->sq_consumers[i]); - if (cstate->cs_node == selfid) + if (cstate->cs_node == PGXC_PARENT_NODE_ID) { SQueueSync *sqsync = sq->sq_sync; @@ -411,13 +410,11 @@ SharedQueueBind(const char *sqname, List *consNodes, { bool found; SharedQueue sq; - int selfid; /* Node Id of the parent data node */ - char ntype = PGXC_NODE_DATANODE; LWLockAcquire(SQueuesLock, LW_EXCLUSIVE); - selfid = PGXCNodeGetNodeIdFromName(PGXC_PARENT_NODE, &ntype); - + PGXC_PARENT_NODE_ID = PGXCNodeGetNodeIdFromName(PGXC_PARENT_NODE, + &PGXC_PARENT_NODE_TYPE); sq = (SharedQueue) hash_search(SharedQueues, sqname, HASH_FIND, &found); if (!found) elog(PANIC, "Shared queue %s not found", sqname); @@ -434,7 +431,7 @@ SharedQueueBind(const char *sqname, List *consNodes, /* Initialize the shared queue */ sq->sq_pid = MyProcPid; - sq->sq_nodeid = selfid; + sq->sq_nodeid = PGXC_PARENT_NODE_ID; OwnLatch(&sq->sq_sync->sqs_producer_latch); i = 0; @@ -446,7 +443,7 @@ SharedQueueBind(const char *sqname, List *consNodes, * Producer won't go to shared queue to hand off tuple to itself, * so we do not need to create queue for that entry. */ - if (nodeid == selfid) + if (nodeid == PGXC_PARENT_NODE_ID) { /* Producer must be in the consNodes list */ Assert(list_member_int(consNodes, nodeid)); @@ -531,7 +528,7 @@ SharedQueueBind(const char *sqname, List *consNodes, if (cstate->cs_node == nodeid) { nconsumers++; - if (nodeid == selfid) + if (nodeid == PGXC_PARENT_NODE_ID) { /* * Current consumer queue is that from which current @@ -1309,19 +1306,18 @@ SharedQueueRelease(const char *sqname) return; } - myid = PGXCNodeGetNodeIdFromName(PGXC_PARENT_NODE, &ntype); /* * Do not bother releasing producer, all necessary work will be * done upon UnBind. */ - if (sq->sq_nodeid != myid) + if (sq->sq_nodeid != PGXC_PARENT_NODE_ID) { elog(LOG, "Looking for consumer %d in %s", myid, sqname); /* find specified node in the consumer lists */ for (i = 0; i < sq->sq_nconsumers; i++) { ConsState *cstate = &(sq->sq_consumers[i]); - if (cstate->cs_node == myid) + if (cstate->cs_node == PGXC_PARENT_NODE_ID) { LWLockAcquire(sqsync->sqs_consumer_sync[i].cs_lwlock, LW_EXCLUSIVE); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 0f042c7f24..5fee421db7 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -108,6 +108,7 @@ #include "libpq/pqsignal.h" #include "miscadmin.h" #ifdef PGXC +#include "catalog/pgxc_node.h" #include "pgxc/pgxc.h" /* COORD */ #include "pgxc/locator.h" @@ -545,6 +546,8 @@ static void ShmemBackendArrayRemove(Backend *bn); #ifdef XCP char *parentPGXCNode = NULL; +int parentPGXCNodeId = -1; +char parentPGXCNodeType = PGXC_NODE_DATANODE; #endif #ifdef PGXC diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 5a2420ad5a..d09945264c 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -88,6 +88,7 @@ #include "mb/pg_wchar.h" #ifdef PGXC +#include "catalog/pgxc_node.h" #include "storage/procarray.h" #include "pgxc/pgxc.h" #include "access/gtm.h" @@ -4059,6 +4060,8 @@ PostgresMain(int argc, char *argv[], #endif #ifdef XCP parentPGXCNode = NULL; + parentPGXCNodeId = -1; + parentPGXCNodeType = PGXC_NODE_DATANODE; cluster_lock_held = false; cluster_ex_lock_held = false; #endif /* XCP */ diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index efb89b14be..fac44220d0 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -628,8 +628,6 @@ PortalStart(Portal portal, ParamListInfo params, { int *consMap; int len; - int selfid; /* Node Id of the parent data node */ - char ntype = PGXC_NODE_DATANODE; ListCell *lc; int i; Locator *locator; @@ -640,12 +638,12 @@ PortalStart(Portal portal, ParamListInfo params, consMap = (int *) palloc0(len * sizeof(int)); queryDesc->squeue = NULL; queryDesc->myindex = -1; - selfid = PGXCNodeGetNodeIdFromName(PGXC_PARENT_NODE, - &ntype); + PGXC_PARENT_NODE_ID = PGXCNodeGetNodeIdFromName(PGXC_PARENT_NODE, + &PGXC_PARENT_NODE_TYPE); i = 0; foreach(lc, queryDesc->plannedstmt->distributionNodes) { - if (selfid == lfirst_int(lc)) + if (PGXC_PARENT_NODE_ID == lfirst_int(lc)) consMap[i] = SQ_CONS_SELF; else consMap[i] = SQ_CONS_NONE; @@ -659,7 +657,7 @@ PortalStart(Portal portal, ParamListInfo params, */ RemoteSubplanMakeUnique( (Node *) queryDesc->plannedstmt->planTree, - selfid); + PGXC_PARENT_NODE_ID); /* * Call ExecutorStart to prepare the plan for execution */ diff --git a/src/include/pgxc/pgxc.h b/src/include/pgxc/pgxc.h index d223d3a3b6..a1d67861b9 100644 --- a/src/include/pgxc/pgxc.h +++ b/src/include/pgxc/pgxc.h @@ -27,6 +27,8 @@ extern bool isPGXCDataNode; extern bool isRestoreMode; #ifdef XCP extern char *parentPGXCNode; +extern int parentPGXCNodeId; +extern char parentPGXCNodeType; #endif typedef enum @@ -59,6 +61,8 @@ extern Datum xc_lockForBackupKey2; #ifdef XCP #define PGXC_PARENT_NODE parentPGXCNode +#define PGXC_PARENT_NODE_ID parentPGXCNodeId +#define PGXC_PARENT_NODE_TYPE parentPGXCNodeType #endif #define REMOTE_CONN_TYPE remoteConnType |