aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/commands/waitlsn.h44
-rw-r--r--src/include/lib/pairingheap.h3
2 files changed, 42 insertions, 5 deletions
diff --git a/src/include/commands/waitlsn.h b/src/include/commands/waitlsn.h
index 10ef63f0c09..0d80248682c 100644
--- a/src/include/commands/waitlsn.h
+++ b/src/include/commands/waitlsn.h
@@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------
*
* waitlsn.h
- * Declarations for LSN waiting routines.
+ * Declarations for LSN replay waiting routines.
*
* Copyright (c) 2024, PostgreSQL Global Development Group
*
@@ -12,23 +12,57 @@
#ifndef WAIT_LSN_H
#define WAIT_LSN_H
+#include "lib/pairingheap.h"
#include "postgres.h"
#include "port/atomics.h"
#include "storage/spin.h"
#include "tcop/dest.h"
-/* Shared memory structures */
+/*
+ * WaitLSNProcInfo – the shared memory structure representing information
+ * about the single process, which may wait for LSN replay. An item of
+ * waitLSN->procInfos array.
+ */
typedef struct WaitLSNProcInfo
{
+ /*
+ * A process number, same as the index of this item in waitLSN->procInfos.
+ * Stored for convenience.
+ */
int procnum;
+
+ /* LSN, which this process is waiting for */
XLogRecPtr waitLSN;
+
+ /* A pairing heap node for participation in waitLSN->waitersHeap */
+ pairingheap_node phNode;
+
+ /* A flag indicating that this item is added to waitLSN->waitersHeap */
+ bool inHeap;
} WaitLSNProcInfo;
+/*
+ * WaitLSNState - the shared memory state for the replay LSN waiting facility.
+ */
typedef struct WaitLSNState
{
- pg_atomic_uint64 minLSN;
- slock_t mutex;
- int numWaitedProcs;
+ /*
+ * The minimum LSN value some process is waiting for. Used for the
+ * fast-path checking if we need to wake up any waiters after replaying a
+ * WAL record.
+ */
+ pg_atomic_uint64 minWaitedLSN;
+
+ /*
+ * A pairing heap of waiting processes order by LSN values (least LSN is
+ * on top).
+ */
+ pairingheap waitersHeap;
+
+ /* A mutex protecting the pairing heap above */
+ slock_t waitersHeapMutex;
+
+ /* An array with per-process information, indexed by the process number */
WaitLSNProcInfo procInfos[FLEXIBLE_ARRAY_MEMBER];
} WaitLSNState;
diff --git a/src/include/lib/pairingheap.h b/src/include/lib/pairingheap.h
index 7eade81535a..9e1c26033a1 100644
--- a/src/include/lib/pairingheap.h
+++ b/src/include/lib/pairingheap.h
@@ -77,6 +77,9 @@ typedef struct pairingheap
extern pairingheap *pairingheap_allocate(pairingheap_comparator compare,
void *arg);
+extern void pairingheap_initialize(pairingheap *heap,
+ pairingheap_comparator compare,
+ void *arg);
extern void pairingheap_free(pairingheap *heap);
extern void pairingheap_add(pairingheap *heap, pairingheap_node *node);
extern pairingheap_node *pairingheap_first(pairingheap *heap);