From 728f152e07f998d2cb4fe5f24ec8da2c3bda98f2 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Fri, 19 Sep 2014 15:17:12 +0200 Subject: Add rmgr callback to name xlog record types for display purposes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is primarily useful for the upcoming pg_xlogdump --stats feature, but also allows to remove some duplicated code in the rmgr_desc routines. Due to the separation and harmonization, the output of dipsplayed records changes somewhat. But since this isn't enduser oriented content that's ok. It's potentially desirable to further change pg_xlogdump's display of records. It previously wasn't possible to show the record type separately from the description forcing it to be in the last column. But that's better done in a separate commit. Author: Abhijit Menon-Sen, slightly editorialized by me Reviewed-By: Álvaro Herrera, Andres Freund, and Heikki Linnakangas Discussion: 20140604104716.GA3989@toroid.org --- src/backend/access/transam/xlog.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/backend/access/transam/xlog.c') diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 34f2fc0e21b..21f0052f68e 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -799,6 +799,7 @@ static bool CheckForStandbyTrigger(void); #ifdef WAL_DEBUG static void xlog_outrec(StringInfo buf, XLogRecord *record); #endif +static void xlog_outdesc(StringInfo buf, RmgrId rmid, XLogRecord *record); static void pg_start_backup_callback(int code, Datum arg); static bool read_backup_label(XLogRecPtr *checkPointLoc, bool *backupEndRequired, bool *backupFromStandby); @@ -1287,7 +1288,7 @@ begin:; appendBinaryStringInfo(&recordbuf, rdata->data, rdata->len); appendStringInfoString(&buf, " - "); - RmgrTable[rechdr->xl_rmid].rm_desc(&buf, (XLogRecord *) recordbuf.data); + xlog_outdesc(&buf, rechdr->xl_rmid, (XLogRecord *) recordbuf.data); } elog(LOG, "%s", buf.data); @@ -6710,7 +6711,7 @@ StartupXLOG(void) (uint32) (EndRecPtr >> 32), (uint32) EndRecPtr); xlog_outrec(&buf, record); appendStringInfoString(&buf, " - "); - RmgrTable[record->xl_rmid].rm_desc(&buf, record); + xlog_outdesc(&buf, record->xl_rmid, record); elog(LOG, "%s", buf.data); pfree(buf.data); } @@ -9624,11 +9625,30 @@ xlog_outrec(StringInfo buf, XLogRecord *record) if (record->xl_info & XLR_BKP_BLOCK(i)) appendStringInfo(buf, "; bkpb%d", i); } - - appendStringInfo(buf, ": %s", RmgrTable[record->xl_rmid].rm_name); } #endif /* WAL_DEBUG */ +/* + * Returns a string describing an XLogRecord, consisting of its identity + * optionally followed by a colon, a space, and a further description. + */ +static void +xlog_outdesc(StringInfo buf, RmgrId rmid, XLogRecord *record) +{ + const char *id; + + appendStringInfoString(buf, RmgrTable[rmid].rm_name); + appendStringInfoChar(buf, '/'); + + id = RmgrTable[rmid].rm_identify(record->xl_info); + if (id == NULL) + appendStringInfo(buf, "UNKNOWN (%X): ", record->xl_info); + else + appendStringInfo(buf, "%s: ", id); + + RmgrTable[rmid].rm_desc(buf, record); +} + /* * Return the (possible) sync flag used for opening a file, depending on the @@ -10664,7 +10684,7 @@ rm_redo_error_callback(void *arg) StringInfoData buf; initStringInfo(&buf); - RmgrTable[record->xl_rmid].rm_desc(&buf, record); + xlog_outdesc(&buf, record->xl_rmid, record); /* don't bother emitting empty description */ if (buf.len > 0) -- cgit v1.2.3