]> granicus.if.org Git - postgresql/commitdiff
Improve code around the recently added rm_identify rmgr callback.
authorAndres Freund <andres@anarazel.de>
Mon, 22 Sep 2014 14:48:14 +0000 (16:48 +0200)
committerAndres Freund <andres@anarazel.de>
Mon, 22 Sep 2014 15:49:34 +0000 (17:49 +0200)
There are four weaknesses in728f152e07f998d2cb4fe5f24ec8da2c3bda98f2:

* append_init() in heapdesc.c was ugly and required that rm_identify
  return values are only valid till the next call. Instead just add a
  couple more switch() cases for the INIT_PAGE cases. Now the returned
  value will always be valid.
* a couple rm_identify() callbacks missed masking xl_info with
  ~XLR_INFO_MASK.
* pg_xlogdump didn't map a NULL rm_identify to UNKNOWN or a similar
  string.
* append_init() was called when id=NULL - which should never actually
  happen. But it's better to be careful.

18 files changed:
contrib/pg_xlogdump/pg_xlogdump.c
src/backend/access/rmgrdesc/clogdesc.c
src/backend/access/rmgrdesc/dbasedesc.c
src/backend/access/rmgrdesc/gindesc.c
src/backend/access/rmgrdesc/gistdesc.c
src/backend/access/rmgrdesc/heapdesc.c
src/backend/access/rmgrdesc/mxactdesc.c
src/backend/access/rmgrdesc/nbtdesc.c
src/backend/access/rmgrdesc/relmapdesc.c
src/backend/access/rmgrdesc/seqdesc.c
src/backend/access/rmgrdesc/smgrdesc.c
src/backend/access/rmgrdesc/spgdesc.c
src/backend/access/rmgrdesc/standbydesc.c
src/backend/access/rmgrdesc/tblspcdesc.c
src/backend/access/rmgrdesc/xactdesc.c
src/backend/access/rmgrdesc/xlogdesc.c
src/backend/access/transam/xlog.c
src/include/access/xlog_internal.h

index 1cd554ac4f70416f69a64ddbe7d0af4cf9df7c95..adc9087a1de1f5fe52514fe594ef692a81a199e2 100644 (file)
@@ -382,8 +382,13 @@ XLogDumpCountRecord(XLogDumpConfig *config, XLogDumpStats *stats, XLogRecPtr Rea
 static void
 XLogDumpDisplayRecord(XLogDumpConfig *config, XLogRecPtr ReadRecPtr, XLogRecord *record)
 {
+       const char         *id;
        const RmgrDescData *desc = &RmgrDescTable[record->xl_rmid];
 
+       id = desc->rm_identify(record->xl_info);
+       if (id == NULL)
+               id = psprintf("UNKNOWN (%x)", record->xl_info & ~XLR_INFO_MASK);
+
        printf("rmgr: %-11s len (rec/tot): %6u/%6u, tx: %10u, lsn: %X/%08X, prev %X/%08X, bkp: %u%u%u%u, desc: %s ",
                   desc->rm_name,
                   record->xl_len, record->xl_tot_len,
@@ -394,7 +399,7 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogRecPtr ReadRecPtr, XLogRecord
                   !!(XLR_BKP_BLOCK(1) & record->xl_info),
                   !!(XLR_BKP_BLOCK(2) & record->xl_info),
                   !!(XLR_BKP_BLOCK(3) & record->xl_info),
-                  desc->rm_identify(record->xl_info));
+                  id);
 
        /* the desc routine will printf the description directly to stdout */
        desc->rm_desc(NULL, record);
index 8beb6d027a75e34f78909894f9262a15f05f75f9..4a12e286e4aafc9918fc9d7800ae90d13161f1e3 100644 (file)
@@ -37,7 +37,7 @@ clog_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case CLOG_ZEROPAGE:
                        id = "ZEROPAGE";
index e36988a736f9d23e737b410d68b251a4308449d2..446e5f97f41438e170488fc487cfda895ef38802 100644 (file)
@@ -46,7 +46,7 @@ dbase_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_DBASE_CREATE:
                        id = "CREATE";
index dd4c791864d6deef87719baaf154e402e661bdfc..2f783cee2bbd77477f274d91103d9d1a0dd418af 100644 (file)
@@ -181,7 +181,7 @@ gin_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_GIN_CREATE_INDEX:
                        id = "CREATE_INDEX";
index f2ed1f672b201d73d6fb914e628f7a4774045139..db3ba13ccdd0bcf0f37ee29a83e597ae126d4720 100644 (file)
@@ -69,7 +69,7 @@ gist_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_GIST_PAGE_UPDATE:
                        id = "PAGE_UPDATE";
index cd9d59d6af8e8b062bcfe0be7bb7884b381825b2..ee2c073f71f73564f113f7da8166063cba2db48d 100644 (file)
@@ -166,36 +166,34 @@ heap2_desc(StringInfo buf, XLogRecord *record)
        }
 }
 
-static const char *
-append_init(const char *str)
-{
-       static char x[32];
-
-       strcpy(x, str);
-       strcat(x, "+INIT");
-
-       return x;
-}
-
 const char *
 heap_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info & XLOG_HEAP_OPMASK)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_HEAP_INSERT:
                        id = "INSERT";
                        break;
+               case XLOG_HEAP_INSERT | XLOG_HEAP_INIT_PAGE:
+                       id = "INSERT+INIT";
+                       break;
                case XLOG_HEAP_DELETE:
                        id = "DELETE";
                        break;
                case XLOG_HEAP_UPDATE:
                        id = "UPDATE";
                        break;
+               case XLOG_HEAP_UPDATE | XLOG_HEAP_INIT_PAGE:
+                       id = "UPDATE+INIT";
+                       break;
                case XLOG_HEAP_HOT_UPDATE:
                        id = "HOT_UPDATE";
                        break;
+               case XLOG_HEAP_HOT_UPDATE | XLOG_HEAP_INIT_PAGE:
+                       id = "HOT_UPDATE+INIT";
+                       break;
                case XLOG_HEAP_LOCK:
                        id = "LOCK";
                        break;
@@ -204,9 +202,6 @@ heap_identify(uint8 info)
                        break;
        }
 
-       if (info & XLOG_HEAP_INIT_PAGE)
-               id = append_init(id);
-
        return id;
 }
 
@@ -215,7 +210,7 @@ heap2_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info & XLOG_HEAP_OPMASK)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_HEAP2_CLEAN:
                        id = "CLEAN";
@@ -232,6 +227,9 @@ heap2_identify(uint8 info)
                case XLOG_HEAP2_MULTI_INSERT:
                        id = "MULTI_INSERT";
                        break;
+               case XLOG_HEAP2_MULTI_INSERT | XLOG_HEAP_INIT_PAGE:
+                       id = "MULTI_INSERT+INIT";
+                       break;
                case XLOG_HEAP2_LOCK_UPDATED:
                        id = "LOCK_UPDATED";
                        break;
@@ -243,8 +241,5 @@ heap2_identify(uint8 info)
                        break;
        }
 
-       if (info & XLOG_HEAP_INIT_PAGE)
-               id = append_init(id);
-
        return id;
 }
index 177aebea079c092031290bc5e47063bd3fe7a679..afc5aca1972e5a84e4269e8ad2110d1bf58d633e 100644 (file)
@@ -77,7 +77,7 @@ multixact_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_MULTIXACT_ZERO_OFF_PAGE:
                        id = "ZERO_OFF_PAGE";
index 7eb3bbd84764cfc87614b9dd7bcc5603f0e7f42b..8b63f2b6ba9fbc2570456dfc860648fb1acb8d79 100644 (file)
@@ -126,7 +126,7 @@ btree_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_BTREE_INSERT_LEAF:
                        id = "INSERT_LEAF";
index 39dcfb500357633bfc6ea5876005820459cc7f6c..ef7c533fe5f05a56c13ace5339476115078f6920 100644 (file)
@@ -36,7 +36,7 @@ relmap_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_RELMAP_UPDATE:
                        id = "UPDATE";
index d44fe62bebec995b666fa53ce5b930c8faaacd5b..73de3969df47cd03bd38ec43953fc3d9876f2797 100644 (file)
@@ -35,7 +35,7 @@ seq_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_SEQ_LOG:
                        id = "LOG";
index ee711bcacc78c95d1535bbf1adad5e9b7b259ab5..109e3eaf04df81afb2de23f3ae49458464473c45 100644 (file)
@@ -47,7 +47,7 @@ smgr_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_SMGR_CREATE:
                        id = "CREATE";
index 5b41748385a3e7351aa8a550203595ae37c08694..3ee0427dcb6a798a237ae411ac1230a59fa0ce69 100644 (file)
@@ -90,7 +90,7 @@ spg_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_SPGIST_CREATE_INDEX:
                        id = "CREATE_INDEX";
index e480687558399c6f2a43438fb056839344af849e..d09041f8dfc5d5969095b599cf594eb15daaf008 100644 (file)
@@ -65,7 +65,7 @@ standby_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_STANDBY_LOCK:
                        id = "LOCK";
index effeaf6680be3cc6033590bd0887a9e94265bfb0..b6b0e6394df88f769fcb7af7a8e71212a7e878a3 100644 (file)
@@ -42,7 +42,7 @@ tblspc_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_TBLSPC_CREATE:
                        id = "CREATE";
index 11e64af506ecc8ca71944202d725698d7f6c7823..22a22efc7313c1db831b8020aec6920179881bc6 100644 (file)
@@ -193,7 +193,7 @@ xact_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_XACT_COMMIT:
                        id = "COMMIT";
index cdefaf57da78947ee5ddbd57715818afc44415f9..e0957ff3a8ce433c091772e313dffffe51191c94 100644 (file)
@@ -139,7 +139,7 @@ xlog_identify(uint8 info)
 {
        const char *id = NULL;
 
-       switch (info)
+       switch (info & ~XLR_INFO_MASK)
        {
                case XLOG_CHECKPOINT_SHUTDOWN:
                        id = "CHECKPOINT_SHUTDOWN";
index 21f0052f68eba9508b51ef7e1d6a675726344a80..544d76e8524d5cecd2b4cb7a9d1a85c5cbc495cd 100644 (file)
@@ -9642,7 +9642,8 @@ xlog_outdesc(StringInfo buf, RmgrId rmid, XLogRecord *record)
 
        id = RmgrTable[rmid].rm_identify(record->xl_info);
        if (id == NULL)
-               appendStringInfo(buf, "UNKNOWN (%X): ", record->xl_info);
+               appendStringInfo(buf, "UNKNOWN (%X): ",
+                                                record->xl_info & ~XLR_INFO_MASK);
        else
                appendStringInfo(buf, "%s: ", id);
 
index a1452b82b8e130ccf5fedcf43bd6029895420af2..27b98995557511a08dceaaf9fc9ab04480b14248 100644 (file)
@@ -244,9 +244,6 @@ struct XLogRecord;
  * "VACUUM". rm_desc can then be called to obtain additional detail for the
  * record, if available (e.g. the last block).
  *
- * The return value from rm_identify is a pointer to a statically allocated
- * buffer, and only valid until the next invocation of the callback.
- *
  * RmgrTable[] is indexed by RmgrId values (see rmgrlist.h).
  */
 typedef struct RmgrData