Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c70f9e8

Browse files
committed
Further cleanup of ReorderBufferCommit().
On closer inspection, we can remove the "volatile" qualifier on "using_subtxn" so long as we initialize that before the PG_TRY block, which there's no particularly good reason not to do. Also, push the "change" variable inside the PG_TRY so as to remove all question of whether it needs "volatile", and remove useless early initializations of "snapshow_now" and "using_subtxn".
1 parent bf007a2 commit c70f9e8

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/backend/replication/logical/reorderbuffer.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,10 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
12581258
TimestampTz commit_time)
12591259
{
12601260
ReorderBufferTXN *txn;
1261-
ReorderBufferIterTXNState *volatile iterstate = NULL;
1262-
ReorderBufferChange *change;
1263-
1261+
volatile Snapshot snapshot_now;
12641262
volatile CommandId command_id = FirstCommandId;
1265-
volatile Snapshot snapshot_now = NULL;
1266-
volatile bool using_subtxn = false;
1263+
bool using_subtxn;
1264+
ReorderBufferIterTXNState *volatile iterstate = NULL;
12671265

12681266
txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
12691267
false);
@@ -1301,19 +1299,21 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
13011299
/* setup the initial snapshot */
13021300
SetupHistoricSnapshot(snapshot_now, txn->tuplecid_hash);
13031301

1302+
/*
1303+
* Decoding needs access to syscaches et al., which in turn use
1304+
* heavyweight locks and such. Thus we need to have enough state around to
1305+
* keep track of those. The easiest way is to simply use a transaction
1306+
* internally. That also allows us to easily enforce that nothing writes
1307+
* to the database by checking for xid assignments.
1308+
*
1309+
* When we're called via the SQL SRF there's already a transaction
1310+
* started, so start an explicit subtransaction there.
1311+
*/
1312+
using_subtxn = IsTransactionOrTransactionBlock();
1313+
13041314
PG_TRY();
13051315
{
1306-
/*
1307-
* Decoding needs access to syscaches et al., which in turn use
1308-
* heavyweight locks and such. Thus we need to have enough state
1309-
* around to keep track of those. The easiest way is to simply use a
1310-
* transaction internally. That also allows us to easily enforce that
1311-
* nothing writes to the database by checking for xid assignments.
1312-
*
1313-
* When we're called via the SQL SRF there's already a transaction
1314-
* started, so start an explicit subtransaction there.
1315-
*/
1316-
using_subtxn = IsTransactionOrTransactionBlock();
1316+
ReorderBufferChange *change;
13171317

13181318
if (using_subtxn)
13191319
BeginInternalSubTransaction("replay");
@@ -1323,7 +1323,7 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
13231323
rb->begin(rb, txn);
13241324

13251325
iterstate = ReorderBufferIterTXNInit(rb, txn);
1326-
while ((change = ReorderBufferIterTXNNext(rb, iterstate)))
1326+
while ((change = ReorderBufferIterTXNNext(rb, iterstate)) != NULL)
13271327
{
13281328
Relation relation = NULL;
13291329
Oid reloid;

0 commit comments

Comments
 (0)