MDEV-15528: Minor cleanup

buf_flush_freed_page(): Reformat in the common style, and
simplify some code. Prefer to request all information from
smaller data structures (buf_page_t) than from fil_space_t
or the global variable srv_immediate_scrub_data_uncompressed.

SysTablespace::open_or_create(): Assert that the temporary
tablespace will not be created in page_compressed format, so that
buf_flush_freed_page() can avoid checking that on every call.

IORequest: Remove duplicated constructors, and do not explicitly
declare a default constructor.
This commit is contained in:
Marko Mäkelä 2020-03-10 09:34:09 +02:00 committed by Sergei Golubchik
parent e0e5d8c594
commit e2e2f89303
3 changed files with 36 additions and 66 deletions

View File

@ -1035,51 +1035,46 @@ page status as NORMAL. It initiates the write to the file only after
releasing the page from flush list and its associated mutex. releasing the page from flush list and its associated mutex.
@param[in,out] bpage freed buffer page @param[in,out] bpage freed buffer page
@param[in] space tablespace object of the freed page */ @param[in] space tablespace object of the freed page */
static void buf_flush_freed_page(buf_page_t* bpage, fil_space_t* space) static void buf_flush_freed_page(buf_page_t *bpage, fil_space_t *space)
{ {
const page_id_t page_id(bpage->id.space(), bpage->id.page_no()); ut_ad(buf_page_in_file(bpage));
BPageMutex* block_mutex = buf_page_get_mutex(bpage); const bool uncompressed= buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE;
const bool uncompressed = (buf_page_get_state(bpage) BPageMutex *block_mutex= uncompressed
== BUF_BLOCK_FILE_PAGE); ? &reinterpret_cast<buf_block_t*>(bpage)->mutex
bool punch_hole = false; : &buf_pool->zip_mutex;
mutex_enter(&buf_pool->mutex); mutex_enter(&buf_pool->mutex);
mutex_enter(block_mutex); mutex_enter(block_mutex);
buf_page_set_io_fix(bpage, BUF_IO_NONE); buf_page_set_io_fix(bpage, BUF_IO_NONE);
bpage->status = buf_page_t::NORMAL; bpage->status= buf_page_t::NORMAL;
buf_flush_write_complete(bpage, false); buf_flush_write_complete(bpage, false);
if (uncompressed) { if (uncompressed)
rw_lock_sx_unlock_gen(&((buf_block_t*) bpage)->lock, rw_lock_sx_unlock_gen(&reinterpret_cast<buf_block_t*>(bpage)->lock,
BUF_IO_WRITE); BUF_IO_WRITE);
}
buf_pool->stat.n_pages_written++; buf_pool->stat.n_pages_written++;
mutex_exit(block_mutex); mutex_exit(&buf_pool->mutex);
mutex_exit(&buf_pool->mutex); const page_id_t page_id(bpage->id);
const auto zip_size= bpage->zip_size();
mutex_exit(block_mutex);
if (space->is_compressed()) { const bool punch_hole=
#if defined(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE) || defined(_WIN32) #if defined(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE) || defined(_WIN32)
punch_hole = (space != fil_system.temp_space space->is_compressed() ||
&& space->is_compressed());
#endif #endif
} false;
if (srv_immediate_scrub_data_uncompressed || punch_hole) { ut_ad(space->id == page_id.space());
/* Zero write the page */ ut_ad(space->zip_size() == zip_size);
ulint type = IORequest::WRITE;
IORequest request(type, NULL);
page_t* frame = const_cast<byte*>(field_ref_zero);
fil_io(request, punch_hole ? true :false, if (punch_hole || srv_immediate_scrub_data_uncompressed)
page_id, space->zip_size(), 0, fil_io(IORequestWrite, punch_hole, page_id, zip_size, 0,
space->physical_size(), frame, NULL, zip_size ? zip_size : srv_page_size,
false, punch_hole); const_cast<byte*>(field_ref_zero), nullptr, false, punch_hole);
}
space->release_for_io(); space->release_for_io();
} }
/********************************************************************//** /********************************************************************//**

View File

@ -912,6 +912,8 @@ SysTablespace::open_or_create(
if (!space) { if (!space) {
return DB_ERROR; return DB_ERROR;
} }
ut_ad(!space->is_compressed());
ut_ad(space->full_crc32());
} else { } else {
ut_ad(!fil_system.sys_space); ut_ad(!fil_system.sys_space);
ut_ad(space_id() == TRX_SYS_SPACE); ut_ad(space_id() == TRX_SYS_SPACE);

View File

@ -212,39 +212,12 @@ public:
PUNCH_HOLE = 64, PUNCH_HOLE = 64,
}; };
/** Default constructor */
IORequest()
:
m_bpage(NULL),
m_fil_node(NULL),
m_type(READ)
{
/* No op */
}
/**
@param[in] type Request type, can be a value that is
ORed from the above enum */
explicit IORequest(ulint type)
:
m_bpage(NULL),
m_fil_node(NULL),
m_type(static_cast<uint16_t>(type))
{
if (!is_punch_hole_supported()) {
clear_punch_hole();
}
}
/** /**
@param[in] type Request type, can be a value that is @param[in] type Request type, can be a value that is
ORed from the above enum ORed from the above enum
@param[in] bpage Page to be written */ @param[in] bpage Page to be written */
IORequest(ulint type, buf_page_t* bpage) IORequest(ulint type= READ, buf_page_t *bpage= nullptr)
: : m_bpage(bpage), m_type(static_cast<uint16_t>(type))
m_bpage(bpage),
m_fil_node(NULL),
m_type(static_cast<uint16_t>(type))
{ {
if (bpage && buf_page_should_punch_hole(bpage)) { if (bpage && buf_page_should_punch_hole(bpage)) {
set_punch_hole(); set_punch_hole();
@ -372,13 +345,13 @@ public:
private: private:
/** Page to be written on write operation. */ /** Page to be written on write operation. */
buf_page_t* m_bpage; buf_page_t* const m_bpage= nullptr;
/** File node */ /** File node */
fil_node_t* m_fil_node; fil_node_t* m_fil_node= nullptr;
/** Request type bit flags */ /** Request type bit flags */
uint16_t m_type; uint16_t m_type= READ;
}; };
/* @} */ /* @} */