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

Commit3e1683d

Browse files
committed
Fix, or at least ameliorate, bugs in logicalrep_worker_launch().
If we failed to get a background worker slot, the code just walkedaway from the logicalrep-worker slot it already had, leaving thatlooking like the worker is still starting up. This led to an indefinitehang in subscription startup, as reported by Thomas Munro. We mustrelease the slot on failure.Also fix a thinko: we must capture the worker slot's generation beforereleasing LogicalRepWorkerLock the first time, else testing to see ifit's changed is pretty meaningless.BTW, the CHECK_FOR_INTERRUPTS() in WaitForReplicationWorkerAttach is aticking time bomb, even without considering the possibility of elog(ERROR)in one of the other functions it calls. Really, this entire business needsa redesign with some actual thought about error recovery. But for nowI'm just band-aiding the case observed in testing.Back-patch to v10 where this code was added.Discussion:https://postgr.es/m/CAEepm=2bP3TBMFBArP6o20AZaRduWjMnjCjt22hSdnA-EvrtCw@mail.gmail.com
1 parent4b17c89 commit3e1683d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,11 @@ get_subscription_list(void)
168168
*/
169169
staticvoid
170170
WaitForReplicationWorkerAttach(LogicalRepWorker*worker,
171+
uint16generation,
171172
BackgroundWorkerHandle*handle)
172173
{
173174
BgwHandleStatusstatus;
174175
intrc;
175-
uint16generation;
176-
177-
/* Remember generation for future identification. */
178-
generation=worker->generation;
179176

180177
for (;;)
181178
{
@@ -282,14 +279,15 @@ logicalrep_workers_find(Oid subid, bool only_running)
282279
}
283280

284281
/*
285-
* Start new apply background worker.
282+
* Start new apply background worker, if possible.
286283
*/
287284
void
288285
logicalrep_worker_launch(Oiddbid,Oidsubid,constchar*subname,Oiduserid,
289286
Oidrelid)
290287
{
291288
BackgroundWorkerbgw;
292289
BackgroundWorkerHandle*bgw_handle;
290+
uint16generation;
293291
inti;
294292
intslot=0;
295293
LogicalRepWorker*worker=NULL;
@@ -406,6 +404,9 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid,
406404
worker->reply_lsn=InvalidXLogRecPtr;
407405
TIMESTAMP_NOBEGIN(worker->reply_time);
408406

407+
/* Before releasing lock, remember generation for future identification. */
408+
generation=worker->generation;
409+
409410
LWLockRelease(LogicalRepWorkerLock);
410411

411412
/* Register the new dynamic worker. */
@@ -428,6 +429,12 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid,
428429

429430
if (!RegisterDynamicBackgroundWorker(&bgw,&bgw_handle))
430431
{
432+
/* Failed to start worker, so clean up the worker slot. */
433+
LWLockAcquire(LogicalRepWorkerLock,LW_EXCLUSIVE);
434+
Assert(generation==worker->generation);
435+
logicalrep_worker_cleanup(worker);
436+
LWLockRelease(LogicalRepWorkerLock);
437+
431438
ereport(WARNING,
432439
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
433440
errmsg("out of background worker slots"),
@@ -436,7 +443,7 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid,
436443
}
437444

438445
/* Now wait until it attaches. */
439-
WaitForReplicationWorkerAttach(worker,bgw_handle);
446+
WaitForReplicationWorkerAttach(worker,generation,bgw_handle);
440447
}
441448

442449
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp