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

Commit3c9bc21

Browse files
committed
Make tablesync worker exit when apply dies while it was waiting for it
This avoids "orphaned" sync workers.This was caused by a thinko in wait_for_sync_status_change.Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>Reported-by: Masahiko Sawada <sawada.mshk@gmail.com>
1 parent34aebcf commit3c9bc21

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ finish_sync_worker(void)
146146
/*
147147
* Wait until the table synchronization change.
148148
*
149-
* Returns false if the relation subscription state disappeared.
149+
* If called from apply worker, it will wait for the synchronization worker to
150+
* change table state in shmem. If called from synchronization worker, it
151+
* will wait for apply worker to change table state in shmem.
152+
*
153+
* Returns false if the opposite worker has disappeared or the table state has
154+
* been reset.
150155
*/
151156
staticbool
152157
wait_for_sync_status_change(Oidrelid,charorigstate)
@@ -161,14 +166,27 @@ wait_for_sync_status_change(Oid relid, char origstate)
161166
CHECK_FOR_INTERRUPTS();
162167

163168
LWLockAcquire(LogicalRepWorkerLock,LW_SHARED);
169+
170+
/* Check if the opposite worker is still running and bail if not. */
164171
worker=logicalrep_worker_find(MyLogicalRepWorker->subid,
165-
relid, false);
172+
am_tablesync_worker() ?InvalidOid :relid,
173+
false);
166174
if (!worker)
167175
{
168176
LWLockRelease(LogicalRepWorkerLock);
169177
return false;
170178
}
179+
180+
/*
181+
* If I'm the synchronization worker, look at my own state. Otherwise
182+
* look at the state of the synchronization worker we found above.
183+
*/
184+
if (am_tablesync_worker())
185+
worker=MyLogicalRepWorker;
186+
187+
Assert(worker->relid==relid);
171188
state=worker->relstate;
189+
172190
LWLockRelease(LogicalRepWorkerLock);
173191

174192
if (state==SUBREL_STATE_UNKNOWN)
@@ -179,7 +197,7 @@ wait_for_sync_status_change(Oid relid, char origstate)
179197

180198
rc=WaitLatch(&MyProc->procLatch,
181199
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
182-
10000L,WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE);
200+
1000L,WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE);
183201

184202
/* emergency bailout if postmaster has died */
185203
if (rc&WL_POSTMASTER_DEATH)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp