From 31dfe47342eabe8ad72c000a103e54a94b49c912 Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Thu, 8 Aug 2019 12:20:56 +0530 Subject: Emit a WARNING if the first backend doesn't complete initialisation We have received a report from the field that a backend apparently stuck on ProcArrayLock in SetGlobalSession(). This is an attempt to check if the stuck backend is actually looping infinitely, waiting for the leader process in the distributed session to initialise. --- src/backend/utils/init/miscinit.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 6cb6db29d9..ba510fa949 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -654,6 +654,7 @@ SetGlobalSession(Oid coordid, int coordpid) BackendId firstBackend = InvalidBackendId; int bCount = 0; int bPids[MaxBackends]; + unsigned int retry_count = 0; /* If nothing changed do nothing */ if (MyCoordId == coordid && MyCoordPid == coordpid) @@ -697,7 +698,14 @@ retry: */ if (bCount > 0) { - /* XXX sleep ? */ + /* + * Sleep for a short while and try again. Emit a WARNING if we + * retry often. + */ + pg_usleep(1000*1000L); + if (++retry_count % 100 == 0) + elog(WARNING, "Retrying %uth time for the first " + "backend to initialise", retry_count); goto retry; } else -- cgit v1.2.3