PT-1717 - resume pt-online-schema-change if it's interrupted

- Updating lower and upper boundaries in the history table
This commit is contained in:
Sveta Smirnova
2024-02-28 18:25:39 +03:00
parent c8c1b2483a
commit a111ed0b70
2 changed files with 65 additions and 3 deletions

View File

@@ -10201,6 +10201,7 @@ sub main {
if ( $o->get('execute') ) {
if ( $o->get('history') ) {
$done_sth->execute();
print ts("Job ${job_id} finished successfully.\n");
}
print ts("Copied rows OK.\n");
}

View File

@@ -69,12 +69,19 @@ is(
) or diag($output);
$output = `/tmp/12345/use -N -e "select count(*) from information_schema.tables where TABLE_SCHEMA='percona' and table_name='pt_osc_history'"`;
is(
$output + 0,
0,
'--history table not created when option --history not provided'
);
unlike(
$output,
qr/Job \d finished successfully/,
'Job id not printed when option --history not provided'
);
($output, $exit) = full_output(
sub { pt_online_schema_change::main(@args, "$dsn,D=pt_osc,t=t",
'--alter', 'engine=innodb', '--execute', '--history') }
@@ -86,6 +93,12 @@ is(
'basic test with option --history finished OK'
) or diag($output);
like(
$output,
qr/Job \d finished successfully/,
'Job id printed for successful copy'
);
$output = `/tmp/12345/use -N -e "select count(*) from information_schema.tables where TABLE_SCHEMA='percona' and table_name='pt_osc_history'"`;
is(
@@ -102,6 +115,14 @@ is(
'Initial row with Job ID was inserted into --history table'
);
$output = `/tmp/12345/use -N -e "select count(*) from percona.pt_osc_history where job_id=1 and lower_boundary is null and upper_boundary is null"`;
is(
$output + 0,
1,
'Lower and upper boundaries were not updated when table altered with single chunk'
);
($output, $exit) = full_output(
sub { pt_online_schema_change::main(@args, "$dsn,D=pt_osc,t=t",
'--alter', 'engine=innodb', '--execute', '--history', '--chunk-size=4') }
@@ -125,7 +146,15 @@ $output = `/tmp/12345/use -N -e "select count(*) from information_schema.tables
is(
$output + 0,
1,
'--history table was created when option --history was provided only once'
'--history table was created only once when option --history was provided'
);
$output = `/tmp/12345/use -N -e "select count(*) from percona.pt_osc_history where job_id=2 and lower_boundary=17 and upper_boundary=20"`;
is(
$output + 0,
1,
'Lower and upper boundaries were updated when table altered with multiple chunks'
);
diag(`/tmp/12345/use -N -e "drop table percona.pt_osc_history"`);
@@ -163,9 +192,17 @@ is(
'Initial row with Job ID was inserted into --history table with --binary-index'
);
$output = `/tmp/12345/use -N -e "select count(*) from percona.pt_osc_history where job_id=1 and lower_boundary is null and upper_boundary is null"`;
is(
$output + 0,
1,
'Lower and upper boundaries were not updated when table altered with single chunk and --binary-index'
);
($output, $exit) = full_output(
sub { pt_online_schema_change::main(@args, "$dsn,D=pt_osc,t=t",
'--alter', 'engine=innodb', '--execute', '--history', '--binary-index') }
'--alter', 'engine=innodb', '--execute', '--history', '--binary-index', '--chunk-size=4') }
);
is(
@@ -189,6 +226,14 @@ is(
'--history table with --binary-index updated'
);
$output = `/tmp/12345/use -N -e "select count(*) from percona.pt_osc_history where job_id=2 and lower_boundary=17 and upper_boundary=20"`;
is(
$output + 0,
1,
'Lower and upper boundaries were updated when table altered with multiple chunks and --binary-index'
);
($output, $exit) = full_output(
sub { pt_online_schema_change::main(@args, "$dsn,D=pt_osc,t=t",
'--alter', 'engine=innodb', '--execute', '--history') }
@@ -233,6 +278,14 @@ is(
'Custom --history table created'
);
$output = `/tmp/12345/use -N -e "select count(*) from pt_1717.pt_1717_history where job_id=1 and lower_boundary is null and upper_boundary is null"`;
is(
$output + 0,
1,
'Lower and upper boundaries were not updated in custom history table when table altered with single chunk'
);
$output = `/tmp/12345/use -N -e "select count(*) from pt_1717.pt_1717_history where db='pt_osc' and tbl='t' and altr='engine=innodb' and json_extract(args, '\$.alter') = 'engine=innodb' and done='yes'"`;
is(
@@ -244,7 +297,7 @@ is(
($output, $exit) = full_output(
sub { pt_online_schema_change::main(@args, "$dsn,D=pt_osc,t=t",
'--alter', 'engine=innodb', '--execute', '--history',
'--history-table=pt_1717.pt_1717_history') }
'--history-table=pt_1717.pt_1717_history', '--chunk-size=4') }
);
is(
@@ -268,6 +321,14 @@ is(
'Custom --history table updated'
);
$output = `/tmp/12345/use -N -e "select count(*) from pt_1717.pt_1717_history where job_id=2 and lower_boundary=17 and upper_boundary=20"`;
is(
$output + 0,
1,
'Lower and upper boundaries in custom history table were updated when table altered with multiple chunks'
);
# #############################################################################
# Done.
# #############################################################################