Skip to content

Commit 2cedbf4

Browse files
committed
Added some codes to flush dirty pages in TWB
1 parent 801c78a commit 2cedbf4

File tree

1 file changed

+96
-24
lines changed

1 file changed

+96
-24
lines changed

storage/innobase/buf/buf0flu.cc

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,32 +2269,104 @@ buf_flush_LRU_list(
22692269

22702270
ut_ad(buf_pool);
22712271

2272-
/* srv_LRU_scan_depth can be arbitrarily large value.
2273-
We cap it with current LRU size. */
2274-
buf_pool_mutex_enter(buf_pool);
2275-
scan_depth = UT_LIST_GET_LEN(buf_pool->LRU);
2276-
if (buf_pool->curr_size < buf_pool->old_size
2277-
&& buf_pool->withdraw_target > 0) {
2278-
withdraw_depth = buf_pool->withdraw_target
2279-
- UT_LIST_GET_LEN(buf_pool->withdraw);
2280-
} else {
2281-
withdraw_depth = 0;
2282-
}
2283-
buf_pool_mutex_exit(buf_pool);
2272+
/* mijin */
2273+
try_again:
2274+
buf_pool_mutex_enter(buf_pool);
2275+
2276+
bool last = false;
2277+
2278+
if (buf_pool->need_to_flush_twb) {
2279+
if (buf_pool->batch_running) {
2280+
/* Another thread is running the batch right now. Wait
2281+
for it to finish. */
2282+
ib_int64_t sig_count = os_event_reset(buf_pool->b_event);
2283+
buf_pool_mutex_exit(buf_pool);
2284+
2285+
os_event_wait_low(buf_pool->b_event, sig_count);
2286+
goto try_again;
2287+
}
22842288

2285-
if (withdraw_depth > srv_LRU_scan_depth) {
2286-
scan_depth = ut_min(withdraw_depth, scan_depth);
2287-
} else {
2288-
scan_depth = ut_min(static_cast<ulint>(srv_LRU_scan_depth),
2289-
scan_depth);
2290-
}
2289+
buf_pool->flush_running = true;
2290+
2291+
for (ulint i = 0; i < buf_pool->first_free; i++) {
2292+
2293+
buf_block_t* block = &buf_pool->twb_block_arr[i];
2294+
buf_page_t* bpage;
2295+
2296+
/* Copy buffer frame from write_buf to tmp_buf. */
2297+
memcpy(block->frame, buf_pool->write_buf + (i * UNIV_PAGE_SIZE), UNIV_PAGE_SIZE);
2298+
2299+
/* Extract a page from the buffer frame. */
2300+
bpage = &block->page;
2301+
2302+
bpage->id.space() = mach_read_from_4(block->frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
2303+
bpage->id.page_no() = mach_read_from_4(block->frame + FIL_PAGE_OFFSET);
2304+
2305+
/* TODO: need to fix lsn part!! */
2306+
bpage->newest_modification = mach_read_from_8(block->frame + FIL_PAGE_LSN);
2307+
bpage->oldest_modification = mach_read_from_8(block->frame + FIL_PAGE_LSN);
2308+
bpage->state = BUF_BLOCK_FILE_PAGE;
2309+
bpage->copy_target = true;
2310+
bpage->buf_pool_index = buf_pool->instance_no;
2311+
2312+
if ((i + 1) == buf_pool->first_free) {
2313+
last = true;
2314+
}
2315+
2316+
/* Flush the target page. */
2317+
mutex_enter(&block->mutex);
2318+
2319+
if (buf_flush_page(buf_pool, bpage, BUF_FLUSH_LRU, false)) {
2320+
n_flushed++;
2321+
} else {
2322+
mutex_exit(&block->mutex);
2323+
}
2324+
2325+
if (last) {
2326+
buf_dblwr_flush_buffered_writes();
2327+
last = false;
2328+
}
2329+
2330+
buf_pool_mutex_enter(buf_pool);
2331+
}
2332+
2333+
buf_pool->first_free = 0;
2334+
buf_pool->need_to_flush_twb = false;
2335+
2336+
buf_pool->flush_running = false;
2337+
os_event_set(buf_pool->f_event);
2338+
2339+
buf_pool_mutex_exit(buf_pool);
2340+
} else {
2341+
/* end */
2342+
2343+
/* srv_LRU_scan_depth can be arbitrarily large value.
2344+
We cap it with current LRU size. */
2345+
buf_pool_mutex_enter(buf_pool);
2346+
scan_depth = UT_LIST_GET_LEN(buf_pool->LRU);
2347+
if (buf_pool->curr_size < buf_pool->old_size
2348+
&& buf_pool->withdraw_target > 0) {
2349+
withdraw_depth = buf_pool->withdraw_target
2350+
- UT_LIST_GET_LEN(buf_pool->withdraw);
2351+
} else {
2352+
withdraw_depth = 0;
2353+
}
2354+
buf_pool_mutex_exit(buf_pool);
2355+
2356+
if (withdraw_depth > srv_LRU_scan_depth) {
2357+
scan_depth = ut_min(withdraw_depth, scan_depth);
2358+
} else {
2359+
scan_depth = ut_min(static_cast<ulint>(srv_LRU_scan_depth),
2360+
scan_depth);
2361+
}
22912362

2292-
/* Currently one of page_cleaners is the only thread
2293-
that can trigger an LRU flush at the same time.
2294-
So, it is not possible that a batch triggered during
2295-
last iteration is still running, */
2296-
buf_flush_do_batch(buf_pool, BUF_FLUSH_LRU, scan_depth,
2297-
0, &n_flushed);
2363+
/* Currently one of page_cleaners is the only thread
2364+
that can trigger an LRU flush at the same time.
2365+
So, it is not possible that a batch triggered during
2366+
last iteration is still running, */
2367+
buf_flush_do_batch(buf_pool, BUF_FLUSH_LRU, scan_depth,
2368+
0, &n_flushed);
2369+
}
22982370

22992371
return(n_flushed);
23002372
}

0 commit comments

Comments
 (0)