Skip to content

Commit 824afeb

Browse files
Add phase information to backup_stem to simplify implementation
1 parent 4698cc2 commit 824afeb

7 files changed

Lines changed: 71 additions & 103 deletions

File tree

sql/handler.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,9 +1519,9 @@ struct backup_target
15191519

15201520
/** BACKUP SERVER processing phase. Phases must occur in this order. */
15211521
enum backup_proc_phase {
1522-
BACKUP_PROC_PHASE_BACKUP_LOCKED, /* concurrent backup guaranteed not to run */
1523-
BACKUP_PROC_PHASE_DDL_LOCKED, /* DDL can't happen concurrently */
1524-
BACKUP_PROC_PHASE_COMMIT_LOCKED}; /* Commits are blocked */
1522+
BACKUP_PROC_PHASE_BACKUP_LOCKED = 0, /* concurrent backup guaranteed not to run */
1523+
BACKUP_PROC_PHASE_DDL_LOCKED, /* DDL can't happen concurrently */
1524+
BACKUP_PROC_PHASE_COMMIT_LOCKED}; /* Commits are blocked */
15251525

15261526
/** BACKUP SERVER ending phase. Phases must occur in this order. */
15271527
enum backup_end_phase {
@@ -1952,10 +1952,11 @@ struct handlerton : public transaction_participant
19521952
Process a unit (file, table etc.) in current phase. Engines should
19531953
define their units in such a way that they may be processed concurrently.
19541954
@param thd current session
1955+
@param phase the processing phase for this step
19551956
@return number of units remaining in processing phase, or negative on error
19561957
@retval 0 on completion
19571958
*/
1958-
int (*backup_step)(THD *thd);
1959+
int (*backup_step)(THD *thd, backup_proc_phase phase);
19591960
/**
19601961
Finish copying and determine the logical time of the backup snapshot.
19611962
@param thd current sesssion

sql/sql_backup.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ static my_bool backup_end(THD *thd, plugin_ref plugin, void *arg) noexcept
217217
return false;
218218
}
219219

220-
static my_bool backup_step(THD *thd, plugin_ref plugin, void *) noexcept
220+
static my_bool backup_step(THD *thd, plugin_ref plugin, void *arg) noexcept
221221
{
222222
handlerton *hton= plugin_hton(plugin);
223223
int res= 0;
224224
if (hton->backup_step)
225-
while ((res= hton->backup_step(thd)))
225+
while ((res= hton->backup_step(thd, *static_cast<backup_proc_phase*>(arg))))
226226
if (res < 0)
227227
break;
228228
return res != 0;
@@ -244,13 +244,14 @@ static bool start_proc_phase(THD *thd, backup_proc_phase phase)
244244
&phase);
245245
}
246246

247-
static bool run_backup_processing(THD *thd)
247+
static bool run_backup_processing(THD *thd, backup_proc_phase phase)
248248
{
249249
/* The backup_step may be invoked in multiple concurrent threads.
250250
At the time backup_end is invoked, all backup_step will have to complete. */
251251
return plugin_foreach_with_mask(thd, backup_step,
252252
MYSQL_STORAGE_ENGINE_PLUGIN,
253-
PLUGIN_IS_DELETED|PLUGIN_IS_READY, nullptr);
253+
PLUGIN_IS_DELETED|PLUGIN_IS_READY,
254+
&phase);
254255
}
255256

256257
static bool run_backup_end_phase(THD *thd, backup_end_phase phase, bool failed)
@@ -271,7 +272,7 @@ static bool upgrade_and_process(THD *thd,
271272
lock_level,
272273
thd->variables.lock_wait_timeout) ||
273274
start_proc_phase(thd, phase);
274-
return fail || run_backup_processing(thd);
275+
return fail || run_backup_processing(thd, phase);
275276
}
276277

277278
bool Sql_cmd_backup::execute(THD *thd)
@@ -323,7 +324,7 @@ bool Sql_cmd_backup::execute(THD *thd)
323324
if (!fail)
324325
{
325326
fail= start_proc_phase(thd, BACKUP_PROC_PHASE_BACKUP_LOCKED) ||
326-
run_backup_processing(thd) ||
327+
run_backup_processing(thd, BACKUP_PROC_PHASE_BACKUP_LOCKED) ||
327328
upgrade_and_process(thd, mdl_request, MDL_BACKUP_WAIT_DDL,
328329
BACKUP_PROC_PHASE_DDL_LOCKED) ||
329330
upgrade_and_process(thd, mdl_request, MDL_BACKUP_WAIT_COMMIT,

storage/innobase/handler/backup_innodb.cc

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class InnoDB_backup
5454
backup_context &context() const noexcept
5555
{ ut_ad(log_sys.latch_have_any()); ut_ad(trx); return trx->lock.backup; }
5656

57-
/** Calls to step() should be ignored */
58-
bool ignore_step=false;
5957
public:
6058
/**
6159
Start of BACKUP SERVER: collect all files to be backed up
@@ -141,13 +139,6 @@ class InnoDB_backup
141139
return fail;
142140
}
143141

144-
void stop_processing() noexcept
145-
{
146-
log_sys.latch.wr_lock();
147-
ignore_step= true;
148-
log_sys.latch.wr_unlock();
149-
}
150-
151142
/**
152143
Process a file that was collected at init().
153144
This may be invoked from multiple concurrent threads.
@@ -162,11 +153,6 @@ class InnoDB_backup
162153
log_sys.latch.wr_lock();
163154
backup_context &ctx{context()};
164155
ut_ad(ctx.max_first_lsn);
165-
if (ignore_step)
166-
{
167-
log_sys.latch.wr_unlock();
168-
return 0;
169-
}
170156
size_t size{queue.size()};
171157
if (!logs.empty())
172158
{
@@ -786,22 +772,13 @@ int innodb_backup_start(THD *thd, backup_target target) noexcept
786772
return innodb_backup.init(thd, target);
787773
}
788774

789-
int innodb_backup_start_proc_phase(THD *thd, backup_proc_phase phase) noexcept
775+
int innodb_backup_step(THD *thd, backup_proc_phase phase) noexcept
790776
{
791-
/* This logic relies of the fact that Backup-locked is the first
792-
processing phase and innodb_backup is initially set to process steps.
793-
If this should change this code may need to be adjusted, possibly
794-
adding a start_processing() method. */
795-
if (phase!=BACKUP_PROC_PHASE_BACKUP_LOCKED)
796-
innodb_backup.stop_processing();
777+
if (phase==BACKUP_PROC_PHASE_BACKUP_LOCKED)
778+
return innodb_backup.step(thd);
797779
return 0;
798780
}
799781

800-
int innodb_backup_step(THD *thd) noexcept
801-
{
802-
return innodb_backup.step(thd);
803-
}
804-
805782
int innodb_backup_end(THD *thd, backup_end_phase phase, bool abort) noexcept
806783
{
807784
if (phase==BACKUP_END_PHASE_BACKUP_LOCKED)

storage/innobase/handler/backup_innodb.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,14 @@
2222
*/
2323
int innodb_backup_start(THD *thd, backup_target target) noexcept;
2424

25-
/**
26-
Start backup processing phase
27-
@param thd current session
28-
@param phase the phase which is started
29-
@return error code
30-
@retval 0 on success
31-
*/
32-
int innodb_backup_start_proc_phase(THD *thd, backup_proc_phase phase) noexcept;
33-
3425
/**
3526
Process a file that was collected in backup_start().
3627
@param thd current session
28+
@param phase current processing phase
3729
@return number of files remaining, or negative on error
3830
@retval 0 on completion
3931
*/
40-
int innodb_backup_step(THD *thd) noexcept;
32+
int innodb_backup_step(THD *thd, backup_proc_phase phase) noexcept;
4133

4234
/**
4335
Finish copying and determine the logical time of the backup snapshot.

storage/innobase/handler/ha_innodb.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4144,7 +4144,6 @@ static int innodb_init(void* p)
41444144

41454145
innobase_hton->update_optimizer_costs= innobase_update_optimizer_costs;
41464146
innobase_hton->backup_start = innodb_backup_start;
4147-
innobase_hton->backup_start_proc_phase = innodb_backup_start_proc_phase;
41484147
innobase_hton->backup_step = innodb_backup_step;
41494148
innobase_hton->backup_end = innodb_backup_end;
41504149
innobase_hton->backup_finalize = innodb_backup_finalize;

storage/maria/ma_backup.cc

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ namespace
114114

115115
bool start_copy_dml_safe() noexcept
116116
{
117-
ddl_locked= true;
118117
if (scan_dbdirs())
119118
return true;
120119
flatten_table_lists();
@@ -129,13 +128,49 @@ namespace
129128
return false;
130129
}
131130

132-
int step() noexcept
131+
int dml_safe_copy_step() noexcept
133132
{
134-
if (!ddl_locked)
133+
if (dml_safe_tables_copied == dml_safe_table_list.size())
135134
return 0;
136-
return unsafe_copy_phase?
137-
unsafe_copy_step():
138-
dml_safe_copy_step();
135+
const table_ref& table = dml_safe_table_list[dml_safe_tables_copied];
136+
if (copy_table(table) != 0)
137+
return -1;
138+
++dml_safe_tables_copied;
139+
return dml_safe_table_list.size() - dml_safe_tables_copied;
140+
}
141+
142+
int unsafe_copy_step() noexcept
143+
{
144+
if (have_control_file)
145+
{
146+
if (copy_control_file() != 0)
147+
return -1;
148+
have_control_file = false;
149+
}
150+
else if(log_files_copied < log_files.size())
151+
{
152+
if (copy_file(log_files[log_files_copied]) != 0)
153+
return -1;
154+
++log_files_copied;
155+
}
156+
else if (unsafe_tables_copied < unsafe_tables_list.size())
157+
{
158+
const table_ref& table = unsafe_tables_list[unsafe_tables_copied];
159+
if (copy_table(table) != 0)
160+
return -1;
161+
++unsafe_tables_copied;
162+
}
163+
else if (misc_files_copied < misc_files.size())
164+
{
165+
if (copy_file(misc_files[misc_files_copied]) != 0)
166+
return -1;
167+
++misc_files_copied;
168+
}
169+
assert(!have_control_file);
170+
return
171+
log_files.size() - log_files_copied +
172+
unsafe_tables_list.size() - unsafe_tables_copied +
173+
misc_files.size() - misc_files_copied;
139174
}
140175

141176
int end(bool /*abort*/) noexcept
@@ -186,7 +221,6 @@ namespace
186221
size_t unsafe_tables_copied= 0;
187222
size_t log_files_copied= 0;
188223
size_t misc_files_copied= 0;
189-
bool ddl_locked= false;
190224
bool unsafe_copy_phase = false;
191225

192226
int scan_dbdirs() noexcept
@@ -382,51 +416,6 @@ namespace
382416
return result;
383417
}
384418

385-
int dml_safe_copy_step() noexcept
386-
{
387-
if (dml_safe_tables_copied == dml_safe_table_list.size())
388-
return 0;
389-
const table_ref& table = dml_safe_table_list[dml_safe_tables_copied];
390-
if (copy_table(table) != 0)
391-
return -1;
392-
++dml_safe_tables_copied;
393-
return dml_safe_table_list.size() - dml_safe_tables_copied;
394-
}
395-
396-
int unsafe_copy_step() noexcept
397-
{
398-
if (have_control_file)
399-
{
400-
if (copy_control_file() != 0)
401-
return -1;
402-
have_control_file = false;
403-
}
404-
else if(log_files_copied < log_files.size())
405-
{
406-
if (copy_file(log_files[log_files_copied]) != 0)
407-
return -1;
408-
++log_files_copied;
409-
}
410-
else if (unsafe_tables_copied < unsafe_tables_list.size())
411-
{
412-
const table_ref& table = unsafe_tables_list[unsafe_tables_copied];
413-
if (copy_table(table) != 0)
414-
return -1;
415-
++unsafe_tables_copied;
416-
}
417-
else if (misc_files_copied < misc_files.size())
418-
{
419-
if (copy_file(misc_files[misc_files_copied]) != 0)
420-
return -1;
421-
++misc_files_copied;
422-
}
423-
assert(!have_control_file);
424-
return
425-
log_files.size() - log_files_copied +
426-
unsafe_tables_list.size() - unsafe_tables_copied +
427-
misc_files.size() - misc_files_copied;
428-
}
429-
430419
int copy_table(const table_ref& table) noexcept
431420
{
432421
dir_ref dir_name = table.first;
@@ -567,9 +556,17 @@ int aria_backup_start_proc_phase(THD *thd, backup_proc_phase phase) noexcept
567556
}
568557
}
569558

570-
int aria_backup_step(THD *thd) noexcept
559+
int aria_backup_step(THD *thd, backup_proc_phase phase) noexcept
571560
{
572-
return aria_backup->step();
561+
switch (phase)
562+
{
563+
case BACKUP_PROC_PHASE_DDL_LOCKED:
564+
return aria_backup->dml_safe_copy_step();
565+
case BACKUP_PROC_PHASE_COMMIT_LOCKED:
566+
return aria_backup->unsafe_copy_step();
567+
default:
568+
return 0;
569+
}
573570
}
574571

575572
int aria_backup_end(THD *thd, backup_end_phase phase, bool abort) noexcept

storage/maria/ma_backup.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ int aria_backup_start(THD *thd, backup_target target) noexcept;
3939
int aria_backup_start_proc_phase(THD *thd, backup_proc_phase phase) noexcept;
4040

4141
/**
42-
Process a file that was collected in backup_start().
42+
Processing step (processes 1 table).
4343
@param thd current session
44+
@param phase current processing phase
4445
@return number of files remaining, or negative on error
4546
@retval 0 on completion
4647
*/
47-
int aria_backup_step(THD *thd) noexcept;
48+
int aria_backup_step(THD *thd, backup_proc_phase phase) noexcept;
4849

4950
/**
5051
Finish copying and determine the logical time of the backup snapshot.

0 commit comments

Comments
 (0)