81
81
using namespace backup;
83
Engine::Engine(THD *t_thd)
89
* Create a default backup backup driver.
91
* Given a list of tables to be backed-up, create instance of backup
92
* driver which will create backup image of these tables.
94
* @param tables (in) list of tables to be backed-up.
95
* @param eng (out) pointer to backup driver instance.
97
* @retval ERROR if cannot create backup driver class.
98
* @retval OK on success.
100
result_t Engine::get_backup(const uint32, const Table_list &tables,
103
DBUG_ENTER("Engine::get_backup");
104
Backup *ptr= new default_backup::Backup(tables, m_thd, TL_READ_NO_INSERT);
111
Backup::Backup(const Table_list &tables, THD *t_thd, thr_lock_type lock_type):
112
Backup_thread_driver(tables)
84
Backup::Backup(const Table_list &tables, THD *t_thd, thr_lock_type lock_type)
85
:Backup_thread_driver(tables)
114
87
DBUG_PRINT("default_backup",("Creating backup driver"));
115
88
locking_thd->m_thd= t_thd; /* save current thread */
122
95
Create a TABLE_LIST * list for iterating through the tables.
123
96
Initialize the list for opening the tables in read mode.
125
locking_thd->tables_in_backup= build_table_list(tables, lock_type);
126
all_tables= locking_thd->tables_in_backup;
98
all_tables= (TABLE_LIST*)my_malloc(tables.count()*sizeof(TABLE_LIST), MYF(MY_WME));
99
DBUG_ASSERT(all_tables); // TODO: report error instead
100
bzero(all_tables, tables.count()*sizeof(TABLE_LIST));
102
for (uint i=0; i < tables.count(); ++i)
104
backup::set_table_list(all_tables[i], tables[i], lock_type, t_thd->mem_root);
106
// link previous entry to this one
108
backup::link_table_list(all_tables[i-1], &all_tables[i]);
111
locking_thd->tables_in_backup= all_tables;
127
112
init_phase_complete= FALSE;
128
113
locks_acquired= FALSE;
121
This method provides a means to stop a current backup by allowing
122
the driver to shutdown gracefully. The method call ends the current
123
table read then attempts to kill the locking thread if it is still
126
result_t Backup::cleanup()
128
DBUG_ENTER("Default_backup::cleanup()");
129
DBUG_PRINT("backup",("Default driver - stop backup"));
136
locking_thd->kill_locking_thread();
145
Since objects representing metadata lock requests for tables open
146
by locking thread use same chunks of memory as elements of
147
'all_tables' table list it is essential to ensure that locking
148
thread has finished before freeing elements of this table list.
150
locking_thd->kill_locking_thread();
151
locking_thd->wait_until_locking_thread_dies();
152
my_free(all_tables, MYF(0));
132
157
* @brief Prelock call to setup locking.
297
330
case LOCK_ACQUIRED: // First time lock ready for validity point
299
332
locks_acquired= TRUE;
300
BACKUP_BREAKPOINT("locking_thread_added");
333
DEBUG_SYNC(locking_thd->m_thd, "default_locking_thread_added");
301
334
DBUG_RETURN(READY);
303
336
default: // If first call, signal end of init phase
331
369
case GET_NEXT_TABLE:
371
if (tbl_num >= m_tables.count())
379
cur_table= all_tables[tbl_num++].table;
380
DBUG_ASSERT(cur_table); // tables should be opened at that time
381
read_set= cur_table->read_set;
382
start_tbl_read(cur_table);
384
buf.table_num= tbl_num;
334
int res= next_table();
336
If no more tables in list, tell backup algorithm we're done else
337
fall through to reading mode.
348
start_tbl_read(cur_table);
350
buf.table_no= tbl_num;
363
397
cur_table->use_all_columns();
364
398
last_read_res = hdl->rnd_next(cur_table->record[0]);
400
Skip all records marked as deleted.
402
while (last_read_res == HA_ERR_RECORD_DELETED)
403
last_read_res= hdl->rnd_next(cur_table->record[0]);
365
404
DBUG_EXECUTE_IF("SLEEP_DRIVER", sleep(4););
367
406
If we are end of file, stop the read process and signal the
540
* Create a default backup restore driver.
542
* Given a list of tables to be restored, create instance of restore
543
* driver which will restore these tables from a backup image.
545
* @param version (in) version of the backup image.
546
* @param tables (in) list of tables to be restored.
547
* @param eng (out) pointer to restore driver instance.
549
* @retval ERROR if cannot create restore driver class.
550
* @retval OK on success.
552
result_t Engine::get_restore(version_t, const uint32,
553
const Table_list &tables, Restore_driver* &drv)
555
DBUG_ENTER("Engine::get_restore");
556
Restore *ptr= new default_backup::Restore(tables, m_thd);
563
Restore::Restore(const Table_list &tables, THD *t_thd): Restore_driver(tables)
579
Restore::Restore(const backup::Logical_snapshot &snap, THD *t_thd)
580
:Restore_driver(snap.get_table_list()), m_snap(snap)
565
582
DBUG_PRINT("default_backup",("Creating restore driver"));
566
583
m_thd= t_thd; /* save current thread */
568
585
tbl_num= 0; /* set table number to 0 */
569
586
mode= INITIALIZE; /* initialize write */
572
Create a TABLE_LIST * list for iterating through the tables.
573
Initialize the list for opening the tables in write mode.
575
tables_in_backup= build_table_list(tables, TL_WRITE);
576
all_tables= tables_in_backup;
577
588
for (int i=0; i < MAX_FIELDS; i++)
579
590
blob_ptr_index= 0;
597
This method provides a means to stop a current restore by allowing
598
the driver to shutdown gracefully. The method call closes the
599
table list by calling end() method.
601
result_t Restore::cleanup()
603
DBUG_ENTER("Default_backup::cleanup()");
604
DBUG_PRINT("backup",("Default driver - stop restore"));
588
619
* @retval OK rows deleted.
589
620
* @retval ERROR problem with deleting rows.
591
result_t Restore::truncate_table(TABLE *tbl)
595
DBUG_ENTER("Default_backup::truncate_table)");
596
DBUG_ASSERT(tbl->file);
598
last_write_res= cur_table->file->ha_delete_all_rows();
600
Check to see if delete all rows was ok. Ignore if the handler
603
if ((last_write_res != 0) && (last_write_res != HA_ERR_WRONG_COMMAND))
610
625
* @brief End restore process.
629
643
* @retval 0 no errors.
630
644
* @retval -1 no more tables in list.
632
int Restore::next_table()
634
DBUG_ENTER("Restore::next_table()");
635
if (cur_table == NULL)
636
cur_table= tables_in_backup->table;
639
tables_in_backup= tables_in_backup->next_global;
640
if (tables_in_backup != NULL)
642
DBUG_ASSERT(tables_in_backup->table);
643
cur_table= tables_in_backup->table;
655
649
* @brief Unpack the data for a row in the table.
719
712
DBUG_ENTER("Restore::send_data");
720
713
DBUG_PRINT("default_restore",("Got packet with %lu bytes from stream %u",
721
(unsigned long)buf.size, buf.table_no));
714
(unsigned long)buf.size, buf.table_num));
717
get_data() should not be called after cancel has been called.
719
DBUG_ASSERT(mode != CANCEL);
724
722
Determine mode of operation and execute mode.
729
Nothing to do in Initialize, continue to GET_NEXT_TABLE.
727
Nothing to do in Initialize, continue to WRITE_RCD.
734
If class has been initialized and we need to read the next table,
735
advance the current table pointer and initialize read process.
743
It is possible for the backup system to send data to this
744
engine out of sequence from the table list. When a non-sequential
745
access is detected, start the table list at the beginning and
746
find the table in question. This is needed if any tables (more
747
than MAX_RETRIES are empty!
749
if ((tbl_num + 1) == buf.table_no) //do normal sequential lookup
751
else //do linear search
756
tables_in_backup= all_tables;
762
while ((i != buf.table_no) && !res);
774
truncate_table(cur_table); /* delete all rows from table */
780
732
Write a row to the table from the data in the buffer.
785
737
max_blob_size= 0;
788
If the table number is different from the stream number, we're
789
receiving data from the backup for a different table. Set the mode to
790
get the next table in the list.
792
if (tbl_num != buf.table_no)
794
mode= GET_NEXT_TABLE;
795
DBUG_RETURN(PROCESSING);
739
// We don't process any data on stream #0
740
if (buf.table_num == 0)
743
// We only proccess data for the tables we are restoring.
744
if (buf.table_num > m_tables.count())
748
Get the opened table instance corresponding to buf.table_num. Note that
749
tables are opened (and locked) by the kernel.
751
cur_table= m_snap.get_opened_table(buf.table_num - 1);
752
DBUG_ASSERT(cur_table); // All tables we are processing should be opened.
755
Change timestamp autoset type to TIMESTAMP_NO_AUTO_SET
756
so that any restored data with timestamp fields will not have their values
759
if (cur_table->timestamp_field)
760
cur_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
762
hdl= cur_table->file;
763
DBUG_ASSERT(hdl); // table should be opened
799
766
uint32 size= buf.size - META_SIZE;
800
767
block_type= *buf.data;