summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@donna.mysql.com>2000-11-16 03:58:58 +0200
committerunknown <monty@donna.mysql.com>2000-11-16 03:58:58 +0200
commit3e6dac34cd5b8ef322d375f3af22137822656c8a (patch)
tree4b8f3df4d2aef33906b1e7e311b909e12f38539e /sql
parentc7d2c59ceb4e3548eb74e5d8fba16e0f41ffc7d9 (diff)
downloadmariadb-git-3e6dac34cd5b8ef322d375f3af22137822656c8a.tar.gz
changed to use IO_CACHE instead of FILE
Docs/manual.texi: Type fixes myisam/mi_create.c: Fixed bug in update from different processes myisam/mi_locking.c: Fixed bug in update from different processes myisam/mi_open.c: Fixed bug in update from different processes myisam/mi_search.c: Fixed bug in update from different processes myisam/myisamdef.h: Fixed bug in update from different processes mysys/Makefile.am: Added mf_iocache2.c sql/log.cc: Changed to use IO_CACHE instead of FILE sql/sql_class.h: Changed to use IO_CACHE instead of FILE sql/sql_repl.cc: Changed to use IO_CACHE instead of FILE BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'sql')
-rw-r--r--sql/log.cc161
-rw-r--r--sql/sql_class.h2
-rw-r--r--sql/sql_repl.cc84
3 files changed, 127 insertions, 120 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 7172d043552..b3f730ce32a 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -319,8 +319,8 @@ err:
int MYSQL_LOG::purge_logs(THD* thd, const char* to_log)
{
- if(!index_file) return LOG_INFO_INVALID;
- if(no_rotate) return LOG_INFO_PURGE_NO_ROTATE;
+ if (index_file < 0) return LOG_INFO_INVALID;
+ if (no_rotate) return LOG_INFO_PURGE_NO_ROTATE;
int error;
char fname[FN_REFLEN];
char* fname_end, *p;
@@ -329,125 +329,132 @@ int MYSQL_LOG::purge_logs(THD* thd, const char* to_log)
DYNAMIC_ARRAY logs_to_purge, logs_to_keep;
my_off_t purge_offset ;
LINT_INIT(purge_offset);
+ IO_CACHE io_cache;
+
pthread_mutex_lock(&LOCK_index);
- if(my_fseek(index_file, 0, MY_SEEK_SET,
- MYF(MY_WME) ) == MY_FILEPOS_ERROR)
- {
- error = LOG_INFO_SEEK;
- goto err;
- }
-
- if(init_dynamic_array(&logs_to_purge, sizeof(char*), 1024, 1024))
- {
- error = LOG_INFO_MEM;
- goto err;
- }
+ if (init_io_cache(&io_cache,index_file, IO_SIZE*2, READ_CACHE, (my_off_t) 0,
+ 0, MYF(MY_WME)))
+ {
+ error = LOG_INFO_MEM;
+ goto err;
+ }
+ if (init_dynamic_array(&logs_to_purge, sizeof(char*), 1024, 1024))
+ {
+ error = LOG_INFO_MEM;
+ goto err;
+ }
logs_to_purge_inited = 1;
- if(init_dynamic_array(&logs_to_keep, sizeof(char*), 1024, 1024))
- {
- error = LOG_INFO_MEM;
- goto err;
- }
+ if (init_dynamic_array(&logs_to_keep, sizeof(char*), 1024, 1024))
+ {
+ error = LOG_INFO_MEM;
+ goto err;
+ }
logs_to_keep_inited = 1;
for(;;)
+ {
+ my_off_t init_purge_offset= my_b_tell(&io_cache);
+ if (!(fname_len=my_b_gets(&io_cache, fname, FN_REFLEN)))
{
- if(!fgets(fname, FN_REFLEN, index_file))
- {
- if(feof(index_file))
- break;
- else
- error = LOG_INFO_IO;
- goto err;
- }
+ if(!io_cache.error)
+ break;
+ error = LOG_INFO_IO;
+ goto err;
+ }
- *(fname_end = (strend(fname) - 1)) = 0; // kill \n
- fname_len = (uint)(fname_end - fname);
-
- if(!memcmp(fname, to_log, fname_len + 1 ))
- {
- found_log = 1;
- purge_offset = my_ftell(index_file, MYF(MY_WME)) - fname_len - 1;
- }
+ fname[--fname_len]=0; // kill \n
+ if(!memcmp(fname, to_log, fname_len + 1 ))
+ {
+ found_log = 1;
+ purge_offset = init_purge_offset;
+ }
- if(!found_log && log_in_use(fname))
- // if one of the logs before the target is in use
- {
- error = LOG_INFO_IN_USE;
- goto err;
- }
+ // if one of the logs before the target is in use
+ if(!found_log && log_in_use(fname))
+ {
+ error = LOG_INFO_IN_USE;
+ goto err;
+ }
- p = sql_memdup(fname, (uint)(fname_end - fname) + 1);
- if((found_log) ?
- insert_dynamic(&logs_to_keep, (gptr) &p) :
- insert_dynamic(&logs_to_purge, (gptr) &p)
- )
- {
- error = LOG_INFO_MEM;
- goto err;
- }
- }
-
- if(!found_log)
+ if (!(p = sql_memdup(fname, (uint)(fname_end - fname) + 1)) ||
+ insert_dynamic(found_log ? &logs_to_keep : &logs_to_purge,
+ (gptr) &p))
{
- error = LOG_INFO_EOF;
+ error = LOG_INFO_MEM;
goto err;
}
+ }
+
+ end_io_cache(&io_cache);
+ if(!found_log)
+ {
+ error = LOG_INFO_EOF;
+ goto err;
+ }
for(i = 0; i < logs_to_purge.elements; i++)
- {
- char* l;
- get_dynamic(&logs_to_purge, (gptr)&l, i);
- if(my_delete(l, MYF(MY_WME)))
- sql_print_error("Error deleting %s during purge", l);
- }
+ {
+ char* l;
+ get_dynamic(&logs_to_purge, (gptr)&l, i);
+ if (my_delete(l, MYF(MY_WME)))
+ sql_print_error("Error deleting %s during purge", l);
+ }
// if we get killed -9 here, the sysadmin would have to do a small
// vi job on the log index file after restart - otherwise, this should
// be safe
- my_fclose(index_file, MYF(MY_WME));
- if(!(index_file = my_fopen(index_file_name, O_BINARY|O_WRONLY,
- MYF(MY_WME))))
+#ifdef HAVE_FTRUNCATE
+ if (ftruncate(index_file,0))
+ {
+ sql_print_error("Ouch! Could not truncate the binlog index file \
+during log purge for write");
+ error = LOG_INFO_FATAL;
+ goto err;
+ }
+ my_seek(index_file, 0, MY_SEEK_CUR,MYF(MY_WME));
+#else
+ my_close(index_file, MYF(MY_WME));
+ my_delete(index_file_name, MYF(MY_WME));
+ if(!(index_file = my_open(index_file_name, O_BINARY | O_RDWR | O_APPEND,
+ MYF(MY_WME))))
{
sql_print_error("Ouch! Could not re-open the binlog index file \
during log purge for write");
error = LOG_INFO_FATAL;
goto err;
}
+#endif
for(i = 0; i < logs_to_keep.elements; i++)
+ {
+ char* l;
+ get_dynamic(&logs_to_keep, (gptr)&l, i);
+ if (my_write(index_file, l, strlen(l), MYF(MY_WME)) ||
+ my_write(index_file, "\n", 1, MYF(MY_WME)))
{
- char* l;
- get_dynamic(&logs_to_keep, (gptr)&l, i);
- fprintf(index_file, "%s\n", l);
+ error = LOG_INFO_FATAL;
+ goto err;
}
- my_fclose(index_file, MYF(MY_WME));
-
- if(!(index_file = my_fopen(index_file_name, O_BINARY|O_RDWR|O_APPEND,
- MYF(MY_WME))))
- {
- sql_print_error("Ouch! Could not re-open the binlog index file \
-during log purge for append");
- error = LOG_INFO_FATAL;
- goto err;
}
+
// now update offsets
adjust_linfo_offsets(purge_offset);
error = 0;
+
err:
pthread_mutex_unlock(&LOCK_index);
if(logs_to_purge_inited)
delete_dynamic(&logs_to_purge);
if(logs_to_keep_inited)
delete_dynamic(&logs_to_keep);
-
+ end_io_cache(&io_cache);
return error;
-
}
+
// we assume that buf has at least FN_REFLEN bytes alloced
void MYSQL_LOG::make_log_name(char* buf, const char* log_ident)
{
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 2af98d6fbf0..1aef744445f 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -98,7 +98,7 @@ public:
char* get_log_fname() { return log_file_name; }
void lock_index() { pthread_mutex_lock(&LOCK_index);}
void unlock_index() { pthread_mutex_unlock(&LOCK_index);}
- FILE* get_index_file() { return index_file;}
+ File get_index_file() { return index_file;}
};
/* character conversion tables */
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 5cdb5ab0706..ba155c72e49 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -720,66 +720,66 @@ int show_binlog_info(THD* thd)
int show_binlogs(THD* thd)
{
const char* errmsg = 0;
- FILE* index_file;
+ File index_file;
char fname[FN_REFLEN];
NET* net = &thd->net;
List<Item> field_list;
String* packet = &thd->packet;
+ IO_CACHE io_cache;
+ uint length;
if(!mysql_bin_log.is_open())
- {
- errmsg = "binlog is not open";
- goto err;
- }
+ {
+ errmsg = "binlog is not open";
+ goto err;
+ }
field_list.push_back(new Item_empty_string("Log_name", 128));
if(send_fields(thd, field_list, 1))
- {
- sql_print_error("Failed in send_fields");
- return 1;
- }
+ {
+ sql_print_error("Failed in send_fields");
+ return 1;
+ }
mysql_bin_log.lock_index();
index_file = mysql_bin_log.get_index_file();
- if(!index_file)
- {
- errmsg = "Uninitialized index file pointer";
- mysql_bin_log.unlock_index();
- goto err;
- }
- if(my_fseek(index_file, 0, MY_SEEK_SET, MYF(MY_WME)))
- {
- errmsg = "Failed on fseek()";
- mysql_bin_log.unlock_index();
- goto err;
- }
-
- while(fgets(fname, sizeof(fname), index_file))
+ if (index_file < 0)
+ {
+ errmsg = "Uninitialized index file pointer";
+ goto err2;
+ }
+ if (init_io_cache(&io_cache, index_file, IO_SIZE, READ_CACHE, 0, 0,
+ MYF(MY_WME)))
+ {
+ errmsg = "Failed on init_io_cache()";
+ goto err2;
+ }
+ while ((length=my_b_gets(&io_cache, fname, sizeof(fname))))
+ {
+ fname[--length]=0;
+ int dir_len = dirname_length(fname);
+ packet->length(0);
+ net_store_data(packet, fname + dir_len, length-dir_len);
+ if(my_net_write(net, (char*) packet->ptr(), packet->length()))
{
- char* fname_end;
- *(fname_end = (strend(fname) - 1)) = 0;
- int dir_len = dirname_length(fname);
- packet->length(0);
- net_store_data(packet, fname + dir_len, (fname_end - fname)-dir_len);
- if(my_net_write(net, (char*) packet->ptr(), packet->length()))
- {
- sql_print_error("Failed in my_net_write");
- mysql_bin_log.unlock_index();
- return 1;
- }
+ sql_print_error("Failed in my_net_write");
+ end_io_cache(&io_cache);
+ mysql_bin_log.unlock_index();
+ return 1;
}
+ }
mysql_bin_log.unlock_index();
+ end_io_cache(&io_cache);
send_eof(net);
- err:
- if(errmsg)
- {
- send_error(net, 0, errmsg);
- return 1;
- }
-
- send_ok(net);
return 0;
+
+err2:
+ mysql_bin_log.unlock_index();
+ end_io_cache(&io_cache);
+err:
+ send_error(net, 0, errmsg);
+ return 1;
}