aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/async.c
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2023-11-29 01:39:55 +0200
committerAlexander Korotkov <akorotkov@postgresql.org>2023-11-29 01:40:56 +0200
commit4ed8f0913bfdb5f3551de3c27fc2c2e880abc5a2 (patch)
treebaa2a0501fa0e31380f68af5ddce0d15f76186a5 /src/backend/commands/async.c
parenta916b47e23290ca24ffd083e5128d994f62966f6 (diff)
downloadpostgresql-4ed8f0913bfdb5f3551de3c27fc2c2e880abc5a2.tar.gz
postgresql-4ed8f0913bfdb5f3551de3c27fc2c2e880abc5a2.zip
Index SLRUs by 64-bit integers rather than by 32-bit integers
We've had repeated bugs in the area of handling SLRU wraparound in the past, some of which have caused data loss. Switching to an indexing system for SLRUs that does not wrap around should allow us to get rid of a whole bunch of problems and improve the overall reliability of the system. This particular patch however only changes the indexing and doesn't address the wraparound per se. This is going to be done in the following patches. Author: Maxim Orlov, Aleksander Alekseev, Alexander Korotkov, Teodor Sigaev Author: Nikita Glukhov, Pavel Borisov, Yura Sokolov Reviewed-by: Jacob Champion, Heikki Linnakangas, Alexander Korotkov Reviewed-by: Japin Li, Pavel Borisov, Tom Lane, Peter Eisentraut, Andres Freund Reviewed-by: Andrey Borodin, Dilip Kumar, Aleksander Alekseev Discussion: https://postgr.es/m/CACG%3DezZe1NQSCnfHOr78AtAZxJZeCvxrts0ygrxYwe%3DpyyjVWA%40mail.gmail.com Discussion: https://postgr.es/m/CAJ7c6TPDOYBYrnCAeyndkBktO0WG2xSdYduTF0nxq%2BvfkmTF5Q%40mail.gmail.com
Diffstat (limited to 'src/backend/commands/async.c')
-rw-r--r--src/backend/commands/async.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index 38ddae08b86..346bc28a36f 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -196,7 +196,7 @@ typedef struct AsyncQueueEntry
*/
typedef struct QueuePosition
{
- int page; /* SLRU page number */
+ int64 page; /* SLRU page number */
int offset; /* byte offset within page */
} QueuePosition;
@@ -443,8 +443,8 @@ static bool tryAdvanceTail = false;
bool Trace_notify = false;
/* local function prototypes */
-static int asyncQueuePageDiff(int p, int q);
-static bool asyncQueuePagePrecedes(int p, int q);
+static int64 asyncQueuePageDiff(int64 p, int64 q);
+static bool asyncQueuePagePrecedes(int64 p, int64 q);
static void queue_listen(ListenActionKind action, const char *channel);
static void Async_UnlistenOnExit(int code, Datum arg);
static void Exec_ListenPreCommit(void);
@@ -477,10 +477,10 @@ static void ClearPendingActionsAndNotifies(void);
* Compute the difference between two queue page numbers (i.e., p - q),
* accounting for wraparound.
*/
-static int
-asyncQueuePageDiff(int p, int q)
+static int64
+asyncQueuePageDiff(int64 p, int64 q)
{
- int diff;
+ int64 diff;
/*
* We have to compare modulo (QUEUE_MAX_PAGE+1)/2. Both inputs should be
@@ -504,7 +504,7 @@ asyncQueuePageDiff(int p, int q)
* extant page, we need not assess entries within a page.
*/
static bool
-asyncQueuePagePrecedes(int p, int q)
+asyncQueuePagePrecedes(int64 p, int64 q)
{
return asyncQueuePageDiff(p, q) < 0;
}
@@ -571,7 +571,7 @@ AsyncShmemInit(void)
NotifyCtl->PagePrecedes = asyncQueuePagePrecedes;
SimpleLruInit(NotifyCtl, "Notify", NUM_NOTIFY_BUFFERS, 0,
NotifySLRULock, "pg_notify", LWTRANCHE_NOTIFY_BUFFER,
- SYNC_HANDLER_NONE);
+ SYNC_HANDLER_NONE, false);
if (!found)
{
@@ -1336,7 +1336,7 @@ asyncQueueIsFull(void)
static bool
asyncQueueAdvance(volatile QueuePosition *position, int entryLength)
{
- int pageno = QUEUE_POS_PAGE(*position);
+ int64 pageno = QUEUE_POS_PAGE(*position);
int offset = QUEUE_POS_OFFSET(*position);
bool pageJump = false;
@@ -1409,7 +1409,7 @@ asyncQueueAddEntries(ListCell *nextNotify)
{
AsyncQueueEntry qe;
QueuePosition queue_head;
- int pageno;
+ int64 pageno;
int offset;
int slotno;