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

Commit799f8bc

Browse files
committed
Shorten timeouts while waiting for logicalrep worker slot attach/detach.
When waiting for a logical replication worker process to start or stop,we have to busy-wait until we see it add or remove itself from theLogicalRepWorker slot in shared memory. Those loops were using aone-second delay between checks, but on any reasonably modern machine, itdoesn't take more than a couple of msec for a worker to spawn or shut down.Reduce the loop delays to 10ms to avoid wasting quite so much time in therelated regression tests.In principle, a better solution would be to fix things so that the waitingprocess can be awakened via its latch at the right time. But that seemsconsiderably more invasive, which is undesirable for a post-beta fix.Worker start/stop performance likely isn't of huge interest anyway forproduction purposes, so we might not ever get around to it.In passing, rearrange the second wait loop in logicalrep_worker_stop()so that the lock is held at the top of the loop, thus saving one lockacquisition/release per call, and making it look more like the other loop.Discussion:https://postgr.es/m/30864.1498861103@sss.pgh.pa.us
1 parentef74e03 commit799f8bc

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ WaitForReplicationWorkerAttach(LogicalRepWorker *worker,
201201

202202
/*
203203
* We need timeout because we generally don't get notified via latch
204-
* about the worker attach.
204+
* about the worker attach. But we don't expect to have to wait long.
205205
*/
206206
rc=WaitLatch(MyLatch,
207207
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
208-
1000L,WAIT_EVENT_BGWORKER_STARTUP);
208+
10L,WAIT_EVENT_BGWORKER_STARTUP);
209209

210210
/* emergency bailout if postmaster has died */
211211
if (rc&WL_POSTMASTER_DEATH)
@@ -408,8 +408,8 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid,
408408
}
409409

410410
/*
411-
* Stop the logical replication workerand wait until it detaches from the
412-
* slot.
411+
* Stop the logical replication workerfor subid/relid, if any, and wait until
412+
*it detaches from theslot.
413413
*/
414414
void
415415
logicalrep_worker_stop(Oidsubid,Oidrelid)
@@ -435,19 +435,19 @@ logicalrep_worker_stop(Oid subid, Oid relid)
435435
generation=worker->generation;
436436

437437
/*
438-
* If we found worker but it does not have proc set it isstarting up,
439-
* wait for it to finish and then kill it.
438+
* If we foundaworker but it does not have proc setthenit isstill
439+
*starting up;wait for it to finish starting and then kill it.
440440
*/
441441
while (worker->in_use&& !worker->proc)
442442
{
443443
intrc;
444444

445445
LWLockRelease(LogicalRepWorkerLock);
446446

447-
/* Waitfor signal. */
447+
/* Waita bit --- we don't expect to have to wait long. */
448448
rc=WaitLatch(MyLatch,
449449
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
450-
1000L,WAIT_EVENT_BGWORKER_STARTUP);
450+
10L,WAIT_EVENT_BGWORKER_STARTUP);
451451

452452
/* emergency bailout if postmaster has died */
453453
if (rc&WL_POSTMASTER_DEATH)
@@ -459,7 +459,7 @@ logicalrep_worker_stop(Oid subid, Oid relid)
459459
CHECK_FOR_INTERRUPTS();
460460
}
461461

462-
/*Check worker status. */
462+
/*Recheck worker status. */
463463
LWLockAcquire(LogicalRepWorkerLock,LW_SHARED);
464464

465465
/*
@@ -480,27 +480,22 @@ logicalrep_worker_stop(Oid subid, Oid relid)
480480

481481
/* Now terminate the worker ... */
482482
kill(worker->proc->pid,SIGTERM);
483-
LWLockRelease(LogicalRepWorkerLock);
484483

485484
/* ... and wait for it to die. */
486485
for (;;)
487486
{
488487
intrc;
489488

490-
LWLockAcquire(LogicalRepWorkerLock,LW_SHARED);
489+
/* is it gone? */
491490
if (!worker->proc||worker->generation!=generation)
492-
{
493-
LWLockRelease(LogicalRepWorkerLock);
494491
break;
495-
}
496-
LWLockRelease(LogicalRepWorkerLock);
497492

498-
CHECK_FOR_INTERRUPTS();
493+
LWLockRelease(LogicalRepWorkerLock);
499494

500-
/* Waitfor more work. */
495+
/* Waita bit --- we don't expect to have to wait long. */
501496
rc=WaitLatch(MyLatch,
502497
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
503-
1000L,WAIT_EVENT_BGWORKER_SHUTDOWN);
498+
10L,WAIT_EVENT_BGWORKER_SHUTDOWN);
504499

505500
/* emergency bailout if postmaster has died */
506501
if (rc&WL_POSTMASTER_DEATH)
@@ -511,7 +506,11 @@ logicalrep_worker_stop(Oid subid, Oid relid)
511506
ResetLatch(MyLatch);
512507
CHECK_FOR_INTERRUPTS();
513508
}
509+
510+
LWLockAcquire(LogicalRepWorkerLock,LW_SHARED);
514511
}
512+
513+
LWLockRelease(LogicalRepWorkerLock);
515514
}
516515

517516
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp