summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Vondra2016-08-23 16:36:13 +0000
committerPavan Deolasee2016-10-18 10:07:45 +0000
commit48ecce663882e35913689dea1eaab86e7ed9614e (patch)
tree49970783e881e511af79db7575425977d42d6861
parent1d51e4fbc81bb9bdc13752d61c3c1681da79840c (diff)
minor PgxcNodeListAndCount() refactoring to fix compiler warnings
While tweaking the code, I've noticed this is the only place using NodeHealthStatus, apparently attempting to save a few bytes. That seems rather pointless given how little memory this will need and how short-lived the memory is (and also how AllocSet doubles the allocation sizes anyway), so I got rid of this. This makes copying the old state easier (a simple memcpy instead of for loops). Note: The PgxcNodeListAndCount() seems a bit unfortunate, as the name suggests to list and count nodes, but in practice it refreshes the status of nodes from catalog, while keeping the health status.
-rw-r--r--src/backend/pgxc/nodemgr/nodemgr.c39
-rw-r--r--src/include/pgxc/nodemgr.h6
2 files changed, 17 insertions, 28 deletions
diff --git a/src/backend/pgxc/nodemgr/nodemgr.c b/src/backend/pgxc/nodemgr/nodemgr.c
index 683cd095d5..5e3290d419 100644
--- a/src/backend/pgxc/nodemgr/nodemgr.c
+++ b/src/backend/pgxc/nodemgr/nodemgr.c
@@ -326,37 +326,32 @@ PgxcNodeListAndCount(void)
Relation rel;
HeapScanDesc scan;
HeapTuple tuple;
- NodeHealthStatus *nodehealth;
- int numNodes = 0;
+ NodeDefinition *nodes = NULL;
+ int numNodes;
LWLockAcquire(NodeTableLock, LW_EXCLUSIVE);
+ numNodes = *shmemNumCoords + *shmemNumDataNodes;
+
+ Assert((*shmemNumCoords >= 0) && (*shmemNumDataNodes >= 0));
+
/*
* Save the existing health status values because nodes
* might get added or deleted here. We will save
* nodeoid, status. No need to differentiate between
* coords and datanodes since oids will be unique anyways
*/
- if (*shmemNumDataNodes != 0 || *shmemNumCoords != 0)
+ if (numNodes > 0)
{
- int i, j;
+ nodes = (NodeDefinition*)palloc(numNodes * sizeof(NodeDefinition));
- numNodes = *shmemNumCoords + *shmemNumDataNodes;
- nodehealth = palloc0(
- numNodes * sizeof(NodeHealthStatus));
+ /* XXX It's possible to call memcpy with */
+ if (*shmemNumCoords > 0)
+ memcpy(nodes, coDefs, *shmemNumCoords * sizeof(NodeDefinition));
- for (i = 0; i < *shmemNumCoords; i++)
- {
- nodehealth[i].nodeoid = coDefs[i].nodeoid;
- nodehealth[i].nodeishealthy = coDefs[i].nodeishealthy;
- }
-
- j = i;
- for (i = 0; i < *shmemNumDataNodes; i++)
- {
- nodehealth[j].nodeoid = dnDefs[i].nodeoid;
- nodehealth[j++].nodeishealthy = dnDefs[i].nodeishealthy;
- }
+ if (*shmemNumDataNodes > 0)
+ memcpy(nodes + *shmemNumCoords, dnDefs,
+ *shmemNumDataNodes * sizeof(NodeDefinition));
}
*shmemNumCoords = 0;
@@ -404,9 +399,9 @@ PgxcNodeListAndCount(void)
node->nodeishealthy = true;
for (i = 0; i < numNodes; i++)
{
- if (nodehealth[i].nodeoid == node->nodeoid)
+ if (nodes[i].nodeoid == node->nodeoid)
{
- node->nodeishealthy = nodehealth[i].nodeishealthy;
+ node->nodeishealthy = nodes[i].nodeishealthy;
break;
}
}
@@ -418,7 +413,7 @@ PgxcNodeListAndCount(void)
*shmemNumCoords, *shmemNumDataNodes);
if (numNodes)
- pfree(nodehealth);
+ pfree(nodes);
/* Finally sort the lists */
if (*shmemNumCoords > 1)
diff --git a/src/include/pgxc/nodemgr.h b/src/include/pgxc/nodemgr.h
index 976384a4e8..0c1dca7abe 100644
--- a/src/include/pgxc/nodemgr.h
+++ b/src/include/pgxc/nodemgr.h
@@ -41,12 +41,6 @@ typedef struct
bool nodeishealthy;
} NodeDefinition;
-typedef struct
-{
- Oid nodeoid;
- bool nodeishealthy;
-} NodeHealthStatus;
-
extern void NodeTablesShmemInit(void);
extern Size NodeTablesShmemSize(void);