Remove BgWriterRecoveryProcessingMode, in favor of a local variable
authorHeikki Linnakangas <heikki@enterprisedb.com>
Wed, 18 Feb 2009 07:59:44 +0000 (09:59 +0200)
committerHeikki Linnakangas <heikki@enterprisedb.com>
Wed, 18 Feb 2009 07:59:44 +0000 (09:59 +0200)
just where we decide whether to perform a checkpoint or restartpoint.

src/backend/postmaster/bgwriter.c

index 79aa36dc3ad46e237f8d85b5a63e4e2b9718e11e..e10ec20414de4b2ead2e8949bf93ea624a8d9a05 100644 (file)
@@ -198,7 +198,6 @@ BackgroundWriterMain(void)
 {
        sigjmp_buf      local_sigjmp_buf;
        MemoryContext bgwriter_context;
-       bool            BgWriterRecoveryMode = true;
 
        BgWriterShmem->bgwriter_pid = MyProcPid;
        am_bg_writer = true;
@@ -419,20 +418,6 @@ BackgroundWriterMain(void)
                        flags |= CHECKPOINT_CAUSE_TIME;
                }
 
-               /*
-                * Check if we've exited recovery. We do this after determining
-                * whether to perform a checkpoint or not, to be sure that we
-                * perform a real checkpoint and not a restartpoint, if someone
-                * requested a checkpoint immediately after exiting recovery. And
-                * we must have the right TimeLineID when we perform a checkpoint;
-                * IsRecoveryProcessingMode() initializes that as a side-effect.
-                */
-               if (BgWriterRecoveryMode && !IsRecoveryProcessingMode())
-               {
-                       elog(DEBUG1, "bgwriter changing from recovery to normal mode");
-                       BgWriterRecoveryMode = false;
-               }
-
                /*
                 * Do a checkpoint if requested, otherwise do one cycle of
                 * dirty-buffer writing.
@@ -440,10 +425,18 @@ BackgroundWriterMain(void)
                if (do_checkpoint)
                {
                        bool    ckpt_performed = false;
+                       bool    do_restartpoint;
 
                        /* use volatile pointer to prevent code rearrangement */
                        volatile BgWriterShmemStruct *bgs = BgWriterShmem;
 
+                       /*
+                        * Check if we should perform a checkpoint or a restartpoint.
+                        * As a side-effect, IsRecoveryProcessingMode() initializes
+                        * TimeLineID if it's not set yet.
+                        */
+                       do_restartpoint = IsRecoveryProcessingMode();
+
                        /*
                         * Atomically fetch the request flags to figure out what kind of a
                         * checkpoint we should perform, and increase the started-counter
@@ -462,7 +455,7 @@ BackgroundWriterMain(void)
                         * implementation will not generate warnings caused by
                         * CheckPointTimeout < CheckPointWarning.
                         */
-                       if (!BgWriterRecoveryMode &&
+                       if (!do_restartpoint &&
                                (flags & CHECKPOINT_CAUSE_XLOG) &&
                                elapsed_secs < CheckPointWarning)
                                ereport(LOG,
@@ -474,7 +467,7 @@ BackgroundWriterMain(void)
                         * Initialize bgwriter-private variables used during checkpoint.
                         */
                        ckpt_active = true;
-                       if (!BgWriterRecoveryMode)
+                       if (!do_restartpoint)
                                ckpt_start_recptr = GetInsertRecPtr();
                        ckpt_start_time = now;
                        ckpt_cached_elapsed = 0;
@@ -482,7 +475,7 @@ BackgroundWriterMain(void)
                        /*
                         * Do the checkpoint.
                         */
-                       if (!BgWriterRecoveryMode)
+                       if (!do_restartpoint)
                        {
                                CreateCheckPoint(flags);
                                ckpt_performed = true;