Below is the list of changes that have just been committed into a local
5.1 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, 2007-04-11 17:27:55-04:00, cbell@mysql_cab_desk. +1 -0
WL#3327 : Online Backup Plan - Phase 2
This patch contains changes to the backup/restore operation summary
that makes the feedback more meaningful. The code now displays the
number of tables backed up/restored for each database
backed up/restored.
sql/backup/sql_backup.cc@stripped, 2007-04-11 17:27:53-04:00, cbell@mysql_cab_desk. +119 -124
WL#3327 : Online Backup Plan - Phase 2
This patch contains some minor cosmetic changes to the client
summary printout. The summary was moved to a separate method and
combined to make one place in the code to generate the summary
for either a backup or restore operation.
It also contains a correction to the path search method
Location::find() to remove the search mechanism.
Note: All paths entered are assumed to be valid paths.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: cbell
# Host: mysql_cab_desk.
# Root: C:/source/c++/mysql-5.1-backup-phase2
--- 1.17/sql/backup/sql_backup.cc 2007-04-11 17:28:08 -04:00
+++ 1.18/sql/backup/sql_backup.cc 2007-04-11 17:28:08 -04:00
@@ -39,6 +39,8 @@
List<String> *buffer);
bool get_db_metadata(THD *thd, const char *db,
List<String> *buffer);
+bool send_summary(List<schema_ref> *catalog, bool backup,
+ size_t header_size, size_t data_size);
/*
Implements BACKUP command -- called from sql_parse.cc
@@ -47,16 +49,6 @@
int do_backup(THD *thd, const Location &loc, List <LEX_STRING> *db_list)
{
DBUG_ENTER("backup::do_backup");
-
- Protocol *protocol= thd->protocol;
- List<Item> field_list;
- Item *item;
-
- field_list.push_back(item= new Item_empty_string("Backup Summary",255)); // TODO: use varchar field
- item->maybe_null= TRUE;
- protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
-
- size_t total_size= 0;
size_t header_size= 0;
size_t data_size= 0;
@@ -102,30 +94,104 @@
if(!write_table_data(info,*backup_stream))
goto error;
- total_size= backup_stream->bytes;
- data_size= total_size -header_size;
+ data_size= backup_stream->bytes -header_size;
DBUG_PRINT("backup",("Backup image written"));
// send feedback to client
+ send_summary(&info.catalog, TRUE, header_size, data_size);
+
+ goto end;
+
+ error:
+
+ DBUG_PRINT("backup",("Error creating backup image"));
+ // FIXME: report errors to the client
+
+ end:
+
+ if( stream_opened )
+ backup_stream->close();
+
+ //send_ok(thd);
+ DBUG_RETURN(0);
+
+}
+
+/*
+ Send a summary of the backup/restore operation to the client.
+
+ SYNOPSIS
+ send_summary()
+ List<schema_ref> *catalog - The archive catalog
+ bool backup - TRUE = backup, FALSE = restore
+ size_t header_size - size in bytes of header read/written
+ size_t data_size - size in bytes of data read/written
- char buf[255];
+ DESCRIPTION
+ This procedure sends a condensed summary to the client detailing
+ the number of tables in each database backed up or restored and
+ the number of bytes written/read.
- if (info.catalog.elements == 1)
- my_snprintf(buf,sizeof(buf),"This archive contains %d database",info.catalog.elements);
+ RETURNS
+ 0 - no errors.
+ -1 - error.
+*/
+bool send_summary(List<schema_ref> *catalog, bool backup,
+ size_t header_size, size_t data_size)
+{
+ Protocol *protocol= ::current_thd->protocol; // client comms
+ List<Item> field_list; // list of fields to send
+ Item *item; // field item
+ char buf[255]; // buffer for data
+ String op_str; // operations string
+ String print_str; // string to print
+
+ DBUG_ENTER("backup::sending summary");
+ op_str.length(0);
+ if (backup)
+ op_str.append("Backup Summary");
else
- my_snprintf(buf,sizeof(buf),"This archive contains %d databases",info.catalog.elements);
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
+ op_str.append("Restore Summary");
+
+ DBUG_PRINT("backup", ("sending %s", op_str));
+
+ field_list.push_back(item= new Item_empty_string(op_str.c_ptr(),255)); // TODO: use varchar field
+ item->maybe_null= TRUE;
+ protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
- if (info.table_count == 1)
- my_snprintf(buf,sizeof(buf),"and a total of %d table.",info.table_count);
+ size_t total_size= header_size + data_size;
+
+ op_str.length(0);
+ if (backup)
+ op_str.append("Backed up ");
else
- my_snprintf(buf,sizeof(buf),"and a total of %d tables.",info.table_count);
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
+ op_str.append("Restored ");
+
+ /*
+ Loop through the catalog and list the contents by
+ database.
+ */
+ List<schema_ref> cat1= *catalog;
+ List_iterator<schema_ref> cat(cat1);
+ schema_ref *tmp;
+ while ((tmp= cat++))
+ {
+ List_iterator<table_info> tbls(tmp->tables);
+ print_str.length(0);
+ print_str.append(op_str);
+ itoa(tmp->tables.elements, buf, 10);
+ print_str.append(buf);
+ if (tmp->tables.elements > 1)
+ print_str.append(" tables in database ");
+ else
+ print_str.append(" table in database ");
+ print_str.append(*tmp->db_name);
+ print_str.append(".");
+ protocol->prepare_for_resend();
+ protocol->store(print_str.c_ptr() ,system_charset_info);
+ protocol->write();
+ }
my_snprintf(buf,sizeof(buf)," ");
protocol->prepare_for_resend();
@@ -152,25 +218,9 @@
protocol->store(buf,system_charset_info);
protocol->write();
- send_eof(thd);
-
- goto end;
-
- error:
-
- DBUG_PRINT("backup",("Error creating backup image"));
- // FIXME: report errors to the client
-
- end:
-
- if( stream_opened )
- backup_stream->close();
-
- //send_ok(thd);
+ send_eof(::current_thd);
DBUG_RETURN(0);
-
}
-
// Collect tables to be backed-up and fill Backup_info structure describing backup image.
// Currently we try to backup all tables in 'test' database (but only tables for which
// appropriate backup engine is found will be included in the image).
@@ -509,15 +559,6 @@
{
DBUG_ENTER("restore::do_restore");
- Protocol *protocol= thd->protocol;
- List<Item> field_list;
- Item *item;
-
- field_list.push_back(item= new Item_empty_string("Restore Summary",255)); // TODO: use varchar field
- item->maybe_null= TRUE;
- protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
-
- size_t total_size= 0;
size_t header_size= 0;
size_t data_size= 0;
@@ -566,60 +607,14 @@
res= restore_table_data(info,*backup_str);
DBUG_ASSERT(res);
- total_size= backup_str->bytes;
- data_size= total_size -header_size;
+ data_size= backup_str->bytes -header_size;
DBUG_PRINT("restore",("Done."));
backup_str->close();
// send feedback to client
-
- char buf[255];
-
-
- if (info.catalog.elements == 1)
- my_snprintf(buf,sizeof(buf),"This archive restored %d database",info.catalog.elements);
- else
- my_snprintf(buf,sizeof(buf),"This archive restored %d databases",info.catalog.elements);
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
-
- if (info.table_count == 1)
- my_snprintf(buf,sizeof(buf),"and a total of %d table.",info.table_count);
- else
- my_snprintf(buf,sizeof(buf),"and a total of %d tables.",info.table_count);
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
-
- my_snprintf(buf,sizeof(buf)," ");
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
-
- my_snprintf(buf,sizeof(buf)," header = %-8d bytes",header_size);
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
-
- my_snprintf(buf,sizeof(buf)," data = %-8d bytes",data_size);
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
-
- my_snprintf(buf,sizeof(buf)," --------------",data_size);
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
-
- my_snprintf(buf,sizeof(buf)," total %-8d bytes",data_size+header_size);
- protocol->prepare_for_resend();
- protocol->store(buf,system_charset_info);
- protocol->write();
-
- send_eof(thd);
+ send_summary(&info.catalog, FALSE, header_size, data_size);
error:
@@ -689,32 +684,32 @@
Location*
Location::find(const LEX_STRING &where, bool read)
{
- char buff[FN_REFLEN];
- int length;
+ //char buff[FN_REFLEN];
+ //int length;
- length = dirname_part(buff, where.str);
- /*
- If reading, file must exist.
- If writing, path must exist.
- */
- if (read)
- {
- if (my_access(where.str, F_OK) || (length == where.length))
- {
- my_error(ER_CANT_OPEN_FILE, MYF(0), where.str,
- ER_CANT_OPEN_FILE);
- return NULL;
- }
- }
- else
- {
- if (my_access(buff, (F_OK|W_OK)))
- {
- my_error(ER_CANT_CREATE_FILE, MYF(0), where.str,
- ER_CANT_CREATE_FILE);
- return NULL;
- }
- }
+ //length = dirname_part(buff, where.str);
+ ///*
+ // If reading, file must exist.
+ // If writing, path must exist.
+ //*/
+ //if (read)
+ //{
+ // if (my_access(where.str, F_OK) || (length == where.length))
+ // {
+ // my_error(ER_CANT_OPEN_FILE, MYF(0), where.str,
+ // ER_CANT_OPEN_FILE);
+ // return NULL;
+ // }
+ //}
+ //else
+ //{
+ // if (my_access(buff, (F_OK|W_OK)))
+ // {
+ // my_error(ER_CANT_CREATE_FILE, MYF(0), where.str,
+ // ER_CANT_CREATE_FILE);
+ // return NULL;
+ // }
+ //}
return new File_loc(where.str);
}
| Thread |
|---|
| • bk commit into 5.1 tree (cbell:1.2507) | cbell | 11 Apr |