Skip to content

Commit 0064316

Browse files
committed
cleanup: reduce code bloat
1 parent fa13255 commit 0064316

File tree

2 files changed

+60
-61
lines changed

2 files changed

+60
-61
lines changed

storage/innobase/include/log0log.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -346,26 +346,6 @@ or the MySQL version that created the redo log file. */
346346
header */
347347
#define LOG_FILE_HDR_SIZE (4 * OS_FILE_LOG_BLOCK_SIZE)
348348

349-
/** Memory mapped file */
350-
class mapped_file_t
351-
{
352-
public:
353-
mapped_file_t()= default;
354-
mapped_file_t(const mapped_file_t &)= delete;
355-
mapped_file_t &operator=(const mapped_file_t &)= delete;
356-
mapped_file_t(mapped_file_t &&)= delete;
357-
mapped_file_t &operator=(mapped_file_t &&)= delete;
358-
~mapped_file_t() noexcept;
359-
360-
dberr_t map(const char *path, bool read_only= false,
361-
bool nvme= false) noexcept;
362-
dberr_t unmap() noexcept;
363-
byte *data() noexcept { return m_area.data(); }
364-
365-
private:
366-
span<byte> m_area;
367-
};
368-
369349
/** Abstraction for reading, writing and flushing file cache to disk */
370350
class file_io
371351
{

storage/innobase/log/log0log.cc

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -221,47 +221,6 @@ void log_t::create()
221221
(aligned_malloc(OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE));
222222
}
223223

224-
mapped_file_t::~mapped_file_t() noexcept
225-
{
226-
if (!m_area.empty())
227-
unmap();
228-
}
229-
230-
dberr_t mapped_file_t::map(const char *path, bool read_only,
231-
bool nvme) noexcept
232-
{
233-
auto fd= mysql_file_open(innodb_log_file_key, path,
234-
read_only ? O_RDONLY : O_RDWR, MYF(MY_WME));
235-
if (fd == -1)
236-
return DB_ERROR;
237-
238-
const auto file_size= os_file_get_size(path).m_total_size;
239-
240-
const int nvme_flag= nvme ? MAP_SYNC : 0;
241-
void *ptr= my_mmap(0, static_cast<size_t>(file_size),
242-
read_only ? PROT_READ : PROT_READ | PROT_WRITE,
243-
MAP_SHARED_VALIDATE | nvme_flag, fd, 0);
244-
mysql_file_close(fd, MYF(MY_WME));
245-
246-
if (ptr == MAP_FAILED)
247-
return DB_ERROR;
248-
249-
m_area= {static_cast<byte *>(ptr),
250-
static_cast<span<byte>::size_type>(file_size)};
251-
return DB_SUCCESS;
252-
}
253-
254-
dberr_t mapped_file_t::unmap() noexcept
255-
{
256-
ut_ad(!m_area.empty());
257-
258-
if (my_munmap(m_area.data(), m_area.size()))
259-
return DB_ERROR;
260-
261-
m_area= {};
262-
return DB_SUCCESS;
263-
}
264-
265224
file_os_io::file_os_io(file_os_io &&rhs) : m_fd(rhs.m_fd)
266225
{
267226
rhs.m_fd= OS_FILE_CLOSED;
@@ -331,6 +290,66 @@ dberr_t file_os_io::flush() noexcept
331290

332291
#include <libpmem.h>
333292

293+
/** Memory mapped file */
294+
class mapped_file_t
295+
{
296+
public:
297+
mapped_file_t()= default;
298+
mapped_file_t(const mapped_file_t &)= delete;
299+
mapped_file_t &operator=(const mapped_file_t &)= delete;
300+
mapped_file_t(mapped_file_t &&)= delete;
301+
mapped_file_t &operator=(mapped_file_t &&)= delete;
302+
~mapped_file_t() noexcept;
303+
304+
dberr_t map(const char *path, bool read_only= false,
305+
bool nvme= false) noexcept;
306+
dberr_t unmap() noexcept;
307+
byte *data() noexcept { return m_area.data(); }
308+
309+
private:
310+
span<byte> m_area;
311+
};
312+
313+
mapped_file_t::~mapped_file_t() noexcept
314+
{
315+
if (!m_area.empty())
316+
unmap();
317+
}
318+
319+
dberr_t mapped_file_t::map(const char *path, bool read_only,
320+
bool nvme) noexcept
321+
{
322+
auto fd= mysql_file_open(innodb_log_file_key, path,
323+
read_only ? O_RDONLY : O_RDWR, MYF(MY_WME));
324+
if (fd == -1)
325+
return DB_ERROR;
326+
327+
const auto file_size= size_t{os_file_get_size(path).m_total_size};
328+
329+
const int nvme_flag= nvme ? MAP_SYNC : 0;
330+
void *ptr=
331+
my_mmap(0, file_size, read_only ? PROT_READ : PROT_READ | PROT_WRITE,
332+
MAP_SHARED_VALIDATE | nvme_flag, fd, 0);
333+
mysql_file_close(fd, MYF(MY_WME));
334+
335+
if (ptr == MAP_FAILED)
336+
return DB_ERROR;
337+
338+
m_area= {static_cast<byte *>(ptr), file_size};
339+
return DB_SUCCESS;
340+
}
341+
342+
dberr_t mapped_file_t::unmap() noexcept
343+
{
344+
ut_ad(!m_area.empty());
345+
346+
if (my_munmap(m_area.data(), m_area.size()))
347+
return DB_ERROR;
348+
349+
m_area= {};
350+
return DB_SUCCESS;
351+
}
352+
334353
static bool is_pmem(const char *path) noexcept
335354
{
336355
mapped_file_t mf;

0 commit comments

Comments
 (0)