Re: LogwrtResult contended spinlock - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: LogwrtResult contended spinlock
Date
Msg-id 20200903183452.GA10634@alvherre.pgsql
Whole thread Raw
In response to Re: LogwrtResult contended spinlock  (Andres Freund <andres@anarazel.de>)
Responses Re: LogwrtResult contended spinlock
List pgsql-hackers
Looking at patterns like this

    if (XLogCtl->LogwrtRqst.Write < EndPos)
        XLogCtl->LogwrtRqst.Write = EndPos;

It seems possible to implement with

    do {
        XLogRecPtr    currwrite;

        currwrite = pg_atomic_read_u64(LogwrtRqst.Write);
    if (currwrite > EndPos)
            break;  // already done by somebody else
        if (pg_atomic_compare_exchange_u64(LogwrtRqst.Write,
                                       currwrite, EndPos))
            break;  // successfully updated
    } while (true);

This assumes that LogwrtRqst.Write never goes backwards, so it doesn't
seem good material for a general routine.

This *seems* correct to me, though this is muddy territory to me.  Also,
are there better ways to go about this?

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



pgsql-hackers by date:

Previous
From: Surafel Temesgen
Date:
Subject: Re: [PATCH] Allow queries in WHEN expression of FOR EACH STATEMENT triggers
Next
From: Tom Lane
Date:
Subject: Re: Creating foreign key on partitioned table is too slow