Coding in WalSndWaitForWal - Mailing list pgsql-hackers

From Jeff Janes
Subject Coding in WalSndWaitForWal
Date
Msg-id CAMkU=1wqiAPcJXemN255qEDALbicWHMA2REwsTEacyAiJS+HXg@mail.gmail.com
Whole thread Raw
Responses Re: Coding in WalSndWaitForWal
List pgsql-hackers
in src/backend/replication/walsender.c, there is the section quoted below.  It looks like nothing interesting happens between the GetFlushRecPtr just before the loop starts, and the one inside the loop the first time through the loop.  If we want to avoid doing  CHECK_FOR_INTERRUPTS(); etc. needlessly, then we should check the result of  GetFlushRecPtr and return early if it is sufficiently advanced--before entering the loop.  If we don't care, then what is the point of updating it twice with no meaningful action in between?  We could just get rid of the section just before the loop starts.  The current coding seems confusing, and increases traffic on a potentially busy spin lock.



    /* Get a more recent flush pointer. */
    if (!RecoveryInProgress())
        RecentFlushPtr = GetFlushRecPtr();
    else
        RecentFlushPtr = GetXLogReplayRecPtr(NULL);

    for (;;)
    {
        long        sleeptime;

        /* Clear any already-pending wakeups */
        ResetLatch(MyLatch);

        CHECK_FOR_INTERRUPTS();

        /* Process any requests or signals received recently */
        if (ConfigReloadPending)
        {
            ConfigReloadPending = false;
            ProcessConfigFile(PGC_SIGHUP);
            SyncRepInitConfig();
        }

        /* Check for input from the client */
        ProcessRepliesIfAny();

        /*
         * If we're shutting down, trigger pending WAL to be written out,
         * otherwise we'd possibly end up waiting for WAL that never gets
         * written, because walwriter has shut down already.
         */
        if (got_STOPPING)
            XLogBackgroundFlush();

        /* Update our idea of the currently flushed position. */
        if (!RecoveryInProgress())
            RecentFlushPtr = GetFlushRecPtr();
        else
            RecentFlushPtr = GetXLogReplayRecPtr(NULL);

Cheers,

Jeff

pgsql-hackers by date:

Previous
From: Mark Dilger
Date:
Subject: Re: Using multiple extended statistics for estimates
Next
From: Amit Kapila
Date:
Subject: Re: CountDBSubscriptions check in dropdb