Emit a WARNING if the first backend doesn't complete initialisation XL_10_STABLE
authorPavan Deolasee <[email protected]>
Thu, 8 Aug 2019 06:50:56 +0000 (12:20 +0530)
committerPavan Deolasee <[email protected]>
Thu, 8 Aug 2019 06:53:49 +0000 (12:23 +0530)
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

index 6cb6db29d935453e65def6d90e54d7cc9c9478cb..ba510fa949edd3c12733b1f5405fedefda18a163 100644 (file)
@@ -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