Patches #5758 with some more error checks (#5804)

Add error checks to detect failed connection and don't ping secondary nodes to detect self reference.
pull/5809/head
Gledis Zeneli 2022-03-15 15:02:47 +03:00 committed by GitHub
parent 5fd0ec7dab
commit 56ab64b747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -283,6 +283,7 @@ citus_add_node(PG_FUNCTION_ARGS)
*/
if (workerNode != NULL &&
workerNode->groupId != COORDINATOR_GROUP_ID &&
workerNode->nodeRole != SecondaryNodeRoleId() &&
IsWorkerTheCurrentNode(workerNode))
{
ereport(ERROR, (errmsg("Node cannot add itself as a worker."),

View File

@ -658,10 +658,17 @@ IsWorkerTheCurrentNode(WorkerNode *workerNode)
workerNode->workerPort,
CurrentUserName(),
NULL);
const char *command =
"SELECT metadata ->> 'server_id' AS server_id FROM pg_dist_node_metadata";
SendRemoteCommand(workerConnection, command);
int resultCode = SendRemoteCommand(workerConnection, command);
if (resultCode == 0)
{
CloseConnection(workerConnection);
return false;
}
PGresult *result = GetRemoteCommandResult(workerConnection, true);