Re: .ready and .done files considered harmful
Nathan Bossart <bossartn@amazon.com>
From: "Bossart, Nathan" <bossartn@amazon.com>
To: Dipesh Pandit <dipesh.pandit@gmail.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>, Robert Haas <robertmhaas@gmail.com>, Jeevan Ladhe <jeevan.ladhe@enterprisedb.com>, Stephen Frost <sfrost@snowman.net>, Andres Freund <andres@anarazel.de>, Hannu
Krosing <hannuk@google.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2021-08-17T16:33:54Z
Lists: pgsql-hackers
On 8/17/21, 5:53 AM, "Dipesh Pandit" <dipesh.pandit@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
Commits
-
Reduce overhead of renaming archive status files.
- 756e221db610 16.0 cited
-
Improve performance of pgarch_readyXlog() with many status files.
- beb4e9ba1652 15.0 landed
-
Prioritize history files when archiving
- b981df4cc09a 12.0 cited