On 8/17/21, 5:53 AM, "Dipesh Pandit" <dipesh.pan...@gmail.com> wrote: >> I personally don't think it's necessary to use an atomic here. A >> spinlock or LWLock would probably work just fine, as contention seems >> unlikely. If we use a lock, we also don't have to worry about memory >> barriers. > > History file should be archived as soon as it gets created. The atomic flag > here will make sure that there is no reordering of read/write instructions > while > accessing the flag in shared memory. Archiver needs to read this flag at the > beginning of each cycle. Write to atomic flag is synchronized and it provides > a lockless read. I think an atomic flag here is an efficient choice unless I > am > missing something.
Sorry, I think my note was not very clear. I agree that a flag should be used for this purpose, but I think we should just use a regular bool protected by a spinlock or LWLock instead of an atomic. The file atomics.h has the following note: * Use higher level functionality (lwlocks, spinlocks, heavyweight locks) * whenever possible. Writing correct code using these facilities is hard. IOW I don't think the extra complexity is necessary. From a performance standpoint, contention seems unlikely. We only need to read the flag roughly once per WAL segment, and we only ever set it in uncommon scenarios such as a timeline switch or the creation of an out-of-order .ready file. Nathan