From 134aff29d03592d59fdf6c7b42270106889a142e Mon Sep 17 00:00:00 2001 From: marko <> Date: Mon, 15 Jan 2007 16:51:39 +0000 Subject: [PATCH] branches/zip: When adding a page to the buffer pool, add it to buf_pool->page_hash and buf_pool->LRU before releasing buf_pool->mutex. buf_page_init_for_read(), buf_page_create(): Allocate the compressed page after the block has been added to the buffer pool. Document the reason for this. --- buf/buf0buf.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/buf/buf0buf.c b/buf/buf0buf.c index d55346dd9a4..aec0153b13c 100644 --- a/buf/buf0buf.c +++ b/buf/buf0buf.c @@ -2231,15 +2231,6 @@ err_exit: ut_ad(block); - if (zip_size) { - void* data; - page_zip_set_size(&block->page.zip, zip_size); - mutex_exit(&block->mutex); - data = buf_buddy_alloc(zip_size, TRUE); - mutex_enter(&block->mutex); - block->page.zip.data = data; - } - buf_page_init(space, offset, block); /* The block must be put to the LRU list, to the old blocks */ @@ -2250,6 +2241,21 @@ err_exit: buf_pool->n_pend_reads++; + if (zip_size) { + void* data; + page_zip_set_size(&block->page.zip, zip_size); + mutex_exit(&block->mutex); + /* buf_pool->mutex may be released and reacquired by + buf_buddy_alloc(). Thus, we must release block->mutex + in order not to break the latching order in + the reacquisition of buf_pool->mutex. We also must + defer this operation until after the block descriptor + has been added to buf_pool->LRU and buf_pool->page_hash. */ + data = buf_buddy_alloc(zip_size, TRUE); + mutex_enter(&block->mutex); + block->page.zip.data = data; + } + /* We set a pass-type x-lock on the frame because then the same thread which called for the read operation (and is running now at this point of code) can wait for the read to complete by waiting @@ -2326,11 +2332,6 @@ buf_page_create( block = free_block; - if (zip_size) { - page_zip_set_size(&block->page.zip, zip_size); - block->page.zip.data = buf_buddy_alloc(zip_size, TRUE); - } - mutex_enter(&block->mutex); buf_page_init(space, offset, block); @@ -2341,6 +2342,21 @@ buf_page_create( buf_block_buf_fix_inc(block, __FILE__, __LINE__); buf_pool->n_pages_created++; + if (zip_size) { + void* data; + page_zip_set_size(&block->page.zip, zip_size); + mutex_exit(&block->mutex); + /* buf_pool->mutex may be released and reacquired by + buf_buddy_alloc(). Thus, we must release block->mutex + in order not to break the latching order in + the reacquisition of buf_pool->mutex. We also must + defer this operation until after the block descriptor + has been added to buf_pool->LRU and buf_pool->page_hash. */ + data = buf_buddy_alloc(zip_size, TRUE); + mutex_enter(&block->mutex); + block->page.zip.data = data; + } + mutex_exit(&(buf_pool->mutex)); mtr_memo_push(mtr, block, MTR_MEMO_BUF_FIX);