Skip to content
/ server Public

Commit a035050

Browse files
committed
squash! 6458cc2
Fix the ARCHIVED_MMAP write path, except for renaming files at log checkpoint, and implementing crash recovery. log_t::archived_mmap_switch_complete(): Attempt to complete log_t::archived_mmap_switch_prepare().
1 parent 6458cc2 commit a035050

File tree

5 files changed

+73
-52
lines changed

5 files changed

+73
-52
lines changed

storage/innobase/buf/buf0flu.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,8 @@ ATTRIBUTE_COLD void buf_flush_ahead(lsn_t lsn, bool furious) noexcept
21722172
if (recv_recovery_is_on())
21732173
recv_sys.apply(true);
21742174

2175-
DBUG_EXECUTE_IF("ib_log_checkpoint_avoid_hard", return;);
2175+
DBUG_EXECUTE_IF("ib_log_checkpoint_avoid_hard",
2176+
if (!log_sys.archive) return;);
21762177

21772178
Atomic_relaxed<lsn_t> &limit= furious
21782179
? buf_flush_sync_lsn : buf_flush_async_lsn;

storage/innobase/include/log0log.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ struct log_t
259259
of the next file created if archive==TRUE; protected by latch */
260260
lsn_t resize_target;
261261
/** Buffer for writing to resize_log; @see buf
262-
Also a spare buffer between append_prepare_archived_mmap() and
263-
archive_new_mmap() */
262+
Also a spare buffer between archived_mmap_switch_prepare()
263+
and archived_mmap_switch_complete() */
264264
byte *resize_buf;
265265
/** Buffer for writing to resize_log; @see flush_buf */
266266
byte *resize_flush_buf;
@@ -402,13 +402,6 @@ struct log_t
402402
@return whether an error occurred */
403403
static bool resize_rename() noexcept;
404404

405-
/** @return pointer for writing to resize_buf
406-
@retval nullptr if no is_mmap() based resizing is active */
407-
inline byte *resize_buf_begin(lsn_t lsn) const noexcept;
408-
/** @return end of resize_buf */
409-
inline const byte *resize_buf_end() const noexcept
410-
{ return resize_buf + resize_target; }
411-
412405
/** Initialise the redo log subsystem. */
413406
void create() noexcept;
414407

@@ -484,9 +477,23 @@ struct log_t
484477
/** Persist the log.
485478
@param lsn desired new value of flushed_to_disk_lsn */
486479
void persist(lsn_t lsn) noexcept;
487-
/** Switch the log buffers. */
488-
inline void archive_new_mmap() noexcept;
480+
/** @return the overflow buffer when ARCHIVED_MMAP is wrapping around */
481+
byte *get_archived_mmap_switch() const noexcept
482+
{
483+
ut_ad(archived_mmap_switch());
484+
return resize_buf + START_OFFSET;
485+
}
489486
#endif
487+
/** @return whether archived_mmap_switch_complete() needs to be called */
488+
bool archived_mmap_switch() const noexcept
489+
{
490+
ut_ad(latch_have_any());
491+
return UNIV_UNLIKELY(archive && resize_buf);
492+
}
493+
/** Attempt to finish archived_mmap_switch_prepare().
494+
@return the current LSN in the new file
495+
@retval 0 if no switch took place */
496+
ATTRIBUTE_COLD lsn_t archived_mmap_switch_complete() noexcept;
490497
/** Create a new log file when the current one will fill up.
491498
@param buf log records to append
492499
@param length size of the log records, in bytes
@@ -539,7 +546,7 @@ struct log_t
539546
/** Wait in append_prepare<ARCHIVED_MMAP>() for buffer to become available
540547
@param late whether the WRITE_BACKOFF flag had already been set
541548
@param ex whether log_sys.latch is exclusively locked */
542-
ATTRIBUTE_COLD void append_prepare_archived_mmap(bool late, bool ex)
549+
ATTRIBUTE_COLD void archived_mmap_switch_prepare(bool late, bool ex)
543550
noexcept;
544551
#endif
545552
public:

storage/innobase/include/mtr0mtr.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,15 @@ struct mtr_t {
688688
ATTRIBUTE_NOINLINE size_t crc32c() noexcept;
689689

690690
/** Commit the mini-transaction log.
691-
@tparam pmem log_sys.is_mmap()
691+
@tparam mmap log_sys.is_mmap()
692692
@param mtr mini-transaction
693693
@param lsns {start_lsn,flush_ahead_lsn} */
694-
template<bool pmem>
694+
template<bool mmap>
695695
static void commit_log(mtr_t *mtr, std::pair<lsn_t,lsn_t> lsns) noexcept;
696696

697-
/** Release log_sys.latch. */
697+
/** Release log_sys.latch.
698+
@tparam mmap log_sys.is_mmap() */
699+
template<bool mmap>
698700
void commit_log_release() noexcept;
699701

700702
/** Append the redo log records to the redo log buffer.

storage/innobase/log/log0log.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,8 @@ static size_t log_pad(lsn_t lsn, size_t pad, byte *begin, byte *extra)
967967
#endif
968968

969969
#ifdef HAVE_PMEM
970-
ATTRIBUTE_COLD void log_t::append_prepare_archived_mmap(bool late, bool ex)
971-
noexcept
970+
ATTRIBUTE_COLD
971+
void log_t::archived_mmap_switch_prepare(bool late, bool ex) noexcept
972972
{
973973
ut_ad(archive);
974974
ut_ad(is_mmap());
@@ -1056,16 +1056,13 @@ ATTRIBUTE_COLD void log_t::append_prepare_archived_mmap(bool late, bool ex)
10561056
}
10571057
while (false);
10581058

1059-
// TODO: adjust this, and clear the WRITE_BACKOFF flag
1060-
ut_ad(lsn - get_flushed_lsn(std::memory_order_relaxed) < capacity() ||
1061-
overwrite_warned);
1062-
persist(lsn); // TODO: pmem_persist()
1059+
ut_ad(lsn - get_flushed_lsn(std::memory_order_relaxed) < capacity());
1060+
persist(lsn);
10631061
/* Above we cleared the WRITE_BACKOFF flag,
10641062
which our caller will recheck. */
10651063
if (ex)
10661064
return;
10671065
latch.wr_unlock();
1068-
buf_flush_ahead(lsn, false);
10691066
}
10701067

10711068
done:

storage/innobase/mtr/mtr0mtr.cc

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,48 @@ void mtr_t::release()
338338
m_memo.clear();
339339
}
340340

341+
#ifdef HAVE_PMEM
342+
ATTRIBUTE_COLD lsn_t log_t::archived_mmap_switch_complete() noexcept
343+
{
344+
ut_ad(latch_have_wr());
345+
if (!archive || !resize_buf)
346+
return 0;
347+
const lsn_t lsn{get_lsn()}, end_lsn{first_lsn + capacity()};
348+
if (lsn < end_lsn)
349+
return 0;
350+
persist(lsn);
351+
my_munmap(buf, file_size);
352+
/* TODO: make the file read-only */
353+
buf= resize_buf;
354+
resize_buf= nullptr;
355+
first_lsn= end_lsn;
356+
file_size= resize_target;
357+
return lsn;
358+
}
359+
#endif
360+
361+
template<bool mmap>
341362
ATTRIBUTE_NOINLINE void mtr_t::commit_log_release() noexcept
342363
{
343364
if (m_latch_ex)
344365
{
366+
completed:
367+
const lsn_t lsn{mmap ? log_sys.archived_mmap_switch_complete() : 0};
345368
log_sys.latch.wr_unlock();
346369
m_latch_ex= false;
370+
if (mmap && lsn)
371+
buf_flush_ahead(lsn, true);
347372
}
348373
else
374+
{
375+
const bool retry{mmap && log_sys.archived_mmap_switch()};
349376
log_sys.latch.rd_unlock();
377+
if (retry)
378+
{
379+
log_sys.latch.wr_lock(SRW_LOCK_CALL);
380+
goto completed;
381+
}
382+
}
350383
}
351384

352385
static ATTRIBUTE_NOINLINE ATTRIBUTE_COLD
@@ -397,12 +430,12 @@ void mtr_t::commit_log(mtr_t *mtr, std::pair<lsn_t,lsn_t> lsns) noexcept
397430
buf_pool.page_cleaner_wakeup();
398431
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
399432

400-
mtr->commit_log_release();
433+
mtr->commit_log_release<mmap>();
401434
mtr->release();
402435
}
403436
else
404437
{
405-
mtr->commit_log_release();
438+
mtr->commit_log_release<mmap>();
406439

407440
for (auto it= mtr->m_memo.rbegin(); it != mtr->m_memo.rend(); )
408441
{
@@ -893,39 +926,20 @@ log_t::append_prepare<log_t::ARCHIVED_MMAP>(size_t size, bool ex) noexcept
893926
(WRITE_TO_BUF - 1)) >=
894927
capacity() -
895928
(lsn= base_lsn.load(std::memory_order_relaxed)) -
896-
first_lsn - size))
929+
first_lsn - size) && !resize_buf)
897930
{
898931
/* The following is inlined here instead of being part of
899932
append_prepare_wait(), in order to increase the locality of reference
900933
and to set the WRITE_BACKOFF flag as soon as possible. */
901934
bool late(write_lsn_offset.fetch_or(WRITE_BACKOFF) & WRITE_BACKOFF);
902935
/* Subtract our LSN overshoot. */
903936
write_lsn_offset.fetch_sub(size);
904-
append_prepare_archived_mmap(late, ex);
937+
archived_mmap_switch_prepare(late, ex);
905938
}
906939

907940
lsn+= l;
908941
return {lsn, buf + FIRST_LSN + (lsn - first_lsn)};
909942
}
910-
911-
inline void log_t::archive_new_mmap() noexcept
912-
{
913-
ut_ad(latch_have_any());
914-
ut_ad(!resize_log.is_opened());
915-
ut_ad(!resize_in_progress());
916-
ut_ad(resize_target >= 4U << 20);
917-
ut_ad(is_latest());
918-
919-
resize_wrap_mutex.wr_lock();
920-
if (resize_buf)
921-
{
922-
my_munmap(buf, size_t(file_size));
923-
buf= resize_buf;
924-
resize_buf= nullptr;
925-
file_size= resize_target;
926-
}
927-
resize_wrap_mutex.wr_unlock();
928-
}
929943
#endif
930944

931945
ATTRIBUTE_COLD void log_t::append_prepare_wait(bool late, bool ex) noexcept
@@ -1299,14 +1313,14 @@ mtr_t::finish_writer(mtr_t *mtr, size_t len)
12991313
#ifdef HAVE_PMEM
13001314
else
13011315
{
1302-
byte *const end= &log_sys.buf[log_sys.file_size];
1316+
const size_t file_size= log_sys.file_size;
1317+
byte *const buf{log_sys.buf};
1318+
byte *const end= &buf[file_size];
13031319
if (UNIV_LIKELY(start.second + len <= end))
13041320
goto write_normal;
1305-
if (mode == log_t::CIRCULAR_MMAP)
1306-
log_sys.archived_lsn= 0;
1307-
else
1308-
log_sys.archive_new_mmap();
1309-
byte *const begin= &log_sys.buf[log_sys.START_OFFSET];
1321+
byte *const begin= mode == log_t::ARCHIVED_MMAP
1322+
? log_sys.get_archived_mmap_switch()
1323+
: buf + log_sys.START_OFFSET;
13101324
for (const mtr_buf_t::block_t &b : mtr->m_log)
13111325
{
13121326
size_t size{b.used()};

0 commit comments

Comments
 (0)