Skip to content

Commit 8d260b2

Browse files
MasaoFujiiCommitfest Bot
authored andcommitted
Optimize slot reuse after garbage collection in logicalrep_worker_launch().
Previously, when logicalrep_worker_launch() ran garbage collection and cleaned up at least one worker slot, it would rescan all worker slots to find a free one. However, since it is guaranteed that at least one slot was freed in this case, this additional scan was unnecessary. This commit removes the redundant scan and makes logicalrep_worker_launch() immediately reuse the freed slot.
1 parent aedba6c commit 8d260b2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/backend/replication/logical/launcher.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ logicalrep_worker_launch(LogicalRepWorkerType wtype,
365365
*/
366366
LWLockAcquire(LogicalRepWorkerLock, LW_EXCLUSIVE);
367367

368-
retry:
369368
/* Find unused worker slot. */
370369
for (i = 0; i < max_logical_replication_workers; i++)
371370
{
@@ -415,11 +414,21 @@ logicalrep_worker_launch(LogicalRepWorkerType wtype,
415414

416415
logicalrep_worker_cleanup(w);
417416
did_cleanup = true;
417+
418+
if (worker == NULL)
419+
{
420+
worker = w;
421+
slot = i;
422+
}
418423
}
419424
}
420425

426+
/*
427+
* Count the current number of sync and parallel apply workers again,
428+
* since garbage collection may have changed it.
429+
*/
421430
if (did_cleanup)
422-
goto retry;
431+
logicalrep_worker_count(subid, &nsyncworkers, &nparallelapplyworkers);
423432
}
424433

425434
/*

0 commit comments

Comments
 (0)