MCPcopy Create free account
hub / github.com/apache/cloudberry / SyncRepQueueInsert

Function SyncRepQueueInsert

src/backend/replication/syncrep.c:508–536  ·  view source on GitHub ↗

* Insert MyProc into the specified SyncRepQueue, maintaining sorted invariant. * * Usually we will go at tail of queue, though it's possible that we arrive * here out of order, so start at tail and work back to insertion point. */

Source from the content-addressed store, hash-verified

506 * here out of order, so start at tail and work back to insertion point.
507 */
508static void
509SyncRepQueueInsert(int mode)
510{
511 PGPROC *proc;
512
513 Assert(mode >= 0 && mode < NUM_SYNC_REP_WAIT_MODE);
514 proc = (PGPROC *) SHMQueuePrev(&(WalSndCtl->SyncRepQueue[mode]),
515 &(WalSndCtl->SyncRepQueue[mode]),
516 offsetof(PGPROC, syncRepLinks));
517
518 while (proc)
519 {
520 /*
521 * Stop at the queue element that we should after to ensure the queue
522 * is ordered by LSN.
523 */
524 if (proc->waitLSN < MyProc->waitLSN)
525 break;
526
527 proc = (PGPROC *) SHMQueuePrev(&(WalSndCtl->SyncRepQueue[mode]),
528 &(proc->syncRepLinks),
529 offsetof(PGPROC, syncRepLinks));
530 }
531
532 if (proc)
533 SHMQueueInsertAfter(&(proc->syncRepLinks), &(MyProc->syncRepLinks));
534 else
535 SHMQueueInsertAfter(&(WalSndCtl->SyncRepQueue[mode]), &(MyProc->syncRepLinks));
536}
537
538/*
539 * Acquire SyncRepLock and cancel any wait currently in progress.

Callers 1

SyncRepWaitForLSNFunction · 0.85

Calls 2

SHMQueuePrevFunction · 0.85
SHMQueueInsertAfterFunction · 0.85

Tested by

no test coverage detected