~jmuc/percona-toolkit/float-log-precision

« back to all changes in this revision

Viewing changes to t/pt-online-schema-change/samples/plugins/block_swap_tables.pm

Merge pt-osc-metadata-lock-bug-1113301.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package pt_online_schema_change_plugin;
 
2
 
 
3
use strict;
 
4
use warnings FATAL => 'all';
 
5
use English qw(-no_match_vars);
 
6
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
 
7
 
 
8
sub new {
 
9
   my ($class, %args) = @_;
 
10
   my $self = { %args };
 
11
   return bless $self, $class;
 
12
}
 
13
 
 
14
sub init {
 
15
   my ($self, %args) = @_;
 
16
   print "PLUGIN: init()\n";
 
17
   $self->{orig_tbl} = $args{orig_tbl};
 
18
}
 
19
 
 
20
sub before_swap_tables {
 
21
   my ($self, %args) = @_;
 
22
   print "PLUGIN: before_swap_tables()\n";
 
23
 
 
24
   my $dbh      = $self->{aux_cxn}->dbh;
 
25
   my $orig_tbl = $self->{orig_tbl};
 
26
 
 
27
   # Start a trx and get a metadata lock on the table being altered.
 
28
   $dbh->do('SET autocommit=0');
 
29
   $dbh->{AutoCommit} = 0;
 
30
   $dbh->do("START TRANSACTION");
 
31
   $dbh->do("SELECT * FROM " . $orig_tbl->{name});
 
32
 
 
33
   return;
 
34
}
 
35
 
 
36
sub before_drop_triggers {
 
37
   my ($self, %args) = @_;
 
38
   print "PLUGIN: before_drop_triggers()\n";
 
39
 
 
40
   my $dbh = $self->{aux_cxn}->dbh;
 
41
 
 
42
   # Commit the trx to release the metadata lock.
 
43
   $dbh->commit();
 
44
}
 
45
 
 
46
1;