Commit 8f7f6b3c authored by marko's avatar marko

Port r106 from branches/5.0:

Protect the increment and decrement operations on the statistic variables
os_n_pending_writes and os_n_pending_reads with os_file_count_mutex.
parent 2a59184a
...@@ -160,15 +160,12 @@ time_t os_last_printout; ...@@ -160,15 +160,12 @@ time_t os_last_printout;
ibool os_has_said_disk_full = FALSE; ibool os_has_said_disk_full = FALSE;
/* The mutex protecting the following counts of pending pread and pwrite /* The mutex protecting the following counts of pending I/O operations */
operations */
static os_mutex_t os_file_count_mutex; static os_mutex_t os_file_count_mutex;
ulint os_file_n_pending_preads = 0; ulint os_file_n_pending_preads = 0;
ulint os_file_n_pending_pwrites = 0; ulint os_file_n_pending_pwrites = 0;
ulint os_n_pending_writes = 0;
/* These are not protected by any mutex */ ulint os_n_pending_reads = 0;
ulint os_n_pending_writes = 0;
ulint os_n_pending_reads = 0;
/*************************************************************************** /***************************************************************************
Gets the operating system version. Currently works only on Windows. */ Gets the operating system version. Currently works only on Windows. */
...@@ -1905,12 +1902,14 @@ os_file_pread( ...@@ -1905,12 +1902,14 @@ os_file_pread(
#if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD) #if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)
os_mutex_enter(os_file_count_mutex); os_mutex_enter(os_file_count_mutex);
os_file_n_pending_preads++; os_file_n_pending_preads++;
os_n_pending_reads++;
os_mutex_exit(os_file_count_mutex); os_mutex_exit(os_file_count_mutex);
n_bytes = pread(file, buf, (ssize_t)n, offs); n_bytes = pread(file, buf, (ssize_t)n, offs);
os_mutex_enter(os_file_count_mutex); os_mutex_enter(os_file_count_mutex);
os_file_n_pending_preads--; os_file_n_pending_preads--;
os_n_pending_reads--;
os_mutex_exit(os_file_count_mutex); os_mutex_exit(os_file_count_mutex);
return(n_bytes); return(n_bytes);
...@@ -1920,6 +1919,10 @@ os_file_pread( ...@@ -1920,6 +1919,10 @@ os_file_pread(
ssize_t ret; ssize_t ret;
ulint i; ulint i;
os_mutex_enter(os_file_count_mutex);
os_n_pending_reads++;
os_mutex_exit(os_file_count_mutex);
/* Protect the seek / read operation with a mutex */ /* Protect the seek / read operation with a mutex */
i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
...@@ -1928,15 +1931,17 @@ os_file_pread( ...@@ -1928,15 +1931,17 @@ os_file_pread(
ret_offset = lseek(file, offs, SEEK_SET); ret_offset = lseek(file, offs, SEEK_SET);
if (ret_offset < 0) { if (ret_offset < 0) {
os_mutex_exit(os_file_seek_mutexes[i]); ret = -1;
} else {
return(-1); ret = read(file, buf, (ssize_t)n);
} }
ret = read(file, buf, (ssize_t)n);
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
os_mutex_enter(os_file_count_mutex);
os_n_pending_reads--;
os_mutex_exit(os_file_count_mutex);
return(ret); return(ret);
} }
#endif #endif
...@@ -1981,12 +1986,14 @@ os_file_pwrite( ...@@ -1981,12 +1986,14 @@ os_file_pwrite(
#if defined(HAVE_PWRITE) && !defined(HAVE_BROKEN_PREAD) #if defined(HAVE_PWRITE) && !defined(HAVE_BROKEN_PREAD)
os_mutex_enter(os_file_count_mutex); os_mutex_enter(os_file_count_mutex);
os_file_n_pending_pwrites++; os_file_n_pending_pwrites++;
os_n_pending_writes++;
os_mutex_exit(os_file_count_mutex); os_mutex_exit(os_file_count_mutex);
ret = pwrite(file, buf, (ssize_t)n, offs); ret = pwrite(file, buf, (ssize_t)n, offs);
os_mutex_enter(os_file_count_mutex); os_mutex_enter(os_file_count_mutex);
os_file_n_pending_pwrites--; os_file_n_pending_pwrites--;
os_n_pending_writes--;
os_mutex_exit(os_file_count_mutex); os_mutex_exit(os_file_count_mutex);
# ifdef UNIV_DO_FLUSH # ifdef UNIV_DO_FLUSH
...@@ -2008,6 +2015,10 @@ os_file_pwrite( ...@@ -2008,6 +2015,10 @@ os_file_pwrite(
off_t ret_offset; off_t ret_offset;
ulint i; ulint i;
os_mutex_enter(os_file_count_mutex);
os_n_pending_writes++;
os_mutex_exit(os_file_count_mutex);
/* Protect the seek / write operation with a mutex */ /* Protect the seek / write operation with a mutex */
i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
...@@ -2016,9 +2027,9 @@ os_file_pwrite( ...@@ -2016,9 +2027,9 @@ os_file_pwrite(
ret_offset = lseek(file, offs, SEEK_SET); ret_offset = lseek(file, offs, SEEK_SET);
if (ret_offset < 0) { if (ret_offset < 0) {
os_mutex_exit(os_file_seek_mutexes[i]); ret = -1;
return(-1); goto func_exit;
} }
ret = write(file, buf, (ssize_t)n); ret = write(file, buf, (ssize_t)n);
...@@ -2036,8 +2047,13 @@ os_file_pwrite( ...@@ -2036,8 +2047,13 @@ os_file_pwrite(
} }
# endif /* UNIV_DO_FLUSH */ # endif /* UNIV_DO_FLUSH */
func_exit:
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
os_mutex_enter(os_file_count_mutex);
os_n_pending_writes--;
os_mutex_exit(os_file_count_mutex);
return(ret); return(ret);
} }
#endif #endif
...@@ -2082,9 +2098,13 @@ os_file_read( ...@@ -2082,9 +2098,13 @@ os_file_read(
low = (DWORD) offset; low = (DWORD) offset;
high = (DWORD) offset_high; high = (DWORD) offset_high;
os_mutex_enter(os_file_count_mutex);
os_n_pending_reads++;
os_mutex_exit(os_file_count_mutex);
/* Protect the seek / read operation with a mutex */ /* Protect the seek / read operation with a mutex */
i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
os_mutex_enter(os_file_seek_mutexes[i]); os_mutex_enter(os_file_seek_mutexes[i]);
ret2 = SetFilePointer(file, low, &high, FILE_BEGIN); ret2 = SetFilePointer(file, low, &high, FILE_BEGIN);
...@@ -2093,17 +2113,21 @@ os_file_read( ...@@ -2093,17 +2113,21 @@ os_file_read(
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
os_mutex_enter(os_file_count_mutex);
os_n_pending_reads--;
os_mutex_exit(os_file_count_mutex);
goto error_handling; goto error_handling;
} }
os_n_pending_reads++;
ret = ReadFile(file, buf, (DWORD) n, &len, NULL); ret = ReadFile(file, buf, (DWORD) n, &len, NULL);
os_n_pending_reads--;
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
os_mutex_enter(os_file_count_mutex);
os_n_pending_reads--;
os_mutex_exit(os_file_count_mutex);
if (ret && len == n) { if (ret && len == n) {
return(TRUE); return(TRUE);
} }
...@@ -2114,12 +2138,8 @@ os_file_read( ...@@ -2114,12 +2138,8 @@ os_file_read(
os_bytes_read_since_printout += n; os_bytes_read_since_printout += n;
try_again: try_again:
os_n_pending_reads++;
ret = os_file_pread(file, buf, n, offset, offset_high); ret = os_file_pread(file, buf, n, offset, offset_high);
os_n_pending_reads--;
if ((ulint)ret == n) { if ((ulint)ret == n) {
return(TRUE); return(TRUE);
...@@ -2193,6 +2213,10 @@ os_file_read_no_error_handling( ...@@ -2193,6 +2213,10 @@ os_file_read_no_error_handling(
low = (DWORD) offset; low = (DWORD) offset;
high = (DWORD) offset_high; high = (DWORD) offset_high;
os_mutex_enter(os_file_count_mutex);
os_n_pending_reads++;
os_mutex_exit(os_file_count_mutex);
/* Protect the seek / read operation with a mutex */ /* Protect the seek / read operation with a mutex */
i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
...@@ -2204,17 +2228,21 @@ os_file_read_no_error_handling( ...@@ -2204,17 +2228,21 @@ os_file_read_no_error_handling(
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
os_mutex_enter(os_file_count_mutex);
os_n_pending_reads--;
os_mutex_exit(os_file_count_mutex);
goto error_handling; goto error_handling;
} }
os_n_pending_reads++;
ret = ReadFile(file, buf, (DWORD) n, &len, NULL); ret = ReadFile(file, buf, (DWORD) n, &len, NULL);
os_n_pending_reads--;
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
os_mutex_enter(os_file_count_mutex);
os_n_pending_reads--;
os_mutex_exit(os_file_count_mutex);
if (ret && len == n) { if (ret && len == n) {
return(TRUE); return(TRUE);
} }
...@@ -2225,12 +2253,8 @@ os_file_read_no_error_handling( ...@@ -2225,12 +2253,8 @@ os_file_read_no_error_handling(
os_bytes_read_since_printout += n; os_bytes_read_since_printout += n;
try_again: try_again:
os_n_pending_reads++;
ret = os_file_pread(file, buf, n, offset, offset_high); ret = os_file_pread(file, buf, n, offset, offset_high);
os_n_pending_reads--;
if ((ulint)ret == n) { if ((ulint)ret == n) {
return(TRUE); return(TRUE);
...@@ -2310,6 +2334,10 @@ os_file_write( ...@@ -2310,6 +2334,10 @@ os_file_write(
low = (DWORD) offset; low = (DWORD) offset;
high = (DWORD) offset_high; high = (DWORD) offset_high;
os_mutex_enter(os_file_count_mutex);
os_n_pending_writes++;
os_mutex_exit(os_file_count_mutex);
/* Protect the seek / write operation with a mutex */ /* Protect the seek / write operation with a mutex */
i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
...@@ -2321,6 +2349,10 @@ os_file_write( ...@@ -2321,6 +2349,10 @@ os_file_write(
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
os_mutex_enter(os_file_count_mutex);
os_n_pending_writes--;
os_mutex_exit(os_file_count_mutex);
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fprintf(stderr, fprintf(stderr,
...@@ -2335,12 +2367,8 @@ os_file_write( ...@@ -2335,12 +2367,8 @@ os_file_write(
return(FALSE); return(FALSE);
} }
os_n_pending_writes++;
ret = WriteFile(file, buf, (DWORD) n, &len, NULL); ret = WriteFile(file, buf, (DWORD) n, &len, NULL);
os_n_pending_writes--;
/* 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. */
...@@ -2352,6 +2380,10 @@ os_file_write( ...@@ -2352,6 +2380,10 @@ os_file_write(
os_mutex_exit(os_file_seek_mutexes[i]); os_mutex_exit(os_file_seek_mutexes[i]);
os_mutex_enter(os_file_count_mutex);
os_n_pending_writes--;
os_mutex_exit(os_file_count_mutex);
if (ret && len == n) { if (ret && len == n) {
return(TRUE); return(TRUE);
...@@ -2402,11 +2434,7 @@ os_file_write( ...@@ -2402,11 +2434,7 @@ os_file_write(
#else #else
ssize_t ret; ssize_t ret;
os_n_pending_writes++;
ret = os_file_pwrite(file, buf, n, offset, offset_high); ret = os_file_pwrite(file, buf, n, offset, offset_high);
os_n_pending_writes--;
if ((ulint)ret == n) { if ((ulint)ret == n) {
......
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