Commit c5be47e7 authored by marko's avatar marko

branches/zip: Remove most direct references to block->state.

buf_block_set_state(): New function.  Also checks the state transitions.

buf_block_set_file_page(): New function.
parent 6c8dfab1
......@@ -835,7 +835,7 @@ btr_search_guess_on_hash(
goto failure;
}
ut_ad(block->state == BUF_BLOCK_FILE_PAGE);
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
ut_ad(page_rec_is_user_rec(rec));
btr_cur_position(index, rec, block, cursor);
......
......@@ -1400,7 +1400,7 @@ loop:
block = guess;
if ((offset != block->offset) || (space != block->space)
|| (block->state != BUF_BLOCK_FILE_PAGE)) {
|| buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE) {
block = NULL;
}
......@@ -1471,7 +1471,7 @@ loop:
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
ut_a(++buf_dbg_counter % 5771 || buf_validate());
ut_a(block->buf_fix_count > 0);
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
if (mode == BUF_GET_NOWAIT) {
......@@ -1649,7 +1649,7 @@ buf_page_optimistic_get_func(
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
ut_a(++buf_dbg_counter % 5771 || buf_validate());
ut_a(block->buf_fix_count > 0);
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
#ifdef UNIV_DEBUG_FILE_ACCESSES
......@@ -1753,7 +1753,7 @@ buf_page_get_known_nowait(
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
ut_a(++buf_dbg_counter % 5771 || buf_validate());
ut_a(block->buf_fix_count > 0);
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
#ifdef UNIV_DEBUG_FILE_ACCESSES
ut_a(block->file_page_was_freed == FALSE);
......@@ -1785,9 +1785,7 @@ buf_page_init_for_backup_restore(
/* Set the state of the block */
block->magic_n = BUF_BLOCK_MAGIC_N;
block->state = BUF_BLOCK_FILE_PAGE;
block->space = space;
block->offset = offset;
buf_block_set_file_page(block, space, offset);
block->lock_hash_val = 0;
......@@ -1837,9 +1835,7 @@ buf_page_init(
/* Set the state of the block */
block->magic_n = BUF_BLOCK_MAGIC_N;
block->state = BUF_BLOCK_FILE_PAGE;
block->space = space;
block->offset = offset;
buf_block_set_file_page(block, space, offset);
block->check_index_page_at_flush = FALSE;
block->index = NULL;
......@@ -2438,6 +2434,12 @@ buf_validate(void)
case BUF_BLOCK_NOT_USED:
n_free++;
break;
case BUF_BLOCK_READY_FOR_USE:
case BUF_BLOCK_MEMORY:
case BUF_BLOCK_REMOVE_HASH:
/* do nothing */
break;
}
mutex_exit(&block->mutex);
......@@ -2604,7 +2606,8 @@ buf_get_latched_pages_number(void)
block = chunk->blocks;
for (j = chunk->size; j--; block++) {
if (block->magic_n != BUF_BLOCK_MAGIC_N) {
if (buf_block_get_state(block)
!= BUF_BLOCK_FILE_PAGE) {
continue;
}
......
......@@ -463,7 +463,7 @@ loop:
mutex_enter(&block->mutex);
block->state = BUF_BLOCK_READY_FOR_USE;
buf_block_set_state(block, BUF_BLOCK_READY_FOR_USE);
UNIV_MEM_VALID(block->frame, UNIV_PAGE_SIZE);
mutex_exit(&block->mutex);
......@@ -868,7 +868,7 @@ buf_LRU_block_free_non_file_page(
ut_ad(block->n_pointers == 0);
ut_a(!block->in_free_list);
block->state = BUF_BLOCK_NOT_USED;
buf_block_set_state(block, BUF_BLOCK_NOT_USED);
#ifdef UNIV_DEBUG
/* Wipe contents of page to reveal possible stale pointers to it */
......@@ -953,7 +953,7 @@ buf_LRU_block_remove_hashed_page(
memset(block->frame + FIL_PAGE_OFFSET, 0xff, 4);
memset(block->frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 0xff, 4);
block->state = BUF_BLOCK_REMOVE_HASH;
buf_block_set_state(block, BUF_BLOCK_REMOVE_HASH);
}
/**********************************************************************
......@@ -971,7 +971,7 @@ buf_LRU_block_free_hashed_page(
#endif /* UNIV_SYNC_DEBUG */
ut_a(buf_block_get_state(block) == BUF_BLOCK_REMOVE_HASH);
block->state = BUF_BLOCK_MEMORY;
buf_block_set_state(block, BUF_BLOCK_MEMORY);
buf_LRU_block_free_non_file_page(block);
}
......
......@@ -543,6 +543,23 @@ buf_block_get_state(
const buf_block_t* block) /* in: pointer to the control block */
__attribute__((pure));
/*************************************************************************
Sets the state of a block. */
UNIV_INLINE
void
buf_block_set_state(
/*================*/
buf_block_t* block, /* in/out: pointer to control block */
enum buf_block_state state); /* in: state */
/*************************************************************************
Map a block to a file page. */
UNIV_INLINE
void
buf_block_set_file_page(
/*====================*/
buf_block_t* block, /* in/out: pointer to control block */
ulint space, /* in: tablespace id */
ulint page_no);/* in: page number */
/*************************************************************************
Gets a pointer to the memory frame of a block. */
UNIV_INLINE
buf_frame_t*
......
......@@ -109,6 +109,55 @@ buf_block_get_state(
return(state);
}
/*************************************************************************
Sets the state of a block. */
UNIV_INLINE
void
buf_block_set_state(
/*================*/
buf_block_t* block, /* in/out: pointer to control block */
enum buf_block_state state) /* in: state */
{
#ifdef UNIV_DEBUG
enum buf_block_state old_state = buf_block_get_state(block);
switch (old_state) {
case BUF_BLOCK_NOT_USED:
ut_a(state == BUF_BLOCK_READY_FOR_USE);
break;
case BUF_BLOCK_READY_FOR_USE:
ut_a(state == BUF_BLOCK_MEMORY
|| state == BUF_BLOCK_FILE_PAGE);
break;
case BUF_BLOCK_MEMORY:
ut_a(state == BUF_BLOCK_NOT_USED);
break;
case BUF_BLOCK_FILE_PAGE:
ut_a(state == BUF_BLOCK_NOT_USED
|| state == BUF_BLOCK_REMOVE_HASH);
break;
case BUF_BLOCK_REMOVE_HASH:
ut_a(state == BUF_BLOCK_MEMORY);
break;
}
#endif /* UNIV_DEBUG */
block->state = state;
ut_ad(buf_block_get_state(block) == state);
}
/*************************************************************************
Map a block to a file page. */
UNIV_INLINE
void
buf_block_set_file_page(
/*====================*/
buf_block_t* block, /* in/out: pointer to control block */
ulint space, /* in: tablespace id */
ulint page_no)/* in: page number */
{
buf_block_set_state(block, BUF_BLOCK_FILE_PAGE);
block->space = space;
block->offset = page_no;
}
/*************************************************************************
Gets a pointer to the memory frame of a block. */
......@@ -120,8 +169,8 @@ buf_block_get_frame(
buf_block_t* block) /* in: pointer to the control block */
{
ut_ad(block);
ut_ad(block->state != BUF_BLOCK_NOT_USED);
ut_ad((block->state != BUF_BLOCK_FILE_PAGE)
ut_ad(buf_block_get_state(block) != BUF_BLOCK_NOT_USED);
ut_ad(buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE
|| (block->buf_fix_count > 0));
return(block->frame);
......@@ -137,7 +186,7 @@ buf_block_get_space(
const buf_block_t* block) /* in: pointer to the control block */
{
ut_ad(block);
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
ut_ad(block->buf_fix_count > 0);
return(block->space);
......@@ -153,7 +202,7 @@ buf_block_get_page_no(
const buf_block_t* block) /* in: pointer to the control block */
{
ut_ad(block);
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
ut_ad(block->buf_fix_count > 0);
return(block->offset);
......@@ -341,7 +390,7 @@ buf_page_io_query(
{
mutex_enter(&(buf_pool->mutex));
ut_ad(block->state == BUF_BLOCK_FILE_PAGE);
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
ut_ad(block->buf_fix_count > 0);
if (block->io_fix != 0) {
......
......@@ -38,7 +38,7 @@ buf_flush_note_modification(
mtr_t* mtr) /* in: mtr */
{
ut_ad(block);
ut_ad(block->state == BUF_BLOCK_FILE_PAGE);
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
ut_ad(block->buf_fix_count > 0);
#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
......@@ -78,7 +78,7 @@ buf_flush_recv_note_modification(
set of mtr's */
{
ut_ad(block);
ut_ad(block->state == BUF_BLOCK_FILE_PAGE);
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
ut_ad(block->buf_fix_count > 0);
#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
......
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