summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorunknown <sasha@mysql.sashanet.com>2002-01-19 22:46:25 -0700
committerunknown <sasha@mysql.sashanet.com>2002-01-19 22:46:25 -0700
commit1e0f2b7a4288b85d6b1d287056e2acfb3257f284 (patch)
tree254bb1b067e503a819145fff488d83709bf9c798 /mysys
parentadd1f37e4b503734c4a51bff6225cfb8739c74bf (diff)
parent5df61c3cdc4499197e420a76b25b942dce0f3ccc (diff)
downloadmariadb-git-1e0f2b7a4288b85d6b1d287056e2acfb3257f284.tar.gz
Ugly merge! But I am not done yet - there are a number of things I need to fix
before I can push BitKeeper/etc/ignore: auto-union Makefile.am: Auto merged include/my_sys.h: Auto merged libmysqld/lib_sql.cc: Auto merged mysql-test/t/rpl_log.test: Auto merged mysys/mf_iocache.c: Auto merged mysys/mf_iocache2.c: Auto merged mysys/thr_mutex.c: Auto merged sql/item_func.cc: Auto merged sql/lex.h: Auto merged sql/mini_client.cc: Auto merged sql/mini_client.h: Auto merged sql/mysql_priv.h: Auto merged sql/repl_failsafe.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_show.cc: Auto merged sql/stacktrace.c: Auto merged sql/structs.h: Auto merged mysql-test/r/rpl000014.result: merge mysql-test/r/rpl000015.result: merge mysql-test/r/rpl000016.result: merge mysql-test/r/rpl_log.result: merge sql/log.cc: merge sql/log_event.cc: merge sql/log_event.h: merge sql/mysqld.cc: merge sql/slave.cc: merge sql/slave.h: merge sql/sql_class.h: merge sql/sql_parse.cc: merge sql/sql_repl.cc: merge sql/sql_yacc.yy: merge
Diffstat (limited to 'mysys')
-rw-r--r--mysys/mf_iocache.c57
-rw-r--r--mysys/mf_iocache2.c18
-rw-r--r--mysys/thr_mutex.c3
3 files changed, 55 insertions, 23 deletions
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index a13e37ceb20..6b0d83212c4 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -122,6 +122,8 @@ int init_io_cache(IO_CACHE *info, File file, uint cachesize,
info->pos_in_file= seek_offset;
info->pre_close = info->pre_read = info->post_read = 0;
info->arg = 0;
+ info->init_count++; /* we assume the user had set it to 0 prior to
+ first call */
info->alloced_buffer = 0;
info->buffer=0;
info->seek_not_done= test(file >= 0);
@@ -446,11 +448,13 @@ int _my_b_seq_read(register IO_CACHE *info, byte *Buffer, uint Count)
info->end_of_file)
goto read_append_buffer;
- if (info->seek_not_done)
- { /* File touched, do seek */
- VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)));
- info->seek_not_done=0;
- }
+ /*
+ With read-append cache we must always do a seek before we read,
+ because the write could have moved the file pointer astray
+ */
+ VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)));
+ info->seek_not_done=0;
+
diff_length=(uint) (pos_in_file & (IO_SIZE-1));
/* now the second stage begins - read from file descriptor */
@@ -506,6 +510,13 @@ int _my_b_seq_read(register IO_CACHE *info, byte *Buffer, uint Count)
memcpy(Buffer,info->buffer,(size_t) length);
Count -= length;
Buffer += length;
+
+ /*
+ added the line below to make
+ DBUG_ASSERT(pos_in_file==info->end_of_file) pass.
+ otherwise this does not appear to be needed
+ */
+ pos_in_file += length;
goto read_append_buffer;
}
}
@@ -527,10 +538,13 @@ read_append_buffer:
/* First copy the data to Count */
uint len_in_buff = (uint) (info->write_pos - info->append_read_pos);
uint copy_len;
+ uint transfer_len;
DBUG_ASSERT(info->append_read_pos <= info->write_pos);
- DBUG_ASSERT(pos_in_file == info->end_of_file);
-
+ /*
+ TODO: figure out if the below assert is needed or correct.
+ */
+ DBUG_ASSERT(pos_in_file == info->end_of_file);
copy_len=min(Count, len_in_buff);
memcpy(Buffer, info->append_read_pos, copy_len);
info->append_read_pos += copy_len;
@@ -540,11 +554,12 @@ read_append_buffer:
/* Fill read buffer with data from write buffer */
memcpy(info->buffer, info->append_read_pos,
- (size_t) (len_in_buff - copy_len));
+ (size_t) (transfer_len=len_in_buff - copy_len));
info->read_pos= info->buffer;
- info->read_end= info->buffer+(len_in_buff - copy_len);
+ info->read_end= info->buffer+transfer_len;
info->append_read_pos=info->write_pos;
- info->pos_in_file+=len_in_buff;
+ info->pos_in_file=pos_in_file+copy_len;
+ info->end_of_file+=len_in_buff;
}
unlock_append_buffer(info);
return Count ? 1 : 0;
@@ -886,12 +901,10 @@ int flush_io_cache(IO_CACHE *info)
if ((length=(uint) (info->write_pos - info->write_buffer)))
{
pos_in_file=info->pos_in_file;
- if (append_cache)
- {
- pos_in_file=info->end_of_file;
- info->seek_not_done=1;
- }
- if (info->seek_not_done)
+ /* if we have append cache, we always open the file with
+ O_APPEND which moves the pos to EOF automatically on every write
+ */
+ if (!append_cache && info->seek_not_done)
{ /* File touched, do seek */
if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) ==
MY_FILEPOS_ERROR)
@@ -901,20 +914,24 @@ int flush_io_cache(IO_CACHE *info)
if (!append_cache)
info->seek_not_done=0;
}
- info->write_pos= info->write_buffer;
if (!append_cache)
info->pos_in_file+=length;
info->write_end= (info->write_buffer+info->buffer_length-
((pos_in_file+length) & (IO_SIZE-1)));
- /* Set this to be used if we are using SEQ_READ_APPEND */
- info->append_read_pos = info->write_buffer;
if (my_write(info->file,info->write_buffer,length,
info->myflags | MY_NABP))
info->error= -1;
else
info->error= 0;
- set_if_bigger(info->end_of_file,(pos_in_file+length));
+ if (!append_cache)
+ {
+ set_if_bigger(info->end_of_file,(pos_in_file+length));
+ }
+ else
+ info->end_of_file+=(info->write_pos-info->append_read_pos);
+
+ info->append_read_pos=info->write_pos=info->write_buffer;
DBUG_RETURN(info->error);
}
}
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c
index c076b53e6a9..ca9c9938cd2 100644
--- a/mysys/mf_iocache2.c
+++ b/mysys/mf_iocache2.c
@@ -31,12 +31,26 @@
void my_b_seek(IO_CACHE *info,my_off_t pos)
{
- my_off_t offset = (pos - info->pos_in_file);
+ my_off_t offset;
DBUG_ENTER("my_b_seek");
DBUG_PRINT("enter",("pos: %lu", (ulong) pos));
- if (info->type == READ_CACHE)
+ /*
+ TODO: verify that it is OK to do seek in the non-append
+ area in SEQ_READ_APPEND cache
+ */
+ /* TODO:
+ a) see if this always works
+ b) see if there is a better way to make it work
+ */
+ if (info->type == SEQ_READ_APPEND)
+ flush_io_cache(info);
+
+ offset=(pos - info->pos_in_file);
+
+ if (info->type == READ_CACHE || info->type == SEQ_READ_APPEND)
{
+ /* TODO: explain why this works if pos < info->pos_in_file */
if ((ulonglong) offset < (ulonglong) (info->read_end - info->buffer))
{
/* The read is in the current buffer; Reuse it */
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 5353e58ba2d..4493c54069f 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -69,7 +69,8 @@ int safe_mutex_lock(safe_mutex_t *mp,const char *file, uint line)
}
if (mp->count++)
{
- fprintf(stderr,"safe_mutex: Error in thread libray: Got mutex at %s, line %d more than 1 time\n", file,line);
+ fprintf(stderr,"safe_mutex: Error in thread libray: Got mutex at %s, \
+line %d more than 1 time\n", file,line);
fflush(stderr);
abort();
}