Commit dfceab2f authored by unknown's avatar unknown

InnoDB: Detect the availability of the Mac OS X fsync() work-around

at run-time, so that an executable compiled on Mac OS X 10.2 can
be run on Mac OS X 10.2 (without the work-around) and Mac OS X 10.3
and later with the work-aroud enabled.


innobase/include/srv0start.h:
  Mac OS X: Add srv_have_fullfsync
innobase/os/os0file.c:
  os_file_flush(): Use F_FULLFSYNC on Mac OS X 10.3, but not on 10.2
innobase/srv/srv0start.c:
  innobase_start_or_create_for_mysql(): When compiled on OS X 10.2,
  detect if the binary is running on OS X 10.3 or later, and set
  srv_have_fullfsync accordingly.
parent d1a45680
......@@ -75,6 +75,10 @@ extern dulint srv_start_lsn;
void set_panic_flag_for_netware(void);
#endif
#ifdef HAVE_DARWIN_THREADS
extern ibool srv_have_fullfsync;
#endif
extern ulint srv_sizeof_trx_t_in_ha_innodb_cc;
extern ibool srv_is_being_started;
......
......@@ -1763,19 +1763,31 @@ os_file_flush(
#else
int ret;
#if defined(HAVE_DARWIN_THREADS) && defined(F_FULLFSYNC)
#if defined(HAVE_DARWIN_THREADS)
# ifndef F_FULLFSYNC
/* The following definition is from the Mac OS X 10.3 <sys/fcntl.h> */
# define F_FULLFSYNC 51 /* fsync + ask the drive to flush to the media */
# elif F_FULLFSYNC != 51
# error "F_FULLFSYNC != 51: ABI incompatibility with Mac OS X 10.3"
# endif
/* Apple has disabled fsync() for internal disk drives in OS X. That
caused corruption for a user when he tested a power outage. Let us in
OS X use a nonstandard flush method recommended by an Apple
engineer. */
ret = fcntl(file, F_FULLFSYNC, NULL);
if (ret) {
/* If we are not on a file system that supports this, then
fall back to a plain fsync. */
if (!srv_have_fullfsync) {
/* If we are not on an operating system that supports this,
then fall back to a plain fsync. */
ret = fsync(file);
} else {
ret = fcntl(file, F_FULLFSYNC, NULL);
if (ret) {
/* If we are not on a file system that supports this,
then fall back to a plain fsync. */
ret = fsync(file);
}
}
#elif HAVE_FDATASYNC
ret = fdatasync(file);
......
......@@ -61,6 +61,11 @@ dulint srv_start_lsn;
/* Log sequence number at shutdown */
dulint srv_shutdown_lsn;
#ifdef HAVE_DARWIN_THREADS
# include <sys/utsname.h>
ibool srv_have_fullfsync = FALSE;
#endif
ibool srv_start_raw_disk_in_use = FALSE;
static ibool srv_start_has_been_called = FALSE;
......@@ -935,6 +940,28 @@ innobase_start_or_create_for_mysql(void)
ulint i;
ibool srv_file_per_table_original_value = srv_file_per_table;
mtr_t mtr;
#ifdef HAVE_DARWIN_THREADS
# ifdef F_FULLFSYNC
/* This executable has been compiled on Mac OS X 10.3 or later.
Assume that F_FULLFSYNC is available at run-time. */
srv_have_fullfsync = TRUE;
# else /* F_FULLFSYNC */
/* This executable has been compiled on Mac OS X 10.2
or earlier. Determine if the executable is running
on Mac OS X 10.3 or later. */
struct utsname utsname;
if (uname(&utsname)) {
fputs("InnoDB: cannot determine Mac OS X version!\n", stderr);
} else {
srv_have_fullfsync = strcmp(utsname.release, "7.") >= 0;
}
if (!srv_have_fullfsync) {
fputs(
"InnoDB: On Mac OS X, fsync() may be broken on internal drives,\n"
"InnoDB: making transactions unsafe!\n", stderr);
}
# endif /* F_FULLFSYNC */
#endif /* HAVE_DARWIN_THREADS */
if (sizeof(ulint) != sizeof(void*)) {
fprintf(stderr,
......
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