【MySQL】SHOW ENGINE INNODB STATUS \G之Pages flushed up to的理解
1)前言以及問題:
我們現在先看截圖
Log sequence number --內存中日志產生的序列號
Log flushed up to --刷入redo日志的值,字節數
Pages flushed up to --這里正是我要講的問題,后面詳述
Last checkpoint at --最后一次檢查點的位置
這里Pages flushed up to到底是什么?而且數據庫沒有寫數據的情況下,總是Pages flushed up to 不等于 Last checkpoint at,這又是為何,并且Pages flushed up to - Last checkpoint at=9(這里你們可以仔細去觀察)?
查過網上資料,也問過一些大佬,答案真的是五花八門
他們中有兩種最主要的答案,一種是顧名思義,臟頁刷新到的LSN;另外一種是:new_modification LSN
2)分析:
對于第一種,說臟頁刷新到磁盤的lsn的,明顯就不成立。其實檢查點的意思就是LSN之前的數據已經落盤,這里檢查點的數據落盤就包含了臟頁的落盤;實際測試過程中Pages flushed up to 明顯大于檢查點的LSN,而且檢查點之后,就不能保證所有數據是落盤的,那么如果說Pages flushed up to 是臟頁刷新到磁盤的lsn,那么就會出現一種情況,lsn1=3000臟頁刷盤了(pages flushed up to是3000),lsn=2800的臟頁沒刷盤,那么你認為這個值有意義嗎?
對于第二種:說是flush list做檢查點的頁的new modification lsn(即一個內存page包含兩個lsn,flush list是按照頁的第一次修改的lsn排序的,只要一個頁修改就加入flush list,而new modification lsn是寫了多少字節數據,new modification lsn 就加多少);為什么數據庫最后沒做修改了,Pages flushed up to 不等于 Last checkpoint at?他們給出的答復是一個頁被多次修改。
為了更清楚,我把這些數據結構貼出來:
每個buffer pool都包含flush list
struct buf_pool_t{
...
UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
UT_LIST_BASE_NODE_T(buf_page_t) free;
...
}
class buf_page_t {
public:
...
//這個值是只要做了修改,lsn就會增加,如果一個頁在內存中沒有修改,就一直是0,也不會加入flush list
lsn_t newest_modification;
/*!< log sequence number of
the youngest modification to
this block, zero if not
modified. Protected by block
mutex */
//這個值,只要當前頁被刷入了磁盤,他的值就會置為0,第一次對頁的修改,就會加入flush list,第二次對該頁修改,此值不會增加,因為flush list 是推進檢查點的。
lsn_t oldest_modification;
/*!< log sequence number of
the START of the log entry
written of the oldest
modification to this block
which has not yet been flushed
on disk; zero if all
modifications are on disk.
Writes to this field must be
covered by both block->mutex
and buf_pool->flush_list_mutex. Hence
reads can happen while holding
any one of the two mutexes */
...
}
按照這種說法,我先繪制一個圖:
DNSYRwh5gDnMPq4xsCAQjHr2i9RqV3WYdApuwVkfnZa8T9GsGwx4Ljw6z4qPhMzy0tXu573f2VmLnOX+6PVW9zPbaz99ab2Qjh0d681wBAEPMIfZxzWB0CWvsd6jnj0itdqpQy+YCXgTkxN5v0RrKzo/NGX368+73xD43tP1yKG86/eWIzHsw4U5PaddrlyOBLmJyQlzObLrY2x87NgrriNbd/3ecqQH7j1d17vowctPI334/LtdvZNf/vA8zeiAgAeYw+zjmkDoktdY71HPHpFa7dShFwwEPDOX+TlYbC++39Mj0PPvdiMZaevgfuRg3drDW3rKuvXgZiSJVZbLkah37sI5PctNzXxgLkp2fUxOT6omqf9aHw5HEPAAc5h9XBMIXfIa6z3q2SNSq5069IKBgGfmICHFluTgxxeRQ5qf/+WRnjM/qz+M5My7j29HDuh9fOcjPWcu3JqP5MwLc7Ox9+9pPaz3gyMIeIA5zD6ukbrkNdZ71LNHpFY7degFAh7yxujoCHiAOcw+rpG65DXWe9SzR6RWO3XoBQIe8sbo6Ah5gDnMPq6RuuQ11nvUs0ekVjt16AVjAS/XOz1SbC5jdHQEPMAcZh/XSF3yGus96tkjUqudOvSCsYCX64dDUGwuY3R0BDzAHGYf10hd8hrrPerZI1KrnTr0goGANzd/hYBXZIyOjoAHmMPs4xqpS15jvUc9e0RqtVOHXiDgIW+Mjo6AB5jD7OMaqUteY71HPXtEarVTh24g4CFvjI6OgAeYw+zjGqlLXmO9Rz17RGq1U4deMBbw9r79Ir+XoNhcxujoCHiAOcw+rpG65DXWe9SzR6RWO3XoBWMBb+fNdn4vQbG5jNHREfAAc5h9XCN1yWus96hnj0itdurQCwYC3uLaAgGvy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2DBwBAGoNHWwYPAIA0y9GyHC3TM2A8gwepPWHpAAAAt0lEQVQAQJr1ZlVV0zNgPIMHAEAag0dbBg8AgDSXP7ZnV5+nZ8B4Bg8AACCEwQMAAAhh8AAAAEIYPAAAgBAGDwAAIITBAwAACGHwAAAAQhg8AACAEAYPAAAghMEDAAAIYfAAAABCGDwAAIAQBg8AACCEwQMAAAhh8AAAAEIYPAAAgBAGDwAAIITBAwAACGHwAAAAQhg8AACAEAYPAAAghMEDAAAIYfAAAABCGDwAAIAQBg8AACDEf5XF+UkhQr+9AAAAAElFTkSuQmCCAA==">
圖中flush list中,page no為3并且oldest modification lsn =400的時候,做了checkpoint了,那么按照第二種說法(Pages flushed up to的值為new modification lsn),則此時的Pages flushed lsn to的值為800;但圖中page no為4的頁的new modification lsn還沒有刷盤;這樣的話,其實Pages flushed up to這值就沒有什么意義了。
3)要想了解真相,我們就得從源碼探究
①首先找到源碼中show engine innodb status \G pages flushed up to的位置,我們發現,他調用了log_buf_pool_get_oldest_modification;從字面意思來說貌似是取buffer pool頁的oldest modification lsn,究竟是哪些頁呢,還需要探究。
log_print(
/*======*/
FILE* file) /*!< in: file where to print */
{
double time_elapsed;
time_t current_time;
log_mutex_enter();
fprintf(file,
"Log sequence number " LSN_PF "\n"
"Log flushed up to " LSN_PF "\n"
"Pages flushed up to " LSN_PF "\n"
"Last checkpoint at " LSN_PF "\n",
log_sys->lsn,
log_sys->flushed_to_disk_lsn,
log_buf_pool_get_oldest_modification(),
log_sys->last_checkpoint_lsn);
...
}
②查看log_buf_pool_get_oldest_modification源代碼
static lsn_t
log_buf_pool_get_oldest_modification(void)
/*======================================*/
{
lsn_t lsn;
ut_ad(log_mutex_own());
lsn = buf_pool_get_oldest_modification();
//這里如果buf_pool_get_oldest_modification返回LSN為0(這里的言下之意是oldest lsn為0,即數據都刷入了磁盤),則取log_sys->lsn
if (!lsn) {
lsn = log_sys->lsn;
}
return(lsn);
}
從這個函數我們可以看出,如果這時候buffer pool中數據臟頁都刷入了磁盤(同時這時候頁沒數據寫入),那么取的就是最大的LSN(log_sys->lsn),也即:show engineinnodb status顯示的Log sequence number。
③但是這里我們任然不知道oldest modification lsn是怎么取的,這就需要查看buf_pool_get_oldest_modification的源代碼:
buf_pool_get_oldest_modification(void)
/*==================================*/
{
lsn_t lsn = 0;
lsn_t oldest_lsn = 0;
/* When we traverse all the flush lists we don't want another
thread to add a dirty page to any flush list. */
log_flush_order_mutex_enter();
//遍歷所有的buffer pool
for (ulint i = 0; i < srv_buf_pool_instances; i++) {
buf_pool_t* buf_pool;
buf_pool = buf_pool_from_array(i);
buf_flush_list_mutex_enter(buf_pool);
buf_page_t* bpage;
/* We don't let log-checkpoint halt because pages from system
temporary are not yet flushed to the disk. Anyway, object
residing in system temporary doesn't generate REDO logging. */
//從這里我們可以看出bpage是取flush list中最大的oldest modifcation LSN(注意這里的邏輯,如果是系統臨時表空間,就不應該算在內)
for (bpage = UT_LIST_GET_LAST(buf_pool->flush_list);
bpage != NULL
&& fsp_is_system_temporary(bpage->id.space());
bpage = UT_LIST_GET_PREV(list, bpage)) {
/* Do nothing. */
}
if (bpage != NULL) {
ut_ad(bpage->in_flush_list);
lsn = bpage->oldest_modification;
}
buf_flush_list_mutex_exit(buf_pool);
//上面是從buffer pool中的flush list取最大oldest modication lsn的page,而這里是從每個buffer pool 的最大oldest modification lsn中取最小的oldest modification lsn 的page。
if (!oldest_lsn || oldest_lsn > lsn) {
oldest_lsn = lsn;
}
}
log_flush_order_mutex_exit();
/* The returned answer may be out of date: the flush_list can
change after the mutex has been released. */
return(oldest_lsn);
}
④到這里,我們整個流程就明朗了,pages flushed up to 取的是所有buffer pool中最大oldest modification lsn頁中的帶有最小的 oldest modification lsn的值,如果去到的oldest modification lsn為0,意味著沒有臟頁,那么我們就取log_sys->lsn的值,即show engineinnodb status顯示的Log sequence number。
舉個例子:我們的buffer pool 設置為4個;第一個buffer pool,我們取flush list 中頁帶oldest modification lsn最大值為100
第二個buffer pool,我們取flush list 中頁帶oldest modification lsn最大值為140;第三個buffer pool,我們取flush list 中頁帶oldest modification lsn最大值為98;第四個buffer pool,我們取flush list 中頁帶oldest modification lsn最大值為130;那么我們得到的pages flushed up to 就是98;
⑤我們知道了這個Pages flushed up to從哪里取的值,但是現在我并不知道這個值的含義啊
我們來看一個函數
/** Make a checkpoint. Note that this function does not flush dirty
blocks from the buffer pool: it only checks what is lsn of the oldest
modification in the pool, and writes information about the lsn in
log files. Use log_make_checkpoint_at() to flush also the pool.
**/
//從這個函數的注釋我們可以明顯知道,這個函數是用來做檢查點的
log_checkpoint(
bool sync,
bool write_always)
{
lsn_t oldest_lsn;
ut_ad(!srv_read_only_mode);
if (recv_recovery_is_on()) {
recv_apply_hashed_log_recs(TRUE);
}
#ifndef _WIN32
switch (srv_unix_file_flush_method) {
case SRV_UNIX_NOSYNC:
break;
case SRV_UNIX_O_DSYNC:
case SRV_UNIX_FSYNC:
case SRV_UNIX_LITTLESYNC:
case SRV_UNIX_O_DIRECT:
case SRV_UNIX_O_DIRECT_NO_FSYNC:
fil_flush_file_spaces(FIL_TYPE_TABLESPACE);
}
#endif /* !_WIN32 */
log_mutex_enter();
ut_ad(!recv_no_log_write);
//取得oldest LSN
oldest_lsn = log_buf_pool_get_oldest_modification();
/* Because log also contains headers and dummy log records,
log_buf_pool_get_oldest_modification() will return log_sys->lsn
if the buffer pool contains no dirty buffers.
We must make sure that the log is flushed up to that lsn.
If there are dirty buffers in the buffer pool, then our
write-ahead-logging algorithm ensures that the log has been
flushed up to oldest_lsn. */
//從這里我們可以知道為什么last checkpoint lsn跟pages flushed up to不相等了,因為在
mysql做檢查點的時候,還要打上MLOG_CHECKPOINT redo 日志,而這個MLOG_CHECKPOINT恰好占用9個字節,所以就有了在臟頁都刷盤之后,pages flushed up to-last checkpoint lsn=9
ut_ad(oldest_lsn >= log_sys->last_checkpoint_lsn);
if (!write_always
&& oldest_lsn
<= log_sys->last_checkpoint_lsn + SIZE_OF_MLOG_CHECKPOINT) {
/* Do nothing, because nothing was logged (other than
a MLOG_CHECKPOINT marker) since the previous checkpoint. */
log_mutex_exit();
return(true);
}
lsn_t flush_lsn = oldest_lsn;
const bool do_write
= srv_shutdown_state == SRV_SHUTDOWN_NONE
|| flush_lsn != log_sys->lsn;
if (fil_names_clear(flush_lsn, do_write)) {
ut_ad(log_sys->lsn >= flush_lsn + SIZE_OF_MLOG_CHECKPOINT);
flush_lsn = log_sys->lsn;
}
log_mutex_exit();
log_write_up_to(flush_lsn, true);
DBUG_EXECUTE_IF(
"using_wa_checkpoint_middle",
if (write_always) {
DEBUG_SYNC_C("wa_checkpoint_middle");
const my_bool b = TRUE;
buf_flush_page_cleaner_disabled_debug_update(
NULL, NULL, NULL, &b);
dict_stats_disabled_debug_update(
NULL, NULL, NULL, &b);
srv_master_thread_disabled_debug_update(
NULL, NULL, NULL, &b);
});
log_mutex_enter();
ut_ad(log_sys->flushed_to_disk_lsn >= flush_lsn);
ut_ad(flush_lsn >= oldest_lsn);
//檢查點大于等于oldest_lsn說明已經刷盤
if (log_sys->last_checkpoint_lsn >= oldest_lsn) {
log_mutex_exit();
return(true);
}
if (log_sys->n_pending_checkpoint_writes > 0) {
/* A checkpoint write is running */
log_mutex_exit();
if (sync) {
/* Wait for the checkpoint write to complete */
rw_lock_s_lock(&log_sys->checkpoint_lock);
rw_lock_s_unlock(&log_sys->checkpoint_lock);
}
return(false);
}
//下一次LSN的位置
log_sys->next_checkpoint_lsn = oldest_lsn;
log_write_checkpoint_info(sync);
ut_ad(!log_mutex_own());
return(true);
}
4)總結:
pages flushed up to指的是下一次即將做checkpoint lsn 的位置;在沒有新數據的寫入的情況下,
pages flushed up to取的是Log sequence number(log_sys->lsn);在沒數據寫入的情況下,為什么last checkpoint point不等于pages flushed up to?是因為做checkpoint是同時redo日志會寫MLOG_CHECKPOINT,而MLOG_CHECKPOINT占用九個字節,所以會出現pages flushed up to-last checkpoint point=9;