Re: .ready and .done files considered harmful
Dipesh Pandit <dipesh.pandit@gmail.com>
From: Dipesh Pandit <dipesh.pandit@gmail.com>
To: "Bossart, Nathan" <bossartn@amazon.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-17T12:52:42Z
Lists: pgsql-hackers
Attachments
- v7-0001-mitigate-directory-scan-for-WAL-archiver.patch (text/x-patch) patch v7-0001
Thanks for the feedback. > + StatusFilePath(archiveStatusPath, xlog, ".ready"); > + if (stat(archiveStatusPath, &stat_buf) == 0) > + PgArchEnableDirScan(); > We may want to call PgArchWakeup() after setting the flag. Yes, added a call to wake up archiver. > > + * - The next anticipated log segment is not available. > > > > I wonder if we really need to perform a directory scan in this case. > > Unless there are other cases where the .ready files are created out of > > order, I think this just causes an unnecessary directory scan every > > time the archiver catches up. > Thinking further, I suppose this is necessary for when lastSegNo gets > reset after processing an out-of-order .ready file. Also, this is necessary when lastTLI gets reset after switching to a new timeline. > + pg_atomic_flag dirScan; > 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. Please find the attached patch v7. Thanks, Dipesh
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