Skip to content

Commit dca8b01

Browse files
author
Amit Kapila
committed
Avoid creating parallel apply state hash table unless required.
This hash table is used to cache the state of streaming transactions being applied by the parallel apply workers. So, this should be created only when we are successful in launching at least one worker. This avoids rare case memory leak when we are never able to launch any worker. Author: Ted Yu Discussion: https://postgr.es/m/CALte62wg0rBR3Vj2beV=HiWo2qG9L0hzKcX=yULNER0wmf4aEw@mail.gmail.com
1 parent e753ae6 commit dca8b01

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/backend/replication/logical/applyparallelworker.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ pa_allocate_worker(TransactionId xid)
475475
if (!pa_can_start())
476476
return;
477477

478+
winfo = pa_launch_parallel_worker();
479+
if (!winfo)
480+
return;
481+
478482
/* First time through, initialize parallel apply worker state hashtable. */
479483
if (!ParallelApplyTxnHash)
480484
{
@@ -490,10 +494,6 @@ pa_allocate_worker(TransactionId xid)
490494
HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
491495
}
492496

493-
winfo = pa_launch_parallel_worker();
494-
if (!winfo)
495-
return;
496-
497497
/* Create an entry for the requested transaction. */
498498
entry = hash_search(ParallelApplyTxnHash, &xid, HASH_ENTER, &found);
499499
if (found)

0 commit comments

Comments
 (0)