Commit 512b8113 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-33966 preparation: Clean up recv_sys.pages bookkeeping

Instead of repurposing buf_page_t::access_time for state()==MEMORY
blocks that are part of recv_sys.pages, let us define an anonymous
union around buf_page_t::hash.  In this way, we will be able to
declare access_time private.
parent 231900e5
...@@ -509,8 +509,19 @@ class buf_page_t ...@@ -509,8 +509,19 @@ class buf_page_t
/** Page id. Protected by buf_pool.page_hash.lock_get() when /** Page id. Protected by buf_pool.page_hash.lock_get() when
the page is in buf_pool.page_hash. */ the page is in buf_pool.page_hash. */
page_id_t id_; page_id_t id_;
/** buf_pool.page_hash link; protected by buf_pool.page_hash.lock_get() */ union {
buf_page_t *hash; /** for in_file(): buf_pool.page_hash link;
protected by buf_pool.page_hash.lock_get() */
buf_page_t *hash;
/** for state()==MEMORY that are part of recv_sys.pages and
protected by recv_sys.mutex */
struct {
/** number of recv_sys.pages entries stored in the block */
uint16_t used_records;
/** the offset of the next free record */
uint16_t free_offset;
};
};
private: private:
/** log sequence number of the START of the log entry written of the /** log sequence number of the START of the log entry written of the
oldest modification to this block which has not yet been written oldest modification to this block which has not yet been written
...@@ -601,16 +612,7 @@ class buf_page_t ...@@ -601,16 +612,7 @@ class buf_page_t
/* @} */ /* @} */
Atomic_counter<unsigned> access_time; /*!< time of first access, or Atomic_counter<unsigned> access_time; /*!< time of first access, or
0 if the block was never accessed 0 if the block was never accessed
in the buffer pool. in the buffer pool. */
For state() == MEMORY
blocks, this field can be repurposed
for something else.
When this field counts log records
and bytes allocated for recv_sys.pages,
the field is protected by
recv_sys_t::mutex. */
buf_page_t() : id_{0} buf_page_t() : id_{0}
{ {
static_assert(NOT_USED == 0, "compatibility"); static_assert(NOT_USED == 0, "compatibility");
......
...@@ -1497,6 +1497,7 @@ void recv_sys_t::clear() ...@@ -1497,6 +1497,7 @@ void recv_sys_t::clear()
{ {
buf_block_t *prev_block= UT_LIST_GET_PREV(unzip_LRU, block); buf_block_t *prev_block= UT_LIST_GET_PREV(unzip_LRU, block);
ut_ad(block->page.state() == buf_page_t::MEMORY); ut_ad(block->page.state() == buf_page_t::MEMORY);
block->page.hash= nullptr;
UT_LIST_REMOVE(blocks, block); UT_LIST_REMOVE(blocks, block);
MEM_MAKE_ADDRESSABLE(block->page.frame, srv_page_size); MEM_MAKE_ADDRESSABLE(block->page.frame, srv_page_size);
buf_block_free(block); buf_block_free(block);
...@@ -1546,14 +1547,11 @@ inline void recv_sys_t::free(const void *data) ...@@ -1546,14 +1547,11 @@ inline void recv_sys_t::free(const void *data)
buf_block_t *block= &chunk->blocks[offs]; buf_block_t *block= &chunk->blocks[offs];
ut_ad(block->page.frame == data); ut_ad(block->page.frame == data);
ut_ad(block->page.state() == buf_page_t::MEMORY); ut_ad(block->page.state() == buf_page_t::MEMORY);
ut_ad(static_cast<uint16_t>(block->page.access_time - 1) < ut_ad(uint16_t(block->page.free_offset - 1) < srv_page_size);
srv_page_size); ut_ad(block->page.used_records);
unsigned a= block->page.access_time; if (!--block->page.used_records)
ut_ad(a >= 1U << 16);
a-= 1U << 16;
block->page.access_time= a;
if (!(a >> 16))
{ {
block->page.hash= nullptr;
UT_LIST_REMOVE(blocks, block); UT_LIST_REMOVE(blocks, block);
MEM_MAKE_ADDRESSABLE(block->page.frame, srv_page_size); MEM_MAKE_ADDRESSABLE(block->page.frame, srv_page_size);
buf_block_free(block); buf_block_free(block);
...@@ -2262,7 +2260,7 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn, ...@@ -2262,7 +2260,7 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn,
ut_ad(tail->lsn == lsn); ut_ad(tail->lsn == lsn);
block= UT_LIST_GET_LAST(blocks); block= UT_LIST_GET_LAST(blocks);
ut_ad(block); ut_ad(block);
const size_t used= static_cast<uint16_t>(block->page.access_time - 1) + 1; const size_t used= uint16_t(block->page.free_offset - 1) + 1;
ut_ad(used >= ALIGNMENT); ut_ad(used >= ALIGNMENT);
const byte *end= const_cast<const log_phys_t*>(tail)->end(); const byte *end= const_cast<const log_phys_t*>(tail)->end();
if (!((reinterpret_cast<size_t>(end + len) ^ if (!((reinterpret_cast<size_t>(end + len) ^
...@@ -2283,7 +2281,7 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn, ...@@ -2283,7 +2281,7 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn,
ut_ad(new_used > used); ut_ad(new_used > used);
if (new_used > srv_page_size) if (new_used > srv_page_size)
break; break;
block->page.access_time= (block->page.access_time & ~0U << 16) | block->page.free_offset=
ut_calc_align<uint16_t>(static_cast<uint16_t>(new_used), ALIGNMENT); ut_calc_align<uint16_t>(static_cast<uint16_t>(new_used), ALIGNMENT);
goto append; goto append;
} }
...@@ -2298,7 +2296,8 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn, ...@@ -2298,7 +2296,8 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn,
block= add_block(); block= add_block();
if (UNIV_UNLIKELY(!block)) if (UNIV_UNLIKELY(!block))
return true; return true;
block->page.access_time= 1U << 16 | block->page.used_records= 1;
block->page.free_offset=
ut_calc_align<uint16_t>(static_cast<uint16_t>(size), ALIGNMENT); ut_calc_align<uint16_t>(static_cast<uint16_t>(size), ALIGNMENT);
static_assert(ut_is_2pow(ALIGNMENT), "ALIGNMENT must be a power of 2"); static_assert(ut_is_2pow(ALIGNMENT), "ALIGNMENT must be a power of 2");
UT_LIST_ADD_FIRST(blocks, block); UT_LIST_ADD_FIRST(blocks, block);
...@@ -2308,7 +2307,7 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn, ...@@ -2308,7 +2307,7 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn,
} }
else else
{ {
size_t free_offset= static_cast<uint16_t>(block->page.access_time); size_t free_offset= block->page.free_offset;
ut_ad(!ut_2pow_remainder(free_offset, ALIGNMENT)); ut_ad(!ut_2pow_remainder(free_offset, ALIGNMENT));
if (UNIV_UNLIKELY(!free_offset)) if (UNIV_UNLIKELY(!free_offset))
{ {
...@@ -2321,7 +2320,8 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn, ...@@ -2321,7 +2320,8 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn,
if (free_offset > srv_page_size) if (free_offset > srv_page_size)
goto create_block; goto create_block;
block->page.access_time= ((block->page.access_time >> 16) + 1) << 16 | block->page.used_records++;
block->page.free_offset=
ut_calc_align<uint16_t>(static_cast<uint16_t>(free_offset), ALIGNMENT); ut_calc_align<uint16_t>(static_cast<uint16_t>(free_offset), ALIGNMENT);
MEM_MAKE_ADDRESSABLE(block->page.frame + free_offset - size, size); MEM_MAKE_ADDRESSABLE(block->page.frame + free_offset - size, size);
buf= block->page.frame + free_offset - size; buf= block->page.frame + free_offset - size;
......
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