PostgreSQL何时执行checkpoint--发送checkpoint信号的函数

RequestCheckpoint(int flags):
	/*
	1、如果checkpoint进程没有起来,则尝试20次大概2s
	2、通过kill命令向checkpoint进程发送信号,通知做checkpoint,发送成功则退出循环,否则也尝试20次
	*/
	for (ntries = 0;; ntries++){
		if (CheckpointerShmem->checkpointer_pid == 0){
			if (ntries >= 20){	/* max wait 2.0 sec */
				elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG,
					 "could not request checkpoint because checkpointer not running");
				break;
			}
		}else if (kill(CheckpointerShmem->checkpointer_pid, SIGINT) != 0){
			if (ntries >= 20){	/* max wait 2.0 sec */
				elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG,
					 "could not signal for checkpoint: %m");
				break;
			}
		}else
			break;				/* signal sent successfully */
		CHECK_FOR_INTERRUPTS();
		pg_usleep(100000L);		/* wait 0.1 sec, then retry */
	}
	if (flags & CHECKPOINT_WAIT){
		for (;;){//等待checkpoint开始
			SpinLockAcquire(&CheckpointerShmem->ckpt_lck);
			new_started = CheckpointerShmem->ckpt_started;//checkpoint开始前会++
			SpinLockRelease(&CheckpointerShmem->ckpt_lck);

			if (new_started != old_started)
				break;

			CHECK_FOR_INTERRUPTS();
			pg_usleep(100000L);
		}
		for (;;){//等待checkpoint结束
			SpinLockAcquire(&CheckpointerShmem->ckpt_lck);
			new_done = CheckpointerShmem->ckpt_done;//checkpoint结束会++
			new_failed = CheckpointerShmem->ckpt_failed;
			SpinLockRelease(&CheckpointerShmem->ckpt_lck);

			if (new_done - new_started >= 0)
				break;

			CHECK_FOR_INTERRUPTS();
			pg_usleep(100000L);
		}
	}

 

你可能感兴趣的:(PostgreSQL何时执行checkpoint--发送checkpoint信号的函数)