Commit e490df51 authored by marko's avatar marko

branches/zip: Simplify the flushing of dirty pages from the buffer pool.

buf_flush_try_page(): Rename to buf_flush_page(), and change the
return type to void.  Replace the parameters space, offset with bpage,
and remove the second page hash lookup.  Note and assert that both
buf_pool_mutex and block_mutex must now be held upon entering the
function.  They will still be released by this function.

buf_flush_try_neighbors(): Replace buf_flush_try_page() with
buf_flush_page().  Make the logic easier to follow by not negating the
precondition of buf_flush_page().

rb://73 approved by Sunny Bains.  This is related to Issue #157.
parent 970a4390
...@@ -725,46 +725,31 @@ buf_flush_write_block_low( ...@@ -725,46 +725,31 @@ buf_flush_write_block_low(
} }
/************************************************************************ /************************************************************************
Writes a page asynchronously from the buffer buf_pool to a file, if it can be Writes a flushable page asynchronously from the buffer pool to a file.
found in the buf_pool and it is in a flushable state. NOTE: in simulated aio NOTE: in simulated aio we must call
we must call os_aio_simulated_wake_handler_threads after we have posted a batch os_aio_simulated_wake_handler_threads after we have posted a batch of
of writes! */ writes! NOTE: buf_pool_mutex and buf_page_get_mutex(bpage) must be
held upon entering this function, and they will be released by this
function. */
static static
ulint void
buf_flush_try_page( buf_flush_page(
/*===============*/ /*===========*/
/* out: 1 if a page was buf_page_t* bpage, /* in: buffer control block */
flushed, 0 otherwise */
ulint space, /* in: space id */
ulint offset, /* in: page offset */
enum buf_flush flush_type) /* in: BUF_FLUSH_LRU enum buf_flush flush_type) /* in: BUF_FLUSH_LRU
or BUF_FLUSH_LIST */ or BUF_FLUSH_LIST */
{ {
buf_page_t* bpage;
mutex_t* block_mutex; mutex_t* block_mutex;
ibool is_uncompressed; ibool is_uncompressed;
ut_ad(flush_type == BUF_FLUSH_LRU || flush_type == BUF_FLUSH_LIST); ut_ad(flush_type == BUF_FLUSH_LRU || flush_type == BUF_FLUSH_LIST);
ut_ad(buf_pool_mutex_own());
ut_ad(buf_page_in_file(bpage));
buf_pool_mutex_enter();
bpage = buf_page_hash_get(space, offset);
if (!bpage) {
buf_pool_mutex_exit();
return(0);
}
ut_a(buf_page_in_file(bpage));
block_mutex = buf_page_get_mutex(bpage); block_mutex = buf_page_get_mutex(bpage);
ut_ad(mutex_own(block_mutex));
mutex_enter(block_mutex); ut_ad(buf_flush_ready_for_flush(bpage, flush_type));
if (!buf_flush_ready_for_flush(bpage, flush_type)) {
mutex_exit(block_mutex);
buf_pool_mutex_exit();
return(0);
}
buf_page_set_io_fix(bpage, BUF_IO_WRITE); buf_page_set_io_fix(bpage, BUF_IO_WRITE);
...@@ -852,8 +837,6 @@ buf_flush_try_page( ...@@ -852,8 +837,6 @@ buf_flush_try_page(
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
buf_flush_write_block_low(bpage); buf_flush_write_block_low(bpage);
return(1);
} }
/*************************************************************** /***************************************************************
...@@ -903,21 +886,20 @@ buf_flush_try_neighbors( ...@@ -903,21 +886,20 @@ buf_flush_try_neighbors(
for (i = low; i < high; i++) { for (i = low; i < high; i++) {
bpage = buf_page_hash_get(space, i); bpage = buf_page_hash_get(space, i);
ut_a(!bpage || buf_page_in_file(bpage));
if (!bpage) { if (!bpage) {
continue; continue;
}
} else if (flush_type == BUF_FLUSH_LRU && i != offset ut_a(buf_page_in_file(bpage));
&& !buf_page_is_old(bpage)) {
/* We avoid flushing 'non-old' blocks in an LRU flush,
because the flushed blocks are soon freed */
continue; /* We avoid flushing 'non-old' blocks in an LRU flush,
} else { because the flushed blocks are soon freed */
if (flush_type != BUF_FLUSH_LRU
|| i == offset
|| buf_page_is_old(bpage)) {
mutex_t* block_mutex = buf_page_get_mutex(bpage); mutex_t* block_mutex = buf_page_get_mutex(bpage);
mutex_enter(block_mutex); mutex_enter(block_mutex);
...@@ -932,23 +914,14 @@ buf_flush_try_neighbors( ...@@ -932,23 +914,14 @@ buf_flush_try_neighbors(
flush the doublewrite buffer before we start flush the doublewrite buffer before we start
waiting. */ waiting. */
buf_pool_mutex_exit(); buf_flush_page(bpage, flush_type);
ut_ad(!mutex_own(block_mutex));
mutex_exit(block_mutex); count++;
/* Note: as we release the buf_pool mutex
above, in buf_flush_try_page we cannot be sure
the page is still in a flushable state:
therefore we check it again inside that
function. */
count += buf_flush_try_page(space, i,
flush_type);
buf_pool_mutex_enter(); buf_pool_mutex_enter();
} else {
mutex_exit(block_mutex);
} }
mutex_exit(block_mutex);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment