Commit aa458506 authored by Marko Mäkelä's avatar Marko Mäkelä

Cleanup: Make fil_space_t::freed_ranges private

fil_space_t::is_freed(): Check if a page is in freed_ranges.

fil_space_t::flush_freed(): Replaces buf_flush_freed_pages().
parent b29a8118
...@@ -1002,63 +1002,58 @@ static page_id_t buf_flush_check_neighbors(const fil_space_t &space, ...@@ -1002,63 +1002,58 @@ static page_id_t buf_flush_check_neighbors(const fil_space_t &space,
return i; return i;
} }
MY_ATTRIBUTE((nonnull, warn_unused_result)) MY_ATTRIBUTE((warn_unused_result))
/** Write punch-hole or zeroes of the freed ranges when /** Apply freed_ranges to the file.
innodb_immediate_scrub_data_uncompressed from the freed ranges. @param writable whether the file is writable
@param space tablespace which may contain ranges of freed pages
@param writable whether the tablespace is writable
@return number of pages written or hole-punched */ @return number of pages written or hole-punched */
static uint32_t buf_flush_freed_pages(fil_space_t *space, bool writable) uint32_t fil_space_t::flush_freed(bool writable)
{ {
const bool punch_hole= space->chain.start->punch_hole == 1; const bool punch_hole= chain.start->punch_hole == 1;
if (!punch_hole && !srv_immediate_scrub_data_uncompressed) if (!punch_hole && !srv_immediate_scrub_data_uncompressed)
return 0; return 0;
mysql_mutex_assert_not_owner(&buf_pool.flush_list_mutex); mysql_mutex_assert_not_owner(&buf_pool.flush_list_mutex);
mysql_mutex_assert_not_owner(&buf_pool.mutex); mysql_mutex_assert_not_owner(&buf_pool.mutex);
space->freed_range_mutex.lock(); freed_range_mutex.lock();
if (space->freed_ranges.empty() || if (freed_ranges.empty() || log_sys.get_flushed_lsn() < get_last_freed_lsn())
log_sys.get_flushed_lsn() < space->get_last_freed_lsn())
{ {
space->freed_range_mutex.unlock(); freed_range_mutex.unlock();
return 0; return 0;
} }
const unsigned physical_size{space->physical_size()}; const unsigned physical{physical_size()};
range_set freed_ranges= std::move(space->freed_ranges); range_set freed= std::move(freed_ranges);
uint32_t written= 0; uint32_t written= 0;
if (!writable); if (!writable);
else if (punch_hole) else if (punch_hole)
{ {
for (const auto &range : freed_ranges) for (const auto &range : freed)
{ {
written+= range.last - range.first + 1; written+= range.last - range.first + 1;
space->reacquire(); reacquire();
space->io(IORequest(IORequest::PUNCH_RANGE), io(IORequest(IORequest::PUNCH_RANGE),
os_offset_t{range.first} * physical_size, os_offset_t{range.first} * physical,
(range.last - range.first + 1) * physical_size, (range.last - range.first + 1) * physical, nullptr);
nullptr);
} }
} }
else else
{ {
for (const auto &range : freed_ranges) for (const auto &range : freed)
{ {
written+= range.last - range.first + 1; written+= range.last - range.first + 1;
for (os_offset_t i= range.first; i <= range.last; i++) for (os_offset_t i= range.first; i <= range.last; i++)
{ {
space->reacquire(); reacquire();
space->io(IORequest(IORequest::WRITE_ASYNC), io(IORequest(IORequest::WRITE_ASYNC), i * physical, physical,
i * physical_size, physical_size, const_cast<byte*>(field_ref_zero));
const_cast<byte*>(field_ref_zero));
} }
} }
} }
space->freed_range_mutex.unlock(); freed_range_mutex.unlock();
return written; return written;
} }
...@@ -1186,7 +1181,7 @@ static ulint buf_free_from_unzip_LRU_list_batch(ulint max) ...@@ -1186,7 +1181,7 @@ static ulint buf_free_from_unzip_LRU_list_batch(ulint max)
static std::pair<fil_space_t*, uint32_t> buf_flush_space(const uint32_t id) static std::pair<fil_space_t*, uint32_t> buf_flush_space(const uint32_t id)
{ {
if (fil_space_t *space= fil_space_t::get(id)) if (fil_space_t *space= fil_space_t::get(id))
return {space, buf_flush_freed_pages(space, true)}; return {space, space->flush_freed(true)};
return {nullptr, 0}; return {nullptr, 0};
} }
...@@ -1568,7 +1563,7 @@ bool buf_flush_list_space(fil_space_t *space, ulint *n_flushed) ...@@ -1568,7 +1563,7 @@ bool buf_flush_list_space(fil_space_t *space, ulint *n_flushed)
bool acquired= space->acquire(); bool acquired= space->acquire();
{ {
const uint32_t written{buf_flush_freed_pages(space, acquired)}; const uint32_t written{space->flush_freed(acquired)};
mysql_mutex_lock(&buf_pool.mutex); mysql_mutex_lock(&buf_pool.mutex);
if (written) if (written)
buf_pool.stat.n_pages_written+= written; buf_pool.stat.n_pages_written+= written;
......
...@@ -685,6 +685,13 @@ buf_read_ahead_linear(const page_id_t page_id, ulint zip_size, bool ibuf) ...@@ -685,6 +685,13 @@ buf_read_ahead_linear(const page_id_t page_id, ulint zip_size, bool ibuf)
return count; return count;
} }
/** @return whether a page has been freed */
inline bool fil_space_t::is_freed(uint32_t page)
{
std::lock_guard<std::mutex> freed_lock(freed_range_mutex);
return freed_ranges.contains(page);
}
/** Issues read requests for pages which recovery wants to read in. /** Issues read requests for pages which recovery wants to read in.
@param[in] space_id tablespace id @param[in] space_id tablespace id
@param[in] page_nos array of page numbers to read, with the @param[in] page_nos array of page numbers to read, with the
...@@ -704,7 +711,7 @@ void buf_read_recv_pages(ulint space_id, const uint32_t* page_nos, ulint n) ...@@ -704,7 +711,7 @@ void buf_read_recv_pages(ulint space_id, const uint32_t* page_nos, ulint n)
for (ulint i = 0; i < n; i++) { for (ulint i = 0; i < n; i++) {
/* Ignore if the page already present in freed ranges. */ /* Ignore if the page already present in freed ranges. */
if (space->freed_ranges.contains(page_nos[i])) { if (space->is_freed(page_nos[i])) {
continue; continue;
} }
......
...@@ -415,28 +415,36 @@ struct fil_space_t final ...@@ -415,28 +415,36 @@ struct fil_space_t final
pthread_t latch_owner; pthread_t latch_owner;
ut_d(Atomic_relaxed<uint32_t> latch_count;) ut_d(Atomic_relaxed<uint32_t> latch_count;)
public: public:
/** MariaDB encryption data */ /** MariaDB encryption data */
fil_space_crypt_t* crypt_data; fil_space_crypt_t *crypt_data;
/** Checks that this tablespace in a list of unflushed tablespaces. */ /** Checks that this tablespace in a list of unflushed tablespaces. */
bool is_in_unflushed_spaces; bool is_in_unflushed_spaces;
/** Checks that this tablespace needs key rotation. */
bool is_in_default_encrypt;
/** Checks that this tablespace needs key rotation. */ private:
bool is_in_default_encrypt; /** mutex to protect freed_ranges and last_freed_lsn */
std::mutex freed_range_mutex;
/** mutex to protect freed ranges */
std::mutex freed_range_mutex;
/** Variables to store freed ranges. This can be used to write /** Ranges of freed page numbers; protected by freed_range_mutex */
zeroes/punch the hole in files. Protected by freed_mutex */ range_set freed_ranges;
range_set freed_ranges;
/** Stores last page freed lsn. Protected by freed_mutex */ /** LSN of freeing last page; protected by freed_range_mutex */
lsn_t last_freed_lsn; lsn_t last_freed_lsn;
public:
/** @return whether doublewrite buffering is needed */ /** @return whether doublewrite buffering is needed */
inline bool use_doublewrite() const; inline bool use_doublewrite() const;
/** @return whether a page has been freed */
inline bool is_freed(uint32_t page);
/** Apply freed_ranges to the file.
@param writable whether the file is writable
@return number of pages written or hole-punched */
uint32_t flush_freed(bool writable);
/** Append a file to the chain of files of a space. /** Append a file to the chain of files of a space.
@param[in] name file name of a file that is not open @param[in] name file name of a file that is not open
@param[in] handle file handle, or OS_FILE_CLOSED @param[in] handle file handle, or OS_FILE_CLOSED
......
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