Skip to content

Commit a7b6ab5

Browse files
committed
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
1 parent 00b047f commit a7b6ab5

File tree

2 files changed

+47
-37
lines changed

2 files changed

+47
-37
lines changed

src/backend/replication/logical/reorderbuffer.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ AssertTXNLsnOrder(ReorderBuffer *rb)
740740
Assert(prev_first_lsn < cur_txn->first_lsn);
741741

742742
/* known-as-subtxn txns must not be listed */
743-
Assert(!cur_txn->is_known_as_subxact);
743+
Assert(!rbtxn_is_known_subxact(cur_txn));
744744

745745
prev_first_lsn = cur_txn->first_lsn;
746746
}
@@ -760,7 +760,7 @@ AssertTXNLsnOrder(ReorderBuffer *rb)
760760
Assert(prev_base_snap_lsn < cur_txn->base_snapshot_lsn);
761761

762762
/* known-as-subtxn txns must not be listed */
763-
Assert(!cur_txn->is_known_as_subxact);
763+
Assert(!rbtxn_is_known_subxact(cur_txn));
764764

765765
prev_base_snap_lsn = cur_txn->base_snapshot_lsn;
766766
}
@@ -783,7 +783,7 @@ ReorderBufferGetOldestTXN(ReorderBuffer *rb)
783783

784784
txn = dlist_head_element(ReorderBufferTXN, node, &rb->toplevel_by_lsn);
785785

786-
Assert(!txn->is_known_as_subxact);
786+
Assert(!rbtxn_is_known_subxact(txn));
787787
Assert(txn->first_lsn != InvalidXLogRecPtr);
788788
return txn;
789789
}
@@ -843,7 +843,7 @@ ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid,
843843

844844
if (!new_sub)
845845
{
846-
if (subtxn->is_known_as_subxact)
846+
if (rbtxn_is_known_subxact(subtxn))
847847
{
848848
/* already associated, nothing to do */
849849
return;
@@ -859,7 +859,7 @@ ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid,
859859
}
860860
}
861861

862-
subtxn->is_known_as_subxact = true;
862+
subtxn->txn_flags |= RBTXN_IS_SUBXACT;
863863
subtxn->toplevel_xid = xid;
864864
Assert(subtxn->nsubtxns == 0);
865865

@@ -1080,7 +1080,7 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn,
10801080
{
10811081
ReorderBufferChange *cur_change;
10821082

1083-
if (txn->serialized)
1083+
if (rbtxn_is_serialized(txn))
10841084
{
10851085
/* serialize remaining changes */
10861086
ReorderBufferSerializeTXN(rb, txn);
@@ -1109,7 +1109,7 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn,
11091109
{
11101110
ReorderBufferChange *cur_change;
11111111

1112-
if (cur_txn->serialized)
1112+
if (rbtxn_is_serialized(cur_txn))
11131113
{
11141114
/* serialize remaining changes */
11151115
ReorderBufferSerializeTXN(rb, cur_txn);
@@ -1273,7 +1273,7 @@ ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
12731273
* they originally were happening inside another subtxn, so we won't
12741274
* ever recurse more than one level deep here.
12751275
*/
1276-
Assert(subtxn->is_known_as_subxact);
1276+
Assert(rbtxn_is_known_subxact(subtxn));
12771277
Assert(subtxn->nsubtxns == 0);
12781278

12791279
ReorderBufferCleanupTXN(rb, subtxn);
@@ -1321,7 +1321,7 @@ ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
13211321
/*
13221322
* Remove TXN from its containing list.
13231323
*
1324-
* Note: if txn->is_known_as_subxact, we are deleting the TXN from its
1324+
* Note: if txn is known as subxact, we are deleting the TXN from its
13251325
* parent's list of known subxacts; this leaves the parent's nsubxacts
13261326
* count too high, but we don't care. Otherwise, we are deleting the TXN
13271327
* from the LSN-ordered list of toplevel TXNs.
@@ -1336,7 +1336,7 @@ ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
13361336
Assert(found);
13371337

13381338
/* remove entries spilled to disk */
1339-
if (txn->serialized)
1339+
if (rbtxn_is_serialized(txn))
13401340
ReorderBufferRestoreCleanup(rb, txn);
13411341

13421342
/* deallocate */
@@ -1353,7 +1353,7 @@ ReorderBufferBuildTupleCidHash(ReorderBuffer *rb, ReorderBufferTXN *txn)
13531353
dlist_iter iter;
13541354
HASHCTL hash_ctl;
13551355

1356-
if (!txn->has_catalog_changes || dlist_is_empty(&txn->tuplecids))
1356+
if (!rbtxn_has_catalog_changes(txn) || dlist_is_empty(&txn->tuplecids))
13571357
return;
13581358

13591359
memset(&hash_ctl, 0, sizeof(hash_ctl));
@@ -1981,7 +1981,7 @@ ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
19811981
* final_lsn to that of their last change; this causes
19821982
* ReorderBufferRestoreCleanup to do the right thing.
19831983
*/
1984-
if (txn->serialized && txn->final_lsn == 0)
1984+
if (rbtxn_is_serialized(txn) && txn->final_lsn == 0)
19851985
{
19861986
ReorderBufferChange *last =
19871987
dlist_tail_element(ReorderBufferChange, node, &txn->changes);
@@ -2129,7 +2129,7 @@ ReorderBufferSetBaseSnapshot(ReorderBuffer *rb, TransactionId xid,
21292129
* operate on its top-level transaction instead.
21302130
*/
21312131
txn = ReorderBufferTXNByXid(rb, xid, true, &is_new, lsn, true);
2132-
if (txn->is_known_as_subxact)
2132+
if (rbtxn_is_known_subxact(txn))
21332133
txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
21342134
NULL, InvalidXLogRecPtr, false);
21352135
Assert(txn->base_snapshot == NULL);
@@ -2276,7 +2276,7 @@ ReorderBufferXidSetCatalogChanges(ReorderBuffer *rb, TransactionId xid,
22762276

22772277
txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
22782278

2279-
txn->has_catalog_changes = true;
2279+
txn->txn_flags |= RBTXN_HAS_CATALOG_CHANGES;
22802280
}
22812281

22822282
/*
@@ -2293,7 +2293,7 @@ ReorderBufferXidHasCatalogChanges(ReorderBuffer *rb, TransactionId xid)
22932293
if (txn == NULL)
22942294
return false;
22952295

2296-
return txn->has_catalog_changes;
2296+
return rbtxn_has_catalog_changes(txn);
22972297
}
22982298

22992299
/*
@@ -2313,7 +2313,7 @@ ReorderBufferXidHasBaseSnapshot(ReorderBuffer *rb, TransactionId xid)
23132313
return false;
23142314

23152315
/* a known subtxn? operate on top-level txn instead */
2316-
if (txn->is_known_as_subxact)
2316+
if (rbtxn_is_known_subxact(txn))
23172317
txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
23182318
NULL, InvalidXLogRecPtr, false);
23192319

@@ -2500,13 +2500,13 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
25002500
rb->spillCount += 1;
25012501
rb->spillBytes += size;
25022502

2503-
/* Don't consider already serialized transaction. */
2504-
rb->spillTxns += txn->serialized ? 0 : 1;
2503+
/* Don't consider already serialized transactions. */
2504+
rb->spillTxns += rbtxn_is_serialized(txn) ? 0 : 1;
25052505

25062506
Assert(spilled == txn->nentries_mem);
25072507
Assert(dlist_is_empty(&txn->changes));
25082508
txn->nentries_mem = 0;
2509-
txn->serialized = true;
2509+
txn->txn_flags |= RBTXN_IS_SERIALIZED;
25102510

25112511
if (fd != -1)
25122512
CloseTransientFile(fd);

src/include/replication/reorderbuffer.h

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,38 @@ typedef struct ReorderBufferChange
158158
dlist_node node;
159159
} ReorderBufferChange;
160160

161+
/* ReorderBufferTXN txn_flags */
162+
#define RBTXN_HAS_CATALOG_CHANGES 0x0001
163+
#define RBTXN_IS_SUBXACT 0x0002
164+
#define RBTXN_IS_SERIALIZED 0x0004
165+
166+
/* Does the transaction have catalog changes? */
167+
#define rbtxn_has_catalog_changes(txn) \
168+
( \
169+
((txn)->txn_flags & RBTXN_HAS_CATALOG_CHANGES) != 0 \
170+
)
171+
172+
/* Is the transaction known as a subxact? */
173+
#define rbtxn_is_known_subxact(txn) \
174+
( \
175+
((txn)->txn_flags & RBTXN_IS_SUBXACT) != 0 \
176+
)
177+
178+
/* Has this transaction been spilled to disk? */
179+
#define rbtxn_is_serialized(txn) \
180+
( \
181+
((txn)->txn_flags & RBTXN_IS_SERIALIZED) != 0 \
182+
)
183+
161184
typedef struct ReorderBufferTXN
162185
{
163-
/*
164-
* The transactions transaction id, can be a toplevel or sub xid.
165-
*/
166-
TransactionId xid;
186+
/* See above */
187+
bits32 txn_flags;
167188

168-
/* did the TX have catalog changes */
169-
bool has_catalog_changes;
189+
/* The transaction's transaction id, can be a toplevel or sub xid. */
190+
TransactionId xid;
170191

171-
/* Do we know this is a subxact? Xid of top-level txn if so */
172-
bool is_known_as_subxact;
192+
/* Xid of top-level transaction, if known */
173193
TransactionId toplevel_xid;
174194

175195
/*
@@ -237,15 +257,6 @@ typedef struct ReorderBufferTXN
237257
*/
238258
uint64 nentries_mem;
239259

240-
/*
241-
* Has this transaction been spilled to disk? It's not always possible to
242-
* deduce that fact by comparing nentries with nentries_mem, because e.g.
243-
* subtransactions of a large transaction might get serialized together
244-
* with the parent - if they're restored to memory they'd have
245-
* nentries_mem == nentries.
246-
*/
247-
bool serialized;
248-
249260
/*
250261
* List of ReorderBufferChange structs, including new Snapshots and new
251262
* CommandIds
@@ -298,7 +309,6 @@ typedef struct ReorderBufferTXN
298309
* Size of this transaction (changes currently in memory, in bytes).
299310
*/
300311
Size size;
301-
302312
} ReorderBufferTXN;
303313

304314
/* so we can define the callbacks used inside struct ReorderBuffer itself */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy