Below is the list of changes that have just been committed into a local
6.0 repository of cbell. When cbell does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2008-03-18 14:03:58-04:00, cbell@mysql_cab_desk. +18 -0
BUG#34858 Server crashes by backup tests
Patch fixes problems encountered when merging runtime code changes
into main for online backup.
Minor changes to consistent snapshot driver.
Major change to backup progress tables. These tables have been turned
into logs using the logging code for the general and slow logs.
include/mysql_com.h@stripped, 2008-03-18 14:03:38-04:00, cbell@mysql_cab_desk. +1 -0
BUG##34858 Server crashes by backup tests
Added define for FLUSH BACKUP LOGS command.
mysql-test/r/backup_progress.result@stripped, 2008-03-18 14:03:39-04:00, cbell@mysql_cab_desk. +12 -3
BUG##34858 Server crashes by backup tests
New result file.
mysql-test/t/backup_progress.test@stripped, 2008-03-18 14:03:39-04:00, cbell@mysql_cab_desk. +20 -3
BUG##34858 Server crashes by backup tests
Test updates due to different structure of tables (they're
logs now and cannot be locked).
mysql-test/t/disabled.def@stripped, 2008-03-18 14:03:40-04:00, cbell@mysql_cab_desk. +0 -6
BUG#34858 Server crashes by backup tests
Reenabled disabled tests.
sql/backup/backup_progress.cc@stripped, 2008-03-18 14:03:47-04:00, cbell@mysql_cab_desk. +78 -661
BUG##34858 Server crashes by backup tests
Refactored code to call the logging functions for the backup logs.
sql/backup/backup_progress.h@stripped, 2008-03-18 14:03:48-04:00, cbell@mysql_cab_desk. +27 -93
BUG##34858 Server crashes by backup tests
Moved enums to mysql_priv.h for higher visibility.
sql/backup/be_snapshot.cc@stripped, 2008-03-18 14:03:49-04:00, cbell@mysql_cab_desk. +1 -0
BUG#34858 Server crashes by backup tests
Added code to perform commit of consistent read to avoid another
problem introduced from changes to handler.cc.
sql/backup/data_backup.cc@stripped, 2008-03-18 14:03:49-04:00, cbell@mysql_cab_desk. +7 -7
BUG##34858 Server crashes by backup tests
Added THD reference to all report_ob* calls.
sql/backup/kernel.cc@stripped, 2008-03-18 14:03:50-04:00, cbell@mysql_cab_desk. +22 -22
BUG##34858 Server crashes by backup tests
Added THD reference to all report_ob* calls. Also moved init calls
to higher in the code to avoid errors during logging when the
error occurs before the backup starts.
sql/log.cc@stripped, 2008-03-18 14:03:41-04:00, cbell@mysql_cab_desk. +1059 -3
BUG##34858 Server crashes by backup tests
Added the backup progress tables to the logging code.
Online backup progress tables are now logged to tables.
Added code to write to the online_backup and online_backup_progress
tables (as logs).
sql/log.h@stripped, 2008-03-18 14:03:41-04:00, cbell@mysql_cab_desk. +156 -0
BUG##34858 Server crashes by backup tests
Added calls to open backup logs and write to them.
sql/mysql_priv.h@stripped, 2008-03-18 14:03:42-04:00, cbell@mysql_cab_desk. +101 -0
BUG##34858 Server crashes by backup tests
Added enums for backup logs.
sql/mysqld.cc@stripped, 2008-03-18 14:03:43-04:00, cbell@mysql_cab_desk. +14 -0
BUG##34858 Server crashes by backup tests
Added variables to use backup logs:
* file name strings
* free for name strings
* creation of name strings
sql/set_var.cc@stripped, 2008-03-18 14:03:44-04:00, cbell@mysql_cab_desk. +54 -0
BUG##34858 Server crashes by backup tests
Added variables for controlling backup logs.
sql/set_var.h@stripped, 2008-03-18 14:03:44-04:00, cbell@mysql_cab_desk. +1 -0
BUG##34858 Server crashes by backup tests
Added variables for controlling backup logs.
sql/sql_parse.cc@stripped, 2008-03-18 14:03:45-04:00, cbell@mysql_cab_desk. +4 -0
BUG##34858 Server crashes by backup tests
Added a flush backup logs option.
sql/sql_yacc.yy@stripped, 2008-03-18 14:03:46-04:00, cbell@mysql_cab_desk. +2 -0
BUG##34858 Server crashes by backup tests
Added a FLUSH BACKUP LOGS option to the FLUSH command.
sql/table.cc@stripped, 2008-03-18 14:03:47-04:00, cbell@mysql_cab_desk. +23 -0
BUG##34858 Server crashes by backup tests
Added code to process the backup logs tables using the original
names from the old code.
diff -Nrup a/include/mysql_com.h b/include/mysql_com.h
--- a/include/mysql_com.h 2008-02-29 09:25:02 -05:00
+++ b/include/mysql_com.h 2008-03-18 14:03:38 -04:00
@@ -135,6 +135,7 @@ enum enum_server_command
#define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */
#define REFRESH_DES_KEY_FILE 0x40000L
#define REFRESH_USER_RESOURCES 0x80000L
+#define REFRESH_BACKUP_LOG 0x200000L
#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
diff -Nrup a/mysql-test/r/backup_progress.result b/mysql-test/r/backup_progress.result
--- a/mysql-test/r/backup_progress.result 2008-02-14 13:14:49 -05:00
+++ b/mysql-test/r/backup_progress.result 2008-03-18 14:03:39 -04:00
@@ -30,9 +30,11 @@ get_lock("bp_starting_state", 0)
1
con2: Send backup command.
BACKUP DATABASE backup_progress to 'backup_progress_orig.bak';
+FLUSH BACKUP LOGS;
con1: Checking locks.
con1: Checking progress.
-INSERT INTO backup_progress.t1_res (id) SELECT backup_id FROM mysql.online_backup WHERE command LIKE "BACKUP DATABASE backup_progress%";
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "BACKUP DATABASE backup_progress%";
+INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
backup_state
starting
@@ -40,6 +42,7 @@ con1: Advance the lock.
SELECT get_lock("bp_running_state", 0);
get_lock("bp_running_state", 0)
1
+FLUSH BACKUP LOGS;
con1: Checking locks.
con1: Checking progress.
SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
@@ -49,6 +52,7 @@ con1: Advance the lock.
SELECT get_lock("bp_vp_state", 0);
get_lock("bp_vp_state", 0)
1
+FLUSH BACKUP LOGS;
con1: Checking locks.
con1: Checking progress.
SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
@@ -58,6 +62,7 @@ con1: Advance the lock.
SELECT get_lock("bp_running_state", 0);
get_lock("bp_running_state", 0)
1
+FLUSH BACKUP LOGS;
con1: Checking locks.
con1: Checking progress.
SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
@@ -103,11 +108,13 @@ get_lock("bp_starting_state", 0)
DELETE FROM backup_progress.t1_res;
con2: Send restore command.
RESTORE FROM 'backup_progress_orig.bak';
+FLUSH BACKUP LOGS;
con1: Checking locks.
con1: Checking progress.
select * from backup_progress.t1_res;
id
-INSERT INTO backup_progress.t1_res (id) SELECT backup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM 'backup_progress_orig.bak'%";
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM%";
+INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
backup_state
starting
@@ -115,6 +122,7 @@ con1: Advance the lock.
SELECT get_lock("bp_running_state", 0);
get_lock("bp_running_state", 0)
1
+FLUSH BACKUP LOGS;
con1: Checking locks.
con1: Checking progress.
SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
@@ -128,7 +136,8 @@ con2: Finish restore command
backup_id
#
DELETE FROM backup_progress.t1_res;
-INSERT INTO backup_progress.t1_res (id) SELECT backup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM 'backup_progress_orig.bak'%";
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM%";
+INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
SELECT ob.* FROM mysql.online_backup AS ob JOIN backup_progress.t1_res AS t1 ON ob.backup_id = t1.id;;
backup_id #
process_id #
diff -Nrup a/mysql-test/t/backup_progress.test b/mysql-test/t/backup_progress.test
--- a/mysql-test/t/backup_progress.test 2008-02-14 13:16:02 -05:00
+++ b/mysql-test/t/backup_progress.test 2008-03-18 14:03:39 -04:00
@@ -66,6 +66,9 @@ connection con2;
send BACKUP DATABASE backup_progress to 'backup_progress_orig.bak';
connection con1;
+
+FLUSH BACKUP LOGS;
+
# Wait for lock to be acquired and execution to reach breakpoint
--echo con1: Checking locks.
let $wait_condition = SELECT state = "debug_sync_point: bp_starting_state"
@@ -81,12 +84,15 @@ let $wait_condition = SELECT backup_stat
--source include/wait_condition.inc
--echo: Display progress
-INSERT INTO backup_progress.t1_res (id) SELECT backup_id FROM mysql.online_backup WHERE command LIKE "BACKUP DATABASE backup_progress%";
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "BACKUP DATABASE backup_progress%";
+INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
--echo con1: Advance the lock.
SELECT get_lock("bp_running_state", 0);
+FLUSH BACKUP LOGS;
+
# Wait for lock to be acquired and execution to reach breakpoint
--echo con1: Checking locks.
let $wait_condition = SELECT state = "debug_sync_point: bp_running_state"
@@ -107,6 +113,8 @@ SELECT backup_state FROM mysql.online_ba
--echo con1: Advance the lock.
SELECT get_lock("bp_vp_state", 0);
+FLUSH BACKUP LOGS;
+
# Wait for lock to be acquired and execution to reach breakpoint
--echo con1: Checking locks.
let $wait_condition = SELECT state = "debug_sync_point: bp_vp_state"
@@ -127,6 +135,8 @@ SELECT backup_state FROM mysql.online_ba
--echo con1: Advance the lock.
SELECT get_lock("bp_running_state", 0);
+FLUSH BACKUP LOGS;
+
# Wait for lock to be acquired and execution to reach breakpoint
--echo con1: Checking locks.
let $wait_condition = SELECT state = "debug_sync_point: bp_running_state"
@@ -172,6 +182,9 @@ DELETE FROM backup_progress.t1_res;
send RESTORE FROM 'backup_progress_orig.bak';
connection con1;
+
+FLUSH BACKUP LOGS;
+
# Wait for lock to be acquired and execution to reach breakpoint
--echo con1: Checking locks.
let $wait_condition = SELECT state = "debug_sync_point: bp_starting_state"
@@ -188,12 +201,15 @@ let $wait_condition = SELECT backup_stat
--echo: Display progress
select * from backup_progress.t1_res;
-INSERT INTO backup_progress.t1_res (id) SELECT backup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM 'backup_progress_orig.bak'%";
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM%";
+INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
--echo con1: Advance the lock.
SELECT get_lock("bp_running_state", 0);
+FLUSH BACKUP LOGS;
+
# Wait for lock to be acquired and execution to reach breakpoint
--echo con1: Checking locks.
let $wait_condition = SELECT state = "debug_sync_point: bp_running_state"
@@ -221,7 +237,8 @@ reap;
#Show results
DELETE FROM backup_progress.t1_res;
-INSERT INTO backup_progress.t1_res (id) SELECT backup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM 'backup_progress_orig.bak'%";
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM%";
+INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
--replace_column 1 # 2 # 3 # 4 # 10 # 11 # 12 #
--query_vertical SELECT ob.* FROM mysql.online_backup AS ob JOIN backup_progress.t1_res AS t1 ON ob.backup_id = t1.id;
--replace_column 1 # 3 # 4 #
diff -Nrup a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
--- a/mysql-test/t/disabled.def 2008-03-10 08:58:17 -04:00
+++ b/mysql-test/t/disabled.def 2008-03-18 14:03:40 -04:00
@@ -34,9 +34,3 @@ backup_security :BUG#34235 pending
backup_snapshot :BUG#34235 pending replacement of test facility with WL#4259
csv_alter_table : Bug#33696 2008-01-21 pcrews no .result file - bug allows NULL columns in CSV tables
ctype_latin2_ch : BUG #33791 2008-01-18 mats Wrong ORDER BY with latin2_czech_cs
-
-backup_errors : Bug#34858 2008-Feb-28 Server crashes by backup tests
-backup_fkey : Bug#34858 2008-Feb-28 Server crashes by backup tests
-backup_no_data : Bug#34858 2008-Feb-28 Server crashes by backup tests
-backup_no_engine : Bug#34858 2008-Feb-28 Server crashes by backup tests
-backup_objects : Bug#34858 2008-Feb-28 Server crashes by backup tests
diff -Nrup a/sql/backup/backup_progress.cc b/sql/backup/backup_progress.cc
--- a/sql/backup/backup_progress.cc 2008-02-26 15:18:12 -05:00
+++ b/sql/backup/backup_progress.cc 2008-03-18 14:03:47 -04:00
@@ -70,139 +70,6 @@ my_bool check_ob_progress_tables(THD *th
}
/**
- Open backup progress table.
-
- This method opens the online backup table specified. It uses the locking
- thread mechanism in be_thread.cc to open the table in a separate thread.
-
- @param char * table_name The name of the table to open.
- @param thr_lock_type lock The lock type -- TL_WRITE or TL_READ.
-
- @returns 0 = success
- @returns 1 = failed to open table
-
- @todo : Replace poling loop with signal.
- */
-Locking_thread_st *open_backup_progress_table(const char *table_name,
- enum thr_lock_type lock)
-{
- TABLE_LIST tables; // List of tables (1 in this case)
- Locking_thread_st *locking_thd; // The locking thread
-
- DBUG_ENTER("open_backup_progress_table()");
-
- /*
- The locking thread will, via open_table(), fail if the table does not
- exist.
- */
-
- /*
- Create a new thread to open and lock the tables.
- */
- locking_thd= new Locking_thread_st();
- if (locking_thd == NULL)
- DBUG_RETURN(locking_thd);
-
- locking_thd->tables_in_backup= (TABLE_LIST*)my_malloc(sizeof(TABLE_LIST), MYF(MY_WME));
- locking_thd->tables_in_backup->init_one_table("mysql", table_name, lock);
-
-
- /*
- Start the locking thread and wait until it is ready.
- */
- locking_thd->start_locking_thread("backup progress locking thread");
-
- /*
- Poll the locking thread until ready.
- */
- while (locking_thd && (locking_thd->lock_state != LOCK_ACQUIRED) &&
- (locking_thd->lock_state != LOCK_ERROR))
- my_sleep(1);
- if (locking_thd->lock_state == LOCK_ERROR)
- {
- delete locking_thd;
- locking_thd= NULL;
- }
- DBUG_RETURN(locking_thd);
-}
-
-/**
- Close backup progress table.
-
- This method closes the online backup table specified. It uses the locking
- thread mechanism in be_thread.cc to close the table in a separate thread.
-
- @param Locking_thread_st *locking_thd The locking thread.
-
- @returns 0 = success
- @returns 1 = failed to close table
-
- @todo : Replace poling loop with signal.
- */
-int close_backup_progress_table(Locking_thread_st *locking_thd)
-{
- DBUG_ENTER("close_backup_progress_table()");
-
- /*
- Tell locking thread to die.
- */
- locking_thd->kill_locking_thread();
-
- /*
- Poll the locking thread until ready.
- */
- while (locking_thd && (locking_thd->lock_state != LOCK_DONE) &&
- (locking_thd->lock_state != LOCK_ERROR))
- my_sleep(1);
- if (locking_thd->lock_state == LOCK_ERROR)
- DBUG_RETURN(1);
- my_free(locking_thd->tables_in_backup, MYF(0));
- delete locking_thd;
- locking_thd= NULL;
- DBUG_RETURN(0);
-}
-
-/**
- Find the row in the table that matches the backup_id.
-
- This method locates the row in the online backup table that matches the
- backup_id passed.
-
- @param TABLE * table The table to search.
- @param ulonglong backup_id The id of the row to locate.
-
- @returns 0 = success
- @returns 1 = failed to find row
- */
-my_bool find_online_backup_row(TABLE *table, ulonglong backup_id)
-{
- uchar key[MAX_KEY_LENGTH]; // key buffer for search
-
- DBUG_ENTER("find_online_backup_row()");
-
- /*
- Create key to find row. We have to use field->store() to be able to
- handle VARCHAR and CHAR fields.
- Assumption here is that the two first fields in the table are
- 'db' and 'name' and the first key is the primary key over the
- same fields.
- */
- table->field[ET_FIELD_BACKUP_ID]->store(backup_id, TRUE);
-
- key_copy(key, table->record[0], table->key_info, table->key_info->key_length);
-
- if (table->file->index_read_idx_map(table->record[0], 0, key, HA_WHOLE_KEY,
- HA_READ_KEY_EXACT))
- {
- DBUG_PRINT("info", ("Row not found"));
- DBUG_RETURN(TRUE);
- }
-
- DBUG_PRINT("info", ("Row found!"));
- DBUG_RETURN(FALSE);
-}
-
-/**
Get text string for state.
@param enum_backup_state state The current state of the operation
@@ -241,137 +108,12 @@ void get_state_string(enum_backup_state
}
/**
- Update an integer field for the row in the table that matches the backup_id.
-
- This method locates the row in the online backup table that matches the
- backup_id passed and updates the field specified.
-
- @param ulonglong backup_id The id of the row to locate.
- @param char * table_name The name of the table to open.
- @param enum_ob_table_field fld Field to update.
- @param ulonglong value Value to set field to.
-
- @returns 0 = success
- @returns 1 = failed to find row
- */
-int update_online_backup_int_field(ulonglong backup_id,
- const char *table_name,
- enum_ob_table_field fld,
- ulonglong value)
-{
- TABLE *table= NULL; // table to open
- TABLE_LIST tables; // List of tables (1 in this case)
- int ret= 0; // return value
- Locking_thread_st *locking_thd= NULL; // The locking thread
-
- DBUG_ENTER("update_int_field()");
-
- locking_thd= open_backup_progress_table(table_name, TL_WRITE);
- if (!locking_thd)
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(0);
- }
-
- table= locking_thd->tables_in_backup->table;
- table->use_all_columns();
-
- if (find_online_backup_row(table, backup_id))
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(1);
- }
-
- store_record(table, record[1]);
-
- /*
- Fill in the data.
- */
- table->field[fld]->store(value, TRUE);
- table->field[fld]->set_notnull();
-
- /*
- Update the row.
- */
- if ((ret= table->file->ha_update_row(table->record[1], table->record[0])))
- table->file->print_error(ret, MYF(0));
-
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(ret);
-}
-
-/**
- Update a datetime field for the row in the table that matches the backup_id.
-
- This method locates the row in the online backup table that matches the
- backup_id passed and updates the field specified.
-
- @param ulonglong backup_id The id of the row to locate.
- @param char * table_name The name of the table to open.
- @param enum_ob_table_field fld Field to update.
- @param my_time_t value Value to set field to.
-
- @returns 0 = success
- @returns 1 = failed to find row
- */
-int update_online_backup_datetime_field(ulonglong backup_id,
- const char *table_name,
- enum_ob_table_field fld,
- time_t value)
-{
- TABLE *table= NULL; // table to open
- TABLE_LIST tables; // List of tables (1 in this case)
- int ret= 0; // return value
- Locking_thread_st *locking_thd= NULL; // The locking thread
-
- DBUG_ENTER("update_int_field()");
-
- locking_thd= open_backup_progress_table(table_name, TL_WRITE);
- if (!locking_thd)
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(0);
- }
-
- table= locking_thd->tables_in_backup->table;
- table->use_all_columns();
-
- if (find_online_backup_row(table, backup_id))
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(1);
- }
-
- store_record(table, record[1]);
-
- /*
- Fill in the data.
- */
- if (value)
- {
- MYSQL_TIME time;
- my_tz_OFFSET0->gmt_sec_to_TIME(&time, (my_time_t)value);
-
- table->field[fld]->set_notnull();
- table->field[fld]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
- }
-
- /*
- Update the row.
- */
- if ((ret= table->file->ha_update_row(table->record[1], table->record[0])))
- table->file->print_error(ret, MYF(0));
-
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(ret);
-}
-
-/**
report_ob_init()
This method inserts a new row in the online_backup table populating it
with the initial values passed. It returns the backup_id of the new row.
+ @param THD thd The current thread class.
@param int process_id The process id of the operation
@param enum_backup_state state The current state of the operation
@param enum_backup_op operation The current state of the operation
@@ -383,118 +125,27 @@ int update_online_backup_datetime_field(
@returns long backup_id The autoincrement value for the new row.
*/
-ulonglong report_ob_init(int process_id,
- enum_backup_state state,
- enum_backup_op operation,
- int error_num,
- const char *user_comment,
- const char *backup_file,
- const char *command)
-{
+ulonglong report_ob_init(THD *thd,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command)
+{
ulonglong backup_id= 0;
int ret= 0; // return value
- TABLE *table= NULL; // table to open
- TABLE_LIST tables; // List of tables (1 in this case)
- char *host= current_thd->security_ctx->host; // host name
- char *user= current_thd->security_ctx->user; // user name
- Locking_thread_st *locking_thd= NULL; // The locking thread
-
DBUG_ENTER("report_ob_init()");
- locking_thd= open_backup_progress_table("online_backup", TL_WRITE);
- if (!locking_thd)
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(0);
- }
-
- table= locking_thd->tables_in_backup->table;
- table->use_all_columns();
-
- THD *t= table->in_use;
- table->in_use= current_thd;
-
- /*
- Get defaults for new record.
- */
- restore_record(table, s->default_values);
-
- /*
- Fill in the data.
- */
- table->field[ET_FIELD_PROCESS_ID]->store(process_id, TRUE);
- table->field[ET_FIELD_PROCESS_ID]->set_notnull();
- table->field[ET_FIELD_BACKUP_STATE]->store(state, TRUE);
- table->field[ET_FIELD_BACKUP_STATE]->set_notnull();
- table->field[ET_FIELD_OPER]->store(operation, TRUE);
- table->field[ET_FIELD_OPER]->set_notnull();
- table->field[ET_FIELD_ERROR_NUM]->store(error_num, TRUE);
- table->field[ET_FIELD_ERROR_NUM]->set_notnull();
-
- if (host)
- {
- if(table->field[ET_FIELD_HOST_OR_SERVER]->store(host,
- strlen(host), system_charset_info))
- goto end;
- table->field[ET_FIELD_HOST_OR_SERVER]->set_notnull();
- }
-
- if (user)
- {
- if (table->field[ET_FIELD_USERNAME]->store(user,
- strlen(user), system_charset_info))
- goto end;
- table->field[ET_FIELD_USERNAME]->set_notnull();
- }
-
- if (user_comment)
- {
- if (table->field[ET_FIELD_COMMENT]->store(user_comment,
- strlen(user_comment), system_charset_info))
- goto end;
- table->field[ET_FIELD_COMMENT]->set_notnull();
- }
-
- if (backup_file)
- {
- if (table->field[ET_FIELD_BACKUP_FILE]->store(backup_file,
- strlen(backup_file), system_charset_info))
- goto end;
- table->field[ET_FIELD_BACKUP_FILE]->set_notnull();
- }
-
- if (command)
- {
- if (table->field[ET_FIELD_COMMAND]->store(command,
- strlen(command), system_charset_info))
- goto end;
- table->field[ET_FIELD_COMMAND]->set_notnull();
- }
- table->in_use= t;
-
- table->next_number_field=table->found_next_number_field;
-
- /*
- Write the row.
- */
- if ((ret= table->file->ha_write_row(table->record[0])))
- table->file->print_error(ret, MYF(0));
-
- /*
- Get last insert id for row.
- */
- backup_id= table->file->insert_id_for_cur_row;
- table->file->ha_release_auto_increment();
-
-end:
-
- ret= close_backup_progress_table(locking_thd);
+ ret= backup_history_log_write(thd, &backup_id, process_id, state, operation,
+ error_num, user_comment, backup_file, command);
/*
Record progress update.
*/
String str;
get_state_string(state, &str);
- report_ob_progress(backup_id, "backup kernel", 0,
+ report_ob_progress(thd, backup_id, "backup kernel", 0,
0, 0, 0, 0, str.c_ptr());
DBUG_RETURN(backup_id);
}
@@ -505,6 +156,7 @@ end:
This method locates the row in the online backup table that matches the
backup_id passed and updates the binlog values.
+ @param THD thd The current thread class.
@param ulonglong backup_id The id of the row to locate.
@param int backup_pos The id of the row to locate.
@param char * binlog_file The filename of the binlog.
@@ -512,62 +164,18 @@ end:
@returns 0 = success
@returns 1 = failed to find row
*/
-int report_ob_binlog_info(ulonglong backup_id,
+int report_ob_binlog_info(THD *thd,
+ ulonglong backup_id,
int binlog_pos,
const char *binlog_file)
{
- TABLE *table= NULL; // table to open
- TABLE_LIST tables; // List of tables (1 in this case)
int ret= 0; // return value
- Locking_thread_st *locking_thd= NULL; // The locking thread
-
DBUG_ENTER("report_ob_binlog_info()");
- locking_thd= open_backup_progress_table("online_backup", TL_WRITE);
- if (!locking_thd)
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(0);
- }
-
- table= locking_thd->tables_in_backup->table;
- table->use_all_columns();
-
- if (find_online_backup_row(table, backup_id))
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(1);
- }
-
- store_record(table, record[1]);
-
- /*
- Fill in the data.
- */
- table->field[ET_FIELD_BINLOG_POS]->store(binlog_pos, TRUE);
- table->field[ET_FIELD_BINLOG_POS]->set_notnull();
-
- THD *t= table->in_use;
- table->in_use= current_thd;
-
- if (binlog_file)
- {
- if(table->field[ET_FIELD_BINLOG_FILE]->store(binlog_file,
- strlen(binlog_file), system_charset_info))
- goto end;
- table->field[ET_FIELD_BINLOG_FILE]->set_notnull();
- }
- table->in_use= t;
-
- /*
- Update the row.
- */
- if ((ret= table->file->ha_update_row(table->record[1], table->record[0])))
- table->file->print_error(ret, MYF(0));
-
-end:
-
- ret= close_backup_progress_table(locking_thd);
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_BINLOG_POS,
+ binlog_pos, 0, 0, 0);
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_BINLOG_FILE,
+ 0, 0, binlog_file, 0);
DBUG_RETURN(ret);
}
@@ -577,20 +185,23 @@ end:
This method locates the row in the online backup table that matches the
backup_id passed and updates the error number value.
+ @param THD thd The current thread class.
@param ulonglong backup_id The id of the row to locate.
@param int error_num New error number.
@returns 0 = success
@returns 1 = failed to find row
*/
-int report_ob_error(ulonglong backup_id,
+int report_ob_error(THD *thd,
+ ulonglong backup_id,
int error_num)
{
int ret= 0; // return value
-
DBUG_ENTER("report_ob_error()");
- update_online_backup_int_field(backup_id, "online_backup",
- ET_FIELD_ERROR_NUM, error_num);
+
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_ERROR_NUM,
+ error_num, 0, 0, 0);
+
DBUG_RETURN(ret);
}
@@ -600,20 +211,23 @@ int report_ob_error(ulonglong backup_id,
This method locates the row in the online backup table that matches the
backup_id passed and updates the number of objects value.
- @param ulonglong backup_id The id of the row to locate.
+ @param THD thd The current thread class.
+ @param ulonglong backup_id The id of the row to locate.
@param int num_objects New error number.
@returns 0 = success
@returns 1 = failed to find row
*/
-int report_ob_num_objects(ulonglong backup_id,
+int report_ob_num_objects(THD *thd,
+ ulonglong backup_id,
int num_objects)
{
int ret= 0; // return value
-
DBUG_ENTER("report_ob_num_objects()");
- update_online_backup_int_field(backup_id, "online_backup",
- ET_FIELD_NUM_OBJ, num_objects);
+
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_NUM_OBJ,
+ num_objects, 0, 0, 0);
+
DBUG_RETURN(ret);
}
@@ -623,20 +237,23 @@ int report_ob_num_objects(ulonglong back
This method locates the row in the online backup table that matches the
backup_id passed and updates the size value.
+ @param THD thd The current thread class.
@param ulonglong backup_id The id of the row to locate.
@param int size New size value.
@returns 0 = success
@returns 1 = failed to find row
*/
-int report_ob_size(ulonglong backup_id,
+int report_ob_size(THD *thd,
+ ulonglong backup_id,
longlong size)
{
int ret= 0; // return value
-
DBUG_ENTER("report_ob_size()");
- update_online_backup_int_field(backup_id, "online_backup",
- ET_FIELD_TOTAL_BYTES, size);
+
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_TOTAL_BYTES,
+ size, 0, 0, 0);
+
DBUG_RETURN(ret);
}
@@ -646,6 +263,7 @@ int report_ob_size(ulonglong backup_id,
This method locates the row in the online backup table that matches the
backup_id passed and updates the start/stop values.
+ @param THD thd The current thread class.
@param ulonglong backup_id The id of the row to locate.
@param my_time_t start Start datetime.
@param my_time_t stop Stop datetime.
@@ -653,19 +271,22 @@ int report_ob_size(ulonglong backup_id,
@returns 0 = success
@returns 1 = failed to find row
*/
-int report_ob_time(ulonglong backup_id,
+int report_ob_time(THD *thd,
+ ulonglong backup_id,
time_t start,
time_t stop)
{
int ret= 0; // return value
-
DBUG_ENTER("report_ob_time()");
+
if (start)
- update_online_backup_datetime_field(backup_id, "online_backup",
- ET_FIELD_START_TIME, start);
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_START_TIME,
+ 0, start, 0, 0);
+
if (stop)
- update_online_backup_datetime_field(backup_id, "online_backup",
- ET_FIELD_STOP_TIME, stop);
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_STOP_TIME,
+ 0, stop, 0, 0);
+
DBUG_RETURN(ret);
}
@@ -675,21 +296,24 @@ int report_ob_time(ulonglong backup_id,
This method updates the validity point time for the backup operation
identified by backup_id.
+ @param THD thd The current thread class.
@param ulonglong backup_id The id of the row to locate.
@param my_time_t vp_time Validity point datetime.
@returns 0 = success
@returns 1 = failed to find row
*/
-int report_ob_vp_time(ulonglong backup_id,
+int report_ob_vp_time(THD *thd,
+ ulonglong backup_id,
time_t vp_time)
{
int ret= 0; // return value
-
DBUG_ENTER("report_ob_vp_time()");
+
if (vp_time)
- update_online_backup_datetime_field(backup_id, "online_backup",
- ET_FIELD_VP, vp_time);
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_VP,
+ 0, vp_time, 0, 0);
+
DBUG_RETURN(ret);
}
@@ -700,70 +324,23 @@ int report_ob_vp_time(ulonglong backup_i
identified by backup_id. This method appends to the those listed in the
table for the backup_id.
+ @param THD thd The current thread class.
@param ulonglong backup_id The id of the row to locate.
@param char * egnine_name The name of the engine to add.
@returns 0 = success
@returns 1 = failed to find row
*/
-int report_ob_engines(ulonglong backup_id,
+int report_ob_engines(THD *thd,
+ ulonglong backup_id,
const char *engine_name)
{
- TABLE *table= NULL; // table to open
- TABLE_LIST tables; // List of tables (1 in this case)
- int ret= 0; // return value
- String str; // engines string
- Locking_thread_st *locking_thd= NULL; // The locking thread
-
- DBUG_ENTER("report_ob_engines()");
-
- locking_thd= open_backup_progress_table("online_backup", TL_WRITE);
- if (!locking_thd)
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(0);
- }
-
- table= locking_thd->tables_in_backup->table;
- table->use_all_columns();
-
- if (find_online_backup_row(table, backup_id))
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(1);
- }
-
- store_record(table, record[1]);
-
- /*
- Fill in the data.
- */
- THD *t= table->in_use;
- table->in_use= current_thd;
-
- str.length(0);
- table->field[ET_FIELD_ENGINES]->val_str(&str);
- if (str.length() > 0)
- str.append(", ");
- str.append(engine_name);
- if (str.length() > 0)
- {
- if(table->field[ET_FIELD_ENGINES]->store(str.c_ptr(),
- str.length(), system_charset_info))
- goto end;
- table->field[ET_FIELD_ENGINES]->set_notnull();
- }
- table->in_use= t;
-
- /*
- Update the row.
- */
- if ((ret= table->file->ha_update_row(table->record[1], table->record[0])))
- table->file->print_error(ret, MYF(0));
+ int ret= 0; // return value
+ DBUG_ENTER("report_ob_vp_time()");
-end:
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_ENGINES,
+ 0, 0, engine_name, 0);
- ret= close_backup_progress_table(locking_thd);
DBUG_RETURN(ret);
}
@@ -773,26 +350,28 @@ end:
This method locates the row in the online backup table that matches the
backup_id passed and updates the state value.
+ @param THD thd The current thread class.
@param ulonglong backup_id The id of the row to locate.
@param enum_backup_state state New state value.
@returns 0 = success
@returns 1 = failed to find row
*/
-int report_ob_state(ulonglong backup_id,
+int report_ob_state(THD *thd,
+ ulonglong backup_id,
enum_backup_state state)
{
int ret= 0; // return value
String str;
-
DBUG_ENTER("report_ob_state()");
- update_online_backup_int_field(backup_id, "online_backup",
- ET_FIELD_BACKUP_STATE, state);
+
+ ret= backup_history_log_update(thd, backup_id, ET_OBH_FIELD_BACKUP_STATE,
+ 0, 0, 0, state);
/*
Record progress update.
*/
get_state_string(state, &str);
- report_ob_progress(backup_id, "backup kernel", 0,
+ report_ob_progress(thd, backup_id, "backup kernel", 0,
0, 0, 0, 0, str.c_ptr());
DBUG_RETURN(ret);
@@ -805,6 +384,7 @@ int report_ob_state(ulonglong backup_id,
the values passed. This method is used to insert progress information during
the backup operation.
+ @param THD thd The current thread class.
@param ulonglong backup_id The id of the master table row.
@param char * object The name of the object processed.
@param my_time_t start Start datetime.
@@ -817,7 +397,8 @@ int report_ob_state(ulonglong backup_id,
@returns 0 = success
@returns 1 = failed to write row
*/
-int report_ob_progress(ulonglong backup_id,
+int report_ob_progress(THD *thd,
+ ulonglong backup_id,
const char *object,
time_t start,
time_t stop,
@@ -827,177 +408,13 @@ int report_ob_progress(ulonglong backup_
const char *notes)
{
int ret= 0; // return value
- TABLE *table= NULL; // table to open
- TABLE_LIST tables; // List of tables (1 in this case)
- Locking_thread_st *locking_thd= NULL; // The locking thread
-
DBUG_ENTER("report_ob_progress()");
- locking_thd= open_backup_progress_table("online_backup_progress", TL_WRITE);
- if (!locking_thd)
- {
- ret= close_backup_progress_table(locking_thd);
- DBUG_RETURN(0);
- }
-
- table= locking_thd->tables_in_backup->table;
- table->use_all_columns();
-
- THD *t= table->in_use;
- table->in_use= current_thd;
-
- /*
- Get defaults for new record.
- */
- restore_record(table, s->default_values);
-
- /*
- Fill in the data.
- */
- table->field[ET_FIELD_BACKUP_ID_FK]->store(backup_id, TRUE);
- table->field[ET_FIELD_BACKUP_ID_FK]->set_notnull();
-
- if (object)
- {
- if (table->field[ET_FIELD_PROG_OBJECT]->store(object,
- strlen(object), system_charset_info))
- goto end;
- table->field[ET_FIELD_PROG_OBJECT]->set_notnull();
- }
-
- if (notes)
- {
- if (table->field[ET_FIELD_PROG_NOTES]->store(notes,
- strlen(notes), system_charset_info))
- goto end;
- table->field[ET_FIELD_PROG_NOTES]->set_notnull();
- }
- table->in_use= t;
+ ret= backup_progress_log_write(thd, backup_id, object, start, stop,
+ size, progress, error_num, notes);
- if (start)
- {
- MYSQL_TIME time;
- my_tz_OFFSET0->gmt_sec_to_TIME(&time, (my_time_t)start);
-
- table->field[ET_FIELD_PROG_START_TIME]->set_notnull();
- table->field[ET_FIELD_PROG_START_TIME]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
- }
-
- if (stop)
- {
- MYSQL_TIME time;
- my_tz_OFFSET0->gmt_sec_to_TIME(&time, (my_time_t)stop);
-
- table->field[ET_FIELD_PROG_STOP_TIME]->set_notnull();
- table->field[ET_FIELD_PROG_STOP_TIME]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
- }
-
- table->field[ET_FIELD_PROG_SIZE]->store(size, TRUE);
- table->field[ET_FIELD_PROG_SIZE]->set_notnull();
- table->field[ET_FIELD_PROGRESS]->store(progress, TRUE);
- table->field[ET_FIELD_PROGRESS]->set_notnull();
- table->field[ET_FIELD_PROG_ERROR_NUM]->store(error_num, TRUE);
- table->field[ET_FIELD_PROG_ERROR_NUM]->set_notnull();
-
- /*
- Write the row.
- */
- if ((ret= table->file->ha_write_row(table->record[0])))
- table->file->print_error(ret, MYF(0));
-
-end:
-
- ret= close_backup_progress_table(locking_thd);
DBUG_RETURN(ret);
}
-/**
- Sums the sizes for the row that matches the backup_id.
-
- This method sums the size entries from the online backup progress rows
- for the backup operation identified by backup_id.
- @param ulonglong backup_id The id of the row to locate.
-
- @returns ulonglong Total size of all backup progress rows
- */
-ulonglong sum_progress_rows(ulonglong backup_id)
-{
- int last_read_res; // result of last read
- TABLE *table= NULL; // table to open
- TABLE_LIST tables; // List of tables (1 in this case)
- ulonglong size= 0; // total size
- handler *hdl; // handler pointer
- Locking_thread_st *locking_thd= NULL; // The locking thread
-
- DBUG_ENTER("sum_progress_rows()");
-
- locking_thd= open_backup_progress_table("online_backup_progress", TL_READ);
- if (!locking_thd)
- {
- close_backup_progress_table(locking_thd);
- DBUG_RETURN(0);
- }
-
- table= locking_thd->tables_in_backup->table;
- table->use_all_columns();
-
- hdl= table->file;
- last_read_res= hdl->ha_rnd_init(1);
- THD *t= table->in_use;
- table->in_use= current_thd;
- while (!hdl->rnd_next(table->record[0]))
- if ((table->field[ET_FIELD_PROGRESS]->val_int() == 100) &&
- (table->field[ET_FIELD_PROG_ERROR_NUM]->val_int() == 0) &&
- ((ulonglong)table->field[ET_FIELD_BACKUP_ID_FK]->val_int() == backup_id))
- size+= table->field[ET_FIELD_PROG_SIZE]->val_int();
- table->in_use= t;
-
- hdl->ha_rnd_end();
-
- close_backup_progress_table(locking_thd);
- DBUG_RETURN(size);
-}
-
-/**
- Print summary for the row that matches the backup_id.
-
- This method prints the summary information for the backup operation
- identified by backup_id.
-
- @param ulonglong backup_id The id of the row to locate.
-
- @returns 0 = success
- @returns 1 = failed to find row
- */
-int print_backup_summary(THD *thd, ulonglong backup_id)
-{
- Protocol *protocol= thd->protocol; // client comms
- List<Item> field_list; // list of fields to send
- String op_str; // operations string
- int ret= 0; // return value
- char buf[255]; // buffer for summary information
- String str;
-
- DBUG_ENTER("print_backup_summary()");
-
- /*
- Send field list.
- */
- op_str.length(0);
- op_str.append("backup_id");
- field_list.push_back(new Item_empty_string(op_str.c_ptr(), op_str.length()));
- protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
-
- /*
- Send field data.
- */
- protocol->prepare_for_resend();
- llstr(backup_id,buf);
- protocol->store(buf, system_charset_info);
- protocol->write();
-
- my_eof(thd);
- DBUG_RETURN(ret);
-}
diff -Nrup a/sql/backup/backup_progress.h b/sql/backup/backup_progress.h
--- a/sql/backup/backup_progress.h 2008-01-31 12:23:30 -05:00
+++ b/sql/backup/backup_progress.h 2008-03-18 14:03:48 -04:00
@@ -25,72 +25,8 @@
#include "my_global.h"
#include "my_time.h"
#include "mysql_priv.h"
+#include "log.h"
-/**
- List of fields for online backup table.
- */
-enum enum_ob_table_field
-{
- ET_FIELD_BACKUP_ID = 0, /* start from 0 to correspond with field array */
- ET_FIELD_PROCESS_ID,
- ET_FIELD_BINLOG_POS,
- ET_FIELD_BINLOG_FILE,
- ET_FIELD_BACKUP_STATE,
- ET_FIELD_OPER,
- ET_FIELD_ERROR_NUM,
- ET_FIELD_NUM_OBJ,
- ET_FIELD_TOTAL_BYTES,
- ET_FIELD_VP,
- ET_FIELD_START_TIME,
- ET_FIELD_STOP_TIME,
- ET_FIELD_HOST_OR_SERVER,
- ET_FIELD_USERNAME,
- ET_FIELD_BACKUP_FILE,
- ET_FIELD_COMMENT,
- ET_FIELD_COMMAND,
- ET_FIELD_ENGINES,
- ET_FIELD_COUNT /* a cool trick to count the number of fields :) */
-};
-
-/**
- List of fields for online backup progress table.
- */
-enum enum_ob_progress_table_field
-{
- ET_FIELD_BACKUP_ID_FK = 0, /* start from 0 to correspond with field array */
- ET_FIELD_PROG_OBJECT,
- ET_FIELD_PROG_START_TIME,
- ET_FIELD_PROG_STOP_TIME,
- ET_FIELD_PROG_SIZE,
- ET_FIELD_PROGRESS,
- ET_FIELD_PROG_ERROR_NUM,
- ET_FIELD_PROG_NOTES,
- ET_FIELD_PROG_COUNT /* a cool trick to count the number of fields :) */
-};
-
-/**
- List of states for online backup table.
- */
-enum enum_backup_state
-{
- BUP_COMPLETE = 1,
- BUP_STARTING,
- BUP_VALIDITY_POINT,
- BUP_RUNNING,
- BUP_ERRORS,
- BUP_CANCEL
-};
-
-/**
- List of operations for online backup table.
- */
-enum enum_backup_op
-{
- OP_BACKUP = 1,
- OP_RESTORE,
- OP_SHOW,
- OP_OTHER
-};
/*
This method attempts to open the online backup progress tables. It returns
@@ -102,19 +38,21 @@ my_bool check_ob_progress_tables(THD *th
This method inserts a new row in the online_backup table populating it with
the initial values passed. It returns the backup_id of the new row.
*/
-ulonglong report_ob_init(int process_id,
- enum_backup_state state,
- enum_backup_op operation,
- int error_num,
- const char *user_comment,
- const char *backup_file,
- const char *command);
+ulonglong report_ob_init(THD *thd,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command);
/*
This method updates the binary log information for the backup operation
identified by backup_id.
*/
-int report_ob_binlog_info(ulonglong backup_id,
+int report_ob_binlog_info(THD *thd,
+ ulonglong backup_id,
int binlog_pos,
const char *binlog_file);
@@ -122,28 +60,32 @@ int report_ob_binlog_info(ulonglong back
This method updates the error number for the backup operation identified by
backup_id.
*/
-int report_ob_error(ulonglong backup_id,
+int report_ob_error(THD *thd,
+ ulonglong backup_id,
int error_num);
/*
This method updates the state for the backup operation identified by
backup_id.
*/
-int report_ob_state(ulonglong backup_id,
+int report_ob_state(THD *thd,
+ ulonglong backup_id,
enum_backup_state state);
/*
This method updates the number of objects for the backup operation identified by
backup_id.
*/
-int report_ob_num_objects(ulonglong backup_id,
+int report_ob_num_objects(THD *thd,
+ ulonglong backup_id,
int num_objects);
/*
This method updates the size for the backup operation identified by
backup_id.
*/
-int report_ob_size(ulonglong backup_id,
+int report_ob_size(THD *thd,
+ ulonglong backup_id,
longlong size);
/*
@@ -154,7 +96,8 @@ int report_ob_size(ulonglong backup_id,
values provided so that it can be called once for start and once again later
for stop).
*/
-int report_ob_time(ulonglong backup_id,
+int report_ob_time(THD *thd,
+ ulonglong backup_id,
time_t start,
time_t stop);
@@ -162,7 +105,8 @@ int report_ob_time(ulonglong backup_id,
This method updates the validity point time for the backup operation
identified by backup_id.
*/
-int report_ob_vp_time(ulonglong backup_id,
+int report_ob_vp_time(THD *thd,
+ ulonglong backup_id,
time_t vp_time);
/*
@@ -170,13 +114,15 @@ int report_ob_vp_time(ulonglong backup_i
identified by backup_id. This method appends to the those listed in the
table for the backup_id.
*/
-int report_ob_engines(ulonglong backup_id,
+int report_ob_engines(THD *thd,
+ ulonglong backup_id,
const char *engine_name);
/*
This method inserts a new row in the progress table.
*/
-int report_ob_progress(ulonglong backup_id,
+int report_ob_progress(THD *thd,
+ ulonglong backup_id,
const char *object,
time_t start,
time_t stop,
@@ -184,18 +130,6 @@ int report_ob_progress(ulonglong backup_
longlong progress,
int error_num,
const char *notes);
-
-/*
- This method sums the size entries from the online backup progress rows
- for the backup operation identified by backup_id.
-*/
-ulonglong sum_progress_rows(ulonglong backup_id);
-
-/*
- This method prints the summary information for the backup operation
- identified by backup_id.
-*/
-int print_backup_summary(THD *thd, ulonglong backup_id);
#endif
diff -Nrup a/sql/backup/be_snapshot.cc b/sql/backup/be_snapshot.cc
--- a/sql/backup/be_snapshot.cc 2007-11-29 23:22:05 -05:00
+++ b/sql/backup/be_snapshot.cc 2008-03-18 14:03:49 -04:00
@@ -121,6 +121,7 @@ result_t Backup::get_data(Buffer &buf)
if (locking_thd->lock_state == LOCK_SIGNAL)
{
locking_thd->lock_state= LOCK_DONE; // set lock done so destructor won't wait
+ ha_autocommit_or_rollback(locking_thd->m_thd, 0);
end_active_trans(locking_thd->m_thd);
close_thread_tables(locking_thd->m_thd);
}
diff -Nrup a/sql/backup/data_backup.cc b/sql/backup/data_backup.cc
--- a/sql/backup/data_backup.cc 2007-12-13 09:08:42 -05:00
+++ b/sql/backup/data_backup.cc 2008-03-18 14:03:49 -04:00
@@ -491,7 +491,7 @@ int write_table_data(THD* thd, Backup_in
/*
Record the backup id and name for this driver.
*/
- report_ob_engines(info.backup_prog_id, p->m_name);
+ report_ob_engines(thd, info.backup_prog_id, p->m_name);
if (!p || !p->is_valid())
{
@@ -600,7 +600,7 @@ int write_table_data(THD* thd, Backup_in
// VP creation
DBUG_PRINT("backup_data",("-- SYNC PHASE --"));
- report_ob_state(info.backup_prog_id, BUP_VALIDITY_POINT);
+ report_ob_state(thd, info.backup_prog_id, BUP_VALIDITY_POINT);
/*
Block commits.
@@ -654,12 +654,12 @@ int write_table_data(THD* thd, Backup_in
*/
BACKUP_BREAKPOINT("bp_vp_state");
info.save_vp_time(vp_time);
- report_ob_vp_time(info.backup_prog_id, vp_time);
- report_ob_state(info.backup_prog_id, BUP_RUNNING);
+ report_ob_vp_time(thd, info.backup_prog_id, vp_time);
+ report_ob_state(thd, info.backup_prog_id, BUP_RUNNING);
BACKUP_BREAKPOINT("bp_running_state");
if (mysql_bin_log.is_open())
- report_ob_binlog_info(info.backup_prog_id,
+ report_ob_binlog_info(thd, info.backup_prog_id,
info.binlog_pos.pos, info.binlog_pos.file);
// get final data from drivers
@@ -1352,7 +1352,7 @@ namespace backup {
/**
Read backup image data from a backup stream and forward it to restore drivers.
*/
-int restore_table_data(THD*, Restore_info &info, IStream &s)
+int restore_table_data(THD* thd, Restore_info &info, IStream &s)
{
DBUG_ENTER("restore::restore_table_data");
@@ -1410,7 +1410,7 @@ int restore_table_data(THD*, Restore_inf
/*
Record the name for this driver.
*/
- report_ob_engines(info.backup_prog_id, snap->name());
+ report_ob_engines(thd, info.backup_prog_id, snap->name());
}
{
diff -Nrup a/sql/backup/kernel.cc b/sql/backup/kernel.cc
--- a/sql/backup/kernel.cc 2008-02-29 09:37:41 -05:00
+++ b/sql/backup/kernel.cc 2008-03-18 14:03:50 -04:00
@@ -149,6 +149,8 @@ execute_backup_command(THD *thd, LEX *le
{
backup::IStream *stream= open_for_read(*loc);
+ backup_prog_id= report_ob_init(thd, thd->id, BUP_STARTING, OP_RESTORE,
+ 0, "", lex->backup_dir.str, thd->query);
if (!stream)
{
my_error(ER_BACKUP_READ_LOC,MYF(0),loc->describe());
@@ -164,9 +166,7 @@ execute_backup_command(THD *thd, LEX *le
start= my_time(0);
- backup_prog_id= report_ob_init(thd->id, BUP_STARTING, OP_RESTORE,
- 0, "", lex->backup_dir.str, thd->query);
- report_ob_time(backup_prog_id, start, 0);
+ report_ob_time(thd, backup_prog_id, start, 0);
BACKUP_BREAKPOINT("bp_starting_state");
Restore_info info(thd,*stream);
@@ -182,7 +182,7 @@ execute_backup_command(THD *thd, LEX *le
info.report_error(log_level::INFO,ER_BACKUP_RESTORE_START);
info.save_start_time(start);
- report_ob_state(backup_prog_id, BUP_RUNNING);
+ report_ob_state(thd, backup_prog_id, BUP_RUNNING);
BACKUP_BREAKPOINT("bp_running_state");
/*
@@ -217,10 +217,10 @@ execute_backup_command(THD *thd, LEX *le
goto restore_error;
}
- report_ob_num_objects(backup_prog_id, info.table_count);
- report_ob_size(backup_prog_id, info.data_size);
- report_ob_time(backup_prog_id, 0, stop);
- report_ob_state(backup_prog_id, BUP_COMPLETE);
+ report_ob_num_objects(thd, backup_prog_id, info.table_count);
+ report_ob_size(thd, backup_prog_id, info.data_size);
+ report_ob_time(thd, backup_prog_id, 0, stop);
+ report_ob_state(thd, backup_prog_id, BUP_COMPLETE);
BACKUP_BREAKPOINT("bp_complete_state");
info.report_error(log_level::INFO,ER_BACKUP_RESTORE_DONE);
@@ -233,12 +233,12 @@ execute_backup_command(THD *thd, LEX *le
res= res ? res : ERROR;
- report_ob_error(backup_prog_id, res);
+ report_ob_error(thd, backup_prog_id, res);
if (stop)
- report_ob_time(backup_prog_id, 0, stop);
+ report_ob_time(thd, backup_prog_id, 0, stop);
- report_ob_state(backup_prog_id, BUP_ERRORS);
+ report_ob_state(thd, backup_prog_id, BUP_ERRORS);
BACKUP_BREAKPOINT("bp_error_state");
finish_restore:
@@ -261,6 +261,8 @@ execute_backup_command(THD *thd, LEX *le
bool remove_location= FALSE;
backup::OStream *stream= open_for_write(*loc);
+ backup_prog_id= report_ob_init(thd, thd->id, BUP_STARTING, OP_BACKUP,
+ 0, "", lex->backup_dir.str, thd->query);
if (!stream)
{
my_error(ER_BACKUP_WRITE_LOC,MYF(0),loc->describe());
@@ -283,9 +285,7 @@ execute_backup_command(THD *thd, LEX *le
Backup_info info(thd);
- backup_prog_id= report_ob_init(thd->id, BUP_STARTING, OP_BACKUP,
- 0, "", lex->backup_dir.str, thd->query);
- report_ob_time(backup_prog_id, start, 0);
+ report_ob_time(thd, backup_prog_id, start, 0);
BACKUP_BREAKPOINT("bp_starting_state");
info.backup_prog_id= backup_prog_id;
@@ -295,7 +295,7 @@ execute_backup_command(THD *thd, LEX *le
info.report_error(log_level::INFO,ER_BACKUP_BACKUP_START);
info.save_start_time(start);
- report_ob_state(backup_prog_id, BUP_RUNNING);
+ report_ob_state(thd, backup_prog_id, BUP_RUNNING);
BACKUP_BREAKPOINT("bp_running_state");
info.save_errors();
@@ -320,7 +320,7 @@ execute_backup_command(THD *thd, LEX *le
goto backup_error;
}
- report_ob_num_objects(backup_prog_id, info.table_count);
+ report_ob_num_objects(thd, backup_prog_id, info.table_count);
if (check_info(thd,info))
{
@@ -350,9 +350,9 @@ execute_backup_command(THD *thd, LEX *le
goto backup_error;
}
- report_ob_size(info.backup_prog_id, info.data_size);
- report_ob_time(info.backup_prog_id, 0, stop);
- report_ob_state(info.backup_prog_id, BUP_COMPLETE);
+ report_ob_size(thd, info.backup_prog_id, info.data_size);
+ report_ob_time(thd, info.backup_prog_id, 0, stop);
+ report_ob_state(thd, info.backup_prog_id, BUP_COMPLETE);
BACKUP_BREAKPOINT("bp_complete_state");
info.report_error(log_level::INFO,ER_BACKUP_BACKUP_DONE);
@@ -366,11 +366,11 @@ execute_backup_command(THD *thd, LEX *le
res= res ? res : ERROR;
- report_ob_error(backup_prog_id, res);
- report_ob_state(backup_prog_id, BUP_ERRORS);
+ report_ob_error(thd, backup_prog_id, res);
+ report_ob_state(thd, backup_prog_id, BUP_ERRORS);
if (stop)
- report_ob_time(backup_prog_id, 0, stop);
+ report_ob_time(thd, backup_prog_id, 0, stop);
/*
If the output stream was opened, a file or other system resource
diff -Nrup a/sql/log.cc b/sql/log.cc
--- a/sql/log.cc 2008-02-19 06:58:25 -05:00
+++ b/sql/log.cc 2008-03-18 14:03:41 -04:00
@@ -114,6 +114,22 @@ char *make_default_log_name(char *buff,c
MYF(MY_UNPACK_FILENAME|MY_REPLACE_EXT));
}
+/**
+ Makes a new file name for the backup logs.
+
+ @param[OUT] buff The buffer to contain the name.
+ @param[IN] bup_name The name prefix for the backup log.
+ @param[IN] log_ext The extension for the file name.
+
+ @returns char * the formatted file name including path.
+*/
+char *make_backup_log_name(char *buff, const char *bup_name, const char* log_ext)
+{
+ strmake(buff, bup_name, FN_REFLEN-5);
+ return fn_format(buff, buff, mysql_data_home, log_ext,
+ MYF(MY_UNPACK_FILENAME|MY_REPLACE_EXT));
+}
+
/*
Helper class to hold a mutex for the duration of the
block.
@@ -460,6 +476,517 @@ err:
return result;
}
+/**
+ Write the backup log entry for the backup history log to a table.
+
+ This method creates a new row in the backup history log with the
+ information provided.
+
+ @param[IN] thd The current thread
+ @param[OUT] backup_id The new row id for the backup history
+ @param[IN] process_id The process id of the operation
+ @param[IN] state The current state of the operation
+ @param[IN] operation The current state of the operation
+ @param[IN] error_num The error number
+ @param[IN] user_comment The user's comment specified in the
+ command (not implemented yet)
+ @param[IN] backup_file The name of the target file
+ @param[IN] command The actual command entered
+
+ @returns TRUE if error.
+*/
+bool Log_to_csv_event_handler::
+ log_backup_history(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command)
+{
+ TABLE_LIST table_list;
+ TABLE *table= NULL;
+ bool result= TRUE;
+ bool need_close= FALSE;
+ bool need_pop= FALSE;
+ bool need_rnd_end= FALSE;
+ Silence_log_table_errors error_handler;
+ Open_tables_state open_tables_backup;
+ bool save_time_zone_used;
+ char *host= current_thd->security_ctx->host; // host name
+ char *user= current_thd->security_ctx->user; // user name
+
+ /*
+ CSV uses TIME_to_timestamp() internally if table needs to be repaired
+ which will set thd->time_zone_used
+ */
+ save_time_zone_used= thd->time_zone_used;
+
+ bzero(& table_list, sizeof(TABLE_LIST));
+ table_list.alias= table_list.table_name= BACKUP_HISTORY_LOG_NAME.str;
+ table_list.table_name_length= BACKUP_HISTORY_LOG_NAME.length;
+
+ table_list.lock_type= TL_WRITE_CONCURRENT_INSERT;
+
+ table_list.db= MYSQL_SCHEMA_NAME.str;
+ table_list.db_length= MYSQL_SCHEMA_NAME.length;
+
+ thd->push_internal_handler(& error_handler);
+ need_pop= TRUE;
+
+ if (!(table= open_performance_schema_table(thd, & table_list,
+ & open_tables_backup)))
+ goto err;
+
+ need_close= TRUE;
+
+ if (table->file->extra(HA_EXTRA_MARK_AS_LOG_TABLE) ||
+ table->file->ha_rnd_init(0))
+ goto err;
+
+ need_rnd_end= TRUE;
+
+ /* Honor next number columns if present */
+ table->next_number_field= table->found_next_number_field;
+
+ /*
+ Get defaults for new record.
+ */
+ restore_record(table, s->default_values);
+
+ /* check that all columns exist */
+ if (table->s->fields < 18)
+ goto err;
+
+ /*
+ Fill in the data.
+ */
+ table->field[ET_OBH_FIELD_PROCESS_ID]->store(process_id, TRUE);
+ table->field[ET_OBH_FIELD_PROCESS_ID]->set_notnull();
+ table->field[ET_OBH_FIELD_BACKUP_STATE]->store(state, TRUE);
+ table->field[ET_OBH_FIELD_BACKUP_STATE]->set_notnull();
+ table->field[ET_OBH_FIELD_OPER]->store(operation, TRUE);
+ table->field[ET_OBH_FIELD_OPER]->set_notnull();
+ table->field[ET_OBH_FIELD_ERROR_NUM]->store(error_num, TRUE);
+ table->field[ET_OBH_FIELD_ERROR_NUM]->set_notnull();
+
+ if (host)
+ {
+ if(table->field[ET_OBH_FIELD_HOST_OR_SERVER]->store(host,
+ strlen(host), system_charset_info))
+ goto err;
+ table->field[ET_OBH_FIELD_HOST_OR_SERVER]->set_notnull();
+ }
+
+ if (user)
+ {
+ if (table->field[ET_OBH_FIELD_USERNAME]->store(user,
+ strlen(user), system_charset_info))
+ goto err;
+ table->field[ET_OBH_FIELD_USERNAME]->set_notnull();
+ }
+
+ if (user_comment)
+ {
+ if (table->field[ET_OBH_FIELD_COMMENT]->store(user_comment,
+ strlen(user_comment), system_charset_info))
+ goto err;
+ table->field[ET_OBH_FIELD_COMMENT]->set_notnull();
+ }
+
+ if (backup_file)
+ {
+ if (table->field[ET_OBH_FIELD_BACKUP_FILE]->store(backup_file,
+ strlen(backup_file), system_charset_info))
+ goto err;
+ table->field[ET_OBH_FIELD_BACKUP_FILE]->set_notnull();
+ }
+
+ if (command)
+ {
+ if (table->field[ET_OBH_FIELD_COMMAND]->store(command,
+ strlen(command), system_charset_info))
+ goto err;
+ table->field[ET_OBH_FIELD_COMMAND]->set_notnull();
+ }
+
+ /* log table entries are not replicated */
+ if (table->file->ha_write_row(table->record[0]))
+ goto err;
+
+ /*
+ Get last insert id for row.
+ */
+ *backup_id= table->file->insert_id_for_cur_row;
+
+ result= FALSE;
+
+err:
+ if (result && !thd->killed)
+ sql_print_error("Failed to write to mysql.online_backup_progress: %s",
+ error_handler.message());
+
+ if (need_rnd_end)
+ {
+ table->file->ha_rnd_end();
+ table->file->ha_release_auto_increment();
+ }
+ if (need_pop)
+ thd->pop_internal_handler();
+ if (need_close)
+ close_performance_schema_table(thd, & open_tables_backup);
+
+ thd->time_zone_used= save_time_zone_used;
+ return result;
+}
+
+/**
+ Update a backup history log entry for the given backup_id to a table.
+
+ This method updates a row in the backup history log using one
+ of four data types as determined by the field (see fld).
+
+ @param[IN] thd The current thread
+ @param[IN] backup_id The row id for the backup history to be updated
+ @param[IN] fld The enum for the field to be updated
+ @param[IN] val_long The value for long fields
+ @param[IN] val_time The value for time fields
+ @param[IN] val_str The value for char * fields
+ @param[IN] val_state The value for state fields
+
+ @returns TRUE if error.
+*/
+bool Log_to_csv_event_handler::
+ log_backup_history_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state)
+{
+ TABLE_LIST table_list;
+ TABLE *table= NULL;
+ bool result= TRUE;
+ bool need_close= FALSE;
+ bool need_pop= FALSE;
+ bool need_rnd_end= FALSE;
+ Silence_log_table_errors error_handler;
+ Open_tables_state open_tables_backup;
+ bool save_time_zone_used;
+ int ret= 0;
+
+ /*
+ CSV uses TIME_to_timestamp() internally if table needs to be repaired
+ which will set thd->time_zone_used
+ */
+ save_time_zone_used= thd->time_zone_used;
+
+ bzero(& table_list, sizeof(TABLE_LIST));
+ table_list.alias= table_list.table_name= BACKUP_HISTORY_LOG_NAME.str;
+ table_list.table_name_length= BACKUP_HISTORY_LOG_NAME.length;
+
+ table_list.lock_type= TL_WRITE_CONCURRENT_INSERT;
+
+ table_list.db= MYSQL_SCHEMA_NAME.str;
+ table_list.db_length= MYSQL_SCHEMA_NAME.length;
+
+ thd->push_internal_handler(& error_handler);
+ need_pop= TRUE;
+
+ if (!(table= open_performance_schema_table(thd, & table_list,
+ & open_tables_backup)))
+ goto err;
+
+ if (find_backup_history_row(table, backup_id))
+ goto err;
+
+ need_close= TRUE;
+
+ store_record(table, record[1]);
+
+ /*
+ Fill in the data.
+ */
+ switch (fld) {
+ case ET_OBH_FIELD_BINLOG_POS:
+ case ET_OBH_FIELD_ERROR_NUM:
+ case ET_OBH_FIELD_NUM_OBJ:
+ case ET_OBH_FIELD_TOTAL_BYTES:
+ {
+ table->field[fld]->store(val_long, TRUE);
+ table->field[fld]->set_notnull();
+ break;
+ }
+ case ET_OBH_FIELD_BINLOG_FILE:
+ {
+ if (val_str)
+ {
+ if(table->field[fld]->store(val_str, strlen(val_str),
+ system_charset_info))
+ goto err;
+ table->field[fld]->set_notnull();
+ }
+ break;
+ }
+ case ET_OBH_FIELD_ENGINES:
+ {
+ String str; // engines string
+ str.length(0);
+ table->field[fld]->val_str(&str);
+ if (str.length() > 0)
+ str.append(", ");
+ str.append(val_str);
+ if (str.length() > 0)
+ {
+ if(table->field[fld]->store(str.c_ptr(),
+ str.length(), system_charset_info))
+ goto err;
+ table->field[fld]->set_notnull();
+ }
+ break;
+ }
+ case ET_OBH_FIELD_START_TIME:
+ case ET_OBH_FIELD_STOP_TIME:
+ case ET_OBH_FIELD_VP:
+ {
+ if (val_time)
+ {
+ MYSQL_TIME time;
+ my_tz_OFFSET0->gmt_sec_to_TIME(&time, (my_time_t)val_time);
+
+ table->field[fld]->set_notnull();
+ table->field[fld]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ }
+ break;
+ }
+ case ET_OBH_FIELD_BACKUP_STATE:
+ {
+ table->field[fld]->store(val_state, TRUE);
+ table->field[fld]->set_notnull();
+ break;
+ }
+ }
+
+ /*
+ Update the row.
+ */
+ if ((ret= table->file->ha_update_row(table->record[1], table->record[0])))
+ goto err;
+
+ result= FALSE;
+
+err:
+ if (result && !thd->killed)
+ sql_print_error("Failed to write to mysql.online_backup_progress: %s",
+ error_handler.message());
+
+ if (need_pop)
+ thd->pop_internal_handler();
+ if (need_close)
+ close_performance_schema_table(thd, & open_tables_backup);
+
+ thd->time_zone_used= save_time_zone_used;
+ return result;
+}
+
+/**
+ Write the backup log entry for the backup progress log to a table.
+
+ This method creates a new row in the backup progress log with the
+ information provided.
+
+ @param[IN] thd The current thread
+ @param[OUT] backup_id The new row id for the backup history
+ @param[IN] object The name of the object processed
+ @param[IN] start Start datetime
+ @param[IN] stop Stop datetime
+ @param[IN] size Size value
+ @param[IN] progress Progress (percent)
+ @param[IN] error_num Error number (should be 0 is success)
+ @param[IN] notes Misc data from engine
+
+ @returns TRUE if error.
+*/
+bool Log_to_csv_event_handler::log_backup_progress(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes)
+{
+ TABLE_LIST table_list;
+ TABLE *table;
+ bool result= TRUE;
+ bool need_close= FALSE;
+ bool need_pop= FALSE;
+ bool need_rnd_end= FALSE;
+ Silence_log_table_errors error_handler;
+ Open_tables_state open_tables_backup;
+ bool save_time_zone_used;
+
+ /*
+ CSV uses TIME_to_timestamp() internally if table needs to be repaired
+ which will set thd->time_zone_used
+ */
+ save_time_zone_used= thd->time_zone_used;
+
+ bzero(& table_list, sizeof(TABLE_LIST));
+ table_list.alias= table_list.table_name= BACKUP_PROGRESS_LOG_NAME.str;
+ table_list.table_name_length= BACKUP_PROGRESS_LOG_NAME.length;
+
+ table_list.lock_type= TL_WRITE_CONCURRENT_INSERT;
+
+ table_list.db= MYSQL_SCHEMA_NAME.str;
+ table_list.db_length= MYSQL_SCHEMA_NAME.length;
+
+ /*
+ 1) open_performance_schema_table generates an error of the
+ table can not be opened or is corrupted.
+ 2) "INSERT INTO general_log" can generate warning sometimes.
+
+ Suppress these warnings and errors, they can't be dealt with
+ properly anyway.
+
+ QQ: this problem needs to be studied in more detail.
+ Comment this 2 lines and run "cast.test" to see what's happening.
+ */
+ thd->push_internal_handler(& error_handler);
+ need_pop= TRUE;
+
+ if (!(table= open_performance_schema_table(thd, & table_list,
+ & open_tables_backup)))
+ goto err;
+
+ need_close= TRUE;
+
+ if (table->file->extra(HA_EXTRA_MARK_AS_LOG_TABLE) ||
+ table->file->ha_rnd_init(0))
+ goto err;
+
+ need_rnd_end= TRUE;
+
+ /* Honor next number columns if present */
+ table->next_number_field= table->found_next_number_field;
+
+ /*
+ Get defaults for new record.
+ */
+ restore_record(table, s->default_values);
+
+ /* check that all columns exist */
+ if (table->s->fields < 8)
+ goto err;
+
+ /*
+ Fill in the data.
+ */
+ table->field[ET_OBP_FIELD_BACKUP_ID_FK]->store(backup_id, TRUE);
+ table->field[ET_OBP_FIELD_BACKUP_ID_FK]->set_notnull();
+
+ if (object)
+ {
+ if (table->field[ET_OBP_FIELD_PROG_OBJECT]->store(object,
+ strlen(object), system_charset_info))
+ goto err;
+ table->field[ET_OBP_FIELD_PROG_OBJECT]->set_notnull();
+ }
+
+ if (notes)
+ {
+ if (table->field[ET_OBP_FIELD_PROG_NOTES]->store(notes,
+ strlen(notes), system_charset_info))
+ goto err;
+ table->field[ET_OBP_FIELD_PROG_NOTES]->set_notnull();
+ }
+
+ if (start)
+ {
+ MYSQL_TIME time;
+ my_tz_OFFSET0->gmt_sec_to_TIME(&time, (my_time_t)start);
+
+ table->field[ET_OBP_FIELD_PROG_START_TIME]->set_notnull();
+ table->field[ET_OBP_FIELD_PROG_START_TIME]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ }
+
+ if (stop)
+ {
+ MYSQL_TIME time;
+ my_tz_OFFSET0->gmt_sec_to_TIME(&time, (my_time_t)stop);
+
+ table->field[ET_OBP_FIELD_PROG_STOP_TIME]->set_notnull();
+ table->field[ET_OBP_FIELD_PROG_STOP_TIME]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ }
+
+ table->field[ET_OBP_FIELD_PROG_SIZE]->store(size, TRUE);
+ table->field[ET_OBP_FIELD_PROG_SIZE]->set_notnull();
+ table->field[ET_OBP_FIELD_PROGRESS]->store(progress, TRUE);
+ table->field[ET_OBP_FIELD_PROGRESS]->set_notnull();
+ table->field[ET_OBP_FIELD_PROG_ERROR_NUM]->store(error_num, TRUE);
+ table->field[ET_OBP_FIELD_PROG_ERROR_NUM]->set_notnull();
+
+ /* log table entries are not replicated */
+ if (table->file->ha_write_row(table->record[0]))
+ goto err;
+
+ result= FALSE;
+
+err:
+ if (result && !thd->killed)
+ sql_print_error("Failed to write to mysql.online_backup_progress: %s",
+ error_handler.message());
+
+ if (need_rnd_end)
+ {
+ table->file->ha_rnd_end();
+ table->file->ha_release_auto_increment();
+ }
+ if (need_pop)
+ thd->pop_internal_handler();
+ if (need_close)
+ close_performance_schema_table(thd, & open_tables_backup);
+
+ thd->time_zone_used= save_time_zone_used;
+ return result;
+}
+
+/**
+ Find the row in the table that matches the backup_id.
+
+ This method locates the row in the online backup table that matches the
+ backup_id passed.
+
+ 2param TABLE table The open table.
+ @param ulonglong backup_id The id of the row to locate.
+
+ @returns 0 = success
+ @returns 1 = failed to find row
+ */
+bool Log_to_csv_event_handler::find_backup_history_row(TABLE *table, ulonglong backup_id)
+{
+ uchar key[MAX_KEY_LENGTH]; // key buffer for search
+ /*
+ Create key to find row. We have to use field->store() to be able to
+ handle VARCHAR and CHAR fields.
+ Assumption here is that the two first fields in the table are
+ 'db' and 'name' and the first key is the primary key over the
+ same fields.
+ */
+ table->field[ET_OBH_FIELD_BACKUP_ID]->store(backup_id, TRUE);
+
+ key_copy(key, table->record[0], table->key_info, table->key_info->key_length);
+
+ if (table->file->index_read_idx_map(table->record[0], 0, key, HA_WHOLE_KEY,
+ HA_READ_KEY_EXACT))
+ return true;
+
+ return false;
+}
/*
Log a query to the slow log table
@@ -666,16 +1193,37 @@ int Log_to_csv_event_handler::
bzero(& table_list, sizeof(TABLE_LIST));
- if (log_table_type == QUERY_LOG_GENERAL)
+ /*
+ Code changed to use a switch now that there are 4 logs.
+ */
+ switch (log_table_type) {
+ case QUERY_LOG_GENERAL:
{
table_list.alias= table_list.table_name= GENERAL_LOG_NAME.str;
table_list.table_name_length= GENERAL_LOG_NAME.length;
+ break;
}
- else
+ case QUERY_LOG_SLOW:
{
DBUG_ASSERT(log_table_type == QUERY_LOG_SLOW);
table_list.alias= table_list.table_name= SLOW_LOG_NAME.str;
table_list.table_name_length= SLOW_LOG_NAME.length;
+ break;
+ }
+ case BACKUP_HISTORY_LOG:
+ {
+ DBUG_ASSERT(log_table_type == BACKUP_HISTORY_LOG);
+ table_list.alias= table_list.table_name= BACKUP_HISTORY_LOG_NAME.str;
+ table_list.table_name_length= BACKUP_HISTORY_LOG_NAME.length;
+ break;
+ }
+ case BACKUP_PROGRESS_LOG:
+ {
+ DBUG_ASSERT(log_table_type == BACKUP_PROGRESS_LOG);
+ table_list.alias= table_list.table_name= BACKUP_PROGRESS_LOG_NAME.str;
+ table_list.table_name_length= BACKUP_PROGRESS_LOG_NAME.length;
+ break;
+ }
}
table_list.lock_type= TL_WRITE_CONCURRENT_INSERT;
@@ -750,6 +1298,110 @@ bool Log_to_file_event_handler::
sql_text, sql_text_len);
}
+/**
+ Write the backup log entry for the backup history log to a file.
+
+ This method creates a new row in the backup history log with the
+ information provided.
+
+ @param[IN] thd The current thread
+ @param[OUT] backup_id The new row id for the backup history
+ @param[IN] process_id The process id of the operation
+ @param[IN] state The current state of the operation
+ @param[IN] operation The current state of the operation
+ @param[IN] error_num The error number
+ @param[IN] user_comment The user's comment specified in the
+ command (not implemented yet)
+ @param[IN] backup_file The name of the target file
+ @param[IN] command The actual command entered
+
+ @returns TRUE if error.
+
+ @TODO Currently not implemented.
+*/
+bool Log_to_file_event_handler::log_backup_history(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command)
+{
+ /*
+ Not writing to files yet...
+ */
+ return true;
+}
+
+/**
+ Update a backup history log entry for the given backup_id to a file.
+
+ This method updates a row in the backup history log using one
+ of four data types as determined by the field (see fld).
+
+ @param[IN] thd The current thread
+ @param[IN] backup_id The row id for the backup history to be updated
+ @param[IN] fld The enum for the field to be updated
+ @param[IN] val_long The value for long fields
+ @param[IN] val_time The value for time fields
+ @param[IN] val_str The value for char * fields
+ @param[IN] val_state The value for state fields
+
+ @returns TRUE if error.
+
+ @TODO Currently not implemented.
+*/
+bool Log_to_file_event_handler::log_backup_history_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state)
+{
+ /*
+ Not writing to files yet...
+ */
+ return true;
+}
+
+/**
+ Write the backup log entry for the backup progress log to a file.
+
+ This method creates a new row in the backup progress log with the
+ information provided.
+
+ @param[IN] thd The current thread
+ @param[OUT] backup_id The new row id for the backup history
+ @param[IN] object The name of the object processed
+ @param[IN] start Start datetime
+ @param[IN] stop Stop datetime
+ @param[IN] size Size value
+ @param[IN] progress Progress (percent)
+ @param[IN] error_num Error number (should be 0 is success)
+ @param[IN] notes Misc data from engine
+
+ @returns TRUE if error.
+
+ @TODO Currently not implemented.
+*/
+bool Log_to_file_event_handler::log_backup_progress(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes)
+{
+ /*
+ Not writing to files yet...
+ */
+ return true;
+}
bool Log_to_file_event_handler::init()
{
@@ -761,6 +1413,12 @@ bool Log_to_file_event_handler::init()
if (opt_log)
mysql_log.open_query_log(sys_var_general_log_path.value);
+ /*
+ Initially, always log the backup logs.
+ */
+ mysql_log.open_backup_history_log(sys_var_backup_history_log_path.value);
+ mysql_log.open_backup_progress_log(sys_var_backup_progress_log_path.value);
+
is_initialized= TRUE;
}
@@ -783,6 +1441,16 @@ void Log_to_file_event_handler::flush()
mysql_slow_log.reopen_file();
}
+/**
+ Close and reopen the backup logs.
+*/
+void Log_to_file_event_handler::flush_backup_logs()
+{
+ /* reopen log files */
+ mysql_backup_history_log.reopen_file();
+ mysql_backup_progress_log.reopen_file();
+}
+
/*
Log error with all enabled log event handlers
@@ -889,6 +1557,31 @@ bool LOGGER::flush_logs(THD *thd)
return rc;
}
+/**
+ Close and reopen the backup logs (with locks).
+
+ @param[IN] thd The current thread.
+
+ @returns FALSE.
+*/
+bool LOGGER::flush_backup_logs(THD *thd)
+{
+ int rc= 0;
+
+ /*
+ Now we lock logger, as nobody should be able to use logging routines while
+ log tables are closed
+ */
+ logger.lock_exclusive();
+
+ /* reopen log files */
+ file_log_handler->flush_backup_logs();
+
+ /* end of log flush */
+ logger.unlock();
+ return rc;
+}
+
/*
Log slow query with all enabled log event handlers
@@ -1033,6 +1726,156 @@ bool LOGGER::general_log_print(THD *thd,
return general_log_write(thd, command, message_buff, message_buff_len);
}
+/**
+ Write the backup log entry for the backup history logs (file or table).
+
+ This method creates a new row in the backup history log with the
+ information provided. It is a high-level wrapper for writing to any
+ of the log types (e.g., FILE or TABLE) as specified by --log-option.
+
+ @Note The backup logs currently only write to tables.
+
+ @param[IN] thd The current thread
+ @param[OUT] backup_id The new row id for the backup history
+ @param[IN] process_id The process id of the operation
+ @param[IN] state The current state of the operation
+ @param[IN] operation The current state of the operation
+ @param[IN] error_num The error number
+ @param[IN] user_comment The user's comment specified in the
+ command (not implemented yet)
+ @param[IN] backup_file The name of the target file
+ @param[IN] command The actual command entered
+
+ @returns TRUE if error.
+*/
+bool LOGGER::backup_history_log_write(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command)
+{
+ bool error= FALSE;
+ Log_event_handler **current_handler= backup_history_log_handler_list;
+ ulong id;
+
+ if (thd)
+ id= thd->thread_id; /* Normal thread */
+ else
+ id= 0; /* Log from connect handler */
+
+ lock_shared();
+ while (*current_handler)
+ error+= (*current_handler++)->
+ log_backup_history(thd, backup_id, process_id, state, operation,
+ error_num, user_comment, backup_file,
+ command) || error;
+ unlock();
+
+ return error;
+}
+
+/**
+ Update a backup history log entry for the given backup_id to a table
+ (file or table).
+
+ This method updates a row in the backup history log using one
+ of four data types as determined by the field (see fld). It is a
+ high-level wrapper for writing to any of the log types (e.g., FILE
+ or TABLE) as specified by --log-option.
+
+ @Note The backup logs currently only write to tables.
+
+ @param[IN] thd The current thread
+ @param[IN] backup_id The row id for the backup history to be updated
+ @param[IN] fld The enum for the field to be updated
+ @param[IN] val_long The value for long fields
+ @param[IN] val_time The value for time fields
+ @param[IN] val_str The value for char * fields
+ @param[IN] val_state The value for state fields
+
+ @returns TRUE if error.
+*/
+bool LOGGER::backup_history_log_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state)
+{
+ bool error= FALSE;
+ Log_event_handler **current_handler= backup_history_log_handler_list;
+ ulong id;
+
+ if (thd)
+ id= thd->thread_id; /* Normal thread */
+ else
+ id= 0; /* Log from connect handler */
+
+ lock_shared();
+ while (*current_handler)
+ error+= (*current_handler++)->
+ log_backup_history_update(thd, backup_id, fld, val_long, val_time,
+ val_str, val_state) || error;
+ unlock();
+
+ return error;
+}
+
+/**
+ Write the backup log entry for the backup progress logs (file or table).
+
+ This method creates a new row in the backup progress log with the
+ information provided. It is a high-level wrapper for writing to any
+ of the log types (e.g., FILE or TABLE) as specified by --log-option.
+
+ @Note The backup logs currently only write to tables.
+
+ @param[IN] thd The current thread
+ @param[OUT] backup_id The new row id for the backup history
+ @param[IN] object The name of the object processed
+ @param[IN] start Start datetime
+ @param[IN] stop Stop datetime
+ @param[IN] size Size value
+ @param[IN] progress Progress (percent)
+ @param[IN] error_num Error number (should be 0 is success)
+ @param[IN] notes Misc data from engine
+
+ @returns TRUE if error.
+*/
+bool LOGGER::backup_progress_log_write(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes)
+{
+ bool error= FALSE;
+ Log_event_handler **current_handler= backup_progress_log_handler_list;
+ ulong id;
+
+ if (thd)
+ id= thd->thread_id; /* Normal thread */
+ else
+ id= 0; /* Log from connect handler */
+
+ lock_shared();
+ while (*current_handler)
+ error+= (*current_handler++)->
+ log_backup_progress(thd, backup_id, object, start,
+ stop, size, progress, error_num, notes) || error;
+ unlock();
+
+ return error;
+}
+
void LOGGER::init_error_log(uint error_log_printer)
{
if (error_log_printer & LOG_NONE)
@@ -1106,6 +1949,71 @@ void LOGGER::init_general_log(uint gener
}
}
+/**
+ Initialize the backup history log.
+
+ This method initializes the backup log handlers. Currently, only
+ log to table is supported.
+
+ @param[IN] backup_history_log_printer The output type for log.
+*/
+void LOGGER::init_backup_history_log(uint backup_history_log_printer)
+{
+ if (backup_history_log_printer & LOG_NONE)
+ {
+ backup_history_log_handler_list[0]= 0;
+ return;
+ }
+
+ switch (backup_history_log_printer) {
+ case LOG_FILE:
+ backup_history_log_handler_list[0]= file_log_handler;
+ backup_history_log_handler_list[1]= 0;
+ break;
+ case LOG_TABLE:
+ backup_history_log_handler_list[0]= table_log_handler;
+ backup_history_log_handler_list[1]= 0;
+ break;
+ case LOG_TABLE|LOG_FILE:
+ backup_history_log_handler_list[0]= file_log_handler;
+ backup_history_log_handler_list[1]= table_log_handler;
+ backup_history_log_handler_list[2]= 0;
+ break;
+ }
+}
+
+/**
+ Initialize the backup progress log.
+
+ This method initializes the backup log handlers. Currently, only
+ log to table is supported.
+
+ @param[IN] backup_history_log_printer The output type for log.
+*/
+void LOGGER::init_backup_progress_log(uint backup_progress_log_printer)
+{
+ if (backup_progress_log_printer & LOG_NONE)
+ {
+ backup_progress_log_handler_list[0]= 0;
+ return;
+ }
+
+ switch (backup_progress_log_printer) {
+ case LOG_FILE:
+ backup_progress_log_handler_list[0]= file_log_handler;
+ backup_progress_log_handler_list[1]= 0;
+ break;
+ case LOG_TABLE:
+ backup_progress_log_handler_list[0]= table_log_handler;
+ backup_progress_log_handler_list[1]= 0;
+ break;
+ case LOG_TABLE|LOG_FILE:
+ backup_progress_log_handler_list[0]= file_log_handler;
+ backup_progress_log_handler_list[1]= table_log_handler;
+ backup_progress_log_handler_list[2]= 0;
+ break;
+ }
+}
bool LOGGER::activate_log_handler(THD* thd, uint log_type)
{
@@ -1151,6 +2059,42 @@ bool LOGGER::activate_log_handler(THD* t
}
}
break;
+ case BACKUP_HISTORY_LOG:
+ {
+ file_log= file_log_handler->get_backup_history_log();
+
+ file_log->open_backup_history_log(sys_var_backup_history_log_path.value);
+ if (table_log_handler->activate_log(thd, BACKUP_HISTORY_LOG))
+ {
+ /* Error printed by open table in activate_log() */
+ res= TRUE;
+ file_log->close(0);
+ }
+ else
+ {
+ init_general_log(log_output_options);
+ opt_log= TRUE;
+ }
+ break;
+ }
+ case BACKUP_PROGRESS_LOG:
+ {
+ file_log= file_log_handler->get_backup_progress_log();
+
+ file_log->open_backup_progress_log(sys_var_backup_progress_log_path.value);
+ if (table_log_handler->activate_log(thd, BACKUP_PROGRESS_LOG))
+ {
+ /* Error printed by open table in activate_log() */
+ res= TRUE;
+ file_log->close(0);
+ }
+ else
+ {
+ init_general_log(log_output_options);
+ opt_log= TRUE;
+ }
+ break;
+ }
default:
DBUG_ASSERT(0);
}
@@ -1173,6 +2117,14 @@ void LOGGER::deactivate_log_handler(THD
tmp_opt= &opt_log;
file_log= file_log_handler->get_mysql_log();
break;
+ case BACKUP_HISTORY_LOG:
+ tmp_opt= &opt_log;
+ file_log= file_log_handler->get_backup_history_log();
+ break;
+ case BACKUP_PROGRESS_LOG:
+ tmp_opt= &opt_log;
+ file_log= file_log_handler->get_backup_progress_log();
+ break;
default:
assert(0); // Impossible
}
@@ -1216,6 +2168,13 @@ int LOGGER::set_handlers(uint error_log_
init_slow_log(slow_log_printer);
init_general_log(general_log_printer);
+ /*
+ Initialize the backup log as tables only.
+ TODO: Add error handler like that above for backup log tables.
+ */
+ init_backup_history_log(4);
+ init_backup_progress_log(4);
+
unlock();
return 0;
@@ -3856,8 +4815,105 @@ bool general_log_write(THD *thd, enum en
/* Write the message to the log if we want to log this king of commands */
if (logger.log_command(thd, command))
return logger.general_log_write(thd, command, query, query_length);
-
+
return FALSE;
+}
+
+/**
+ Write the backup log entry for the backup history logs.
+
+ This method is a pass-through to allow calling of the logging
+ functions for the backup history log.
+
+ @param[IN] thd The current thread
+ @param[OUT] backup_id The new row id for the backup history
+ @param[IN] process_id The process id of the operation
+ @param[IN] state The current state of the operation
+ @param[IN] operation The current state of the operation
+ @param[IN] error_num The error number
+ @param[IN] user_comment The user's comment specified in the
+ command (not implemented yet)
+ @param[IN] backup_file The name of the target file
+ @param[IN] command The actual command entered
+
+ @returns results of logging function (i.e., TRUE if error)
+*/
+bool backup_history_log_write(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command)
+{
+ /* Write the message to the log if we want to log this king of commands */
+ return logger.backup_history_log_write(thd, backup_id, process_id, state,
+ operation, error_num, user_comment,
+ backup_file, command);
+}
+
+/**
+ Update a backup history log entry for the given backup_id.
+
+ This method is a pass-through to allow calling of the logging
+ functions for the backup history log.
+
+ @param[IN] thd The current thread
+ @param[IN] backup_id The row id for the backup history to be updated
+ @param[IN] fld The enum for the field to be updated
+ @param[IN] val_long The value for long fields
+ @param[IN] val_time The value for time fields
+ @param[IN] val_str The value for char * fields
+ @param[IN] val_state The value for state fields
+
+ @returns results of logging function (i.e., TRUE if error)
+*/
+bool backup_history_log_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state)
+{
+ /* Write the message to the log if we want to log this king of commands */
+ return logger.backup_history_log_update(thd, backup_id, fld, val_long,
+ val_time, val_str, val_state);
+}
+
+/**
+ Write the backup log entry for the backup progress log.
+
+ This method is a pass-through to allow calling of the logging
+ functions for the backup history log.
+
+ @param[IN] thd The current thread
+ @param[OUT] backup_id The new row id for the backup history
+ @param[IN] object The name of the object processed
+ @param[IN] start Start datetime
+ @param[IN] stop Stop datetime
+ @param[IN] size Size value
+ @param[IN] progress Progress (percent)
+ @param[IN] error_num Error number (should be 0 is success)
+ @param[IN] notes Misc data from engine
+
+ @returns results of logging function (i.e., TRUE if error)
+*/
+bool backup_progress_log_write(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes)
+{
+ /* Write the message to the log if we want to log this king of commands */
+ return logger.backup_progress_log_write(thd, backup_id, object, start,
+ stop, size, progress, error_num, notes);
}
void MYSQL_BIN_LOG::rotate_and_purge(uint flags)
diff -Nrup a/sql/log.h b/sql/log.h
--- a/sql/log.h 2008-02-03 04:00:47 -05:00
+++ b/sql/log.h 2008-03-18 14:03:41 -04:00
@@ -218,6 +218,18 @@ public:
return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0,
WRITE_CACHE);
}
+ bool open_backup_history_log(const char *log_name)
+ {
+ char buf[FN_REFLEN];
+ return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0,
+ WRITE_CACHE);
+ }
+ bool open_backup_progress_log(const char *log_name)
+ {
+ char buf[FN_REFLEN];
+ return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0,
+ WRITE_CACHE);
+ }
private:
time_t last_time;
@@ -411,6 +423,34 @@ public:
const char *command_type, uint command_type_len,
const char *sql_text, uint sql_text_len,
CHARSET_INFO *client_cs)= 0;
+
+ virtual bool log_backup_history(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command)= 0;
+
+ virtual bool log_backup_history_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state)= 0;
+
+ virtual bool log_backup_progress(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes)= 0;
virtual ~Log_event_handler() {}
};
@@ -441,18 +481,59 @@ public:
const char *sql_text, uint sql_text_len,
CHARSET_INFO *client_cs);
+ /*
+ Note: Due to lack of auto_increment capability in CSV, the engine used
+ for backup logs is actually MyISAM. Future work may change this back to
+ CSV to conform to standard set, but there is nothing that prohibits the
+ use of MyISAM tables for logs.
+ */
+ virtual bool log_backup_history(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command);
+
+ virtual bool log_backup_history_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state);
+
+ virtual bool log_backup_progress(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes);
+
int activate_log(THD *thd, uint log_type);
+
+private:
+ virtual bool find_backup_history_row(TABLE *table, ulonglong backup_id);
};
/* type of the log table */
#define QUERY_LOG_SLOW 1
#define QUERY_LOG_GENERAL 2
+#define BACKUP_HISTORY_LOG 3
+#define BACKUP_PROGRESS_LOG 4
class Log_to_file_event_handler: public Log_event_handler
{
MYSQL_QUERY_LOG mysql_log;
MYSQL_QUERY_LOG mysql_slow_log;
+ MYSQL_QUERY_LOG mysql_backup_history_log;
+ MYSQL_QUERY_LOG mysql_backup_progress_log;
bool is_initialized;
public:
Log_to_file_event_handler(): is_initialized(FALSE)
@@ -472,10 +553,41 @@ public:
const char *command_type, uint command_type_len,
const char *sql_text, uint sql_text_len,
CHARSET_INFO *client_cs);
+
+ virtual bool log_backup_history(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command);
+
+ virtual bool log_backup_history_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state);
+
+ virtual bool log_backup_progress(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes);
void flush();
+ void flush_backup_logs();
void init_pthread_objects();
MYSQL_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; }
MYSQL_QUERY_LOG *get_mysql_log() { return &mysql_log; }
+ MYSQL_QUERY_LOG *get_backup_history_log() { return &mysql_backup_history_log; }
+ MYSQL_QUERY_LOG *get_backup_progress_log() { return &mysql_backup_progress_log; }
};
@@ -494,6 +606,8 @@ class LOGGER
Log_event_handler *error_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
Log_event_handler *slow_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
Log_event_handler *general_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
+ Log_event_handler *backup_history_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
+ Log_event_handler *backup_progress_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
public:
@@ -517,6 +631,7 @@ public:
void init_base();
void init_log_tables();
bool flush_logs(THD *thd);
+ bool flush_backup_logs(THD *thd);
/* Perform basic logger cleanup. this will leave e.g. error log open. */
void cleanup_base();
/* Free memory. Nothing could be logged after this function is called */
@@ -529,6 +644,33 @@ public:
const char *format, va_list args);
bool general_log_write(THD *thd, enum enum_server_command command,
const char *query, uint query_length);
+ bool backup_history_log_write(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command);
+
+ bool backup_history_log_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state);
+
+ bool backup_progress_log_write(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes);
/* we use this function to setup all enabled log event handlers */
int set_handlers(uint error_log_printer,
@@ -537,6 +679,8 @@ public:
void init_error_log(uint error_log_printer);
void init_slow_log(uint slow_log_printer);
void init_general_log(uint general_log_printer);
+ void init_backup_history_log(uint backup_history_log_printer);
+ void init_backup_progress_log(uint backup_progress_log_printer);
void deactivate_log_handler(THD* thd, uint log_type);
bool activate_log_handler(THD* thd, uint log_type);
MYSQL_QUERY_LOG *get_slow_log_file_handler()
@@ -549,6 +693,18 @@ public:
{
if (file_log_handler)
return file_log_handler->get_mysql_log();
+ return NULL;
+ }
+ MYSQL_QUERY_LOG *get_backup_history_log_file_handler()
+ {
+ if (file_log_handler)
+ return file_log_handler->get_backup_history_log();
+ return NULL;
+ }
+ MYSQL_QUERY_LOG *get_backup_progress_log_file_handler()
+ {
+ if (file_log_handler)
+ return file_log_handler->get_backup_progress_log();
return NULL;
}
};
diff -Nrup a/sql/mysql_priv.h b/sql/mysql_priv.h
--- a/sql/mysql_priv.h 2008-02-26 11:54:31 -05:00
+++ b/sql/mysql_priv.h 2008-03-18 14:03:42 -04:00
@@ -863,6 +863,102 @@ bool general_log_print(THD *thd, enum en
bool general_log_write(THD *thd, enum enum_server_command command,
const char *query, uint query_length);
+
+/**
+ List of states for online backup table.
+ */
+enum enum_backup_state
+{
+ BUP_UNKNOWN = 0,
+ BUP_COMPLETE,
+ BUP_STARTING,
+ BUP_VALIDITY_POINT,
+ BUP_RUNNING,
+ BUP_ERRORS,
+ BUP_CANCEL
+};
+
+/**
+ List of operations for online backup table.
+ */
+enum enum_backup_operation
+{
+ OP_BACKUP = 1,
+ OP_RESTORE,
+ OP_SHOW,
+ OP_OTHER
+};
+
+/**
+ List of fields for online backup table.
+ */
+enum enum_backup_history_table_field
+{
+ ET_OBH_FIELD_BACKUP_ID = 0, /* start from 0 to correspond with field array */
+ ET_OBH_FIELD_PROCESS_ID,
+ ET_OBH_FIELD_BINLOG_POS,
+ ET_OBH_FIELD_BINLOG_FILE,
+ ET_OBH_FIELD_BACKUP_STATE,
+ ET_OBH_FIELD_OPER,
+ ET_OBH_FIELD_ERROR_NUM,
+ ET_OBH_FIELD_NUM_OBJ,
+ ET_OBH_FIELD_TOTAL_BYTES,
+ ET_OBH_FIELD_VP,
+ ET_OBH_FIELD_START_TIME,
+ ET_OBH_FIELD_STOP_TIME,
+ ET_OBH_FIELD_HOST_OR_SERVER,
+ ET_OBH_FIELD_USERNAME,
+ ET_OBH_FIELD_BACKUP_FILE,
+ ET_OBH_FIELD_COMMENT,
+ ET_OBH_FIELD_COMMAND,
+ ET_OBH_FIELD_ENGINES,
+ ET_OBH_FIELD_COUNT /* a cool trick to count the number of fields :) */
+};
+
+/**
+ List of fields for online backup progress table.
+ */
+enum enum_backup_progress_table_field
+{
+ ET_OBP_FIELD_BACKUP_ID_FK = 0, /* start from 0 to correspond with field array */
+ ET_OBP_FIELD_PROG_OBJECT,
+ ET_OBP_FIELD_PROG_START_TIME,
+ ET_OBP_FIELD_PROG_STOP_TIME,
+ ET_OBP_FIELD_PROG_SIZE,
+ ET_OBP_FIELD_PROGRESS,
+ ET_OBP_FIELD_PROG_ERROR_NUM,
+ ET_OBP_FIELD_PROG_NOTES,
+ ET_OBP_FIELD_PROG_COUNT /* a cool trick to count the number of fields :) */
+};
+
+bool backup_history_log_write(THD *thd,
+ ulonglong *backup_id,
+ int process_id,
+ enum_backup_state state,
+ enum_backup_operation operation,
+ int error_num,
+ const char *user_comment,
+ const char *backup_file,
+ const char *command);
+
+bool backup_history_log_update(THD *thd,
+ ulonglong backup_id,
+ enum_backup_history_table_field fld,
+ ulonglong val_long,
+ time_t val_time,
+ const char *val_str,
+ int val_state);
+
+bool backup_progress_log_write(THD *thd,
+ ulonglong backup_id,
+ const char *object,
+ time_t start,
+ time_t stop,
+ longlong size,
+ longlong progress,
+ int error_num,
+ const char *notes);
+
#include "sql_class.h"
#include "sql_acl.h"
#include "tztime.h"
@@ -1397,6 +1493,8 @@ extern LEX_STRING INFORMATION_SCHEMA_NAM
extern LEX_STRING MYSQL_SCHEMA_NAME;
extern LEX_STRING GENERAL_LOG_NAME;
extern LEX_STRING SLOW_LOG_NAME;
+extern LEX_STRING BACKUP_HISTORY_LOG_NAME;
+extern LEX_STRING BACKUP_PROGRESS_LOG_NAME;
extern const LEX_STRING partition_keywords[];
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
@@ -1588,6 +1686,7 @@ void remove_db_from_cache(const char *db
void flush_tables();
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
char *make_default_log_name(char *buff,const char* log_ext);
+char *make_backup_log_name(char *buff, const char *bup_name, const char* log_ext);
#ifdef WITH_PARTITION_STORAGE_ENGINE
uint fast_alter_partition_table(THD *thd, TABLE *table,
@@ -1972,6 +2071,7 @@ extern bool mysqld_embedded;
extern bool using_update_log, opt_large_files, server_id_supplied;
extern bool opt_update_log, opt_bin_log, opt_error_log;
extern my_bool opt_log, opt_slow_log;
+extern my_bool opt_backup_history_log, opt_backup_progress_log;
extern ulong log_output_options;
extern my_bool opt_log_queries_not_using_indexes;
extern bool opt_disable_networking, opt_skip_show_db;
@@ -2000,6 +2100,7 @@ extern uint opt_large_page_size;
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
extern char *opt_logname, *opt_slow_logname;
+extern char *opt_backup_history_logname, *opt_backup_progress_logname;
extern const char *log_output_str;
extern MYSQL_BIN_LOG mysql_bin_log;
diff -Nrup a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc 2008-03-10 08:58:17 -04:00
+++ b/sql/mysqld.cc 2008-03-18 14:03:43 -04:00
@@ -409,6 +409,7 @@ static pthread_cond_t COND_thread_cache,
extern DDL_blocker_class *DDL_blocker;
bool opt_update_log, opt_bin_log;
my_bool opt_log, opt_slow_log;
+my_bool opt_backup_history_log, opt_backup_progress_log;
ulong log_output_options;
my_bool opt_log_queries_not_using_indexes= 0;
bool opt_error_log= IF_WIN(1,0);
@@ -691,6 +692,7 @@ char *master_info_file;
char *relay_log_info_file, *report_user, *report_password, *report_host;
char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
char *opt_logname, *opt_slow_logname;
+char *opt_backup_history_logname, *opt_backup_progress_logname;
/* Static variables */
@@ -1322,6 +1324,8 @@ void clean_up(bool print_message)
my_free(sys_init_slave.value, MYF(MY_ALLOW_ZERO_PTR));
my_free(sys_var_general_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
my_free(sys_var_slow_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(sys_var_backup_history_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(sys_var_backup_progress_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
free_tmpdir(&mysql_tmpdir_list);
#ifdef HAVE_REPLICATION
my_free(slave_load_tmpdir,MYF(MY_ALLOW_ZERO_PTR));
@@ -3484,6 +3488,16 @@ static int init_common_variables(const c
s= opt_slow_logname ? opt_slow_logname : make_default_log_name(buff, "-slow.log");
sys_var_slow_log_path.value= my_strdup(s, MYF(0));
sys_var_slow_log_path.value_length= strlen(s);
+
+ s= opt_logname ? opt_logname : make_backup_log_name(buff,
+ "online_backup", ".log");
+ sys_var_backup_history_log_path.value= my_strdup(s, MYF(0));
+ sys_var_backup_history_log_path.value_length= strlen(s);
+
+ s= opt_logname ? opt_logname : make_backup_log_name(buff,
+ "online_backup_progress", ".log");
+ sys_var_backup_progress_log_path.value= my_strdup(s, MYF(0));
+ sys_var_backup_progress_log_path.value_length= strlen(s);
if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
return 1;
diff -Nrup a/sql/set_var.cc b/sql/set_var.cc
--- a/sql/set_var.cc 2008-02-26 11:54:31 -05:00
+++ b/sql/set_var.cc 2008-03-18 14:03:44 -04:00
@@ -148,6 +148,10 @@ static bool sys_update_general_log_path(
static void sys_default_general_log_path(THD *thd, enum_var_type type);
static bool sys_update_slow_log_path(THD *thd, set_var * var);
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
+static bool sys_update_backup_history_log_path(THD *thd, set_var * var);
+static void sys_default_backup_history_log_path(THD *thd, enum_var_type type);
+static bool sys_update_backup_progress_log_path(THD *thd, set_var * var);
+static void sys_default_backup_progress_log_path(THD *thd, enum_var_type type);
/*
Variable definition list
@@ -699,6 +703,16 @@ sys_var_str sys_var_slow_log_path(&vars,
sys_update_slow_log_path,
sys_default_slow_log_path,
opt_slow_logname);
+sys_var_str sys_var_backup_history_log_path(&vars, "backup_history_log_file",
+ sys_check_log_path,
+ sys_update_backup_history_log_path,
+ sys_default_backup_history_log_path,
+ opt_backup_history_logname);
+sys_var_str sys_var_backup_progress_log_path(&vars, "backup_progress_log_file",
+ sys_check_log_path,
+ sys_update_backup_progress_log_path,
+ sys_default_backup_progress_log_path,
+ opt_backup_progress_logname);
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
&log_output_typelib, 0);
@@ -2360,6 +2374,12 @@ bool update_sys_var_str_path(THD *thd, s
case QUERY_LOG_GENERAL:
file_log= logger.get_log_file_handler();
break;
+ case BACKUP_HISTORY_LOG:
+ file_log= logger.get_backup_history_log_file_handler();
+ break;
+ case BACKUP_PROGRESS_LOG:
+ file_log= logger.get_backup_progress_log_file_handler();
+ break;
default:
assert(0); // Impossible
}
@@ -2393,6 +2413,12 @@ bool update_sys_var_str_path(THD *thd, s
case QUERY_LOG_GENERAL:
file_log->open_query_log(sys_var_general_log_path.value);
break;
+ case BACKUP_HISTORY_LOG:
+ file_log->open_backup_history_log(sys_var_backup_history_log_path.value);
+ break;
+ case BACKUP_PROGRESS_LOG:
+ file_log->open_backup_progress_log(sys_var_backup_progress_log_path.value);
+ break;
default:
DBUG_ASSERT(0);
}
@@ -2434,6 +2460,34 @@ static void sys_default_slow_log_path(TH
0, "-slow.log", opt_slow_log,
QUERY_LOG_SLOW);
}
+
+static bool sys_update_backup_history_log_path(THD *thd, set_var * var)
+{
+ return update_sys_var_str_path(thd, &sys_var_backup_history_log_path,
+ var, ".log", opt_log, BACKUP_HISTORY_LOG);
+}
+
+
+static void sys_default_backup_history_log_path(THD *thd, enum_var_type type)
+{
+ (void) update_sys_var_str_path(thd, &sys_var_backup_history_log_path,
+ 0, ".log", opt_log, BACKUP_HISTORY_LOG);
+}
+
+
+static bool sys_update_backup_progress_log_path(THD *thd, set_var * var)
+{
+ return update_sys_var_str_path(thd, &sys_var_backup_progress_log_path,
+ var, ".log", opt_log, BACKUP_PROGRESS_LOG);
+}
+
+
+static void sys_default_backup_progress_log_path(THD *thd, enum_var_type type)
+{
+ (void) update_sys_var_str_path(thd, &sys_var_backup_progress_log_path,
+ 0, ".log", opt_log, BACKUP_PROGRESS_LOG);
+}
+
bool sys_var_log_output::update(THD *thd, set_var *var)
diff -Nrup a/sql/set_var.h b/sql/set_var.h
--- a/sql/set_var.h 2008-02-08 11:02:58 -05:00
+++ b/sql/set_var.h 2008-03-18 14:03:44 -04:00
@@ -1277,6 +1277,7 @@ uchar* find_named(I_List<NAMED_LIST> *li
NAMED_LIST **found);
extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
+extern sys_var_str sys_var_backup_history_log_path, sys_var_backup_progress_log_path;
/* key_cache functions */
KEY_CACHE *get_key_cache(LEX_STRING *cache_name);
diff -Nrup a/sql/sql_parse.cc b/sql/sql_parse.cc
--- a/sql/sql_parse.cc 2008-03-10 08:58:18 -04:00
+++ b/sql/sql_parse.cc 2008-03-18 14:03:45 -04:00
@@ -6482,6 +6482,10 @@ bool reload_acl_and_cache(THD *thd, ulon
if (flush_error_log())
result=1;
}
+ if (options & REFRESH_BACKUP_LOG)
+ {
+ logger.flush_backup_logs(thd);
+ }
#ifdef HAVE_QUERY_CACHE
if (options & REFRESH_QUERY_CACHE_FREE)
{
diff -Nrup a/sql/sql_yacc.yy b/sql/sql_yacc.yy
--- a/sql/sql_yacc.yy 2008-03-03 06:18:35 -05:00
+++ b/sql/sql_yacc.yy 2008-03-18 14:03:46 -04:00
@@ -9762,6 +9762,8 @@ flush_option:
{ Lex->type|= REFRESH_GRANT; }
| LOGS_SYM
{ Lex->type|= REFRESH_LOG; }
+ | BACKUP_SYM LOGS_SYM
+ { Lex->type|= REFRESH_BACKUP_LOG; }
| STATUS_SYM
{ Lex->type|= REFRESH_STATUS; }
| SLAVE
diff -Nrup a/sql/table.cc b/sql/table.cc
--- a/sql/table.cc 2008-02-11 11:06:02 -05:00
+++ b/sql/table.cc 2008-03-18 14:03:47 -04:00
@@ -33,6 +33,12 @@ LEX_STRING GENERAL_LOG_NAME= {C_STRING_W
/* SLOW_LOG name */
LEX_STRING SLOW_LOG_NAME= {C_STRING_WITH_LEN("slow_log")};
+/* BACKUP_HISTORY_LOG name */
+LEX_STRING BACKUP_HISTORY_LOG_NAME= {C_STRING_WITH_LEN("online_backup")};
+
+/* BACKUP_PROGRESS_LOG name */
+LEX_STRING BACKUP_PROGRESS_LOG_NAME= {C_STRING_WITH_LEN("online_backup_progress")};
+
/* Functions defined in this file */
void open_table_error(TABLE_SHARE *share, int error, int db_errno,
@@ -245,6 +251,23 @@ TABLE_CATEGORY get_table_category(const
{
return TABLE_CATEGORY_PERFORMANCE;
}
+
+ if ((name->length == BACKUP_HISTORY_LOG_NAME.length) &&
+ (my_strcasecmp(system_charset_info,
+ BACKUP_HISTORY_LOG_NAME.str,
+ name->str) == 0))
+ {
+ return TABLE_CATEGORY_PERFORMANCE;
+ }
+
+ if ((name->length == BACKUP_PROGRESS_LOG_NAME.length) &&
+ (my_strcasecmp(system_charset_info,
+ BACKUP_PROGRESS_LOG_NAME.str,
+ name->str) == 0))
+ {
+ return TABLE_CATEGORY_PERFORMANCE;
+ }
+
}
return TABLE_CATEGORY_USER;
| Thread |
|---|
| • bk commit into 6.0 tree (cbell:1.2589) BUG#34858 | cbell | 18 Mar |