Adds a method to determine if current node is primary

pull/7720/head
German Eichberger 2024-11-01 21:40:33 +00:00
parent f6959715dc
commit 2f87e83f4c
2 changed files with 28 additions and 0 deletions

View File

@ -167,6 +167,7 @@ PG_FUNCTION_INFO_V1(citus_nodeport_for_nodeid);
PG_FUNCTION_INFO_V1(citus_coordinator_nodeid); PG_FUNCTION_INFO_V1(citus_coordinator_nodeid);
PG_FUNCTION_INFO_V1(citus_is_coordinator); PG_FUNCTION_INFO_V1(citus_is_coordinator);
PG_FUNCTION_INFO_V1(citus_internal_mark_node_not_synced); PG_FUNCTION_INFO_V1(citus_internal_mark_node_not_synced);
PG_FUNCTION_INFO_V1(citus_is_primary_node);
/* /*
* DefaultNodeMetadata creates a NodeMetadata struct with the fields set to * DefaultNodeMetadata creates a NodeMetadata struct with the fields set to
@ -1664,6 +1665,26 @@ citus_is_coordinator(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(isCoordinator); PG_RETURN_BOOL(isCoordinator);
} }
/*
* citus_is_primary_node returns whether the current node is a primary for
* a given group_id. We consider the node a primary if it has
* pg_dist_node entries marked as primary
*/
Datum
citus_is_primary_node(PG_FUNCTION_ARGS)
{
CheckCitusVersion(ERROR);
bool isPrimary = false;
int32 groupId = GetLocalGroupId();
WorkerNode *workerNode = PrimaryNodeForGroup(groupId, NULL);
if (workerNode != NULL && workerNode->nodeId == GetLocalNodeId())
{
isPrimary = true;
}
PG_RETURN_BOOL(isPrimary);
}
/* /*
* EnsureParentSessionHasExclusiveLockOnPgDistNode ensures given session id * EnsureParentSessionHasExclusiveLockOnPgDistNode ensures given session id

View File

@ -0,0 +1,7 @@
CREATE FUNCTION pg_catalog.citus_is_primary_node()
RETURNS bool
LANGUAGE c
STRICT
AS 'MODULE_PATHNAME', $$citus_is_primary_node$$;
COMMENT ON FUNCTION pg_catalog.citus_is_primary_node()
IS 'returns whether the current node is the primary node in the group';