checkpoint中用于控制刷盘频率的函数是什么
这篇文章主要介绍“checkpoint中用于控制刷盘频率的函数是什么”,在日常操作中,相信很多人在checkpoint中用于控制刷盘频率的函数是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”checkpoint中用于控制刷盘频率的函数是什么”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
一、数据结构宏定义
checkpoints request flag bits
checkpoints request flag bits,检查点请求标记位定义.
/**OR-ablerequestflagbitsforcheckpoints.The"cause"bitsareusedonly*forloggingpurposes.Note:theflagsmustbedefinedsothatit's*sensibletoORtogetherrequestflagsarisingfromdifferentrequestors.*//*ThesedirectlyaffectthebehaviorofCreateCheckPointandsubsidiaries*/#defineCHECKPOINT_IS_SHUTDOWN0x0001/*Checkpointisforshutdown*/#defineCHECKPOINT_END_OF_RECOVERY0x0002/*Likeshutdowncheckpoint,but*issuedatendofWALrecovery*/#defineCHECKPOINT_IMMEDIATE0x0004/*Doitwithoutdelays*/#defineCHECKPOINT_FORCE0x0008/*Forceevenifnoactivity*/#defineCHECKPOINT_FLUSH_ALL0x0010/*Flushallpages,includingthose*belongingtounloggedtables*//*TheseareimportanttoRequestCheckpoint*/#defineCHECKPOINT_WAIT0x0020/*Waitforcompletion*/#defineCHECKPOINT_REQUESTED0x0040/*Checkpointrequesthasbeenmade*//*Theseindicatethecauseofacheckpointrequest*/#defineCHECKPOINT_CAUSE_XLOG0x0080/*XLOGconsumption*/#defineCHECKPOINT_CAUSE_TIME0x0100/*Elapsedtime*/
WRITES_PER_ABSORB
/*intervalforcallingAbsorbSyncRequestsinCheckpointWriteDelay*///调用AbsorbSyncRequests的间隔,默认值为1000#defineWRITES_PER_ABSORB1000二、源码解读
CheckpointWriteDelay
CheckpointWriteDelay,控制checkpoint的频率,逻辑不复杂,判断checkpoint flags非CHECKPOINT_IMMEDIATE/非shutdown_requested/非CHECKPOINT_IMMEDIATE并且checkpoint处于调度中,如满足上述条件,则调用AbsorbSyncRequests处理sync,休眠100ms;不如满足上述条件,则absorb_counter计数器减一,如计数器≤0,则调用AbsorbSyncRequests处理sync.
/**CheckpointWriteDelay--controlrateofcheckpoint*控制checkpoint的频率**ThisfunctioniscalledaftereachpagewriteperformedbyBufferSync().*ItisresponsibleforthrottlingBufferSync()'swriteratetohit*checkpoint_completion_target.**Thecheckpointrequestflagsshouldbepassedin;currentlytheonlyone*examinedisCHECKPOINT_IMMEDIATE,whichdisablesdelaysbetweenwrites.**'progress'isanestimateofhowmuchoftheworkhasbeendone,asa*fractionbetween0.0meaningnone,and1.0meaningalldone.*/voidCheckpointWriteDelay(intflags,doubleprogress){staticintabsorb_counter=WRITES_PER_ABSORB;/*Donothingifcheckpointisbeingexecutedbynon-checkpointerprocess*/if(!AmCheckpointerProcess())return;/**Performtheusualdutiesandtakeanap,unlesswe'rebehindschedule,*inwhichcasewejusttrytocatchupasquicklyaspossible.*/if(!(flags&CHECKPOINT_IMMEDIATE)&&//非CHECKPOINT_IMMEDIATE!shutdown_requested&&//非关闭请求!ImmediateCheckpointRequested()&&//非CHECKPOINT_IMMEDIATEIsCheckpointOnSchedule(progress))//处于checkpoint调度中{if(got_SIGHUP){got_SIGHUP=false;ProcessConfigFile(PGC_SIGHUP);/*updateshmemcopiesofconfigvariables*/UpdateSharedMemoryConfig();}//Absorb吸收(处理)同步请求AbsorbSyncRequests();//重置为WRITES_PER_ABSORB(1000)absorb_counter=WRITES_PER_ABSORB;//检查归档是否超时CheckArchiveTimeout();/**Reportinterimactivitystatisticstothestatscollector.*///统计信息pgstat_send_bgwriter();/**Thissleepusedtobeconnectedtobgwriter_delay,typically200ms.*Thatresultedinmorefrequentwakeupsifnotmuchworktodo.*CheckpointerandbgwriterarenolongerrelatedsotaketheBig*Sleep.*///休眠100mspg_usleep(100000L);}elseif(--absorb_counter<=0)//Absorb计数器减一{//如计数器小于等于0/**AbsorbpendingfsyncrequestsaftereachWRITES_PER_ABSORBwrite*operationsevenwhenwedon'tsleep,topreventoverflowofthe*fsyncrequestqueue.*///Absorb同步请求AbsorbSyncRequests();//重置计数器absorb_counter=WRITES_PER_ABSORB;}}
到此,关于“checkpoint中用于控制刷盘频率的函数是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。