Commit 3d570330 authored by marko's avatar marko

branches/zip: Optimize buf_page_try_get_func().

buf_block_hash_get(): New function, similar to buf_page_hash_get().

buf_page_get_block(): Remove the const qualifiers.  This is a low-level
function, and the operations on block->mutex are non-const.

buf_page_try_get_func(): Implement with lower-level predicates, somewhat
similar to buf_page_get_known_nowait().

lock_rec_print(): Remove the unused variable zip_size and the
call to fil_space_get_zip_size().  Adapt to buf_page_try_get() returning
a const pointer.
parent 1110b563
......@@ -2196,7 +2196,7 @@ Given a tablespace id and page number tries to get that page. If the
page is not in the buffer pool it is not loaded and NULL is returned.
Suitable for using when holding the kernel mutex. */
buf_block_t*
const buf_block_t*
buf_page_try_get_func(
/*==================*/
ulint space_id,/* in: tablespace id */
......@@ -2206,33 +2206,64 @@ buf_page_try_get_func(
mtr_t* mtr) /* in: mini-transaction */
{
buf_block_t* block;
ulint zip_size;
ibool success;
ulint fix_type;
ut_ad(mtr);
mutex_enter(&buf_pool->mutex);
block = buf_block_hash_get(space_id, page_no);
if (!block) {
mutex_exit(&buf_pool->mutex);
return(NULL);
}
mutex_enter(&block->mutex);
mutex_exit(&buf_pool->mutex);
zip_size = fil_space_get_zip_size(space_id);
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
ut_a(buf_block_get_space(block) == space_id);
ut_a(buf_block_get_page_no(block) == page_no);
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
/* If the page is not in the buffer pool, we cannot load it
because we may have the kernel mutex and ibuf operations would
break the latching order */
buf_block_buf_fix_inc(block, file, line);
mutex_exit(&block->mutex);
block = buf_page_get_gen(space_id, zip_size, page_no, RW_NO_LATCH,
NULL, BUF_GET_IF_IN_POOL,
__FILE__, __LINE__, mtr);
if (block != NULL) {
block = buf_page_get_nowait(space_id, zip_size,
page_no, RW_S_LATCH, mtr);
fix_type = MTR_MEMO_PAGE_S_FIX;
success = rw_lock_s_lock_func_nowait(&block->lock, file, line);
if (block == NULL) {
/* Let us try to get an X-latch. If the current thread
is holding an X-latch on the page, we cannot get an
S-latch. */
if (!success) {
/* Let us try to get an X-latch. If the current thread
is holding an X-latch on the page, we cannot get an
S-latch. */
block = buf_page_get_nowait(space_id, zip_size, page_no,
RW_X_LATCH, mtr);
}
fix_type = MTR_MEMO_PAGE_X_FIX;
success = rw_lock_x_lock_func_nowait(&block->lock,
file, line);
}
if (!success) {
mutex_enter(&block->mutex);
buf_block_buf_fix_dec(block);
mutex_exit(&block->mutex);
return(NULL);
}
mtr_memo_push(mtr, block, fix_type);
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
ut_a(++buf_dbg_counter % 5771 || buf_validate());
ut_a(block->page.buf_fix_count > 0);
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->page.file_page_was_freed == FALSE);
#endif /* UNIV_DEBUG_FILE_ACCESSES */
#ifdef UNIV_SYNC_DEBUG
buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
#endif /* UNIV_SYNC_DEBUG */
buf_pool->n_page_gets++;
return(block);
}
......
......@@ -228,7 +228,7 @@ Given a tablespace id and page number tries to get that page. If the
page is not in the buffer pool it is not loaded and NULL is returned.
Suitable for using when holding the kernel mutex. */
buf_block_t*
const buf_block_t*
buf_page_try_get_func(
/*==================*/
ulint space_id,/* in: tablespace id */
......@@ -778,11 +778,11 @@ buf_page_set_accessed(
Gets the buf_block_t handle of a buffered file block if an uncompressed
page frame exists, or NULL. */
UNIV_INLINE
const buf_block_t*
buf_block_t*
buf_page_get_block(
/*===============*/
/* out: control block, or NULL */
const buf_page_t* bpage) /* in: control block */
/* out: control block, or NULL */
buf_page_t* bpage) /* in: control block, or NULL */
__attribute__((pure));
#ifdef UNIV_DEBUG
/*************************************************************************
......@@ -941,6 +941,16 @@ buf_page_hash_get(
/* out: block, NULL if not found */
ulint space, /* in: space id */
ulint offset);/* in: offset of the page within space */
/**********************************************************************
Returns the control block of a file page, NULL if not found
or an uncompressed page frame does not exist. */
UNIV_INLINE
buf_block_t*
buf_block_hash_get(
/*===============*/
/* out: block, NULL if not found */
ulint space, /* in: space id */
ulint offset);/* in: offset of the page within space */
/***********************************************************************
Increments the pool clock by one and returns its new value. Remember that
in the 32 bit version the clock wraps around at 4 billion! */
......
......@@ -464,17 +464,18 @@ buf_page_set_accessed(
Gets the buf_block_t handle of a buffered file block if an uncompressed
page frame exists, or NULL. */
UNIV_INLINE
const buf_block_t*
buf_block_t*
buf_page_get_block(
/*===============*/
/* out: control block, or NULL */
const buf_page_t* bpage) /* in: control block */
/* out: control block, or NULL */
buf_page_t* bpage) /* in: control block, or NULL */
{
ut_ad(buf_page_in_file(bpage));
ut_ad(mutex_own(buf_page_get_mutex((buf_page_t*) bpage)));
if (UNIV_LIKELY(bpage != NULL)) {
ut_ad(buf_page_in_file(bpage));
if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) {
return((const buf_block_t*) bpage);
if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) {
return((buf_block_t*) bpage);
}
}
return(NULL);
......@@ -919,6 +920,20 @@ buf_page_hash_get(
return(bpage);
}
/**********************************************************************
Returns the control block of a file page, NULL if not found
or an uncompressed page frame does not exist. */
UNIV_INLINE
buf_block_t*
buf_block_hash_get(
/*===============*/
/* out: block, NULL if not found */
ulint space, /* in: space id */
ulint offset) /* in: offset of the page within space */
{
return(buf_page_get_block(buf_page_hash_get(space, offset)));
}
/************************************************************************
Returns TRUE if the page can be found in the buffer pool hash table. NOTE
that it is possible that the page is not yet read from disk, though. */
......
......@@ -4193,22 +4193,20 @@ lock_rec_print(
FILE* file, /* in: file where to print */
const lock_t* lock) /* in: record type lock */
{
buf_block_t* block;
ulint space;
ulint zip_size;
ulint page_no;
ulint i;
mtr_t mtr;
mem_heap_t* heap = NULL;
ulint offsets_[REC_OFFS_NORMAL_SIZE];
ulint* offsets = offsets_;
const buf_block_t* block;
ulint space;
ulint page_no;
ulint i;
mtr_t mtr;
mem_heap_t* heap = NULL;
ulint offsets_[REC_OFFS_NORMAL_SIZE];
ulint* offsets = offsets_;
rec_offs_init(offsets_);
ut_ad(mutex_own(&kernel_mutex));
ut_a(lock_get_type_low(lock) == LOCK_REC);
space = lock->un_member.rec_lock.space;
zip_size = fil_space_get_zip_size(space);
page_no = lock->un_member.rec_lock.page_no;
fprintf(file, "RECORD LOCKS space id %lu page no %lu n bits %lu ",
......@@ -4249,29 +4247,27 @@ lock_rec_print(
block = buf_page_try_get(space, page_no, &mtr);
#ifdef UNIV_SYNC_DEBUG
if (block) {
buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
}
#endif /* UNIV_SYNC_DEBUG */
for (i = 0; i < lock_rec_get_n_bits(lock); i++) {
if (lock_rec_get_nth_bit(lock, i)) {
for (i = 0; i < lock_rec_get_n_bits(lock); i++) {
fprintf(file, "Record lock, heap no %lu ", (ulong) i);
if (lock_rec_get_nth_bit(lock, i)) {
if (block) {
const rec_t* rec
= page_find_rec_with_heap_no(
buf_block_get_frame(block), i);
offsets = rec_get_offsets(
rec, lock->index, offsets,
ULINT_UNDEFINED, &heap);
fprintf(file, "Record lock, heap no %lu ",
(ulong) i);
rec_print_new(file, rec, offsets);
putc('\n', file);
}
putc('\n', file);
}
} else {
for (i = 0; i < lock_rec_get_n_bits(lock); i++) {
fprintf(file, "Record lock, heap no %lu\n", (ulong) i);
}
}
......
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