Re: Atomic ops for unlogged LSN - Mailing list pgsql-hackers

From John Morris
Subject Re: Atomic ops for unlogged LSN
Date
Msg-id BYAPR13MB267749E1F4399B76C0939FFBA03EA@BYAPR13MB2677.namprd13.prod.outlook.com
Whole thread Raw
In response to Re: Atomic ops for unlogged LSN  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
Responses Re: Atomic ops for unlogged LSN
List pgsql-hackers


> what happens if …  reader here stores the old unloggedLSN value
> to control file and the server restarts (clean exit). So, the old
>value is loaded back to unloggedLSN upon restart and the callers of
> GetFakeLSNForUnloggedRel() will see an old/repeated value too. Is it a
> problem?

 

First, a clarification. The value being saved is the “next” unlogged LSN,
not one which has already been used.
(we are doing “fetch and add”,  not “add and fetch”)

 

You have a good point about shutdown and startup.  It is vital we
don’t repeat an unlogged LSN. This situation could easily happen
If other readers were active while we were shutting down.

 

>With an atomic variable, it is guaranteed that the readers
>don't see a torn-value, but no synchronization is provided.

The atomic increment also ensures the sequence
of values is correct, specifically we don’t see
repeated values like we might with a conventional increment.
As a side effect, the instruction enforces a memory barrier, but we are not
relying on a barrier in this case.

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: remaining sql/json patches
Next
From: Ashutosh Bapat
Date:
Subject: Re: logicalrep_message_type throws an error