lock_and_rename
Lock and rename a table.
Parameters
Required Arguments
Returns
Exit status
sync_one_table
Sync one table between one source host and multiple destination hosts. The first DSN in $args{dsns} specifies the source host, database (D), and table (t). The other DSNs are the destination hosts. If a destination DSN does not specify a database or table, the source database or table are used as defaults. Else, the destination-specific database or table are used. This allows you to sync tables with different names.
Parameters
Required Arguments
Returns
Exit status
sync_via_replication
Sync multiple destination hosts to one source host via replication. The first DSN in $args{dsns} specifies the source host. If --sync-to-master is specified, then the source host is a master and there is only one destination host which is its slave. Else, destination hosts are auto-discovered with MasterSlave::recurse_to_slaves().
Parameters
Required Arguments
Returns
Exit status
See Also
filter_diffs()
sync_all
Sync every table between one source host and multiple destination hosts. The first DSN in $args{dsns} specifies the source host. The other DSNs are the destination hosts. Unlike sync_one_table, the database and table names must be the same on the source and destination hosts.
Parameters
Required Arguments
Returns
Exit status
lock_server
Lock a host with FLUSH TABLES WITH READ LOCK. This implements --lock 3 by calling TableSyncer::lock_and_wait().
Parameters
Required Arguments
src | Hashref with source host information |
dst | Hashref with destination host information |
OptionParser | OptionParser object |
DSNParser | DSNParser object |
TableSyncer | TableSyncer object |
unlock_server
Unlock a host with UNLOCK TABLES. This implements --lock 3 by calling TableSyncer::unlock().
Parameters
Required Arguments
src | Hashref with source host information |
dst | Hashref with destination host information |
OptionParser | OptionParser object |
DSNParser | DSNParser object |
TableSyncer | TableSyncer object |
sync_a_table
Sync the destination host table to the source host table. This sub is not called directly but indirectly via the other sync_* subs. In turn, this sub calls TableSyncer::sync_table() which actually does the sync work. Calling sync_table() requires a fair amount of prep work that this sub does/simplifies. New RowDiff and ChangeHandler objects are created, so those packages need to be available.
Parameters
Required Arguments
src | Hashref with source host information |
dst | Hashref with destination host information |
plugins | Arrayref of TableSync* objects |
OptionParser | OptionParser object |
Quoter | Quoter object |
TableParser | TableParser object |
MySQLDump | MySQLDump object |
TableSyncer | TableSyncer object |
Returns
Exit status
get_change_dbh
Return the dbh to write to for syncing changes. Write statements are executed on the “change dbh”. If --sync-to-master or --replicate is specified, the source (master) dbh is the “change dbh”. This means changes replicate to all slaves. Else, the destination dbh is the change dbh. This is the case when two independent servers (or perhaps one table on the same server) are synced. This sub implements --[no]check-slave because writing to a slave is generally a bad thing.
Parameters
Required Arguments
Returns
Either $args{src}->{dbh} or $args{dst}->{dbh} if no checks fail.
See Also
make_action_subs()
make_action_subs
Make callbacks for ChangeHandler::new() actions argument. This sub implements --print and --execute.
Parameters
Required Arguments
Returns
Arrayref of callbacks (coderefs)
print_err
Try to extract the MySQL error message and print it.
Parameters
$msg | Error message |
$database | Database name being synced when error occurred |
$table | Table name being synced when error occurred |
$host | Host name error occurred on |
get_cxn
Connect to host specified by DSN.
Parameters
$dsn | Host DSN |
%args | Arguments |
Required Arguments
Returns
dbh
ok_to_sync
Check that the destination host table can be synced to the source host table. All sorts of sanity checks are performed to help ensure that syncing the table won’t cause problems in sync_a_table() or TableSyncer::sync_table().
Parameters
Required Arguments
Returns
Table structure (from TableParser::parse()) if ok to sync, else it dies.
filter_diffs
Filter different slave tables according to the various schema object filters. This sub is called in sync_via_replication() to implement schema object filters like --databases and --tables.
Parameters
$skip_table | Hashref of databases and tables to skip |
$databases | Hashref of databases to skip |
$tables | Hashref of tables to skip |
@diffs | Array of hashrefs, one for each different slave table |
Returns
Array of different slave tables that pass the filters
disconnect
Disconnect host dbhs created by get_cxn(). To make sure all dbh are closed, pt-table-sync keeps track of the dbh it opens and this sub helps keep track of the dbh that are closed.
Parameters
@hosts | Array of hashrefs with host information, one for each host |
print_sql
Callback for TableSyncer::sync_table() if --print --verbose --verbose is specified. The callback simply prints the SQL statements passed to it by sync_table(). They’re usually (always?) identical statements.
Parameters
$src_sql | SQL statement to be executed on the sourch host |
$dst_sql | SQL statement to be executed on the destination host |
cmd_conflict_col
Compare --conflict-column values for --bidirectional. This sub is used as a callback in set_bidirectional_callbacks().
Parameters
$left_val | Column value from left (usually the source host) |
$right_val | Column value from right (usually the destination host) |
$cmp | Type of conflict comparison, --conflict-comparison |
$val | Value for certain types of comparisons, --conflict-value |
$thr | Threshold for certain types of comparisons, --conflict-threshold |
Returns
One of the constants above, UPDATE_* or FAILED_THRESHOLD
set_bidirectional_callbacks
Set syncer plugin callbacks for --bidirectional.
Parameters
Required Arguments
get_plugins
Get internal TableSync* plugins.
Returns
Hash of available algoritms and the plugin/module names that implement them, like “chunk => TableSyncChunk”.
get_server_time
Return HH:MM:SS of SELECT NOW() from the server.
Parameters