Clean up representation of flags in struct ReorderBufferTXN
This simplifies addition of further flags. Author: Nikhil Sontakke Discussion: https://postgr.es/m/CAMGcDxeViP+R-OL7QhzUV9eKCVjURobuY1Zijik4Ay_Ddwo4Cg@mail.gmail.com
This commit is contained in:
parent
00b047fa67
commit
a7b6ab5db1
@ -740,7 +740,7 @@ AssertTXNLsnOrder(ReorderBuffer *rb)
|
|||||||
Assert(prev_first_lsn < cur_txn->first_lsn);
|
Assert(prev_first_lsn < cur_txn->first_lsn);
|
||||||
|
|
||||||
/* known-as-subtxn txns must not be listed */
|
/* known-as-subtxn txns must not be listed */
|
||||||
Assert(!cur_txn->is_known_as_subxact);
|
Assert(!rbtxn_is_known_subxact(cur_txn));
|
||||||
|
|
||||||
prev_first_lsn = cur_txn->first_lsn;
|
prev_first_lsn = cur_txn->first_lsn;
|
||||||
}
|
}
|
||||||
@ -760,7 +760,7 @@ AssertTXNLsnOrder(ReorderBuffer *rb)
|
|||||||
Assert(prev_base_snap_lsn < cur_txn->base_snapshot_lsn);
|
Assert(prev_base_snap_lsn < cur_txn->base_snapshot_lsn);
|
||||||
|
|
||||||
/* known-as-subtxn txns must not be listed */
|
/* known-as-subtxn txns must not be listed */
|
||||||
Assert(!cur_txn->is_known_as_subxact);
|
Assert(!rbtxn_is_known_subxact(cur_txn));
|
||||||
|
|
||||||
prev_base_snap_lsn = cur_txn->base_snapshot_lsn;
|
prev_base_snap_lsn = cur_txn->base_snapshot_lsn;
|
||||||
}
|
}
|
||||||
@ -783,7 +783,7 @@ ReorderBufferGetOldestTXN(ReorderBuffer *rb)
|
|||||||
|
|
||||||
txn = dlist_head_element(ReorderBufferTXN, node, &rb->toplevel_by_lsn);
|
txn = dlist_head_element(ReorderBufferTXN, node, &rb->toplevel_by_lsn);
|
||||||
|
|
||||||
Assert(!txn->is_known_as_subxact);
|
Assert(!rbtxn_is_known_subxact(txn));
|
||||||
Assert(txn->first_lsn != InvalidXLogRecPtr);
|
Assert(txn->first_lsn != InvalidXLogRecPtr);
|
||||||
return txn;
|
return txn;
|
||||||
}
|
}
|
||||||
@ -843,7 +843,7 @@ ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid,
|
|||||||
|
|
||||||
if (!new_sub)
|
if (!new_sub)
|
||||||
{
|
{
|
||||||
if (subtxn->is_known_as_subxact)
|
if (rbtxn_is_known_subxact(subtxn))
|
||||||
{
|
{
|
||||||
/* already associated, nothing to do */
|
/* already associated, nothing to do */
|
||||||
return;
|
return;
|
||||||
@ -859,7 +859,7 @@ ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subtxn->is_known_as_subxact = true;
|
subtxn->txn_flags |= RBTXN_IS_SUBXACT;
|
||||||
subtxn->toplevel_xid = xid;
|
subtxn->toplevel_xid = xid;
|
||||||
Assert(subtxn->nsubtxns == 0);
|
Assert(subtxn->nsubtxns == 0);
|
||||||
|
|
||||||
@ -1080,7 +1080,7 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn,
|
|||||||
{
|
{
|
||||||
ReorderBufferChange *cur_change;
|
ReorderBufferChange *cur_change;
|
||||||
|
|
||||||
if (txn->serialized)
|
if (rbtxn_is_serialized(txn))
|
||||||
{
|
{
|
||||||
/* serialize remaining changes */
|
/* serialize remaining changes */
|
||||||
ReorderBufferSerializeTXN(rb, txn);
|
ReorderBufferSerializeTXN(rb, txn);
|
||||||
@ -1109,7 +1109,7 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn,
|
|||||||
{
|
{
|
||||||
ReorderBufferChange *cur_change;
|
ReorderBufferChange *cur_change;
|
||||||
|
|
||||||
if (cur_txn->serialized)
|
if (rbtxn_is_serialized(cur_txn))
|
||||||
{
|
{
|
||||||
/* serialize remaining changes */
|
/* serialize remaining changes */
|
||||||
ReorderBufferSerializeTXN(rb, cur_txn);
|
ReorderBufferSerializeTXN(rb, cur_txn);
|
||||||
@ -1273,7 +1273,7 @@ ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
|
|||||||
* they originally were happening inside another subtxn, so we won't
|
* they originally were happening inside another subtxn, so we won't
|
||||||
* ever recurse more than one level deep here.
|
* ever recurse more than one level deep here.
|
||||||
*/
|
*/
|
||||||
Assert(subtxn->is_known_as_subxact);
|
Assert(rbtxn_is_known_subxact(subtxn));
|
||||||
Assert(subtxn->nsubtxns == 0);
|
Assert(subtxn->nsubtxns == 0);
|
||||||
|
|
||||||
ReorderBufferCleanupTXN(rb, subtxn);
|
ReorderBufferCleanupTXN(rb, subtxn);
|
||||||
@ -1321,7 +1321,7 @@ ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
|
|||||||
/*
|
/*
|
||||||
* Remove TXN from its containing list.
|
* Remove TXN from its containing list.
|
||||||
*
|
*
|
||||||
* Note: if txn->is_known_as_subxact, we are deleting the TXN from its
|
* Note: if txn is known as subxact, we are deleting the TXN from its
|
||||||
* parent's list of known subxacts; this leaves the parent's nsubxacts
|
* parent's list of known subxacts; this leaves the parent's nsubxacts
|
||||||
* count too high, but we don't care. Otherwise, we are deleting the TXN
|
* count too high, but we don't care. Otherwise, we are deleting the TXN
|
||||||
* from the LSN-ordered list of toplevel TXNs.
|
* from the LSN-ordered list of toplevel TXNs.
|
||||||
@ -1336,7 +1336,7 @@ ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
|
|||||||
Assert(found);
|
Assert(found);
|
||||||
|
|
||||||
/* remove entries spilled to disk */
|
/* remove entries spilled to disk */
|
||||||
if (txn->serialized)
|
if (rbtxn_is_serialized(txn))
|
||||||
ReorderBufferRestoreCleanup(rb, txn);
|
ReorderBufferRestoreCleanup(rb, txn);
|
||||||
|
|
||||||
/* deallocate */
|
/* deallocate */
|
||||||
@ -1353,7 +1353,7 @@ ReorderBufferBuildTupleCidHash(ReorderBuffer *rb, ReorderBufferTXN *txn)
|
|||||||
dlist_iter iter;
|
dlist_iter iter;
|
||||||
HASHCTL hash_ctl;
|
HASHCTL hash_ctl;
|
||||||
|
|
||||||
if (!txn->has_catalog_changes || dlist_is_empty(&txn->tuplecids))
|
if (!rbtxn_has_catalog_changes(txn) || dlist_is_empty(&txn->tuplecids))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(&hash_ctl, 0, sizeof(hash_ctl));
|
memset(&hash_ctl, 0, sizeof(hash_ctl));
|
||||||
@ -1981,7 +1981,7 @@ ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
|
|||||||
* final_lsn to that of their last change; this causes
|
* final_lsn to that of their last change; this causes
|
||||||
* ReorderBufferRestoreCleanup to do the right thing.
|
* ReorderBufferRestoreCleanup to do the right thing.
|
||||||
*/
|
*/
|
||||||
if (txn->serialized && txn->final_lsn == 0)
|
if (rbtxn_is_serialized(txn) && txn->final_lsn == 0)
|
||||||
{
|
{
|
||||||
ReorderBufferChange *last =
|
ReorderBufferChange *last =
|
||||||
dlist_tail_element(ReorderBufferChange, node, &txn->changes);
|
dlist_tail_element(ReorderBufferChange, node, &txn->changes);
|
||||||
@ -2129,7 +2129,7 @@ ReorderBufferSetBaseSnapshot(ReorderBuffer *rb, TransactionId xid,
|
|||||||
* operate on its top-level transaction instead.
|
* operate on its top-level transaction instead.
|
||||||
*/
|
*/
|
||||||
txn = ReorderBufferTXNByXid(rb, xid, true, &is_new, lsn, true);
|
txn = ReorderBufferTXNByXid(rb, xid, true, &is_new, lsn, true);
|
||||||
if (txn->is_known_as_subxact)
|
if (rbtxn_is_known_subxact(txn))
|
||||||
txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
|
txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
|
||||||
NULL, InvalidXLogRecPtr, false);
|
NULL, InvalidXLogRecPtr, false);
|
||||||
Assert(txn->base_snapshot == NULL);
|
Assert(txn->base_snapshot == NULL);
|
||||||
@ -2276,7 +2276,7 @@ ReorderBufferXidSetCatalogChanges(ReorderBuffer *rb, TransactionId xid,
|
|||||||
|
|
||||||
txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
|
txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
|
||||||
|
|
||||||
txn->has_catalog_changes = true;
|
txn->txn_flags |= RBTXN_HAS_CATALOG_CHANGES;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2293,7 +2293,7 @@ ReorderBufferXidHasCatalogChanges(ReorderBuffer *rb, TransactionId xid)
|
|||||||
if (txn == NULL)
|
if (txn == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return txn->has_catalog_changes;
|
return rbtxn_has_catalog_changes(txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2313,7 +2313,7 @@ ReorderBufferXidHasBaseSnapshot(ReorderBuffer *rb, TransactionId xid)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* a known subtxn? operate on top-level txn instead */
|
/* a known subtxn? operate on top-level txn instead */
|
||||||
if (txn->is_known_as_subxact)
|
if (rbtxn_is_known_subxact(txn))
|
||||||
txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
|
txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
|
||||||
NULL, InvalidXLogRecPtr, false);
|
NULL, InvalidXLogRecPtr, false);
|
||||||
|
|
||||||
@ -2500,13 +2500,13 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
|
|||||||
rb->spillCount += 1;
|
rb->spillCount += 1;
|
||||||
rb->spillBytes += size;
|
rb->spillBytes += size;
|
||||||
|
|
||||||
/* Don't consider already serialized transaction. */
|
/* Don't consider already serialized transactions. */
|
||||||
rb->spillTxns += txn->serialized ? 0 : 1;
|
rb->spillTxns += rbtxn_is_serialized(txn) ? 0 : 1;
|
||||||
|
|
||||||
Assert(spilled == txn->nentries_mem);
|
Assert(spilled == txn->nentries_mem);
|
||||||
Assert(dlist_is_empty(&txn->changes));
|
Assert(dlist_is_empty(&txn->changes));
|
||||||
txn->nentries_mem = 0;
|
txn->nentries_mem = 0;
|
||||||
txn->serialized = true;
|
txn->txn_flags |= RBTXN_IS_SERIALIZED;
|
||||||
|
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
@ -158,18 +158,38 @@ typedef struct ReorderBufferChange
|
|||||||
dlist_node node;
|
dlist_node node;
|
||||||
} ReorderBufferChange;
|
} ReorderBufferChange;
|
||||||
|
|
||||||
|
/* ReorderBufferTXN txn_flags */
|
||||||
|
#define RBTXN_HAS_CATALOG_CHANGES 0x0001
|
||||||
|
#define RBTXN_IS_SUBXACT 0x0002
|
||||||
|
#define RBTXN_IS_SERIALIZED 0x0004
|
||||||
|
|
||||||
|
/* Does the transaction have catalog changes? */
|
||||||
|
#define rbtxn_has_catalog_changes(txn) \
|
||||||
|
( \
|
||||||
|
((txn)->txn_flags & RBTXN_HAS_CATALOG_CHANGES) != 0 \
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Is the transaction known as a subxact? */
|
||||||
|
#define rbtxn_is_known_subxact(txn) \
|
||||||
|
( \
|
||||||
|
((txn)->txn_flags & RBTXN_IS_SUBXACT) != 0 \
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Has this transaction been spilled to disk? */
|
||||||
|
#define rbtxn_is_serialized(txn) \
|
||||||
|
( \
|
||||||
|
((txn)->txn_flags & RBTXN_IS_SERIALIZED) != 0 \
|
||||||
|
)
|
||||||
|
|
||||||
typedef struct ReorderBufferTXN
|
typedef struct ReorderBufferTXN
|
||||||
{
|
{
|
||||||
/*
|
/* See above */
|
||||||
* The transactions transaction id, can be a toplevel or sub xid.
|
bits32 txn_flags;
|
||||||
*/
|
|
||||||
|
/* The transaction's transaction id, can be a toplevel or sub xid. */
|
||||||
TransactionId xid;
|
TransactionId xid;
|
||||||
|
|
||||||
/* did the TX have catalog changes */
|
/* Xid of top-level transaction, if known */
|
||||||
bool has_catalog_changes;
|
|
||||||
|
|
||||||
/* Do we know this is a subxact? Xid of top-level txn if so */
|
|
||||||
bool is_known_as_subxact;
|
|
||||||
TransactionId toplevel_xid;
|
TransactionId toplevel_xid;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -237,15 +257,6 @@ typedef struct ReorderBufferTXN
|
|||||||
*/
|
*/
|
||||||
uint64 nentries_mem;
|
uint64 nentries_mem;
|
||||||
|
|
||||||
/*
|
|
||||||
* Has this transaction been spilled to disk? It's not always possible to
|
|
||||||
* deduce that fact by comparing nentries with nentries_mem, because e.g.
|
|
||||||
* subtransactions of a large transaction might get serialized together
|
|
||||||
* with the parent - if they're restored to memory they'd have
|
|
||||||
* nentries_mem == nentries.
|
|
||||||
*/
|
|
||||||
bool serialized;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* List of ReorderBufferChange structs, including new Snapshots and new
|
* List of ReorderBufferChange structs, including new Snapshots and new
|
||||||
* CommandIds
|
* CommandIds
|
||||||
@ -298,7 +309,6 @@ typedef struct ReorderBufferTXN
|
|||||||
* Size of this transaction (changes currently in memory, in bytes).
|
* Size of this transaction (changes currently in memory, in bytes).
|
||||||
*/
|
*/
|
||||||
Size size;
|
Size size;
|
||||||
|
|
||||||
} ReorderBufferTXN;
|
} ReorderBufferTXN;
|
||||||
|
|
||||||
/* so we can define the callbacks used inside struct ReorderBuffer itself */
|
/* so we can define the callbacks used inside struct ReorderBuffer itself */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user