Remove COMMIT_TS_SETTS record.
authorFujii Masao <fujii@postgresql.org>
Sun, 11 Apr 2021 15:00:18 +0000 (00:00 +0900)
committerFujii Masao <fujii@postgresql.org>
Sun, 11 Apr 2021 15:04:30 +0000 (00:04 +0900)
Commit 438fc4a39c prevented the WAL replay from writing
COMMIT_TS_SETTS record. By this change there is no code that
generates COMMIT_TS_SETTS record in PostgreSQL core.
Also we can think that there are no extensions using the record
because we've not received so far any complaints about the issue
that commit 438fc4a39c fixed. Therefore this commit removes
COMMIT_TS_SETTS record and its related code. Even without
this record, the timestamp required for commit timestamp feature
can be acquired from the COMMIT record.

Bump WAL page magic.

Reported-by: lx zou <zoulx1982@163.com>
Author: Fujii Masao
Reviewed-by: Alvaro Herrera
Discussion: https://postgr.es/m/16931-620d0f2fdc6108f1@postgresql.org

src/backend/access/rmgrdesc/committsdesc.c
src/backend/access/transam/commit_ts.c
src/backend/access/transam/twophase.c
src/backend/access/transam/xact.c
src/include/access/commit_ts.h
src/include/access/xlog_internal.h

index 7ebd3d35efd02245c71b4a80d0a6f49ed44cb059..26bad44b964aacfcfbe127ec2c496f7eb3ad7a6d 100644 (file)
@@ -38,31 +38,6 @@ commit_ts_desc(StringInfo buf, XLogReaderState *record)
        appendStringInfo(buf, "pageno %d, oldestXid %u",
                         trunc->pageno, trunc->oldestXid);
    }
-   else if (info == COMMIT_TS_SETTS)
-   {
-       xl_commit_ts_set *xlrec = (xl_commit_ts_set *) rec;
-       int         nsubxids;
-
-       appendStringInfo(buf, "set %s/%d for: %u",
-                        timestamptz_to_str(xlrec->timestamp),
-                        xlrec->nodeid,
-                        xlrec->mainxid);
-       nsubxids = ((XLogRecGetDataLen(record) - SizeOfCommitTsSet) /
-                   sizeof(TransactionId));
-       if (nsubxids > 0)
-       {
-           int         i;
-           TransactionId *subxids;
-
-           subxids = palloc(sizeof(TransactionId) * nsubxids);
-           memcpy(subxids,
-                  XLogRecGetData(record) + SizeOfCommitTsSet,
-                  sizeof(TransactionId) * nsubxids);
-           for (i = 0; i < nsubxids; i++)
-               appendStringInfo(buf, ", %u", subxids[i]);
-           pfree(subxids);
-       }
-   }
 }
 
 const char *
@@ -74,8 +49,6 @@ commit_ts_identify(uint8 info)
            return "ZEROPAGE";
        case COMMIT_TS_TRUNCATE:
            return "TRUNCATE";
-       case COMMIT_TS_SETTS:
-           return "SETTS";
        default:
            return NULL;
    }
index 268bdba3398226ed45ff362bb1f90fddea5d28a8..0985fa155caea741e9d23be6773834e2af6a72d5 100644 (file)
@@ -114,9 +114,6 @@ static void ActivateCommitTs(void);
 static void DeactivateCommitTs(void);
 static void WriteZeroPageXlogRec(int pageno);
 static void WriteTruncateXlogRec(int pageno, TransactionId oldestXid);
-static void WriteSetTimestampXlogRec(TransactionId mainxid, int nsubxids,
-                                    TransactionId *subxids, TimestampTz timestamp,
-                                    RepOriginId nodeid);
 
 /*
  * TransactionTreeSetCommitTsData
@@ -133,18 +130,11 @@ static void WriteSetTimestampXlogRec(TransactionId mainxid, int nsubxids,
  * permanent) so we need to keep the information about them here. If the
  * subtrans implementation changes in the future, we might want to revisit the
  * decision of storing timestamp info for each subxid.
- *
- * The write_xlog parameter tells us whether to include an XLog record of this
- * or not.  Normally, this is called from transaction commit routines (both
- * normal and prepared) and the information will be stored in the transaction
- * commit XLog record, and so they should pass "false" for this.  The XLog redo
- * code should use "false" here as well.  Other callers probably want to pass
- * true, so that the given values persist in case of crashes.
  */
 void
 TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
                               TransactionId *subxids, TimestampTz timestamp,
-                              RepOriginId nodeid, bool write_xlog)
+                              RepOriginId nodeid)
 {
    int         i;
    TransactionId headxid;
@@ -161,13 +151,6 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
    if (!commitTsShared->commitTsActive)
        return;
 
-   /*
-    * Comply with the WAL-before-data rule: if caller specified it wants this
-    * value to be recorded in WAL, do so before touching the data.
-    */
-   if (write_xlog)
-       WriteSetTimestampXlogRec(xid, nsubxids, subxids, timestamp, nodeid);
-
    /*
     * Figure out the latest Xid in this batch: either the last subxid if
     * there's any, otherwise the parent xid.
@@ -993,28 +976,6 @@ WriteTruncateXlogRec(int pageno, TransactionId oldestXid)
    (void) XLogInsert(RM_COMMIT_TS_ID, COMMIT_TS_TRUNCATE);
 }
 
-/*
- * Write a SETTS xlog record
- */
-static void
-WriteSetTimestampXlogRec(TransactionId mainxid, int nsubxids,
-                        TransactionId *subxids, TimestampTz timestamp,
-                        RepOriginId nodeid)
-{
-   xl_commit_ts_set record;
-
-   record.timestamp = timestamp;
-   record.nodeid = nodeid;
-   record.mainxid = mainxid;
-
-   XLogBeginInsert();
-   XLogRegisterData((char *) &record,
-                    offsetof(xl_commit_ts_set, mainxid) +
-                    sizeof(TransactionId));
-   XLogRegisterData((char *) subxids, nsubxids * sizeof(TransactionId));
-   XLogInsert(RM_COMMIT_TS_ID, COMMIT_TS_SETTS);
-}
-
 /*
  * CommitTS resource manager's routines
  */
@@ -1055,29 +1016,6 @@ commit_ts_redo(XLogReaderState *record)
 
        SimpleLruTruncate(CommitTsCtl, trunc->pageno);
    }
-   else if (info == COMMIT_TS_SETTS)
-   {
-       xl_commit_ts_set *setts = (xl_commit_ts_set *) XLogRecGetData(record);
-       int         nsubxids;
-       TransactionId *subxids;
-
-       nsubxids = ((XLogRecGetDataLen(record) - SizeOfCommitTsSet) /
-                   sizeof(TransactionId));
-       if (nsubxids > 0)
-       {
-           subxids = palloc(sizeof(TransactionId) * nsubxids);
-           memcpy(subxids,
-                  XLogRecGetData(record) + SizeOfCommitTsSet,
-                  sizeof(TransactionId) * nsubxids);
-       }
-       else
-           subxids = NULL;
-
-       TransactionTreeSetCommitTsData(setts->mainxid, nsubxids, subxids,
-                                      setts->timestamp, setts->nodeid, false);
-       if (subxids)
-           pfree(subxids);
-   }
    else
        elog(PANIC, "commit_ts_redo: unknown op code %u", info);
 }
index 3137cb3ecc153fffaeb40ba27859c1d795799d03..b6581349a35bd3dd4dc0deb66beff9b259110a05 100644 (file)
@@ -2246,7 +2246,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
 
    TransactionTreeSetCommitTsData(xid, nchildren, children,
                                   replorigin_session_origin_timestamp,
-                                  replorigin_session_origin, false);
+                                  replorigin_session_origin);
 
    /*
     * We don't currently try to sleep before flush here ... nor is there any
index c83aa16f2ce74b293f67ad318dfb78ea47b4fc15..441445927e8d719bef19acfea61fdd2342bead4c 100644 (file)
@@ -1366,7 +1366,7 @@ RecordTransactionCommit(void)
 
        TransactionTreeSetCommitTsData(xid, nchildren, children,
                                       replorigin_session_origin_timestamp,
-                                      replorigin_session_origin, false);
+                                      replorigin_session_origin);
    }
 
    /*
@@ -5804,7 +5804,7 @@ xact_redo_commit(xl_xact_parsed_commit *parsed,
 
    /* Set the transaction commit timestamp and metadata */
    TransactionTreeSetCommitTsData(xid, parsed->nsubxacts, parsed->subxacts,
-                                  commit_time, origin_id, false);
+                                  commit_time, origin_id);
 
    if (standbyState == STANDBY_DISABLED)
    {
index 750369104ac59e9b7daed80d141bd61d88c2d361..608a1643cdd9c0cb6d041ab087bd4cc04d69e691 100644 (file)
@@ -25,7 +25,7 @@ extern bool check_track_commit_timestamp(bool *newval, void **extra,
 
 extern void TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
                                           TransactionId *subxids, TimestampTz timestamp,
-                                          RepOriginId nodeid, bool write_xlog);
+                                          RepOriginId nodeid);
 extern bool TransactionIdGetCommitTsData(TransactionId xid,
                                         TimestampTz *ts, RepOriginId *nodeid);
 extern TransactionId GetLatestCommitTsData(TimestampTz *ts,
@@ -50,7 +50,6 @@ extern int    committssyncfiletag(const FileTag *ftag, char *path);
 /* XLOG stuff */
 #define COMMIT_TS_ZEROPAGE     0x00
 #define COMMIT_TS_TRUNCATE     0x10
-#define COMMIT_TS_SETTS            0x20
 
 typedef struct xl_commit_ts_set
 {
index da94f2d472a6a1694466e2c0999536d88bfc3148..26a743b6b6c396c8dd281ff266cda37091a8159b 100644 (file)
@@ -31,7 +31,7 @@
 /*
  * Each page of XLOG file has a header like this:
  */
-#define XLOG_PAGE_MAGIC 0xD10C /* can be used as WAL version indicator */
+#define XLOG_PAGE_MAGIC 0xD10D /* can be used as WAL version indicator */
 
 typedef struct XLogPageHeaderData
 {