Skip to content

Commit 6f6f284

Browse files
committed
Simplify printing of LSNs
Add a macro LSN_FORMAT_ARGS for use in printf-style printing of LSNs. Convert all applicable code to use it. Reviewed-by: Ashutosh Bapat <[email protected]> Reviewed-by: Kyotaro Horiguchi <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/CAExHW5ub5NaTELZ3hJUCE6amuvqAtsSxc7O+uK7y4t9Rrk23cw@mail.gmail.com
1 parent ade89ba commit 6f6f284

36 files changed

+212
-308
lines changed

contrib/amcheck/verify_nbtree.c

+19-38
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,7 @@ bt_target_page_check(BtreeCheckState *state)
10781078
state->targetblock,
10791079
BTreeTupleGetNAtts(itup, state->rel),
10801080
P_ISLEAF(topaque) ? "heap" : "index",
1081-
(uint32) (state->targetlsn >> 32),
1082-
(uint32) state->targetlsn)));
1081+
LSN_FORMAT_ARGS(state->targetlsn))));
10831082
}
10841083
}
10851084

@@ -1120,8 +1119,7 @@ bt_target_page_check(BtreeCheckState *state)
11201119
errdetail_internal("Index tid=(%u,%u) tuple size=%zu lp_len=%u page lsn=%X/%X.",
11211120
state->targetblock, offset,
11221121
tupsize, ItemIdGetLength(itemid),
1123-
(uint32) (state->targetlsn >> 32),
1124-
(uint32) state->targetlsn),
1122+
LSN_FORMAT_ARGS(state->targetlsn)),
11251123
errhint("This could be a torn page problem.")));
11261124

11271125
/* Check the number of index tuple attributes */
@@ -1147,8 +1145,7 @@ bt_target_page_check(BtreeCheckState *state)
11471145
BTreeTupleGetNAtts(itup, state->rel),
11481146
P_ISLEAF(topaque) ? "heap" : "index",
11491147
htid,
1150-
(uint32) (state->targetlsn >> 32),
1151-
(uint32) state->targetlsn)));
1148+
LSN_FORMAT_ARGS(state->targetlsn))));
11521149
}
11531150

11541151
/*
@@ -1195,8 +1192,7 @@ bt_target_page_check(BtreeCheckState *state)
11951192
RelationGetRelationName(state->rel)),
11961193
errdetail_internal("Index tid=%s points to heap tid=%s page lsn=%X/%X.",
11971194
itid, htid,
1198-
(uint32) (state->targetlsn >> 32),
1199-
(uint32) state->targetlsn)));
1195+
LSN_FORMAT_ARGS(state->targetlsn))));
12001196
}
12011197

12021198
/*
@@ -1225,8 +1221,7 @@ bt_target_page_check(BtreeCheckState *state)
12251221
RelationGetRelationName(state->rel)),
12261222
errdetail_internal("Index tid=%s posting list offset=%d page lsn=%X/%X.",
12271223
itid, i,
1228-
(uint32) (state->targetlsn >> 32),
1229-
(uint32) state->targetlsn)));
1224+
LSN_FORMAT_ARGS(state->targetlsn))));
12301225
}
12311226

12321227
ItemPointerCopy(current, &last);
@@ -1282,8 +1277,7 @@ bt_target_page_check(BtreeCheckState *state)
12821277
itid,
12831278
P_ISLEAF(topaque) ? "heap" : "index",
12841279
htid,
1285-
(uint32) (state->targetlsn >> 32),
1286-
(uint32) state->targetlsn)));
1280+
LSN_FORMAT_ARGS(state->targetlsn))));
12871281
}
12881282

12891283
/* Fingerprint leaf page tuples (those that point to the heap) */
@@ -1390,8 +1384,7 @@ bt_target_page_check(BtreeCheckState *state)
13901384
itid,
13911385
P_ISLEAF(topaque) ? "heap" : "index",
13921386
htid,
1393-
(uint32) (state->targetlsn >> 32),
1394-
(uint32) state->targetlsn)));
1387+
LSN_FORMAT_ARGS(state->targetlsn))));
13951388
}
13961389
/* Reset, in case scantid was set to (itup) posting tuple's max TID */
13971390
skey->scantid = scantid;
@@ -1442,8 +1435,7 @@ bt_target_page_check(BtreeCheckState *state)
14421435
nitid,
14431436
P_ISLEAF(topaque) ? "heap" : "index",
14441437
nhtid,
1445-
(uint32) (state->targetlsn >> 32),
1446-
(uint32) state->targetlsn)));
1438+
LSN_FORMAT_ARGS(state->targetlsn))));
14471439
}
14481440

14491441
/*
@@ -1500,8 +1492,7 @@ bt_target_page_check(BtreeCheckState *state)
15001492
RelationGetRelationName(state->rel)),
15011493
errdetail_internal("Last item on page tid=(%u,%u) page lsn=%X/%X.",
15021494
state->targetblock, offset,
1503-
(uint32) (state->targetlsn >> 32),
1504-
(uint32) state->targetlsn)));
1495+
LSN_FORMAT_ARGS(state->targetlsn))));
15051496
}
15061497
}
15071498

@@ -1907,8 +1898,7 @@ bt_child_highkey_check(BtreeCheckState *state,
19071898
RelationGetRelationName(state->rel)),
19081899
errdetail_internal("Target block=%u child block=%u target page lsn=%X/%X.",
19091900
state->targetblock, blkno,
1910-
(uint32) (state->targetlsn >> 32),
1911-
(uint32) state->targetlsn)));
1901+
LSN_FORMAT_ARGS(state->targetlsn))));
19121902

19131903
/* Check level for non-ignorable page */
19141904
if (!P_IGNORE(opaque) && opaque->btpo.level != target_level - 1)
@@ -1993,8 +1983,7 @@ bt_child_highkey_check(BtreeCheckState *state,
19931983
RelationGetRelationName(state->rel)),
19941984
errdetail_internal("Target block=%u child block=%u target page lsn=%X/%X.",
19951985
state->targetblock, blkno,
1996-
(uint32) (state->targetlsn >> 32),
1997-
(uint32) state->targetlsn)));
1986+
LSN_FORMAT_ARGS(state->targetlsn))));
19981987
pivotkey_offset = P_HIKEY;
19991988
}
20001989
itemid = PageGetItemIdCareful(state, state->targetblock,
@@ -2024,8 +2013,7 @@ bt_child_highkey_check(BtreeCheckState *state,
20242013
RelationGetRelationName(state->rel)),
20252014
errdetail_internal("Target block=%u child block=%u target page lsn=%X/%X.",
20262015
state->targetblock, blkno,
2027-
(uint32) (state->targetlsn >> 32),
2028-
(uint32) state->targetlsn)));
2016+
LSN_FORMAT_ARGS(state->targetlsn))));
20292017
itup = state->lowkey;
20302018
}
20312019

@@ -2037,8 +2025,7 @@ bt_child_highkey_check(BtreeCheckState *state,
20372025
RelationGetRelationName(state->rel)),
20382026
errdetail_internal("Target block=%u child block=%u target page lsn=%X/%X.",
20392027
state->targetblock, blkno,
2040-
(uint32) (state->targetlsn >> 32),
2041-
(uint32) state->targetlsn)));
2028+
LSN_FORMAT_ARGS(state->targetlsn))));
20422029
}
20432030
}
20442031

@@ -2178,8 +2165,7 @@ bt_child_check(BtreeCheckState *state, BTScanInsert targetkey,
21782165
RelationGetRelationName(state->rel)),
21792166
errdetail_internal("Parent block=%u child block=%u parent page lsn=%X/%X.",
21802167
state->targetblock, childblock,
2181-
(uint32) (state->targetlsn >> 32),
2182-
(uint32) state->targetlsn)));
2168+
LSN_FORMAT_ARGS(state->targetlsn))));
21832169

21842170
for (offset = P_FIRSTDATAKEY(copaque);
21852171
offset <= maxoffset;
@@ -2220,8 +2206,7 @@ bt_child_check(BtreeCheckState *state, BTScanInsert targetkey,
22202206
RelationGetRelationName(state->rel)),
22212207
errdetail_internal("Parent block=%u child index tid=(%u,%u) parent page lsn=%X/%X.",
22222208
state->targetblock, childblock, offset,
2223-
(uint32) (state->targetlsn >> 32),
2224-
(uint32) state->targetlsn)));
2209+
LSN_FORMAT_ARGS(state->targetlsn))));
22252210
}
22262211

22272212
pfree(child);
@@ -2292,8 +2277,7 @@ bt_downlink_missing_check(BtreeCheckState *state, bool rightsplit,
22922277
errdetail_internal("Block=%u level=%u left sibling=%u page lsn=%X/%X.",
22932278
blkno, opaque->btpo.level,
22942279
opaque->btpo_prev,
2295-
(uint32) (pagelsn >> 32),
2296-
(uint32) pagelsn)));
2280+
LSN_FORMAT_ARGS(pagelsn))));
22972281
return;
22982282
}
22992283

@@ -2314,8 +2298,7 @@ bt_downlink_missing_check(BtreeCheckState *state, bool rightsplit,
23142298
RelationGetRelationName(state->rel)),
23152299
errdetail_internal("Block=%u page lsn=%X/%X.",
23162300
blkno,
2317-
(uint32) (pagelsn >> 32),
2318-
(uint32) pagelsn)));
2301+
LSN_FORMAT_ARGS(pagelsn))));
23192302

23202303
/* Descend from the given page, which is an internal page */
23212304
elog(DEBUG1, "checking for interrupted multi-level deletion due to missing downlink in index \"%s\"",
@@ -2381,8 +2364,7 @@ bt_downlink_missing_check(BtreeCheckState *state, bool rightsplit,
23812364
RelationGetRelationName(state->rel)),
23822365
errdetail_internal("Top parent/target block=%u leaf block=%u top parent/under check lsn=%X/%X.",
23832366
blkno, childblk,
2384-
(uint32) (pagelsn >> 32),
2385-
(uint32) pagelsn)));
2367+
LSN_FORMAT_ARGS(pagelsn))));
23862368

23872369
/*
23882370
* Iff leaf page is half-dead, its high key top parent link should point
@@ -2408,8 +2390,7 @@ bt_downlink_missing_check(BtreeCheckState *state, bool rightsplit,
24082390
RelationGetRelationName(state->rel)),
24092391
errdetail_internal("Block=%u level=%u page lsn=%X/%X.",
24102392
blkno, opaque->btpo.level,
2411-
(uint32) (pagelsn >> 32),
2412-
(uint32) pagelsn)));
2393+
LSN_FORMAT_ARGS(pagelsn))));
24132394
}
24142395

24152396
/*

contrib/pageinspect/rawpage.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ page_header(PG_FUNCTION_ARGS)
309309
{
310310
char lsnchar[64];
311311

312-
snprintf(lsnchar, sizeof(lsnchar), "%X/%X",
313-
(uint32) (lsn >> 32), (uint32) lsn);
312+
snprintf(lsnchar, sizeof(lsnchar), "%X/%X", LSN_FORMAT_ARGS(lsn));
314313
values[0] = CStringGetTextDatum(lsnchar);
315314
}
316315
else

src/backend/access/heap/rewriteheap.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,7 @@ logical_rewrite_log_mapping(RewriteState state, TransactionId xid,
997997
snprintf(path, MAXPGPATH,
998998
"pg_logical/mappings/" LOGICAL_REWRITE_FORMAT,
999999
dboid, relid,
1000-
(uint32) (state->rs_begin_lsn >> 32),
1001-
(uint32) state->rs_begin_lsn,
1000+
LSN_FORMAT_ARGS(state->rs_begin_lsn),
10021001
xid, GetCurrentTransactionId());
10031002

10041003
dlist_init(&src->mappings);
@@ -1120,8 +1119,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
11201119
snprintf(path, MAXPGPATH,
11211120
"pg_logical/mappings/" LOGICAL_REWRITE_FORMAT,
11221121
xlrec->mapped_db, xlrec->mapped_rel,
1123-
(uint32) (xlrec->start_lsn >> 32),
1124-
(uint32) xlrec->start_lsn,
1122+
LSN_FORMAT_ARGS(xlrec->start_lsn),
11251123
xlrec->mapped_xid, XLogRecGetXid(r));
11261124

11271125
fd = OpenTransientFile(path,

src/backend/access/rmgrdesc/replorigindesc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ replorigin_desc(StringInfo buf, XLogReaderState *record)
3131

3232
appendStringInfo(buf, "set %u; lsn %X/%X; force: %d",
3333
xlrec->node_id,
34-
(uint32) (xlrec->remote_lsn >> 32),
35-
(uint32) xlrec->remote_lsn,
34+
LSN_FORMAT_ARGS(xlrec->remote_lsn),
3635
xlrec->force);
3736
break;
3837
}

src/backend/access/rmgrdesc/xactdesc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId
306306
{
307307
appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s",
308308
origin_id,
309-
(uint32) (parsed.origin_lsn >> 32),
310-
(uint32) parsed.origin_lsn,
309+
LSN_FORMAT_ARGS(parsed.origin_lsn),
311310
timestamptz_to_str(parsed.origin_timestamp));
312311
}
313312
}

src/backend/access/rmgrdesc/xlogdesc.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ xlog_desc(StringInfo buf, XLogReaderState *record)
4949
"oldest xid %u in DB %u; oldest multi %u in DB %u; "
5050
"oldest/newest commit timestamp xid: %u/%u; "
5151
"oldest running xid %u; %s",
52-
(uint32) (checkpoint->redo >> 32), (uint32) checkpoint->redo,
52+
LSN_FORMAT_ARGS(checkpoint->redo),
5353
checkpoint->ThisTimeLineID,
5454
checkpoint->PrevTimeLineID,
5555
checkpoint->fullPageWrites ? "true" : "false",
@@ -89,8 +89,7 @@ xlog_desc(StringInfo buf, XLogReaderState *record)
8989
XLogRecPtr startpoint;
9090

9191
memcpy(&startpoint, rec, sizeof(XLogRecPtr));
92-
appendStringInfo(buf, "%X/%X",
93-
(uint32) (startpoint >> 32), (uint32) startpoint);
92+
appendStringInfo(buf, "%X/%X", LSN_FORMAT_ARGS(startpoint));
9493
}
9594
else if (info == XLOG_PARAMETER_CHANGE)
9695
{

src/backend/access/transam/timeline.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
402402
"%s%u\t%X/%X\t%s\n",
403403
(srcfd < 0) ? "" : "\n",
404404
parentTLI,
405-
(uint32) (switchpoint >> 32), (uint32) (switchpoint),
405+
LSN_FORMAT_ARGS(switchpoint),
406406
reason);
407407

408408
nbytes = strlen(buffer);

src/backend/access/transam/twophase.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -1342,16 +1342,14 @@ XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, int *len)
13421342
ereport(ERROR,
13431343
(errcode_for_file_access(),
13441344
errmsg("could not read two-phase state from WAL at %X/%X",
1345-
(uint32) (lsn >> 32),
1346-
(uint32) lsn)));
1345+
LSN_FORMAT_ARGS(lsn))));
13471346

13481347
if (XLogRecGetRmid(xlogreader) != RM_XACT_ID ||
13491348
(XLogRecGetInfo(xlogreader) & XLOG_XACT_OPMASK) != XLOG_XACT_PREPARE)
13501349
ereport(ERROR,
13511350
(errcode_for_file_access(),
13521351
errmsg("expected two-phase state data is not present in WAL at %X/%X",
1353-
(uint32) (lsn >> 32),
1354-
(uint32) lsn)));
1352+
LSN_FORMAT_ARGS(lsn))));
13551353

13561354
if (len != NULL)
13571355
*len = XLogRecGetDataLen(xlogreader);

0 commit comments

Comments
 (0)