Skip to content

Commit 950300e

Browse files
AliSQLAliSQL
authored andcommitted
[Feature] Issue#3 OPTMIZE AND BUGFIX LOG_WRITE_UP_TO
optimize log_write_up_to, port from upstream =================== Committer: Yasufumi Kinoshita Date: 2013-10-17 10:05:54 UTC Revision ID: [email protected] WL#7050 - InnoDB: Refactor redo log write code for better performance - This is rewrite of log_write_up_to() to improve its performance in case where innodb_flush_log_at_trx_commit = 2. In log_write_up_to(): * Remove wait mode. We always wait with one exception. And that is when doing log sync from master thread. It makes that synchronous as well because that happens only once per second. * Because we only have one log group therefore we don't need two flush_events. * Remove unnecessary fields like written_to_some_lsn, written_to_all_lsn. * If only write is requested we don't have to acquire the log_sys::mutex after we release it. We currently do that only to do event handling but event handling is really only needed in case where flush is requested i.e.: a thread should be waiting on the event iff it is interested in flushing. Writes are serialized under log_sys::mutex. This patch was originally written by Inaam Rana. rb#2389 Approved by Sunny and Yasufumi =========== Adjustment for performance was done therough inherited rb#3373 - optimize log_write_up_to() more * remove the second log_sys->mutex obtain also for "innodb_flush_log_at_trx_commit = 1" path * remove unnecessary ut_memcpy. (because log_group_write_buf() is protected by log_sys->mutex) * remove dirty-read from flush_to_disk=true case. (to avoid regression at some cases) (to keep current arbitration for write/fsync contention between log and data file) * fix wrong handling of O_DSYNC - revive log_buffer_sync_in_background(). (because it needs to be used) Bugfix: =================== bug#73109, skip redo log write when log_sys->buf_free is equal to log_sys->buf_next_to_write
1 parent fffe0c3 commit 950300e

12 files changed

Lines changed: 129 additions & 350 deletions

mysql-test/suite/sys_vars/r/innodb_monitor_disable_basic.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ log_lsn_checkpoint_age disabled
150150
log_lsn_buf_pool_oldest disabled
151151
log_max_modified_age_async disabled
152152
log_max_modified_age_sync disabled
153-
log_pending_log_writes disabled
153+
log_pending_log_flushes disabled
154154
log_pending_checkpoint_writes disabled
155155
log_num_log_io disabled
156156
log_waits disabled

mysql-test/suite/sys_vars/r/innodb_monitor_enable_basic.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ log_lsn_checkpoint_age disabled
150150
log_lsn_buf_pool_oldest disabled
151151
log_max_modified_age_async disabled
152152
log_max_modified_age_sync disabled
153-
log_pending_log_writes disabled
153+
log_pending_log_flushes disabled
154154
log_pending_checkpoint_writes disabled
155155
log_num_log_io disabled
156156
log_waits disabled

mysql-test/suite/sys_vars/r/innodb_monitor_reset_all_basic.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ log_lsn_checkpoint_age disabled
150150
log_lsn_buf_pool_oldest disabled
151151
log_max_modified_age_async disabled
152152
log_max_modified_age_sync disabled
153-
log_pending_log_writes disabled
153+
log_pending_log_flushes disabled
154154
log_pending_checkpoint_writes disabled
155155
log_num_log_io disabled
156156
log_waits disabled

mysql-test/suite/sys_vars/r/innodb_monitor_reset_basic.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ log_lsn_checkpoint_age disabled
150150
log_lsn_buf_pool_oldest disabled
151151
log_max_modified_age_async disabled
152152
log_max_modified_age_sync disabled
153-
log_pending_log_writes disabled
153+
log_pending_log_flushes disabled
154154
log_pending_checkpoint_writes disabled
155155
log_num_log_io disabled
156156
log_waits disabled

storage/innobase/buf/buf0flu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ buf_flush_write_block_low(
916916
}
917917
#else
918918
/* Force the log to the disk before writing the modified block */
919-
log_write_up_to(bpage->newest_modification, LOG_WAIT_ALL_GROUPS, TRUE);
919+
log_write_up_to(bpage->newest_modification, TRUE);
920920
#endif
921921
switch (buf_page_get_state(bpage)) {
922922
case BUF_BLOCK_POOL_WATCH:

storage/innobase/ibuf/ibuf0ibuf.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4420,7 +4420,7 @@ ibuf_delete_rec(
44204420
btr_cur_set_deleted_flag_for_ibuf(
44214421
btr_pcur_get_rec(pcur), NULL, TRUE, mtr);
44224422
ibuf_mtr_commit(mtr);
4423-
log_write_up_to(LSN_MAX, LOG_WAIT_ALL_GROUPS, TRUE);
4423+
log_write_up_to(LSN_MAX, TRUE);
44244424
DBUG_SUICIDE();
44254425
}
44264426
#endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */

storage/innobase/include/log0log.h

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ extern ibool log_debug_writes;
6262
# define log_do_write TRUE
6363
#endif /* UNIV_DEBUG */
6464

65-
/** Wait modes for log_write_up_to @{ */
66-
#define LOG_NO_WAIT 91
67-
#define LOG_WAIT_ONE_GROUP 92
68-
#define LOG_WAIT_ALL_GROUPS 93
6965
/* @} */
7066
/** Maximum number of log groups in log_group_t::checkpoint_buf */
7167
#define LOG_MAX_N_GROUPS 32
@@ -203,8 +199,6 @@ log_write_up_to(
203199
/*============*/
204200
lsn_t lsn, /*!< in: log sequence number up to which
205201
the log should be written, LSN_MAX if not specified */
206-
ulint wait, /*!< in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP,
207-
or LOG_WAIT_ALL_GROUPS */
208202
ibool flush_to_disk);
209203
/*!< in: TRUE if we want the written log
210204
also to be flushed to disk */
@@ -723,8 +717,6 @@ struct log_group_t{
723717
lsn_t lsn; /*!< lsn used to fix coordinates within
724718
the log group */
725719
lsn_t lsn_offset; /*!< the offset of the above lsn */
726-
ulint n_pending_writes;/*!< number of currently pending flush
727-
writes for this log group */
728720
byte** file_header_bufs_ptr;/*!< unaligned buffers */
729721
byte** file_header_bufs;/*!< buffers for each file
730722
header in the group */
@@ -819,30 +811,7 @@ struct log_t{
819811
groups */
820812
volatile bool is_extending; /*!< this is set to true during extend
821813
the log buffer size */
822-
lsn_t written_to_some_lsn;
823-
/*!< first log sequence number not yet
824-
written to any log group; for this to
825-
be advanced, it is enough that the
826-
write i/o has been completed for any
827-
one log group */
828-
lsn_t written_to_all_lsn;
829-
/*!< first log sequence number not yet
830-
written to some log group; for this to
831-
be advanced, it is enough that the
832-
write i/o has been completed for all
833-
log groups.
834-
Note that since InnoDB currently
835-
has only one log group therefore
836-
this value is redundant. Also it
837-
is possible that this value
838-
falls behind the
839-
flushed_to_disk_lsn transiently.
840-
It is appropriate to use either
841-
flushed_to_disk_lsn or
842-
write_lsn which are always
843-
up-to-date and accurate. */
844-
lsn_t write_lsn; /*!< end lsn for the current running
845-
write */
814+
lsn_t write_lsn; /*!< last written lsn */
846815
ulint write_end_offset;/*!< the data in buffer has
847816
been written up to this offset
848817
when the current write ends:
@@ -853,31 +822,17 @@ struct log_t{
853822
lsn_t flushed_to_disk_lsn;
854823
/*!< how far we have written the log
855824
AND flushed to disk */
856-
ulint n_pending_writes;/*!< number of currently
857-
pending flushes or writes */
858-
/* NOTE on the 'flush' in names of the fields below: starting from
859-
4.0.14, we separate the write of the log file and the actual fsync()
860-
or other method to flush it to disk. The names below shhould really
861-
be 'flush_or_write'! */
862-
os_event_t no_flush_event; /*!< this event is in the reset state
863-
when a flush or a write is running;
864-
a thread should wait for this without
825+
ulint n_pending_flushes; /*!< number of currently pending flushes.*/
826+
os_event_t flush_event; /*!< this event is in the reset state
827+
when a flush is running; a thread
828+
should wait for this without
865829
owning the log mutex, but NOTE that
866830
to set or reset this event, the
867831
thread MUST own the log mutex! */
868832
ibool one_flushed; /*!< during a flush, this is
869833
first FALSE and becomes TRUE
870834
when one log group has been
871835
written or flushed */
872-
os_event_t one_flushed_event;/*!< this event is reset when the
873-
flush or write has not yet completed
874-
for any log group; e.g., this means
875-
that a transaction has been committed
876-
when this is set; a thread should wait
877-
for this without owning the log mutex,
878-
but NOTE that to set or reset this
879-
event, the thread MUST own the log
880-
mutex! */
881836
ulint n_log_ios; /*!< number of log i/os initiated thus
882837
far */
883838
ulint n_log_ios_old; /*!< number of log i/o's at the

storage/innobase/include/srv0mon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ enum monitor_id_t {
291291
MONITOR_OVLD_BUF_OLDEST_LSN,
292292
MONITOR_OVLD_MAX_AGE_ASYNC,
293293
MONITOR_OVLD_MAX_AGE_SYNC,
294-
MONITOR_PENDING_LOG_WRITE,
294+
MONITOR_PENDING_LOG_FLUSH,
295295
MONITOR_PENDING_CHECKPOINT_WRITE,
296296
MONITOR_LOG_IO,
297297
MONITOR_OVLD_LOG_WAITS,

0 commit comments

Comments
 (0)