From: Date: January 27 2008 9:39pm Subject: bk commit into 6.0 tree (vvaintroub:1.2781) List-Archive: http://lists.mysql.com/commits/41288 Message-Id: <200801272039.m0RKdcfQ005223@mail.mysql.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Below is the list of changes that have just been committed into a local= =0A6.0 repository of vvaintroub. When vvaintroub does a push these changes= =0Awill be propagated to the main repository and, within 24 hours after= the=0Apush, to the public repository.=0AFor information on how to access= the public repository=0Asee http://dev.mysql.com/doc/mysql/en/installing-source-tree.html= =0A=0AChangeSet@stripped, 2008-01-27 21:04:23+01:00, vvaintroub@wva. +7 -0= =0A Windows: Remove mutex synchronization from my_pread()/my_pwrite().= =0A - implement pread()/pwrite() with native Windows ReadFile/WriteFile= =0A - implement my_lock() with LockFileEx/UnlockFileEx=0A - Get rid of= file-seek mutex also in Innodb and Falcon=0A=0A include/my_sys.h@stripped,= 2008-01-27 21:04:18+01:00, vvaintroub@wva. +1 -1=0A Get rid of Windows-specific= file-seek mutex=0A=0A mysys/my_lock.c@stripped, 2008-01-27 21:04:19+01:00,= vvaintroub@wva. +39 -20=0A Implement my_lock() with native Win32 functions= LockFileEx and UnlockFile=0A to remove mutex from my_file_info.=0A=0A= mysys/my_open.c@stripped, 2008-01-27 21:04:19+01:00, vvaintroub@wva. +2 -2= =0A Get rid of "seek"-mutex=0A=0A mysys/my_pread.c@stripped, 2008-01-27= 21:04:19+01:00, vvaintroub@wva. +75 -3=0A Implement pread() and pwrite()= with native Windows functions, remove=0A thread serialization via mutex= in pread/pwrite.=0A=0A mysys/my_seek.c@stripped, 2008-01-27 21:04:20+01:00,= vvaintroub@wva. +1 -1=0A Get rid of file-seek mutex.=0A=0A storage/falcon/SerialLogFile.cpp@stripped,= 2008-01-27 21:04:20+01:00, vvaintroub@wva. +11 -18=0A implement positional= read/write on Windows without file-seek mutex.=0A=0A storage/innobase/os/os0file.c@stripped,= 2008-01-27 21:04:21+01:00, vvaintroub@wva. +15 -102=0A implement positional= read/write on Windows without file-seek mutex.=0A=0Adiff -Nrup a/include/my_sys.h= b/include/my_sys.h=0A--- a/include/my_sys.h 2007-12-06 01:16:53 +01:00= =0A+++ b/include/my_sys.h 2008-01-27 21:04:18 +01:00=0A@@ -303,7 +303,7= @@ struct st_my_file_info=0A {=0A char * name;=0A enum file_type type;= =0A-#if defined(THREAD) && !defined(HAVE_PREAD)=0A+#if defined(THREAD) &&= !defined(HAVE_PREAD) && !defined(__WIN__)=0A pthread_mutex_t mutex;=0A= #endif=0A };=0Adiff -Nrup a/mysys/my_lock.c b/mysys/my_lock.c=0A--- a/mysys/my_lock.c= 2006-12-23 20:19:46 +01:00=0A+++ b/mysys/my_lock.c 2008-01-27 21:04:19= +01:00=0A@@ -48,6 +48,10 @@ int my_lock(File fd, int locktype, my_of=0A= #ifdef __NETWARE__=0A int nxErrno;=0A #endif=0A+#ifdef __WIN__=0A+ DWORD= lastError;=0A+#endif=0A+=0A DBUG_ENTER("my_lock");=0A DBUG_PRINT("my",("Fd:= %d Op: %d start: %ld Length: %ld MyFlags: %d",=0A fd,locktype,(long)= start,(long) length,MyFlags));=0A@@ -97,29 +101,42 @@ int my_lock(File= fd, int locktype, my_of=0A DBUG_RETURN(0);=0A }=0A }=0A-#elif= defined(HAVE_LOCKING)=0A- /* Windows */=0A+#elif defined(__WIN__)=0A = {=0A- my_bool error=3D FALSE;=0A- pthread_mutex_lock(&my_file_info[fd].mutex);= =0A- if (MyFlags & MY_SEEK_NOT_DONE) =0A+ =0A+ LARGE_INTEGER liOffset,liLength;= =0A+ DWORD dwFlags;=0A+ OVERLAPPED ov=3D {0};=0A+ HANDLE hFile=3D= (HANDLE)_get_osfhandle(fd);=0A+=0A+ lastError=3D 0;=0A+=0A+ liOffset.QuadPart=3D= start;=0A+ liLength.QuadPart=3D length;=0A+=0A+ ov.Offset=3D = liOffset.LowPart;=0A+ ov.OffsetHigh=3D liOffset.HighPart;=0A+=0A+= if (locktype =3D=3D F_UNLCK)=0A {=0A- if( my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags= & ~MY_SEEK_NOT_DONE))=0A- =3D=3D MY_FILEPOS_ERROR )=0A- = {=0A- /*=0A- If my_seek fails my_errno will already contain= an error code;=0A- just unlock and return error code.=0A- = */=0A- DBUG_PRINT("error",("my_errno: %d (%d)",my_errno,errno));= =0A- pthread_mutex_unlock(&my_file_info[fd].mutex);=0A- DBUG_RETURN(-1);= =0A- }=0A+ /* The lock flags are currently ignored by Windows= */=0A+ if(UnlockFileEx(hFile, 0, liLength.LowPart, liLength.HighPart,= &ov))=0A+ DBUG_RETURN(0);=0A+ else=0A+ lastError=3D= GetLastError();=0A }=0A- error=3D locking(fd,locktype,(ulong) length)= && errno !=3D EINVAL;=0A- pthread_mutex_unlock(&my_file_info[fd].mutex);= =0A- if (!error)=0A- DBUG_RETURN(0);=0A+ else if (locktype =3D=3D= F_RDLCK)=0A+ /* read lock is mapped to a shared lock. */=0A+ = dwFlags=3D 0;=0A+ else=0A+ /* write lock is mapped to an= exclusive lock. */=0A+ dwFlags=3D LOCKFILE_EXCLUSIVE_LOCK;=0A+=0A+= if (MyFlags & MY_DONT_WAIT)=0A+ dwFlags|=3D LOCKFILE_FAIL_IMMEDIATELY;= =0A+=0A+ if (LockFileEx(hFile, dwFlags, 0, liLength.LowPart, liLength.HighPart,= &ov))=0A+ DBUG_RETURN(0);=0A }=0A #else=0A #if defined(HAVE_FCNTL)= =0A@@ -171,6 +188,8 @@ int my_lock(File fd, int locktype, my_of=0A =0A #ifdef= __NETWARE__=0A my_errno =3D nxErrno;=0A+#elif defined(__WIN__)=0A+ my_errno= =3D (lastError =3D=3D ERROR_IO_PENDING)? EAGAIN:lastError?lastError : -1;= =0A #else=0A /* We got an error. We don't want EACCES errors */=0A my_errno=3D(errno= =3D=3D EACCES) ? EAGAIN : errno ? errno : -1;=0Adiff -Nrup a/mysys/my_open.c= b/mysys/my_open.c=0A--- a/mysys/my_open.c 2007-08-13 15:11:10 +02:00=0A+++= b/mysys/my_open.c 2008-01-27 21:04:19 +01:00=0A@@ -108,7 +108,7 @@ int= my_close(File fd, myf MyFlags)=0A if ((uint) fd < my_file_limit && my_file_info[fd].type= !=3D UNOPEN)=0A {=0A my_free(my_file_info[fd].name, MYF(0));=0A-#if= defined(THREAD) && !defined(HAVE_PREAD)=0A+#if defined(THREAD) && !defined(HAVE_PREAD)= && !defined (__WIN__)=0A pthread_mutex_destroy(&my_file_info[fd].mutex);= =0A #endif=0A my_file_info[fd].type =3D UNOPEN;=0A@@ -153,7 +153,7 @@= File my_register_filename(File fd, const=0A my_file_opened++;=0A= my_file_total_opened++;=0A my_file_info[fd].type =3D type_of_file;= =0A-#if defined(THREAD) && !defined(HAVE_PREAD)=0A+#if defined(THREAD) &&= !defined(HAVE_PREAD) && !defined(__WIN__)=0A pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST);= =0A #endif=0A pthread_mutex_unlock(&THR_LOCK_open);=0Adiff -Nrup a/mysys/my_pread.c= b/mysys/my_pread.c=0A--- a/mysys/my_pread.c 2007-05-31 16:45:16 +02:00= =0A+++ b/mysys/my_pread.c 2008-01-27 21:04:19 +01:00=0A@@ -16,10 +16,82= @@=0A #include "mysys_priv.h"=0A #include "mysys_err.h"=0A #include = =0A-#ifdef HAVE_PREAD=0A+#if defined (HAVE_PREAD) && !defined(__WIN__)=0A= #include =0A #endif=0A =0A+#ifdef __WIN__=0A+extern void _dosmaperr(DWORD);= =0A+=0A+/*=0A+ Positional read and write on Windows.=0A+=0A+ NOTE: =0A+= - this functions require NT-based kernel.=0A+ - they can read/write at= most 4GB at once.=0A+ - unlike Posix pread/pwrite, they change file pointer= position.=0A+*/=0A+static size_t pread(File Filedes, uchar *Buffer, size_t= Count, my_off_t offset)=0A+{=0A+ DWORD nBytesRead;=0A+ HANDLE= hFile;=0A+ OVERLAPPED ov=3D{0};=0A+ LARGE_INTEGER li;=0A+=0A+= if(!Count)=0A+ return 0;=0A+#ifdef _WIN64=0A+ if(Count > UINT_MAX)= =0A+ Count =3D UINT_MAX;=0A+#endif=0A+=0A+ hFile=3D (HANDLE)_get_osfhandle(Filedes);= =0A+ li.QuadPart=3D offset;=0A+ ov.Offset=3D li.LowPart;=0A+ ov.OffsetHigh=3D= li.HighPart;=0A+=0A+ if(!ReadFile(hFile, Buffer, (DWORD)Count, &nBytesRead,= &ov))=0A+ {=0A+ DWORD lastError =3D GetLastError();=0A+ if(lastError= =3D=3D ERROR_HANDLE_EOF)=0A+ return 0; /*return 0 at EOF*/=0A+ = _dosmaperr(lastError);=0A+ return -1;=0A+ }=0A+ else=0A+ return= nBytesRead;=0A+}=0A+=0A+static size_t pwrite(File Filedes, const uchar= *Buffer, size_t Count, my_off_t offset)=0A+{=0A+ DWORD nBytesWritten;= =0A+ HANDLE hFile;=0A+ OVERLAPPED ov=3D{0};=0A+ LARGE_INTEGER= li;=0A+=0A+ if(!Count)=0A+ return 0;=0A+=0A+#ifdef _WIN64=0A+ if(Count= > UINT_MAX)=0A+ Count =3D UINT_MAX;=0A+#endif=0A+=0A+ hFile=3D = (HANDLE)_get_osfhandle(Filedes);=0A+ li.QuadPart=3D offset;=0A+= ov.Offset=3D li.LowPart;=0A+ ov.OffsetHigh=3D li.HighPart;=0A+=0A+= if(!WriteFile(hFile, Buffer, (DWORD)Count, &nBytesWritten, &ov))=0A+ = {=0A+ _dosmaperr(GetLastError());=0A+ return -1;=0A+ }=0A+ else= =0A+ return nBytesWritten;=0A+}=0A+#endif=0A+=0A /*=0A Read a chunk= of bytes from a file from a given position=0A =0A@@ -55,7 +127,7 @@ size_t= my_pread(File Filedes, uchar *Buf=0A #ifndef __WIN__=0A errno=3D0;= /* Linux doesn't reset this */=0A #endif=0A-#ifndef HAVE_PREAD=0A+#if= !defined (HAVE_PREAD) && !defined (__WIN__)=0A pthread_mutex_lock(&my_file_info[Filedes].mutex);= =0A readbytes=3D (uint) -1;=0A error=3D (lseek(Filedes, offset,= MY_SEEK_SET) =3D=3D (my_off_t) -1 ||=0A@@ -131,7 +203,7 @@ size_t my_pwrite(int= Filedes, const ucha=0A =0A for (;;)=0A {=0A-#ifndef HAVE_PREAD=0A+#if= !defined (HAVE_PREAD) && !defined (__WIN__)=0A int error;=0A writenbytes=3D= (size_t) -1;=0A pthread_mutex_lock(&my_file_info[Filedes].mutex);=0Adiff= -Nrup a/mysys/my_seek.c b/mysys/my_seek.c=0A--- a/mysys/my_seek.c 2007-06-05= 00:43:02 +02:00=0A+++ b/mysys/my_seek.c 2008-01-27 21:04:20 +01:00=0A@@= -56,7 +56,7 @@ my_off_t my_seek(File fd, my_off_t pos, =0A Make sure= we are using a valid file descriptor!=0A */=0A DBUG_ASSERT(fd !=3D= -1);=0A-#if defined(THREAD) && !defined(HAVE_PREAD)=0A+#if defined(THREAD)= && !defined(HAVE_PREAD) && !defined(__WIN__)=0A if (MyFlags & MY_THREADSAFE)= =0A {=0A pthread_mutex_lock(&my_file_info[fd].mutex);=0Adiff -Nrup= a/storage/falcon/SerialLogFile.cpp b/storage/falcon/SerialLogFile.cpp=0A---= a/storage/falcon/SerialLogFile.cpp 2007-11-28 18:20:53 +01:00=0A+++ b/storage/falcon/SerialLogFile.cpp= 2008-01-27 21:04:20 +01:00=0A@@ -175,22 +175,16 @@ void SerialLogFile::write(int64= position=0A priority.schedule(PRIORITY_HIGH);=0A =0A #ifdef _WIN32= =0A- =0A- Sync sync(&syncObject, "SerialLogFile::write");=0A- sync.lock(Exclusive);= =0A- =0A- if (position !=3D offset)=0A- {=0A- LARGE_INTEGER pos;=0A- = pos.QuadPart =3D position;=0A+ LARGE_INTEGER pos;=0A+ pos.QuadPart =3D= offset;=0A =0A- if (!SetFilePointerEx(handle, pos, NULL, FILE_BEGIN))= =0A- throw SQLError(IO_ERROR, "serial log SetFilePointerEx failed with= %d", GetLastError());=0A- }=0A+ OVERLAPPED ov =3D {0};=0A+ ov.Offset =3D= pos.LowPart;=0A+ ov.OffsetHigh =3D pos.HighPart;=0A =0A DWORD ret;=0A= =0A- if (!WriteFile(handle, data, effectiveLength, &ret, NULL))=0A+ if= (!WriteFile(handle, data, effectiveLength, &ret, &ov))=0A {=0A int= lastError =3D GetLastError();=0A =0A@@ -252,18 +246,17 @@ uint32 SerialLogFile::read(int64= positio=0A priority.schedule(PRIORITY_HIGH);=0A =0A #ifdef _WIN32=0A-= Sync sync(&syncObject, "SerialLogFile::read");=0A- sync.lock(Exclusive);= =0A ASSERT(position < writePoint || writePoint =3D=3D 0);=0A LARGE_INTEGER= pos;=0A pos.QuadPart =3D position;=0A- =0A- if (!SetFilePointerEx(handle,= pos, NULL, FILE_BEGIN))=0A- throw SQLError(IO_ERROR, "serial log SetFilePointer= failed with %d", GetLastError());=0A+=0A+ OVERLAPPED ov =3D {0};=0A+ ov.Offset= =3D pos.LowPart;=0A+ ov.OffsetHigh =3D pos.HighPart;=0A =0A DWORD ret;= =0A =0A- if (!ReadFile(handle, data, effectiveLength, &ret, NULL))=0A+ if= (!ReadFile(handle, data, effectiveLength, &ret, &ov))=0A throw SQLError(IO_ERROR,= "serial log ReadFile failed with %d", GetLastError());=0A =0A offset =3D= position + effectiveLength;=0Adiff -Nrup a/storage/innobase/os/os0file.c= b/storage/innobase/os/os0file.c=0A--- a/storage/innobase/os/os0file.c 2007-08-16= 01:44:21 +02:00=0A+++ b/storage/innobase/os/os0file.c 2008-01-27 21:04:21= +01:00=0A@@ -2133,11 +2133,8 @@ os_file_read(=0A #ifdef __WIN__=0A BOOL= ret;=0A DWORD len;=0A- DWORD ret2;=0A- DWORD low;=0A- DWORD high;= =0A ibool retry;=0A- ulint i;=0A+ OVERLAPPED ov;=0A =0A ut_a((offset= & 0xFFFFFFFFUL) =3D=3D offset);=0A =0A@@ -2149,34 +2146,15 @@ try_again:= =0A ut_ad(buf);=0A ut_ad(n > 0);=0A =0A- low =3D (DWORD) offset;=0A- high= =3D (DWORD) offset_high;=0A+ memset(&ov, 0, sizeof(ov));=0A+ ov.Offset= =3D (DWORD) offset;=0A+ ov.OffsetHigh =3D (DWORD) offset_high;=0A =0A = os_mutex_enter(os_file_count_mutex);=0A os_n_pending_reads++;=0A os_mutex_exit(os_file_count_mutex);= =0A =0A- /* Protect the seek / read operation with a mutex */=0A- i =3D= ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;=0A-=0A- os_mutex_enter(os_file_seek_mutexes[i]);= =0A-=0A- ret2 =3D SetFilePointer(file, low, &high, FILE_BEGIN);=0A-=0A-= if (ret2 =3D=3D 0xFFFFFFFF && GetLastError() !=3D NO_ERROR) {=0A-=0A- = os_mutex_exit(os_file_seek_mutexes[i]);=0A-=0A- os_mutex_enter(os_file_count_mutex);= =0A- os_n_pending_reads--;=0A- os_mutex_exit(os_file_count_mutex);=0A-= =0A- goto error_handling;=0A- }=0A-=0A- ret =3D ReadFile(file, buf, (DWORD)= n, &len, NULL);=0A-=0A- os_mutex_exit(os_file_seek_mutexes[i]);=0A+ ret= =3D ReadFile(file, buf, (DWORD) n, &len, &ov);=0A =0A os_mutex_enter(os_file_count_mutex);= =0A os_n_pending_reads--;=0A@@ -2205,9 +2183,6 @@ try_again:=0A (ulong)n,= (ulong)offset_high,=0A (ulong)offset, (long)ret);=0A #endif=0A-#ifdef= __WIN__=0A-error_handling:=0A-#endif=0A retry =3D os_file_handle_error(NULL,= "read");=0A =0A if (retry) {=0A@@ -2250,11 +2225,8 @@ os_file_read_no_error_handling(= =0A #ifdef __WIN__=0A BOOL ret;=0A DWORD len;=0A- DWORD ret2;=0A- DWORD= low;=0A- DWORD high;=0A+ OVERLAPPED ov;=0A ibool retry;=0A- ulint = i;=0A =0A ut_a((offset & 0xFFFFFFFFUL) =3D=3D offset);=0A =0A@@ -2266,34= +2238,15 @@ try_again:=0A ut_ad(buf);=0A ut_ad(n > 0);=0A =0A- low =3D= (DWORD) offset;=0A- high =3D (DWORD) offset_high;=0A+ memset(&ov, 0, sizeof(ov));= =0A+ ov.Offset =3D (DWORD) offset;=0A+ ov.OffsetHigh =3D (DWORD) offset_high;= =0A =0A os_mutex_enter(os_file_count_mutex);=0A os_n_pending_reads++;= =0A os_mutex_exit(os_file_count_mutex);=0A =0A- /* Protect the seek / read= operation with a mutex */=0A- i =3D ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;= =0A-=0A- os_mutex_enter(os_file_seek_mutexes[i]);=0A-=0A- ret2 =3D SetFilePointer(file,= low, &high, FILE_BEGIN);=0A-=0A- if (ret2 =3D=3D 0xFFFFFFFF && GetLastError()= !=3D NO_ERROR) {=0A-=0A- os_mutex_exit(os_file_seek_mutexes[i]);=0A-=0A-= os_mutex_enter(os_file_count_mutex);=0A- os_n_pending_reads--;=0A- os_mutex_exit(os_file_count_mutex);= =0A-=0A- goto error_handling;=0A- }=0A-=0A- ret =3D ReadFile(file, buf,= (DWORD) n, &len, NULL);=0A-=0A- os_mutex_exit(os_file_seek_mutexes[i]);= =0A+ ret =3D ReadFile(file, buf, (DWORD) n, &len, &ov);=0A =0A os_mutex_enter(os_file_count_mutex);= =0A os_n_pending_reads--;=0A@@ -2316,9 +2269,6 @@ try_again:=0A return(TRUE);= =0A }=0A #endif=0A-#ifdef __WIN__=0A-error_handling:=0A-#endif=0A retry= =3D os_file_handle_error_no_exit(NULL, "read");=0A =0A if (retry) {=0A@@= -2372,10 +2322,7 @@ os_file_write(=0A #ifdef __WIN__=0A BOOL ret;=0A= DWORD len;=0A- DWORD ret2;=0A- DWORD low;=0A- DWORD high;=0A- ulint= i;=0A+ OVERLAPPED ov;=0A ulint n_retries =3D 0;=0A ulint err;=0A = =0A@@ -2387,47 +2334,15 @@ os_file_write(=0A ut_ad(buf);=0A ut_ad(n >= 0);=0A retry:=0A- low =3D (DWORD) offset;=0A- high =3D (DWORD) offset_high;= =0A+ memset(&ov, 0, sizeof(ov));=0A+ ov.Offset =3D (DWORD) offset;=0A+ ov.OffsetHigh= =3D (DWORD) offset_high;=0A =0A os_mutex_enter(os_file_count_mutex);=0A= os_n_pending_writes++;=0A os_mutex_exit(os_file_count_mutex);=0A =0A-= /* Protect the seek / write operation with a mutex */=0A- i =3D ((ulint)= file) % OS_FILE_N_SEEK_MUTEXES;=0A-=0A- os_mutex_enter(os_file_seek_mutexes[i]);= =0A-=0A- ret2 =3D SetFilePointer(file, low, &high, FILE_BEGIN);=0A-=0A-= if (ret2 =3D=3D 0xFFFFFFFF && GetLastError() !=3D NO_ERROR) {=0A-=0A- = os_mutex_exit(os_file_seek_mutexes[i]);=0A-=0A- os_mutex_enter(os_file_count_mutex);= =0A- os_n_pending_writes--;=0A- os_mutex_exit(os_file_count_mutex);=0A-= =0A- ut_print_timestamp(stderr);=0A-=0A- fprintf(stderr,=0A- " InnoDB:= Error: File pointer positioning to"=0A- " file %s failed at\n"=0A- = "InnoDB: offset %lu %lu. Operating system"=0A- " error number %lu.\n"= =0A- "InnoDB: Some operating system error numbers"=0A- " are described= at\n"=0A- "InnoDB: "=0A- "http://dev.mysql.com/doc/refman/5.1/en/"= =0A- "operating-system-error-codes.html\n",=0A- name, (ulong) offset_high,= (ulong) offset,=0A- (ulong) GetLastError());=0A-=0A- return(FALSE);= =0A- }=0A-=0A- ret =3D WriteFile(file, buf, (DWORD) n, &len, NULL);=0A+= ret =3D WriteFile(file, buf, (DWORD) n, &len, &ov);=0A =0A /* Always do= fsync to reduce the probability that when the OS crashes,=0A a database= page is only partially physically written to disk. */=0A@@ -2437,8 +2352,6= @@ retry:=0A ut_a(TRUE =3D=3D os_file_flush(file));=0A }=0A # endif= /* UNIV_DO_FLUSH */=0A-=0A- os_mutex_exit(os_file_seek_mutexes[i]);=0A= =0A os_mutex_enter(os_file_count_mutex);=0A os_n_pending_writes--;=0A