new_smart_shutdown_20100331.patch

application/octet-stream

Filename: new_smart_shutdown_20100331.patch
Type: application/octet-stream
Part: 0
Message: Re: pending patch: Re: HS/SR and smart shutdown

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: context
File+
src/backend/postmaster/postmaster.c 28 0
*** a/src/backend/postmaster/postmaster.c
--- b/src/backend/postmaster/postmaster.c
***************
*** 278,283 **** typedef enum
--- 278,284 ----
  	PM_RECOVERY_CONSISTENT,		/* consistent recovery mode */
  	PM_RUN,						/* normal "database is alive" state */
  	PM_WAIT_BACKUP,				/* waiting for online backup mode to end */
+ 	PM_WAIT_READONLY,			/* waiting for read only backends to exit */
  	PM_WAIT_BACKENDS,			/* waiting for live backends to exit */
  	PM_SHUTDOWN,				/* waiting for bgwriter to do shutdown ckpt */
  	PM_SHUTDOWN_2,				/* waiting for archiver and walsenders to
***************
*** 2173,2179 **** pmdie(SIGNAL_ARGS)
  				/* and the walwriter too */
  				if (WalWriterPID != 0)
  					signal_child(WalWriterPID, SIGTERM);
! 				pmState = PM_WAIT_BACKUP;
  			}
  
  			/*
--- 2174,2181 ----
  				/* and the walwriter too */
  				if (WalWriterPID != 0)
  					signal_child(WalWriterPID, SIGTERM);
! 				/* online backup mode is active only when normal processing */
! 				pmState = (pmState == PM_RUN) ? PM_WAIT_BACKUP : PM_WAIT_READONLY;
  			}
  
  			/*
***************
*** 2209,2214 **** pmdie(SIGNAL_ARGS)
--- 2211,2217 ----
  			}
  			if (pmState == PM_RUN ||
  				pmState == PM_WAIT_BACKUP ||
+ 				pmState == PM_WAIT_READONLY ||
  				pmState == PM_WAIT_BACKENDS ||
  				pmState == PM_RECOVERY_CONSISTENT)
  			{
***************
*** 2771,2776 **** HandleChildCrash(int pid, int exitstatus, const char *procname)
--- 2774,2780 ----
  		pmState == PM_RECOVERY_CONSISTENT ||
  		pmState == PM_RUN ||
  		pmState == PM_WAIT_BACKUP ||
+ 		pmState == PM_WAIT_READONLY ||
  		pmState == PM_SHUTDOWN)
  		pmState = PM_WAIT_BACKENDS;
  }
***************
*** 2847,2852 **** PostmasterStateMachine(void)
--- 2851,2879 ----
  	}
  
  	/*
+ 	 * If we are in a state-machine state that implies waiting for read only
+ 	 * backends to exit, see if they're all gone, and change state if so.
+ 	 */
+ 	if (pmState == PM_WAIT_READONLY)
+ 	{
+ 		/*
+ 		 * PM_WAIT_READONLY state ends when we have no regular backends that
+ 		 * have been started during recovery. Since those backends might be
+ 		 * waiting for the WAL record that conflicts with their queries to be
+ 		 * replayed, recovery and replication need to remain until all read
+ 		 * only backends have been gone away.
+ 		 */
+ 		if (CountChildren(BACKEND_TYPE_NORMAL) == 0)
+ 		{
+ 			if (StartupPID != 0)
+ 				signal_child(StartupPID, SIGTERM);
+ 			if (WalReceiverPID != 0)
+ 				signal_child(WalReceiverPID, SIGTERM);
+ 			pmState = PM_WAIT_BACKENDS;
+ 		}
+ 	}
+ 
+ 	/*
  	 * If we are in a state-machine state that implies waiting for backends to
  	 * exit, see if they're all gone, and change state if so.
  	 */