Commit a89939c8 authored by marko@hundin.mysql.fi's avatar marko@hundin.mysql.fi

InnoDB: Do not flush after each write, not even when creating the

data files.  Previously, writes were flushed until the doublewrite
buffer was created.  That would be too slow on systems where
os_file_flush() [or fsync(2)] is slow.  (Bug #12125)
parent d3567611
...@@ -17,7 +17,9 @@ Created 10/21/1995 Heikki Tuuri ...@@ -17,7 +17,9 @@ Created 10/21/1995 Heikki Tuuri
#include <time.h> #include <time.h>
#endif #endif
#ifdef UNIV_DO_FLUSH
extern ibool os_do_not_call_flush_at_each_write; extern ibool os_do_not_call_flush_at_each_write;
#endif /* UNIV_DO_FLUSH */
extern ibool os_has_said_disk_full; extern ibool os_has_said_disk_full;
extern ibool os_aio_print_debug; extern ibool os_aio_print_debug;
......
...@@ -33,9 +33,13 @@ ulint os_innodb_umask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; ...@@ -33,9 +33,13 @@ ulint os_innodb_umask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
ulint os_innodb_umask = 0; ulint os_innodb_umask = 0;
#endif #endif
#ifdef UNIV_DO_FLUSH
/* If the following is set to TRUE, we do not call os_file_flush in every /* If the following is set to TRUE, we do not call os_file_flush in every
os_file_write. We can set this TRUE when the doublewrite buffer is used. */ os_file_write. We can set this TRUE when the doublewrite buffer is used. */
ibool os_do_not_call_flush_at_each_write = FALSE; ibool os_do_not_call_flush_at_each_write = FALSE;
#else
/* We do not call os_file_flush in every os_file_write. */
#endif /* UNIV_DO_FLUSH */
/* We use these mutexes to protect lseek + file i/o operation, if the /* We use these mutexes to protect lseek + file i/o operation, if the
OS does not provide an atomic pread or pwrite, or similar */ OS does not provide an atomic pread or pwrite, or similar */
...@@ -1974,6 +1978,7 @@ os_file_pwrite( ...@@ -1974,6 +1978,7 @@ os_file_pwrite(
os_file_n_pending_pwrites--; os_file_n_pending_pwrites--;
os_mutex_exit(os_file_count_mutex); os_mutex_exit(os_file_count_mutex);
# ifdef UNIV_DO_FLUSH
if (srv_unix_file_flush_method != SRV_UNIX_LITTLESYNC if (srv_unix_file_flush_method != SRV_UNIX_LITTLESYNC
&& srv_unix_file_flush_method != SRV_UNIX_NOSYNC && srv_unix_file_flush_method != SRV_UNIX_NOSYNC
&& !os_do_not_call_flush_at_each_write) { && !os_do_not_call_flush_at_each_write) {
...@@ -1984,6 +1989,7 @@ os_file_pwrite( ...@@ -1984,6 +1989,7 @@ os_file_pwrite(
ut_a(TRUE == os_file_flush(file)); ut_a(TRUE == os_file_flush(file));
} }
# endif /* UNIV_DO_FLUSH */
return(ret); return(ret);
#else #else
...@@ -2006,6 +2012,7 @@ os_file_pwrite( ...@@ -2006,6 +2012,7 @@ os_file_pwrite(
ret = write(file, buf, (ssize_t)n); ret = write(file, buf, (ssize_t)n);
# ifdef UNIV_DO_FLUSH
if (srv_unix_file_flush_method != SRV_UNIX_LITTLESYNC if (srv_unix_file_flush_method != SRV_UNIX_LITTLESYNC
&& srv_unix_file_flush_method != SRV_UNIX_NOSYNC && srv_unix_file_flush_method != SRV_UNIX_NOSYNC
&& !os_do_not_call_flush_at_each_write) { && !os_do_not_call_flush_at_each_write) {
...@@ -2016,6 +2023,7 @@ os_file_pwrite( ...@@ -2016,6 +2023,7 @@ os_file_pwrite(
ut_a(TRUE == os_file_flush(file)); ut_a(TRUE == os_file_flush(file));
} }
# endif /* UNIV_DO_FLUSH */
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
...@@ -2282,9 +2290,11 @@ retry: ...@@ -2282,9 +2290,11 @@ retry:
/* Always do fsync to reduce the probability that when the OS crashes, /* Always do fsync to reduce the probability that when the OS crashes,
a database page is only partially physically written to disk. */ a database page is only partially physically written to disk. */
# ifdef UNIV_DO_FLUSH
if (!os_do_not_call_flush_at_each_write) { if (!os_do_not_call_flush_at_each_write) {
ut_a(TRUE == os_file_flush(file)); ut_a(TRUE == os_file_flush(file));
} }
# endif /* UNIV_DO_FLUSH */
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
...@@ -3498,10 +3508,12 @@ os_aio_windows_handle( ...@@ -3498,10 +3508,12 @@ os_aio_windows_handle(
if (ret && len == slot->len) { if (ret && len == slot->len) {
ret_val = TRUE; ret_val = TRUE;
# ifdef UNIV_DO_FLUSH
if (slot->type == OS_FILE_WRITE if (slot->type == OS_FILE_WRITE
&& !os_do_not_call_flush_at_each_write) { && !os_do_not_call_flush_at_each_write) {
ut_a(TRUE == os_file_flush(slot->file)); ut_a(TRUE == os_file_flush(slot->file));
} }
# endif /* UNIV_DO_FLUSH */
} else { } else {
os_file_handle_error(slot->name, "Windows aio"); os_file_handle_error(slot->name, "Windows aio");
...@@ -3582,10 +3594,12 @@ os_aio_posix_handle( ...@@ -3582,10 +3594,12 @@ os_aio_posix_handle(
*message1 = slot->message1; *message1 = slot->message1;
*message2 = slot->message2; *message2 = slot->message2;
# ifdef UNIV_DO_FLUSH
if (slot->type == OS_FILE_WRITE if (slot->type == OS_FILE_WRITE
&& !os_do_not_call_flush_at_each_write) { && !os_do_not_call_flush_at_each_write) {
ut_a(TRUE == os_file_flush(slot->file)); ut_a(TRUE == os_file_flush(slot->file));
} }
# endif /* UNIV_DO_FLUSH */
os_mutex_exit(array->mutex); os_mutex_exit(array->mutex);
......
...@@ -97,8 +97,9 @@ trx_doublewrite_init( ...@@ -97,8 +97,9 @@ trx_doublewrite_init(
/* Since we now start to use the doublewrite buffer, no need to call /* Since we now start to use the doublewrite buffer, no need to call
fsync() after every write to a data file */ fsync() after every write to a data file */
#ifdef UNIV_DO_FLUSH
os_do_not_call_flush_at_each_write = TRUE; os_do_not_call_flush_at_each_write = TRUE;
#endif /* UNIV_DO_FLUSH */
mutex_create(&(trx_doublewrite->mutex)); mutex_create(&(trx_doublewrite->mutex));
mutex_set_level(&(trx_doublewrite->mutex), SYNC_DOUBLEWRITE); mutex_set_level(&(trx_doublewrite->mutex), SYNC_DOUBLEWRITE);
......
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