Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde63f8d

Browse files
author
Amit Kapila
committed
Fix assertion failure in apply worker.
During exit, the logical replication apply worker tries to release sessionlevel locks, if any. However, if the apply worker exits due to an errorbefore its connection is initialized, trying to release locks can lead toassertion failure. The locks will be acquired once the worker isinitialized, so we don't need to release them till the workerinitialization is complete.Reported-by: Alexander LakhinAuthor: Hou Zhijie based on inputs from Sawada Masahiko and Amit KapilaReviewed-by: Amit KapilaDiscussion:https://postgr.es/m/2185d65f-5aae-3efa-c48f-fb42b173ef5c@gmail.com
1 parent6489875 commitde63f8d

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

‎src/backend/replication/logical/applyparallelworker.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,8 @@ ParallelApplyWorkerMain(Datum main_arg)
873873
intworker_slot=DatumGetInt32(main_arg);
874874
charoriginname[NAMEDATALEN];
875875

876+
InitializingApplyWorker= true;
877+
876878
/* Setup signal handling. */
877879
pqsignal(SIGHUP,SignalHandlerForConfigReload);
878880
pqsignal(SIGINT,SignalHandlerForShutdownRequest);
@@ -940,6 +942,8 @@ ParallelApplyWorkerMain(Datum main_arg)
940942

941943
InitializeApplyWorker();
942944

945+
InitializingApplyWorker= false;
946+
943947
/* Setup replication origin tracking. */
944948
StartTransactionCommand();
945949
ReplicationOriginNameForLogicalRep(MySubscription->oid,InvalidOid,

‎src/backend/replication/logical/launcher.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,11 @@ logicalrep_worker_onexit(int code, Datum arg)
797797
* Session level locks may be acquired outside of a transaction in
798798
* parallel apply mode and will not be released when the worker
799799
* terminates, so manually release all locks before the worker exits.
800+
*
801+
* The locks will be acquired once the worker is initialized.
800802
*/
801-
LockReleaseAll(DEFAULT_LOCKMETHOD, true);
803+
if (!InitializingApplyWorker)
804+
LockReleaseAll(DEFAULT_LOCKMETHOD, true);
802805

803806
ApplyLauncherWakeup();
804807
}

‎src/backend/replication/logical/worker.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ static TransactionId stream_xid = InvalidTransactionId;
331331
*/
332332
staticuint32parallel_stream_nchanges=0;
333333

334+
/* Are we initializing a apply worker? */
335+
boolInitializingApplyWorker= false;
336+
334337
/*
335338
* We enable skipping all data modification changes (INSERT, UPDATE, etc.) for
336339
* the subscription if the remote transaction's finish LSN matches the subskiplsn.
@@ -4526,6 +4529,8 @@ ApplyWorkerMain(Datum main_arg)
45264529
WalRcvStreamOptionsoptions;
45274530
intserver_version;
45284531

4532+
InitializingApplyWorker= true;
4533+
45294534
/* Attach to slot */
45304535
logicalrep_worker_attach(worker_slot);
45314536

@@ -4548,6 +4553,8 @@ ApplyWorkerMain(Datum main_arg)
45484553

45494554
InitializeApplyWorker();
45504555

4556+
InitializingApplyWorker= false;
4557+
45514558
/* Connect to the origin and start the replication. */
45524559
elog(DEBUG1,"connecting to publisher using connection string \"%s\"",
45534560
MySubscription->conninfo);

‎src/include/replication/worker_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ extern PGDLLIMPORT LogicalRepWorker *MyLogicalRepWorker;
225225

226226
externPGDLLIMPORTboolin_remote_transaction;
227227

228+
externPGDLLIMPORTboolInitializingApplyWorker;
229+
228230
externvoidlogicalrep_worker_attach(intslot);
229231
externLogicalRepWorker*logicalrep_worker_find(Oidsubid,Oidrelid,
230232
boolonly_running);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp