• Tom Lane's avatar
    Reduce delay for last logicalrep feedback message when master goes idle. · f32678c0
    Tom Lane authored
    The regression tests contain numerous cases where we do some activity on a
    master server and then wait till the slave has ack'd flushing its copy of
    that transaction.  Because WAL flush on the slave is asynchronous to the
    logicalrep worker process, the worker cannot send such a feedback message
    during the LogicalRepApplyLoop iteration where it processes the last data
    from the master.  In the previous coding, the feedback message would come
    out only when the loop's WaitLatchOrSocket call returned WL_TIMEOUT.  That
    requires one full second of delay (NAPTIME_PER_CYCLE); and to add insult
    to injury, it could take more than that if the WaitLatchOrSocket was
    interrupted a few times by latch-setting events.
    
    In reality we can expect the slave's walwriter process to have flushed the
    WAL data after, more or less, WalWriterDelay (typically 200ms).  Hence,
    if there are unacked transactions pending, make the wait delay only that
    long rather than the full NAPTIME_PER_CYCLE.  Also, move one of the
    send_feedback() calls into the loop main line, so that we'll check for the
    need to send feedback even if we were woken by a latch event and not either
    socket data or timeout.
    
    It's not clear how much this matters for production purposes, but
    it's definitely helpful for testing.
    
    Discussion: https://postgr.es/m/30864.1498861103@sss.pgh.pa.us
    f32678c0
worker.c 41.7 KB