Use dlists instead of SHM_QUEUE for predicate locking

Part of a series to remove SHM_QUEUE. ilist.h style lists are more widely used
and have an easier to use interface.

Reviewed-by: Thomas Munro <thomas.munro@gmail.com> (in an older version)
Discussion: https://postgr.es/m/20221120055930.t6kl3tyivzhlrzu2@awork3.anarazel.de
Discussion: https://postgr.es/m/20200211042229.msv23badgqljrdg2@alap3.anarazel.de
This commit is contained in:
Andres Freund 2023-01-19 18:50:01 -08:00
parent 7670add9f4
commit 9600371764
2 changed files with 250 additions and 501 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@
#ifndef PREDICATE_INTERNALS_H
#define PREDICATE_INTERNALS_H
#include "lib/ilist.h"
#include "storage/lock.h"
#include "storage/lwlock.h"
@ -84,13 +85,14 @@ typedef struct SERIALIZABLEXACT
SerCommitSeqNo lastCommitBeforeSnapshot; /* when not committed or
* no conflict out */
} SeqNo;
SHM_QUEUE outConflicts; /* list of write transactions whose data we
dlist_head outConflicts; /* list of write transactions whose data we
* couldn't read. */
SHM_QUEUE inConflicts; /* list of read transactions which couldn't
dlist_head inConflicts; /* list of read transactions which couldn't
* see our write. */
SHM_QUEUE predicateLocks; /* list of associated PREDICATELOCK objects */
SHM_QUEUE finishedLink; /* list link in
dlist_head predicateLocks; /* list of associated PREDICATELOCK objects */
dlist_node finishedLink; /* list link in
* FinishedSerializableTransactions */
dlist_node xactLink; /* PredXact->activeList/availableList */
/*
* perXactPredicateListLock is only used in parallel queries: it protects
@ -103,7 +105,7 @@ typedef struct SERIALIZABLEXACT
* for r/o transactions: list of concurrent r/w transactions that we could
* potentially have conflicts with, and vice versa for r/w transactions
*/
SHM_QUEUE possibleUnsafeConflicts;
dlist_head possibleUnsafeConflicts;
TransactionId topXid; /* top level xid for the transaction, if one
* exists; else invalid */
@ -139,28 +141,10 @@ typedef struct SERIALIZABLEXACT
*/
#define SXACT_FLAG_PARTIALLY_RELEASED 0x00000800
/*
* The following types are used to provide an ad hoc list for holding
* SERIALIZABLEXACT objects. An HTAB is overkill, since there is no need to
* access these by key -- there are direct pointers to these objects where
* needed. If a shared memory list is created, these types can probably be
* eliminated in favor of using the general solution.
*/
typedef struct PredXactListElementData
{
SHM_QUEUE link;
SERIALIZABLEXACT sxact;
} PredXactListElementData;
typedef struct PredXactListElementData *PredXactListElement;
#define PredXactListElementDataSize \
((Size)MAXALIGN(sizeof(PredXactListElementData)))
typedef struct PredXactListData
{
SHM_QUEUE availableList;
SHM_QUEUE activeList;
dlist_head availableList;
dlist_head activeList;
/*
* These global variables are maintained when registering and cleaning up
@ -187,7 +171,7 @@ typedef struct PredXactListData
* seq no */
SERIALIZABLEXACT *OldCommittedSxact; /* shared copy of dummy sxact */
PredXactListElement element;
SERIALIZABLEXACT *element;
} PredXactListData;
typedef struct PredXactListData *PredXactList;
@ -208,8 +192,8 @@ typedef struct PredXactListData *PredXactList;
*/
typedef struct RWConflictData
{
SHM_QUEUE outLink; /* link for list of conflicts out from a sxact */
SHM_QUEUE inLink; /* link for list of conflicts in to a sxact */
dlist_node outLink; /* link for list of conflicts out from a sxact */
dlist_node inLink; /* link for list of conflicts in to a sxact */
SERIALIZABLEXACT *sxactOut;
SERIALIZABLEXACT *sxactIn;
} RWConflictData;
@ -221,7 +205,7 @@ typedef struct RWConflictData *RWConflict;
typedef struct RWConflictPoolHeaderData
{
SHM_QUEUE availableList;
dlist_head availableList;
RWConflict element;
} RWConflictPoolHeaderData;
@ -303,7 +287,7 @@ typedef struct PREDICATELOCKTARGET
PREDICATELOCKTARGETTAG tag; /* unique identifier of lockable object */
/* data */
SHM_QUEUE predicateLocks; /* list of PREDICATELOCK objects assoc. with
dlist_head predicateLocks; /* list of PREDICATELOCK objects assoc. with
* predicate lock target */
} PREDICATELOCKTARGET;
@ -336,9 +320,9 @@ typedef struct PREDICATELOCK
PREDICATELOCKTAG tag; /* unique identifier of lock */
/* data */
SHM_QUEUE targetLink; /* list link in PREDICATELOCKTARGET's list of
dlist_node targetLink; /* list link in PREDICATELOCKTARGET's list of
* predicate locks */
SHM_QUEUE xactLink; /* list link in SERIALIZABLEXACT's list of
dlist_node xactLink; /* list link in SERIALIZABLEXACT's list of
* predicate locks */
SerCommitSeqNo commitSeqNo; /* only used for summarized predicate locks */
} PREDICATELOCK;