Remove non-fast promotion.
authorFujii Masao <fujii@postgresql.org>
Wed, 29 Jul 2020 12:24:26 +0000 (21:24 +0900)
committerFujii Masao <fujii@postgresql.org>
Wed, 29 Jul 2020 12:24:26 +0000 (21:24 +0900)
When fast promotion was supported in 9.3, non-fast promotion became
undocumented feature and it's basically not available for ordinary users.
However we decided not to remove non-fast promotion at that moment,
to leave it for a release or two for debugging purpose or as an emergency
method because fast promotion might have some issues, and then to
remove it later. Now, several versions were released since that decision
and there is no longer reason to keep supporting non-fast promotion.
Therefore this commit removes non-fast promotion.

Author: Fujii Masao
Reviewed-by: Hamid Akhtar, Kyotaro Horiguchi
Discussion: https://postgr.es/m/76066434-648f-f567-437b-54853b43398f@oss.nttdata.com

src/backend/access/transam/xlog.c
src/backend/postmaster/postmaster.c
src/bin/pg_ctl/pg_ctl.c
src/include/access/xlog.h

index 184c6672f3be0d1a6ae66c6ea43819f5c72e6b7f..756b838e6a54368c217b439e470ae3fcfb4d387d 100644 (file)
@@ -299,9 +299,6 @@ bool        wal_receiver_create_temp_slot = false;
 /* are we currently in standby mode? */
 bool       StandbyMode = false;
 
-/* whether request for fast promotion has been made yet */
-static bool fast_promote = false;
-
 /*
  * if recoveryStopsBefore/After returns true, it saves information of the stop
  * point here
@@ -6322,7 +6319,7 @@ StartupXLOG(void)
    DBState     dbstate_at_startup;
    XLogReaderState *xlogreader;
    XLogPageReadPrivate private;
-   bool        fast_promoted = false;
+   bool        promoted = false;
    struct stat st;
 
    /*
@@ -7727,14 +7724,14 @@ StartupXLOG(void)
         * the rule that TLI only changes in shutdown checkpoints, which
         * allows some extra error checking in xlog_redo.
         *
-        * In fast promotion, only create a lightweight end-of-recovery record
+        * In promotion, only create a lightweight end-of-recovery record
         * instead of a full checkpoint. A checkpoint is requested later,
         * after we're fully out of recovery mode and already accepting
         * queries.
         */
        if (bgwriterLaunched)
        {
-           if (fast_promote)
+           if (LocalPromoteIsTriggered)
            {
                checkPointLoc = ControlFile->checkPoint;
 
@@ -7745,7 +7742,7 @@ StartupXLOG(void)
                record = ReadCheckpointRecord(xlogreader, checkPointLoc, 1, false);
                if (record != NULL)
                {
-                   fast_promoted = true;
+                   promoted = true;
 
                    /*
                     * Insert a special WAL record to mark the end of
@@ -7762,7 +7759,7 @@ StartupXLOG(void)
                }
            }
 
-           if (!fast_promoted)
+           if (!promoted)
                RequestCheckpoint(CHECKPOINT_END_OF_RECOVERY |
                                  CHECKPOINT_IMMEDIATE |
                                  CHECKPOINT_WAIT);
@@ -7953,12 +7950,12 @@ StartupXLOG(void)
    WalSndWakeup();
 
    /*
-    * If this was a fast promotion, request an (online) checkpoint now. This
+    * If this was a promotion, request an (online) checkpoint now. This
     * isn't required for consistency, but the last restartpoint might be far
     * back, and in case of a crash, recovering from it might take a longer
     * than is appropriate now that we're not in standby mode anymore.
     */
-   if (fast_promoted)
+   if (promoted)
        RequestCheckpoint(CHECKPOINT_FORCE);
 }
 
@@ -12592,29 +12589,10 @@ CheckForStandbyTrigger(void)
    if (LocalPromoteIsTriggered)
        return true;
 
-   if (IsPromoteSignaled())
+   if (IsPromoteSignaled() && CheckPromoteSignal())
    {
-       /*
-        * In 9.1 and 9.2 the postmaster unlinked the promote file inside the
-        * signal handler. It now leaves the file in place and lets the
-        * Startup process do the unlink. This allows Startup to know whether
-        * it should create a full checkpoint before starting up (fallback
-        * mode). Fast promotion takes precedence.
-        */
-       if (stat(PROMOTE_SIGNAL_FILE, &stat_buf) == 0)
-       {
-           unlink(PROMOTE_SIGNAL_FILE);
-           unlink(FALLBACK_PROMOTE_SIGNAL_FILE);
-           fast_promote = true;
-       }
-       else if (stat(FALLBACK_PROMOTE_SIGNAL_FILE, &stat_buf) == 0)
-       {
-           unlink(FALLBACK_PROMOTE_SIGNAL_FILE);
-           fast_promote = false;
-       }
-
        ereport(LOG, (errmsg("received promote request")));
-
+       RemovePromoteSignalFiles();
        ResetPromoteSignaled();
        SetPromoteIsTriggered();
        return true;
@@ -12629,7 +12607,6 @@ CheckForStandbyTrigger(void)
                (errmsg("promote trigger file found: %s", PromoteTriggerFile)));
        unlink(PromoteTriggerFile);
        SetPromoteIsTriggered();
-       fast_promote = true;
        return true;
    }
    else if (errno != ENOENT)
@@ -12648,20 +12625,17 @@ void
 RemovePromoteSignalFiles(void)
 {
    unlink(PROMOTE_SIGNAL_FILE);
-   unlink(FALLBACK_PROMOTE_SIGNAL_FILE);
 }
 
 /*
- * Check to see if a promote request has arrived. Should be
- * called by postmaster after receiving SIGUSR1.
+ * Check to see if a promote request has arrived.
  */
 bool
 CheckPromoteSignal(void)
 {
    struct stat stat_buf;
 
-   if (stat(PROMOTE_SIGNAL_FILE, &stat_buf) == 0 ||
-       stat(FALLBACK_PROMOTE_SIGNAL_FILE, &stat_buf) == 0)
+   if (stat(PROMOTE_SIGNAL_FILE, &stat_buf) == 0)
        return true;
 
    return false;
index dec02586c7f12148d421b17089382301b2b794fa..1db6a3d29d01e935781c7a55ab6171bcd6deeb9c 100644 (file)
@@ -5333,7 +5333,12 @@ sigusr1_handler(SIGNAL_ARGS)
         pmState == PM_HOT_STANDBY || pmState == PM_WAIT_READONLY) &&
        CheckPromoteSignal())
    {
-       /* Tell startup process to finish recovery */
+       /*
+        * Tell startup process to finish recovery.
+        *
+        * Leave the promote signal file in place and let the Startup
+        * process do the unlink.
+        */
        signal_child(StartupPID, SIGUSR2);
    }
 
index 3c03ace7ed6ba3b328001775d0756c9365023d9d..1cdc3ebaa338d7b9be54b195635d3529bc4e79fd 100644 (file)
@@ -1195,11 +1195,6 @@ do_promote(void)
        exit(1);
    }
 
-   /*
-    * For 9.3 onwards, "fast" promotion is performed. Promotion with a full
-    * checkpoint is still possible by writing a file called
-    * "fallback_promote" instead of "promote"
-    */
    snprintf(promote_file, MAXPGPATH, "%s/promote", pg_data);
 
    if ((prmfile = fopen(promote_file, "w")) == NULL)
index 219a7299e1f0e5c6fbe4d5dd89b5df27a4778484..221af87e715b8e2525b31867cf4a4b7143ef17d6 100644 (file)
@@ -394,6 +394,5 @@ extern SessionBackupState get_backup_status(void);
 
 /* files to signal promotion to primary */
 #define PROMOTE_SIGNAL_FILE        "promote"
-#define FALLBACK_PROMOTE_SIGNAL_FILE  "fallback_promote"
 
 #endif                         /* XLOG_H */