mirror of
https://github.com/postgres/postgres.git
synced 2025-11-25 12:03:53 +03:00
Previously, backend ID was an index into the ProcState array, in the shared cache invalidation manager (sinvaladt.c). The entry in the ProcState array was reserved at backend startup by scanning the array for a free entry, and that was also when the backend got its backend ID. Things become slightly simpler if we redefine backend ID to be the index into the PGPROC array, and directly use it also as an index to the ProcState array. This uses a little more memory, as we reserve a few extra slots in the ProcState array for aux processes that don't need them, but the simplicity is worth it. Aux processes now also have a backend ID. This simplifies the reservation of BackendStatusArray and ProcSignal slots. You can now convert a backend ID into an index into the PGPROC array simply by subtracting 1. We still use 0-based "pgprocnos" in various places, for indexes into the PGPROC array, but the only difference now is that backend IDs start at 1 while pgprocnos start at 0. (The next commmit will get rid of the term "backend ID" altogether and make everything 0-based.) There is still a 'backendId' field in PGPROC, now part of 'vxid' which encapsulates the backend ID and local transaction ID together. It's needed for prepared xacts. For regular backends, the backendId is always equal to pgprocno + 1, but for prepared xact PGPROC entries, it's the ID of the original backend that processed the transaction. Reviewed-by: Andres Freund, Reid Thompson Discussion: https://www.postgresql.org/message-id/8171f1aa-496f-46a6-afc3-c46fe7a9b407@iki.fi
42 lines
1.4 KiB
C
42 lines
1.4 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* sinvaladt.h
|
|
* POSTGRES shared cache invalidation data manager.
|
|
*
|
|
* The shared cache invalidation manager is responsible for transmitting
|
|
* invalidation messages between backends. Any message sent by any backend
|
|
* must be delivered to all already-running backends before it can be
|
|
* forgotten. (If we run out of space, we instead deliver a "RESET"
|
|
* message to backends that have fallen too far behind.)
|
|
*
|
|
* The struct type SharedInvalidationMessage, defining the contents of
|
|
* a single message, is defined in sinval.h.
|
|
*
|
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/storage/sinvaladt.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef SINVALADT_H
|
|
#define SINVALADT_H
|
|
|
|
#include "storage/lock.h"
|
|
#include "storage/sinval.h"
|
|
|
|
/*
|
|
* prototypes for functions in sinvaladt.c
|
|
*/
|
|
extern Size SInvalShmemSize(void);
|
|
extern void CreateSharedInvalidationState(void);
|
|
extern void SharedInvalBackendInit(bool sendOnly);
|
|
|
|
extern void SIInsertDataEntries(const SharedInvalidationMessage *data, int n);
|
|
extern int SIGetDataEntries(SharedInvalidationMessage *data, int datasize);
|
|
extern void SICleanupQueue(bool callerHasWriteLock, int minFree);
|
|
|
|
extern LocalTransactionId GetNextLocalTransactionId(void);
|
|
|
|
#endif /* SINVALADT_H */
|