aboutsummaryrefslogtreecommitdiff
path: root/src/include/commands/waitlsn.h
blob: f719feadb050a4b25a9c74f3c4e5289fe560463f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*-------------------------------------------------------------------------
 *
 * waitlsn.h
 *	  Declarations for LSN replay waiting routines.
 *
 * Copyright (c) 2024, PostgreSQL Global Development Group
 *
 * src/include/commands/waitlsn.h
 *
 *-------------------------------------------------------------------------
 */
#ifndef WAIT_LSN_H
#define WAIT_LSN_H

#include "lib/pairingheap.h"
#include "postgres.h"
#include "port/atomics.h"
#include "storage/latch.h"
#include "storage/spin.h"
#include "tcop/dest.h"

/*
 * 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
{
	/* LSN, which this process is waiting for */
	XLogRecPtr	waitLSN;

	/*
	 * A pointer to the latch, which should be set once the waitLSN is
	 * replayed.
	 */
	Latch	   *latch;

	/* A pairing heap node for participation in waitLSNState->waitersHeap */
	pairingheap_node phNode;

	/*
	 * A flag indicating that this item is present in
	 * waitLSNState->waitersHeap
	 */
	bool		inHeap;
} WaitLSNProcInfo;

/*
 * WaitLSNState - the shared memory state for the replay LSN waiting facility.
 */
typedef struct WaitLSNState
{
	/*
	 * 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.  Could be read lock-less.  Update protected by WaitLSNLock.
	 */
	pg_atomic_uint64 minWaitedLSN;

	/*
	 * A pairing heap of waiting processes order by LSN values (least LSN is
	 * on top).  Protected by WaitLSNLock.
	 */
	pairingheap waitersHeap;

	/*
	 * An array with per-process information, indexed by the process number.
	 * Protected by WaitLSNLock.
	 */
	WaitLSNProcInfo procInfos[FLEXIBLE_ARRAY_MEMBER];
} WaitLSNState;

extern PGDLLIMPORT WaitLSNState *waitLSNState;

extern Size WaitLSNShmemSize(void);
extern void WaitLSNShmemInit(void);
extern void WaitLSNSetLatches(XLogRecPtr currentLSN);
extern void WaitLSNCleanup(void);

#endif							/* WAIT_LSN_H */