MDEV-17401: LOAD DATA from very big file into MyISAM table results in EOF error and corrupt index

my_read fixed as in higher versions.
my_pread made as my_read aware of partial read of huge chunks of files
MY_FULL_IO enabled for file operations
This commit is contained in:
Oleksandr Byelkin 2018-10-12 09:07:05 +02:00
parent b7eca63620
commit b68d8a05d3
3 changed files with 51 additions and 31 deletions

View file

@ -282,6 +282,10 @@ int init_io_cache(IO_CACHE *info, File file, size_t cachesize,
} }
info->inited=info->aio_result.pending=0; info->inited=info->aio_result.pending=0;
#endif #endif
if (type == READ_CACHE || type == WRITE_CACHE || type == SEQ_READ_APPEND)
info->myflags|= MY_FULL_IO;
else
info->myflags&= ~MY_FULL_IO;
DBUG_RETURN(0); DBUG_RETURN(0);
} /* init_io_cache */ } /* init_io_cache */

View file

@ -47,8 +47,7 @@
size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset, size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset,
myf MyFlags) myf MyFlags)
{ {
size_t readbytes; size_t readbytes, save_count= 0;
int error= 0;
DBUG_ENTER("my_pread"); DBUG_ENTER("my_pread");
@ -66,11 +65,10 @@ size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset,
#else #else
readbytes= pread(Filedes, Buffer, Count, offset); readbytes= pread(Filedes, Buffer, Count, offset);
#endif #endif
error = (readbytes != Count);
if (error) if (readbytes != Count)
{ {
my_errno= errno ? errno : -1; my_errno= errno;
if (errno == 0 || (readbytes != (size_t) -1 && if (errno == 0 || (readbytes != (size_t) -1 &&
(MyFlags & (MY_NABP | MY_FNABP)))) (MyFlags & (MY_NABP | MY_FNABP))))
my_errno= HA_ERR_FILE_TOO_SHORT; my_errno= HA_ERR_FILE_TOO_SHORT;
@ -82,6 +80,18 @@ size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset,
(int) readbytes)); (int) readbytes));
continue; /* Interrupted */ continue; /* Interrupted */
} }
/* Do a read retry if we didn't get enough data on first read */
if (readbytes != (size_t) -1 && readbytes != 0 &&
(MyFlags & MY_FULL_IO))
{
Buffer+= readbytes;
Count-= readbytes;
save_count+= readbytes;
offset+= readbytes;
continue;
}
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
{ {
if (readbytes == (size_t) -1) if (readbytes == (size_t) -1)
@ -97,8 +107,10 @@ size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset,
DBUG_RETURN(MY_FILE_ERROR); /* Return with error */ DBUG_RETURN(MY_FILE_ERROR); /* Return with error */
} }
if (MyFlags & (MY_NABP | MY_FNABP)) if (MyFlags & (MY_NABP | MY_FNABP))
DBUG_RETURN(0); /* Read went ok; Return 0 */ readbytes= 0; /* Read went ok; Return 0 */
DBUG_RETURN(readbytes); /* purecov: inspected */ else
readbytes+= save_count;
DBUG_RETURN(readbytes);
} }
} /* my_pread */ } /* my_pread */

View file

@ -35,17 +35,16 @@
size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags) size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags)
{ {
size_t readbytes, save_count; size_t readbytes, save_count= 0;
DBUG_ENTER("my_read"); DBUG_ENTER("my_read");
DBUG_PRINT("my",("fd: %d Buffer: %p Count: %lu MyFlags: %d", DBUG_PRINT("my",("fd: %d Buffer: %p Count: %lu MyFlags: %lu",
Filedes, Buffer, (ulong) Count, MyFlags)); Filedes, Buffer, (ulong) Count, (ulong) MyFlags));
save_count= Count;
if (!(MyFlags & (MY_WME | MY_FAE | MY_FNABP))) if (!(MyFlags & (MY_WME | MY_FAE | MY_FNABP)))
MyFlags|= my_global_flags; MyFlags|= my_global_flags;
for (;;) for (;;)
{ {
errno= 0; /* Linux, Windows don't reset this on EOF/success */ errno= 0; /* Linux, Windows don't reset this on EOF/success */
#ifdef _WIN32 #ifdef _WIN32
readbytes= my_win_read(Filedes, Buffer, Count); readbytes= my_win_read(Filedes, Buffer, Count);
#else #else
@ -61,47 +60,52 @@ size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags)
if (readbytes != Count) if (readbytes != Count)
{ {
my_errno= errno; int got_errno= my_errno= errno;
if (errno == 0 || (readbytes != (size_t) -1 &&
(MyFlags & (MY_NABP | MY_FNABP))))
my_errno= HA_ERR_FILE_TOO_SHORT;
DBUG_PRINT("warning",("Read only %d bytes off %lu from %d, errno: %d", DBUG_PRINT("warning",("Read only %d bytes off %lu from %d, errno: %d",
(int) readbytes, (ulong) Count, Filedes, (int) readbytes, (ulong) Count, Filedes,
my_errno)); got_errno));
if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR) if (got_errno == 0 || (readbytes != (size_t) -1 &&
{ (MyFlags & (MY_NABP | MY_FNABP))))
my_errno= HA_ERR_FILE_TOO_SHORT;
if ((readbytes == 0 || (int) readbytes == -1) && got_errno == EINTR)
{
DBUG_PRINT("debug", ("my_read() was interrupted and returned %ld", DBUG_PRINT("debug", ("my_read() was interrupted and returned %ld",
(long) readbytes)); (long) readbytes));
continue; /* Interrupted */ continue; /* Interrupted */
} }
/* Do a read retry if we didn't get enough data on first read */
if (readbytes != (size_t) -1 && readbytes != 0 &&
(MyFlags & MY_FULL_IO))
{
Buffer+= readbytes;
Count-= readbytes;
save_count+= readbytes;
continue;
}
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
{ {
if (readbytes == (size_t) -1) if (readbytes == (size_t) -1)
my_error(EE_READ, my_error(EE_READ,
MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))),
my_filename(Filedes),my_errno); my_filename(Filedes), got_errno);
else if (MyFlags & (MY_NABP | MY_FNABP)) else if (MyFlags & (MY_NABP | MY_FNABP))
my_error(EE_EOFERR, my_error(EE_EOFERR,
MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))),
my_filename(Filedes),my_errno); my_filename(Filedes), got_errno);
} }
if (readbytes == (size_t) -1 || if (readbytes == (size_t) -1 ||
((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO))) ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
DBUG_RETURN(MY_FILE_ERROR); /* Return with error */ DBUG_RETURN(MY_FILE_ERROR); /* Return with error */
if (readbytes != (size_t) -1 && (MyFlags & MY_FULL_IO))
{
Buffer+= readbytes;
Count-= readbytes;
continue;
}
} }
if (MyFlags & (MY_NABP | MY_FNABP)) if (MyFlags & (MY_NABP | MY_FNABP))
readbytes= 0; /* Ok on read */ readbytes= 0; /* Ok on read */
else if (MyFlags & MY_FULL_IO) else
readbytes= save_count; readbytes+= save_count;
break; break;
} }
DBUG_RETURN(readbytes); DBUG_RETURN(readbytes);