diff options
author | Eugene Kosov <claprix@yandex.ru> | 2021-12-03 17:21:59 +0600 |
---|---|---|
committer | Eugene Kosov <claprix@yandex.ru> | 2021-12-06 14:06:17 +0600 |
commit | 0064316f19c2b3fe07d0722c05b205b4f2906d35 (patch) | |
tree | cc9efa8314c92e101e136983f127db37162976e7 | |
parent | fa1325512b002f4f517dacd851fea998a7af498c (diff) | |
download | mariadb-git-bb-10.5-kevgs.tar.gz |
cleanup: reduce code bloatbb-10.5-kevgs
-rw-r--r-- | storage/innobase/include/log0log.h | 20 | ||||
-rw-r--r-- | storage/innobase/log/log0log.cc | 101 |
2 files changed, 60 insertions, 61 deletions
diff --git a/storage/innobase/include/log0log.h b/storage/innobase/include/log0log.h index 1dcff513d7c..46cd6bbc4a2 100644 --- a/storage/innobase/include/log0log.h +++ b/storage/innobase/include/log0log.h @@ -346,26 +346,6 @@ or the MySQL version that created the redo log file. */ header */ #define LOG_FILE_HDR_SIZE (4 * OS_FILE_LOG_BLOCK_SIZE) -/** Memory mapped file */ -class mapped_file_t -{ -public: - mapped_file_t()= default; - mapped_file_t(const mapped_file_t &)= delete; - mapped_file_t &operator=(const mapped_file_t &)= delete; - mapped_file_t(mapped_file_t &&)= delete; - mapped_file_t &operator=(mapped_file_t &&)= delete; - ~mapped_file_t() noexcept; - - dberr_t map(const char *path, bool read_only= false, - bool nvme= false) noexcept; - dberr_t unmap() noexcept; - byte *data() noexcept { return m_area.data(); } - -private: - span<byte> m_area; -}; - /** Abstraction for reading, writing and flushing file cache to disk */ class file_io { diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc index 906979ffe20..914337d2a54 100644 --- a/storage/innobase/log/log0log.cc +++ b/storage/innobase/log/log0log.cc @@ -221,47 +221,6 @@ void log_t::create() (aligned_malloc(OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE)); } -mapped_file_t::~mapped_file_t() noexcept -{ - if (!m_area.empty()) - unmap(); -} - -dberr_t mapped_file_t::map(const char *path, bool read_only, - bool nvme) noexcept -{ - auto fd= mysql_file_open(innodb_log_file_key, path, - read_only ? O_RDONLY : O_RDWR, MYF(MY_WME)); - if (fd == -1) - return DB_ERROR; - - const auto file_size= os_file_get_size(path).m_total_size; - - const int nvme_flag= nvme ? MAP_SYNC : 0; - void *ptr= my_mmap(0, static_cast<size_t>(file_size), - read_only ? PROT_READ : PROT_READ | PROT_WRITE, - MAP_SHARED_VALIDATE | nvme_flag, fd, 0); - mysql_file_close(fd, MYF(MY_WME)); - - if (ptr == MAP_FAILED) - return DB_ERROR; - - m_area= {static_cast<byte *>(ptr), - static_cast<span<byte>::size_type>(file_size)}; - return DB_SUCCESS; -} - -dberr_t mapped_file_t::unmap() noexcept -{ - ut_ad(!m_area.empty()); - - if (my_munmap(m_area.data(), m_area.size())) - return DB_ERROR; - - m_area= {}; - return DB_SUCCESS; -} - file_os_io::file_os_io(file_os_io &&rhs) : m_fd(rhs.m_fd) { rhs.m_fd= OS_FILE_CLOSED; @@ -331,6 +290,66 @@ dberr_t file_os_io::flush() noexcept #include <libpmem.h> +/** Memory mapped file */ +class mapped_file_t +{ +public: + mapped_file_t()= default; + mapped_file_t(const mapped_file_t &)= delete; + mapped_file_t &operator=(const mapped_file_t &)= delete; + mapped_file_t(mapped_file_t &&)= delete; + mapped_file_t &operator=(mapped_file_t &&)= delete; + ~mapped_file_t() noexcept; + + dberr_t map(const char *path, bool read_only= false, + bool nvme= false) noexcept; + dberr_t unmap() noexcept; + byte *data() noexcept { return m_area.data(); } + +private: + span<byte> m_area; +}; + +mapped_file_t::~mapped_file_t() noexcept +{ + if (!m_area.empty()) + unmap(); +} + +dberr_t mapped_file_t::map(const char *path, bool read_only, + bool nvme) noexcept +{ + auto fd= mysql_file_open(innodb_log_file_key, path, + read_only ? O_RDONLY : O_RDWR, MYF(MY_WME)); + if (fd == -1) + return DB_ERROR; + + const auto file_size= size_t{os_file_get_size(path).m_total_size}; + + const int nvme_flag= nvme ? MAP_SYNC : 0; + void *ptr= + my_mmap(0, file_size, read_only ? PROT_READ : PROT_READ | PROT_WRITE, + MAP_SHARED_VALIDATE | nvme_flag, fd, 0); + mysql_file_close(fd, MYF(MY_WME)); + + if (ptr == MAP_FAILED) + return DB_ERROR; + + m_area= {static_cast<byte *>(ptr), file_size}; + return DB_SUCCESS; +} + +dberr_t mapped_file_t::unmap() noexcept +{ + ut_ad(!m_area.empty()); + + if (my_munmap(m_area.data(), m_area.size())) + return DB_ERROR; + + m_area= {}; + return DB_SUCCESS; +} + static bool is_pmem(const char *path) noexcept { mapped_file_t mf; |