summaryrefslogtreecommitdiff
path: root/mysys/mf_iocache.c
diff options
context:
space:
mode:
Diffstat (limited to 'mysys/mf_iocache.c')
-rw-r--r--mysys/mf_iocache.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index 58d4756b702..b1cf940d70d 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -27,7 +27,7 @@
also info->read_pos is set to info->read_end.
If called through open_cached_file(), then the temporary file will
only be created if a write exeeds the file buffer or if one calls
- flush_io_cache().
+ my_b_flush_io_cache().
If one uses SEQ_READ_APPEND, then two buffers are allocated, one for
reading and another for writing. Reads are first done from disk and
@@ -43,7 +43,7 @@ TODO:
each time the write buffer gets full and it's written to disk, we will
always do a disk read to read a part of the buffer from disk to the
read buffer.
- This should be fixed so that when we do a flush_io_cache() and
+ This should be fixed so that when we do a my_b_flush_io_cache() and
we have been reading the write buffer, we should transfer the rest of the
write buffer to the read buffer before we start to reuse it.
*/
@@ -164,13 +164,13 @@ int init_io_cache(IO_CACHE *info, File file, uint cachesize,
(ulong) info, (int) type, (ulong) seek_offset));
info->file= file;
- info->type= 0; /* Don't set it until mutex are created */
+ info->type= TYPE_NOT_SET; /* Don't set it until mutex are created */
info->pos_in_file= seek_offset;
info->pre_close = info->pre_read = info->post_read = 0;
info->arg = 0;
info->alloced_buffer = 0;
info->buffer=0;
- info->seek_not_done= test(file >= 0);
+ info->seek_not_done= test(file >= 0 && seek_offset != my_tell(file, MYF(0)));
info->disk_writes= 0;
#ifdef THREAD
info->share=0;
@@ -183,8 +183,10 @@ int init_io_cache(IO_CACHE *info, File file, uint cachesize,
{ /* Assume file isn't growing */
if (!(cache_myflags & MY_DONT_CHECK_FILESIZE))
{
- /* Calculate end of file to not allocate to big buffers */
+ /* Calculate end of file to avoid allocating oversized buffers */
end_of_file=my_seek(file,0L,MY_SEEK_END,MYF(0));
+ /* Need to reset seek_not_done now that we just did a seek. */
+ info->seek_not_done= end_of_file == seek_offset ? 0 : 1;
if (end_of_file < seek_offset)
end_of_file=seek_offset;
/* Trim cache size if the file is very small */
@@ -359,7 +361,7 @@ my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type,
if (info->type == WRITE_CACHE && type == READ_CACHE)
info->end_of_file=my_b_tell(info);
/* flush cache if we want to reuse it */
- if (!clear_cache && flush_io_cache(info))
+ if (!clear_cache && my_b_flush_io_cache(info,1))
DBUG_RETURN(1);
info->pos_in_file=seek_offset;
/* Better to do always do a seek */
@@ -972,7 +974,7 @@ int _my_b_read_r(register IO_CACHE *cache, byte *Buffer, uint Count)
cache->read_end= cshare->read_end;
cache->pos_in_file= cshare->pos_in_file;
- len= ((cache->error == -1) ? -1 : cache->read_end - cache->buffer);
+ len= (int) ((cache->error == -1) ? -1 : cache->read_end - cache->buffer);
}
cache->read_pos= cache->buffer;
cache->seek_not_done= 0;
@@ -1396,7 +1398,7 @@ int _my_b_write(register IO_CACHE *info, const byte *Buffer, uint Count)
Count-=rest_length;
info->write_pos+=rest_length;
- if (flush_io_cache(info))
+ if (my_b_flush_io_cache(info,1))
return 1;
if (Count >= IO_SIZE)
{ /* Fill first intern buffer */
@@ -1683,6 +1685,7 @@ int end_io_cache(IO_CACHE *info)
int error=0;
IO_CACHE_CALLBACK pre_close;
DBUG_ENTER("end_io_cache");
+ DBUG_PRINT("enter",("cache: 0x%lx", (ulong) info));
#ifdef THREAD
/*
@@ -1701,14 +1704,14 @@ int end_io_cache(IO_CACHE *info)
{
info->alloced_buffer=0;
if (info->file != -1) /* File doesn't exist */
- error=flush_io_cache(info);
+ error= my_b_flush_io_cache(info,1);
my_free((gptr) info->buffer,MYF(MY_WME));
info->buffer=info->read_pos=(byte*) 0;
}
if (info->type == SEQ_READ_APPEND)
{
/* Destroy allocated mutex */
- info->type=0;
+ info->type= TYPE_NOT_SET;
#ifdef THREAD
pthread_mutex_destroy(&info->append_buffer_lock);
#endif