added --plugin to pt-table-checksum

This commit is contained in:
Kenny Gryp
2014-03-25 16:44:59 +01:00
parent e85cf5f452
commit d84c3b26b5

View File

@@ -9223,6 +9223,30 @@ sub main {
my $slaves = []; # all slaves (that we can find) my $slaves = []; # all slaves (that we can find)
my $slave_lag_cxns; # slaves whose lag we'll check my $slave_lag_cxns; # slaves whose lag we'll check
# ########################################################################
# Create --plugin.
# ########################################################################
my $plugin;
if ( my $file = $o->get('plugin') ) {
die "--plugin file $file does not exist\n" unless -f $file;
eval {
require $file;
};
die "Error loading --plugin $file: $EVAL_ERROR" if $EVAL_ERROR;
eval {
$plugin = pt_table_checksum_plugin->new(
master_cxn => $master_cxn,
explain => $o->get('explain'),
quiet => $o->get('quiet'),
resume => $o->get('resume'),
Quoter => $q,
TableParser => $tp,
);
};
die "Error creating --plugin: $EVAL_ERROR" if $EVAL_ERROR;
print "Created plugin from $file.\n";
}
my $replica_lag; # ReplicaLagWaiter object my $replica_lag; # ReplicaLagWaiter object
my $replica_lag_pr; # Progress for ReplicaLagWaiter my $replica_lag_pr; # Progress for ReplicaLagWaiter
my $sys_load; # MySQLStatusWaiter object my $sys_load; # MySQLStatusWaiter object
@@ -9447,6 +9471,11 @@ sub main {
# ##################################################################### # #####################################################################
if ( $o->get('replicate-check') && $o->get('replicate-check-only') ) { if ( $o->get('replicate-check') && $o->get('replicate-check-only') ) {
PTDEBUG && _d('Will --replicate-check and exit'); PTDEBUG && _d('Will --replicate-check and exit');
# --plugin hook
if ( $plugin && $plugin->can('before_replicate_check') ) {
$plugin->before_replicate_check();
}
foreach my $slave ( @$slaves ) { foreach my $slave ( @$slaves ) {
my $diffs = $rc->find_replication_differences( my $diffs = $rc->find_replication_differences(
@@ -9467,6 +9496,11 @@ sub main {
} }
} }
# --plugin hook
if ( $plugin && $plugin->can('after_replicate_check') ) {
$plugin->after_replicate_check();
}
PTDEBUG && _d('Exit status', $exit_status, 'oktorun', $oktorun); PTDEBUG && _d('Exit status', $exit_status, 'oktorun', $oktorun);
return $exit_status; return $exit_status;
} }
@@ -9562,6 +9596,12 @@ sub main {
return $ms->get_slave_lag($dbh); return $ms->get_slave_lag($dbh);
}; };
# The plugin is able to override the slavelag check so tools like pt-heartbeat
# or other replicators (Tungsten...) can be used to measure replication lag
if ( $plugin && $plugin->can('override_slavelag_check') ) {
$get_lag = $plugin->override_slavelag_check(oktorun => \$oktorun);
}
$replica_lag = new ReplicaLagWaiter( $replica_lag = new ReplicaLagWaiter(
slaves => $slave_lag_cxns, slaves => $slave_lag_cxns,
max_lag => $o->get('max-lag'), max_lag => $o->get('max-lag'),
@@ -10168,6 +10208,19 @@ sub main {
}, },
}; };
# ########################################################################
# Init the --plugin.
# ########################################################################
# --plugin hook
if ( $plugin && $plugin->can('init') ) {
$plugin->init(
slaves => $slaves,
slave_lag_cxns => $slave_lag_cxns,
repl_table => $repl_table,
);
}
# ######################################################################## # ########################################################################
# Checksum each table. # Checksum each table.
# ######################################################################## # ########################################################################
@@ -10175,6 +10228,7 @@ sub main {
TABLE: TABLE:
while ( $oktorun && $have_time->() && (my $tbl = $schema_iter->next()) ) { while ( $oktorun && $have_time->() && (my $tbl = $schema_iter->next()) ) {
eval { eval {
# Results, stats, and info related to checksuming this table can # Results, stats, and info related to checksuming this table can
# be saved here. print_checksum_results() uses this info. # be saved here. print_checksum_results() uses this info.
$tbl->{checksum_results} = {}; $tbl->{checksum_results} = {};
@@ -10272,6 +10326,12 @@ sub main {
@$all_cols; @$all_cols;
$tbl->{checksum_cols} = \@cols; $tbl->{checksum_cols} = \@cols;
# --plugin hook
if ( $plugin && $plugin->can('before_checksum_table') ) {
$plugin->before_checksum_table(
tbl => $tbl);
}
# Finally, checksum the table. # Finally, checksum the table.
# The "1 while" loop is necessary because we're executing REPLACE # The "1 while" loop is necessary because we're executing REPLACE
# statements which don't return rows and NibbleIterator only # statements which don't return rows and NibbleIterator only
@@ -10280,6 +10340,11 @@ sub main {
# from the done callback, uses this start time. # from the done callback, uses this start time.
$tbl->{checksum_results}->{start_time} = time; $tbl->{checksum_results}->{start_time} = time;
1 while $nibble_iter->next(); 1 while $nibble_iter->next();
# --plugin hook
if ( $plugin && $plugin->can('after_checksum_table') ) {
$plugin->after_checksum_table();
}
} }
}; };
if ( $EVAL_ERROR ) { if ( $EVAL_ERROR ) {
@@ -12054,6 +12119,18 @@ if the PID file exists and the PID it contains is no longer running, the
tool will overwrite the PID file with the current PID. The PID file is tool will overwrite the PID file with the current PID. The PID file is
removed automatically when the tool exits. removed automatically when the tool exits.
=item --plugin
type: string
Perl module file that defines a C<pt_table_checksum_plugin> class.
A plugin allows you to write a Perl module that can hook into many parts
of pt-table-checksum. This requires a good knowledge of Perl and
Percona Toolkit conventions, which are beyond this scope of this
documentation. Please contact Percona if you have questions or need help.
See L<"PLUGIN"> for more information.
=item --port =item --port
short form: -P; type: int; group: Connection short form: -P; type: int; group: Connection
@@ -12402,6 +12479,39 @@ differences.
=back =back
=head1 PLUGIN
The file specified by L<"--plugin"> must define a class (i.e. a package)
called C<pt_table_checksum_plugin> with a C<new()> subroutine.
The tool will create an instance of this class and call any hooks that
it defines. No hooks are required, but a plugin isn't very useful without
them.
These hooks, in this order, are called if defined:
init
before_replicate_check
after_replicate_check
override_slavelag_check
before_checksum_table
after_checksum_table
Each hook is passed different arguments. To see which arguments are passed
to a hook, search for the hook's name in the tool's source code, like:
# --plugin hook
if ( $plugin && $plugin->can('init') ) {
$plugin->init(
slaves => $slaves,
slave_lag_cxns => $slave_lag_cxns,
repl_table => $repl_table,
);
}
The comment C<# --plugin hook> precedes every hook call.
Please contact Percona if you have questions or need help.
=head1 DSN OPTIONS =head1 DSN OPTIONS
These DSN options are used to create a DSN. Each option is given like These DSN options are used to create a DSN. Each option is given like