summaryrefslogtreecommitdiff
path: root/sql/log.cc
diff options
context:
space:
mode:
authorunknown <gluh@gluh.mysql.r18.ru>2003-03-11 16:32:17 +0400
committerunknown <gluh@gluh.mysql.r18.ru>2003-03-11 16:32:17 +0400
commit4901295af1d1e5fa30225eae5c21862f9d00be42 (patch)
tree1a27ba4c4a93d54b53e2469bc0f8e600f74e91cb /sql/log.cc
parentbbc8f836c0400f361458bffd42d71ea2177a9e18 (diff)
parent92457d6e45dff4561c53bdd7feec1595585a65af (diff)
downloadmariadb-git-4901295af1d1e5fa30225eae5c21862f9d00be42.tar.gz
Conflicts relsolving
mysql-test/t/rpl_rotate_logs.test: Auto merged sql/lex.h: Auto merged sql/mysql_priv.h: Auto merged sql/set_var.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_lex.h: Auto merged sql/sql_repl.cc: Auto merged sql/sql_repl.h: Auto merged
Diffstat (limited to 'sql/log.cc')
-rw-r--r--sql/log.cc87
1 files changed, 81 insertions, 6 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 6b06bd781ce..65497a3e065 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -687,6 +687,19 @@ err:
DBUG_RETURN(error);
}
+/*
+ Update log index_file
+*/
+
+int MYSQL_LOG::update_log_index(LOG_INFO* log_info)
+{
+ if (copy_up_file_and_fill(&index_file, log_info->index_file_start_offset))
+ return LOG_INFO_IO;
+
+ // now update offsets in index file for running threads
+ adjust_linfo_offsets(log_info->index_file_start_offset);
+ return 0;
+}
/*
Remove all logs before the given log from disk and from the index file.
@@ -739,21 +752,76 @@ int MYSQL_LOG::purge_logs(THD* thd, const char* to_log)
If we get killed -9 here, the sysadmin would have to edit
the log index file after restart - otherwise, this should be safe
*/
+ error= update_log_index(&log_info);
- if (copy_up_file_and_fill(&index_file, log_info.index_file_start_offset))
- {
- error= LOG_INFO_IO;
+err:
+ pthread_mutex_unlock(&LOCK_index);
+ DBUG_RETURN(error);
+}
+
+/*
+ Remove all logs before the given file date from disk and from the
+ index file.
+
+ SYNOPSIS
+ purge_logs_before_date()
+ thd Thread pointer
+ before_date Delete all log files before given date.
+
+ NOTES
+ If any of the logs before the deleted one is in use,
+ only purge logs up to this one.
+
+ RETURN VALUES
+ 0 ok
+ LOG_INFO_PURGE_NO_ROTATE Binary file that can't be rotated
+*/
+
+int MYSQL_LOG::purge_logs_before_date(THD* thd, time_t purge_time)
+{
+ int error;
+ LOG_INFO log_info;
+ MY_STAT stat_area;
+
+ DBUG_ENTER("purge_logs_before_date");
+
+ if (no_rotate)
+ DBUG_RETURN(LOG_INFO_PURGE_NO_ROTATE);
+
+ pthread_mutex_lock(&LOCK_index);
+
+ /*
+ Delete until we find curren file
+ or a file that is used or a file
+ that is older than purge_time.
+ */
+ if ((error=find_log_pos(&log_info, NullS, 0 /*no mutex*/)))
goto err;
+
+ while (strcmp(log_file_name, log_info.log_file_name) &&
+ !log_in_use(log_info.log_file_name))
+ {
+ /* It's not fatal even if we can't delete a log file */
+ if (!my_stat(log_info.log_file_name, &stat_area, MYF(0)) ||
+ stat_area.st_mtime >= purge_time)
+ break;
+ my_delete(log_info.log_file_name, MYF(0));
+ if (find_next_log(&log_info, 0))
+ break;
}
- // now update offsets in index file for running threads
- adjust_linfo_offsets(log_info.index_file_start_offset);
+ /*
+ If we get killed -9 here, the sysadmin would have to edit
+ the log index file after restart - otherwise, this should be safe
+ */
+ error= update_log_index(&log_info);
err:
pthread_mutex_unlock(&LOCK_index);
DBUG_RETURN(error);
}
+
#endif /* HAVE_REPLICATION */
@@ -1043,6 +1111,7 @@ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command,
bool MYSQL_LOG::write(Log_event* event_info)
{
bool error=0;
+ bool should_rotate = 0;
DBUG_ENTER("MYSQL_LOG::write(event)");
if (!inited) // Can't use mutex if not init
@@ -1055,7 +1124,6 @@ bool MYSQL_LOG::write(Log_event* event_info)
/* In most cases this is only called if 'is_open()' is true */
if (is_open())
{
- bool should_rotate = 0;
THD *thd=event_info->thd;
const char *local_db = event_info->get_db();
#ifdef USING_TRANSACTIONS
@@ -1192,6 +1260,13 @@ err:
}
pthread_mutex_unlock(&LOCK_log);
+ if (should_rotate && expire_logs_days)
+ {
+ long purge_time= time(0) - expire_logs_days*24*60*60;
+ if (purge_time >= 0)
+ error= purge_logs_before_date(current_thd, purge_time);
+ }
+
DBUG_RETURN(error);
}