repack: clarify final phase of concurrent mode in file header comment

Started by Chao Li8 months ago5 messageshackers

Thread notes

1 note#refactor
hackorum-bot#refactor
hackorum-bot
2 days ago

@global #refactor

#refactor
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

Hi,

The file header comment in repack.c briefly explains the workflow of concurrent mode as:

1. Lock the table with ShareUpdateExclusiveLock
2. Do an initial copy as non-concurrent mode
3. While the initial copy is going on, accumulates concurrent changes to a file
4. After the initial copy, read the file and re-apply the changes
5. Upgrade to AccessExclusiveLock and swap the relfilenodes

When I read the comment, I got confused at step 4. While that re-apply pass is running, concurrent changes can still occur, so what happens to those changes?

After reading the code, I see that there is actually an extra step after upgrading to AccessExclusiveLock to process the remaining changes.

I am afraid other readers may have the same confusion, so I am proposing this small patch to make the file header comment a bit clearer.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

t139348_1
v1-0001-repack-clarify-final-phase-of-concurrent-mode-in-.patchapplication/octet-stream; name=v1-0001-repack-clarify-final-phase-of-concurrent-mode-in-.patch; x-unix-mode=0644Download+4-4
#2Jakub Wartak
jakub.wartak@enterprisedb.com
In reply to: Chao Li (#1)
Re: repack: clarify final phase of concurrent mode in file header comment

On Thu, Apr 16, 2026 at 5:33 AM Chao Li <li.evan.chao@gmail.com> wrote:

Hi,

The file header comment in repack.c briefly explains the workflow of concurrent mode as:

1. Lock the table with ShareUpdateExclusiveLock
2. Do an initial copy as non-concurrent mode
3. While the initial copy is going on, accumulates concurrent changes to a file
4. After the initial copy, read the file and re-apply the changes
5. Upgrade to AccessExclusiveLock and swap the relfilenodes

When I read the comment, I got confused at step 4. While that re-apply pass is running, concurrent changes can still occur, so what happens to those changes?

After reading the code, I see that there is actually an extra step after upgrading to AccessExclusiveLock to process the remaining changes.

I am afraid other readers may have the same confusion, so I am proposing this small patch to make the file header comment a bit clearer.

LGTM, so +1

-J.

#3Chao Li
li.evan.chao@gmail.com
In reply to: Jakub Wartak (#2)
Re: repack: clarify final phase of concurrent mode in file header comment

On Jun 10, 2026, at 16:33, Jakub Wartak <jakub.wartak@enterprisedb.com> wrote:

On Thu, Apr 16, 2026 at 5:33 AM Chao Li <li.evan.chao@gmail.com> wrote:

Hi,

The file header comment in repack.c briefly explains the workflow of concurrent mode as:

1. Lock the table with ShareUpdateExclusiveLock
2. Do an initial copy as non-concurrent mode
3. While the initial copy is going on, accumulates concurrent changes to a file
4. After the initial copy, read the file and re-apply the changes
5. Upgrade to AccessExclusiveLock and swap the relfilenodes

When I read the comment, I got confused at step 4. While that re-apply pass is running, concurrent changes can still occur, so what happens to those changes?

After reading the code, I see that there is actually an extra step after upgrading to AccessExclusiveLock to process the remaining changes.

I am afraid other readers may have the same confusion, so I am proposing this small patch to make the file header comment a bit clearer.

LGTM, so +1

-J.

Thanks for the review.

Rebased to v2.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

t139348_3
v2-0001-repack-clarify-final-phase-of-concurrent-mode-in-.patchapplication/octet-stream; name=v2-0001-repack-clarify-final-phase-of-concurrent-mode-in-.patch; x-unix-mode=0644Download+4-4
#4Alvaro Herrera
alvherre@kurilemu.de
In reply to: Chao Li (#1)
Re: repack: clarify final phase of concurrent mode in file header comment

On 2026-Apr-16, Chao Li wrote:

The file header comment in repack.c briefly explains the workflow of concurrent mode as:

1. Lock the table with ShareUpdateExclusiveLock
2. Do an initial copy as non-concurrent mode
3. While the initial copy is going on, accumulates concurrent changes to a file
4. After the initial copy, read the file and re-apply the changes
5. Upgrade to AccessExclusiveLock and swap the relfilenodes

When I read the comment, I got confused at step 4. While that re-apply
pass is running, concurrent changes can still occur, so what happens
to those changes?

Somebody independently mentioned this a few days ago, so I have pushed
this patch, thanks.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/

#5Chao Li
li.evan.chao@gmail.com
In reply to: Alvaro Herrera (#4)
Re: repack: clarify final phase of concurrent mode in file header comment

On Nov 26, 2026, at 00:41, Álvaro Herrera <alvherre@kurilemu.de> wrote:

On 2026-Apr-16, Chao Li wrote:

The file header comment in repack.c briefly explains the workflow of concurrent mode as:

1. Lock the table with ShareUpdateExclusiveLock
2. Do an initial copy as non-concurrent mode
3. While the initial copy is going on, accumulates concurrent changes to a file
4. After the initial copy, read the file and re-apply the changes
5. Upgrade to AccessExclusiveLock and swap the relfilenodes

When I read the comment, I got confused at step 4. While that re-apply
pass is running, concurrent changes can still occur, so what happens
to those changes?

Somebody independently mentioned this a few days ago, so I have pushed
this patch, thanks.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/

Thanks for pushing and back-patching to 19.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/