From 5b6fdd001ecac052861ca708d99f316edf9a41c2 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Wed, 30 Dec 2015 23:20:19 +0300 Subject: [PATCH] Bug #79378: buf_block_align() makes incorrect assumptions about chunk size Code in buf_block_align() depended on srv_buf_pool_chunk_unit to find the chunk corresponding to a given pointer. The problem was that srv_buf_pool_chunk_unit does not necessarily reflect the real chunk size in bytes as explained in the bug report. Fix the algorithm buf_block_align() to not depend on any specific chunk size, but use std::map properly to find the corresponding element in the chunk map. --- storage/innobase/buf/buf0buf.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 33bf2b2..eeb0d63 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -3855,14 +3855,18 @@ buf_block_from_ahi(const byte* ptr) ut_ad(buf_chunk_map_ref == buf_chunk_map_reg); ut_ad(!buf_pool_resizing); - const byte* bound = reinterpret_cast(ptr) - > srv_buf_pool_chunk_unit - ? ptr - srv_buf_pool_chunk_unit : 0; - it = chunk_map->upper_bound(bound); + buf_chunk_t* chunk; - ut_a(it != chunk_map->end()); + it = chunk_map->upper_bound(ptr); + + ut_a(it != chunk_map->begin()); + + if (it == chunk_map->end()) { + chunk = chunk_map->rbegin()->second; + } else { + chunk = (--it)->second; + } - buf_chunk_t* chunk = it->second; ulint offs = ptr - chunk->blocks->frame; offs >>= UNIV_PAGE_SIZE_SHIFT;