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. Reviewed by: Vladislav Lesin
This commit is contained in:
parent
7d4077cc11
commit
998a625d00
@ -513,8 +513,19 @@ public: // FIXME: fix fil_iterate()
|
||||
/** Page id. Protected by buf_pool.page_hash.lock_get() when
|
||||
the page is in buf_pool.page_hash. */
|
||||
page_id_t id_;
|
||||
/** buf_pool.page_hash link; protected by buf_pool.page_hash.lock_get() */
|
||||
buf_page_t *hash;
|
||||
union {
|
||||
/** 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:
|
||||
/** log sequence number of the START of the log entry written of the
|
||||
oldest modification to this block which has not yet been written
|
||||
@ -605,16 +616,7 @@ public:
|
||||
/* @} */
|
||||
Atomic_counter<unsigned> access_time; /*!< time of first access, or
|
||||
0 if the block was never accessed
|
||||
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. */
|
||||
in the buffer pool. */
|
||||
buf_page_t() : id_{0}
|
||||
{
|
||||
static_assert(NOT_USED == 0, "compatibility");
|
||||
|
@ -1486,6 +1486,7 @@ void recv_sys_t::clear()
|
||||
{
|
||||
buf_block_t *prev_block= UT_LIST_GET_PREV(unzip_LRU, block);
|
||||
ut_ad(block->page.state() == buf_page_t::MEMORY);
|
||||
block->page.hash= nullptr;
|
||||
UT_LIST_REMOVE(blocks, block);
|
||||
MEM_MAKE_ADDRESSABLE(block->page.frame, srv_page_size);
|
||||
buf_block_free(block);
|
||||
@ -1534,14 +1535,11 @@ inline void recv_sys_t::free(const void *data)
|
||||
buf_block_t *block= &chunk->blocks[offs];
|
||||
ut_ad(block->page.frame == page_align(data));
|
||||
ut_ad(block->page.state() == buf_page_t::MEMORY);
|
||||
ut_ad(static_cast<uint16_t>(block->page.access_time - 1) <
|
||||
srv_page_size);
|
||||
unsigned a= block->page.access_time;
|
||||
ut_ad(a >= 1U << 16);
|
||||
a-= 1U << 16;
|
||||
block->page.access_time= a;
|
||||
if (!(a >> 16))
|
||||
ut_ad(uint16_t(block->page.free_offset - 1) < srv_page_size);
|
||||
ut_ad(block->page.used_records);
|
||||
if (!--block->page.used_records)
|
||||
{
|
||||
block->page.hash= nullptr;
|
||||
UT_LIST_REMOVE(blocks, block);
|
||||
MEM_MAKE_ADDRESSABLE(block->page.frame, srv_page_size);
|
||||
buf_block_free(block);
|
||||
@ -2250,7 +2248,7 @@ bool recv_sys_t::add(map::iterator it, lsn_t start_lsn, lsn_t lsn,
|
||||
ut_ad(tail->lsn == lsn);
|
||||
block= UT_LIST_GET_LAST(blocks);
|
||||
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);
|
||||
const byte *end= const_cast<const log_phys_t*>(tail)->end();
|
||||
if (!((reinterpret_cast<size_t>(end + len) ^
|
||||
@ -2271,7 +2269,7 @@ append:
|
||||
ut_ad(new_used > used);
|
||||
if (new_used > srv_page_size)
|
||||
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);
|
||||
goto append;
|
||||
}
|
||||
@ -2286,7 +2284,8 @@ append:
|
||||
block= add_block();
|
||||
if (UNIV_UNLIKELY(!block))
|
||||
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);
|
||||
static_assert(ut_is_2pow(ALIGNMENT), "ALIGNMENT must be a power of 2");
|
||||
UT_LIST_ADD_FIRST(blocks, block);
|
||||
@ -2296,7 +2295,7 @@ append:
|
||||
}
|
||||
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));
|
||||
if (UNIV_UNLIKELY(!free_offset))
|
||||
{
|
||||
@ -2309,7 +2308,8 @@ append:
|
||||
if (free_offset > srv_page_size)
|
||||
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);
|
||||
MEM_MAKE_ADDRESSABLE(block->page.frame + free_offset - size, size);
|
||||
buf= block->page.frame + free_offset - size;
|
||||
|
Loading…
x
Reference in New Issue
Block a user