mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-04 03:26:19 +00:00
Compare commits
38 Commits
Changelog
...
release-v3
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d9b0219d9e | ||
![]() |
1d3a44c5da | ||
![]() |
a6a3199a3c | ||
![]() |
fadf758cb4 | ||
![]() |
25ba843cdd | ||
![]() |
4906b6a348 | ||
![]() |
18dba10c60 | ||
![]() |
5039621d29 | ||
![]() |
c30baedf41 | ||
![]() |
06359e5d1a | ||
![]() |
44a2819055 | ||
![]() |
3ef8ca77ff | ||
![]() |
19b0927001 | ||
![]() |
9ccecb2d50 | ||
![]() |
2de6e9ba9e | ||
![]() |
f8e3ece9ee | ||
![]() |
5f79b34dfc | ||
![]() |
e038b275ef | ||
![]() |
2eccd39129 | ||
![]() |
ef04237618 | ||
![]() |
df2cc0c9ca | ||
![]() |
6aacdda0e6 | ||
![]() |
b2dd791512 | ||
![]() |
e7580f2519 | ||
![]() |
22208f01a2 | ||
![]() |
f85d8b0194 | ||
![]() |
8b67b26f7e | ||
![]() |
0e4df890c4 | ||
![]() |
0fd43b871d | ||
![]() |
8c731e52c0 | ||
![]() |
95e95f95d6 | ||
![]() |
e84d985e3f | ||
![]() |
0869d14d19 | ||
![]() |
8231dae4c0 | ||
![]() |
aad0a26789 | ||
![]() |
8d03f3c8b8 | ||
![]() |
eafbaca786 | ||
![]() |
5da16d53f4 |
@@ -18,6 +18,11 @@ BEGIN {
|
||||
OptionParser
|
||||
DSNParser
|
||||
Daemon
|
||||
Lmo::Utils
|
||||
Lmo::Meta
|
||||
Lmo::Object
|
||||
Lmo::Types
|
||||
Lmo
|
||||
VersionParser
|
||||
));
|
||||
}
|
||||
@@ -2527,6 +2532,655 @@ sub _d {
|
||||
# End Daemon package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# Lmo::Utils package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the GitHub repository at,
|
||||
# lib/Lmo/Utils.pm
|
||||
# t/lib/Lmo/Utils.t
|
||||
# See https://github.com/percona/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
{
|
||||
package Lmo::Utils;
|
||||
|
||||
use strict;
|
||||
use warnings qw( FATAL all );
|
||||
require Exporter;
|
||||
our (@ISA, @EXPORT, @EXPORT_OK);
|
||||
|
||||
BEGIN {
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = @EXPORT_OK = qw(
|
||||
_install_coderef
|
||||
_unimport_coderefs
|
||||
_glob_for
|
||||
_stash_for
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
no strict 'refs';
|
||||
sub _glob_for {
|
||||
return \*{shift()}
|
||||
}
|
||||
|
||||
sub _stash_for {
|
||||
return \%{ shift() . "::" };
|
||||
}
|
||||
}
|
||||
|
||||
sub _install_coderef {
|
||||
my ($to, $code) = @_;
|
||||
|
||||
return *{ _glob_for $to } = $code;
|
||||
}
|
||||
|
||||
sub _unimport_coderefs {
|
||||
my ($target, @names) = @_;
|
||||
return unless @names;
|
||||
my $stash = _stash_for($target);
|
||||
foreach my $name (@names) {
|
||||
if ($stash->{$name} and defined(&{$stash->{$name}})) {
|
||||
delete $stash->{$name};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
}
|
||||
# ###########################################################################
|
||||
# End Lmo::Utils package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# Lmo::Meta package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the GitHub repository at,
|
||||
# lib/Lmo/Meta.pm
|
||||
# t/lib/Lmo/Meta.t
|
||||
# See https://github.com/percona/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
{
|
||||
package Lmo::Meta;
|
||||
use strict;
|
||||
use warnings qw( FATAL all );
|
||||
|
||||
my %metadata_for;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
return bless { @_ }, $class
|
||||
}
|
||||
|
||||
sub metadata_for {
|
||||
my $self = shift;
|
||||
my ($class) = @_;
|
||||
|
||||
return $metadata_for{$class} ||= {};
|
||||
}
|
||||
|
||||
sub class { shift->{class} }
|
||||
|
||||
sub attributes {
|
||||
my $self = shift;
|
||||
return keys %{$self->metadata_for($self->class)}
|
||||
}
|
||||
|
||||
sub attributes_for_new {
|
||||
my $self = shift;
|
||||
my @attributes;
|
||||
|
||||
my $class_metadata = $self->metadata_for($self->class);
|
||||
while ( my ($attr, $meta) = each %$class_metadata ) {
|
||||
if ( exists $meta->{init_arg} ) {
|
||||
push @attributes, $meta->{init_arg}
|
||||
if defined $meta->{init_arg};
|
||||
}
|
||||
else {
|
||||
push @attributes, $attr;
|
||||
}
|
||||
}
|
||||
return @attributes;
|
||||
}
|
||||
|
||||
1;
|
||||
}
|
||||
# ###########################################################################
|
||||
# End Lmo::Meta package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# Lmo::Object package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the GitHub repository at,
|
||||
# lib/Lmo/Object.pm
|
||||
# t/lib/Lmo/Object.t
|
||||
# See https://github.com/percona/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
{
|
||||
package Lmo::Object;
|
||||
|
||||
use strict;
|
||||
use warnings qw( FATAL all );
|
||||
|
||||
use Carp ();
|
||||
use Scalar::Util qw(blessed);
|
||||
|
||||
use Lmo::Meta;
|
||||
use Lmo::Utils qw(_glob_for);
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $args = $class->BUILDARGS(@_);
|
||||
|
||||
my $class_metadata = Lmo::Meta->metadata_for($class);
|
||||
|
||||
my @args_to_delete;
|
||||
while ( my ($attr, $meta) = each %$class_metadata ) {
|
||||
next unless exists $meta->{init_arg};
|
||||
my $init_arg = $meta->{init_arg};
|
||||
|
||||
if ( defined $init_arg ) {
|
||||
$args->{$attr} = delete $args->{$init_arg};
|
||||
}
|
||||
else {
|
||||
push @args_to_delete, $attr;
|
||||
}
|
||||
}
|
||||
|
||||
delete $args->{$_} for @args_to_delete;
|
||||
|
||||
for my $attribute ( keys %$args ) {
|
||||
if ( my $coerce = $class_metadata->{$attribute}{coerce} ) {
|
||||
$args->{$attribute} = $coerce->($args->{$attribute});
|
||||
}
|
||||
if ( my $isa_check = $class_metadata->{$attribute}{isa} ) {
|
||||
my ($check_name, $check_sub) = @$isa_check;
|
||||
$check_sub->($args->{$attribute});
|
||||
}
|
||||
}
|
||||
|
||||
while ( my ($attribute, $meta) = each %$class_metadata ) {
|
||||
next unless $meta->{required};
|
||||
Carp::confess("Attribute ($attribute) is required for $class")
|
||||
if ! exists $args->{$attribute}
|
||||
}
|
||||
|
||||
my $self = bless $args, $class;
|
||||
|
||||
my @build_subs;
|
||||
my $linearized_isa = mro::get_linear_isa($class);
|
||||
|
||||
for my $isa_class ( @$linearized_isa ) {
|
||||
unshift @build_subs, *{ _glob_for "${isa_class}::BUILD" }{CODE};
|
||||
}
|
||||
my @args = %$args;
|
||||
for my $sub (grep { defined($_) && exists &$_ } @build_subs) {
|
||||
$sub->( $self, @args);
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub BUILDARGS {
|
||||
shift; # No need for the classname
|
||||
if ( @_ == 1 && ref($_[0]) ) {
|
||||
Carp::confess("Single parameters to new() must be a HASH ref, not $_[0]")
|
||||
unless ref($_[0]) eq ref({});
|
||||
return {%{$_[0]}} # We want a new reference, always
|
||||
}
|
||||
else {
|
||||
return { @_ };
|
||||
}
|
||||
}
|
||||
|
||||
sub meta {
|
||||
my $class = shift;
|
||||
$class = Scalar::Util::blessed($class) || $class;
|
||||
return Lmo::Meta->new(class => $class);
|
||||
}
|
||||
|
||||
1;
|
||||
}
|
||||
# ###########################################################################
|
||||
# End Lmo::Object package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# Lmo::Types package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the GitHub repository at,
|
||||
# lib/Lmo/Types.pm
|
||||
# t/lib/Lmo/Types.t
|
||||
# See https://github.com/percona/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
{
|
||||
package Lmo::Types;
|
||||
|
||||
use strict;
|
||||
use warnings qw( FATAL all );
|
||||
|
||||
use Carp ();
|
||||
use Scalar::Util qw(looks_like_number blessed);
|
||||
|
||||
|
||||
our %TYPES = (
|
||||
Bool => sub { !$_[0] || (defined $_[0] && looks_like_number($_[0]) && $_[0] == 1) },
|
||||
Num => sub { defined $_[0] && looks_like_number($_[0]) },
|
||||
Int => sub { defined $_[0] && looks_like_number($_[0]) && $_[0] == int($_[0]) },
|
||||
Str => sub { defined $_[0] },
|
||||
Object => sub { defined $_[0] && blessed($_[0]) },
|
||||
FileHandle => sub { local $@; require IO::Handle; fileno($_[0]) && $_[0]->opened },
|
||||
|
||||
map {
|
||||
my $type = /R/ ? $_ : uc $_;
|
||||
$_ . "Ref" => sub { ref $_[0] eq $type }
|
||||
} qw(Array Code Hash Regexp Glob Scalar)
|
||||
);
|
||||
|
||||
sub check_type_constraints {
|
||||
my ($attribute, $type_check, $check_name, $val) = @_;
|
||||
( ref($type_check) eq 'CODE'
|
||||
? $type_check->($val)
|
||||
: (ref $val eq $type_check
|
||||
|| ($val && $val eq $type_check)
|
||||
|| (exists $TYPES{$type_check} && $TYPES{$type_check}->($val)))
|
||||
)
|
||||
|| Carp::confess(
|
||||
qq<Attribute ($attribute) does not pass the type constraint because: >
|
||||
. qq<Validation failed for '$check_name' with value >
|
||||
. (defined $val ? Lmo::Dumper($val) : 'undef') )
|
||||
}
|
||||
|
||||
sub _nested_constraints {
|
||||
my ($attribute, $aggregate_type, $type) = @_;
|
||||
|
||||
my $inner_types;
|
||||
if ( $type =~ /\A(ArrayRef|Maybe)\[(.*)\]\z/ ) {
|
||||
$inner_types = _nested_constraints($1, $2);
|
||||
}
|
||||
else {
|
||||
$inner_types = $TYPES{$type};
|
||||
}
|
||||
|
||||
if ( $aggregate_type eq 'ArrayRef' ) {
|
||||
return sub {
|
||||
my ($val) = @_;
|
||||
return unless ref($val) eq ref([]);
|
||||
|
||||
if ($inner_types) {
|
||||
for my $value ( @{$val} ) {
|
||||
return unless $inner_types->($value)
|
||||
}
|
||||
}
|
||||
else {
|
||||
for my $value ( @{$val} ) {
|
||||
return unless $value && ($value eq $type
|
||||
|| (Scalar::Util::blessed($value) && $value->isa($type)));
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
elsif ( $aggregate_type eq 'Maybe' ) {
|
||||
return sub {
|
||||
my ($value) = @_;
|
||||
return 1 if ! defined($value);
|
||||
if ($inner_types) {
|
||||
return unless $inner_types->($value)
|
||||
}
|
||||
else {
|
||||
return unless $value eq $type
|
||||
|| (Scalar::Util::blessed($value) && $value->isa($type));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Carp::confess("Nested aggregate types are only implemented for ArrayRefs and Maybe");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
}
|
||||
# ###########################################################################
|
||||
# End Lmo::Types package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# Lmo package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the GitHub repository at,
|
||||
# lib/Lmo.pm
|
||||
# t/lib/Lmo.t
|
||||
# See https://github.com/percona/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
{
|
||||
BEGIN {
|
||||
$INC{"Lmo.pm"} = __FILE__;
|
||||
package Lmo;
|
||||
our $VERSION = '0.30_Percona'; # Forked from 0.30 of Mo.
|
||||
|
||||
|
||||
use strict;
|
||||
use warnings qw( FATAL all );
|
||||
|
||||
use Carp ();
|
||||
use Scalar::Util qw(looks_like_number blessed);
|
||||
|
||||
use Lmo::Meta;
|
||||
use Lmo::Object;
|
||||
use Lmo::Types;
|
||||
|
||||
use Lmo::Utils;
|
||||
|
||||
my %export_for;
|
||||
sub import {
|
||||
warnings->import(qw(FATAL all));
|
||||
strict->import();
|
||||
|
||||
my $caller = scalar caller(); # Caller's package
|
||||
my %exports = (
|
||||
extends => \&extends,
|
||||
has => \&has,
|
||||
with => \&with,
|
||||
override => \&override,
|
||||
confess => \&Carp::confess,
|
||||
);
|
||||
|
||||
$export_for{$caller} = \%exports;
|
||||
|
||||
for my $keyword ( keys %exports ) {
|
||||
_install_coderef "${caller}::$keyword" => $exports{$keyword};
|
||||
}
|
||||
|
||||
if ( !@{ *{ _glob_for "${caller}::ISA" }{ARRAY} || [] } ) {
|
||||
@_ = "Lmo::Object";
|
||||
goto *{ _glob_for "${caller}::extends" }{CODE};
|
||||
}
|
||||
}
|
||||
|
||||
sub extends {
|
||||
my $caller = scalar caller();
|
||||
for my $class ( @_ ) {
|
||||
_load_module($class);
|
||||
}
|
||||
_set_package_isa($caller, @_);
|
||||
_set_inherited_metadata($caller);
|
||||
}
|
||||
|
||||
sub _load_module {
|
||||
my ($class) = @_;
|
||||
|
||||
(my $file = $class) =~ s{::|'}{/}g;
|
||||
$file .= '.pm';
|
||||
{ local $@; eval { require "$file" } } # or warn $@;
|
||||
return;
|
||||
}
|
||||
|
||||
sub with {
|
||||
my $package = scalar caller();
|
||||
require Role::Tiny;
|
||||
for my $role ( @_ ) {
|
||||
_load_module($role);
|
||||
_role_attribute_metadata($package, $role);
|
||||
}
|
||||
Role::Tiny->apply_roles_to_package($package, @_);
|
||||
}
|
||||
|
||||
sub _role_attribute_metadata {
|
||||
my ($package, $role) = @_;
|
||||
|
||||
my $package_meta = Lmo::Meta->metadata_for($package);
|
||||
my $role_meta = Lmo::Meta->metadata_for($role);
|
||||
|
||||
%$package_meta = (%$role_meta, %$package_meta);
|
||||
}
|
||||
|
||||
sub has {
|
||||
my $names = shift;
|
||||
my $caller = scalar caller();
|
||||
|
||||
my $class_metadata = Lmo::Meta->metadata_for($caller);
|
||||
|
||||
for my $attribute ( ref $names ? @$names : $names ) {
|
||||
my %args = @_;
|
||||
my $method = ($args{is} || '') eq 'ro'
|
||||
? sub {
|
||||
Carp::confess("Cannot assign a value to a read-only accessor at reader ${caller}::${attribute}")
|
||||
if $#_;
|
||||
return $_[0]{$attribute};
|
||||
}
|
||||
: sub {
|
||||
return $#_
|
||||
? $_[0]{$attribute} = $_[1]
|
||||
: $_[0]{$attribute};
|
||||
};
|
||||
|
||||
$class_metadata->{$attribute} = ();
|
||||
|
||||
if ( my $type_check = $args{isa} ) {
|
||||
my $check_name = $type_check;
|
||||
|
||||
if ( my ($aggregate_type, $inner_type) = $type_check =~ /\A(ArrayRef|Maybe)\[(.*)\]\z/ ) {
|
||||
$type_check = Lmo::Types::_nested_constraints($attribute, $aggregate_type, $inner_type);
|
||||
}
|
||||
|
||||
my $check_sub = sub {
|
||||
my ($new_val) = @_;
|
||||
Lmo::Types::check_type_constraints($attribute, $type_check, $check_name, $new_val);
|
||||
};
|
||||
|
||||
$class_metadata->{$attribute}{isa} = [$check_name, $check_sub];
|
||||
my $orig_method = $method;
|
||||
$method = sub {
|
||||
$check_sub->($_[1]) if $#_;
|
||||
goto &$orig_method;
|
||||
};
|
||||
}
|
||||
|
||||
if ( my $builder = $args{builder} ) {
|
||||
my $original_method = $method;
|
||||
$method = sub {
|
||||
$#_
|
||||
? goto &$original_method
|
||||
: ! exists $_[0]{$attribute}
|
||||
? $_[0]{$attribute} = $_[0]->$builder
|
||||
: goto &$original_method
|
||||
};
|
||||
}
|
||||
|
||||
if ( my $code = $args{default} ) {
|
||||
Carp::confess("${caller}::${attribute}'s default is $code, but should be a coderef")
|
||||
unless ref($code) eq 'CODE';
|
||||
my $original_method = $method;
|
||||
$method = sub {
|
||||
$#_
|
||||
? goto &$original_method
|
||||
: ! exists $_[0]{$attribute}
|
||||
? $_[0]{$attribute} = $_[0]->$code
|
||||
: goto &$original_method
|
||||
};
|
||||
}
|
||||
|
||||
if ( my $role = $args{does} ) {
|
||||
my $original_method = $method;
|
||||
$method = sub {
|
||||
if ( $#_ ) {
|
||||
Carp::confess(qq<Attribute ($attribute) doesn't consume a '$role' role">)
|
||||
unless Scalar::Util::blessed($_[1]) && eval { $_[1]->does($role) }
|
||||
}
|
||||
goto &$original_method
|
||||
};
|
||||
}
|
||||
|
||||
if ( my $coercion = $args{coerce} ) {
|
||||
$class_metadata->{$attribute}{coerce} = $coercion;
|
||||
my $original_method = $method;
|
||||
$method = sub {
|
||||
if ( $#_ ) {
|
||||
return $original_method->($_[0], $coercion->($_[1]))
|
||||
}
|
||||
goto &$original_method;
|
||||
}
|
||||
}
|
||||
|
||||
_install_coderef "${caller}::$attribute" => $method;
|
||||
|
||||
if ( $args{required} ) {
|
||||
$class_metadata->{$attribute}{required} = 1;
|
||||
}
|
||||
|
||||
if ($args{clearer}) {
|
||||
_install_coderef "${caller}::$args{clearer}"
|
||||
=> sub { delete shift->{$attribute} }
|
||||
}
|
||||
|
||||
if ($args{predicate}) {
|
||||
_install_coderef "${caller}::$args{predicate}"
|
||||
=> sub { exists shift->{$attribute} }
|
||||
}
|
||||
|
||||
if ($args{handles}) {
|
||||
_has_handles($caller, $attribute, \%args);
|
||||
}
|
||||
|
||||
if (exists $args{init_arg}) {
|
||||
$class_metadata->{$attribute}{init_arg} = $args{init_arg};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub _has_handles {
|
||||
my ($caller, $attribute, $args) = @_;
|
||||
my $handles = $args->{handles};
|
||||
|
||||
my $ref = ref $handles;
|
||||
my $kv;
|
||||
if ( $ref eq ref [] ) {
|
||||
$kv = { map { $_,$_ } @{$handles} };
|
||||
}
|
||||
elsif ( $ref eq ref {} ) {
|
||||
$kv = $handles;
|
||||
}
|
||||
elsif ( $ref eq ref qr// ) {
|
||||
Carp::confess("Cannot delegate methods based on a Regexp without a type constraint (isa)")
|
||||
unless $args->{isa};
|
||||
my $target_class = $args->{isa};
|
||||
$kv = {
|
||||
map { $_, $_ }
|
||||
grep { $_ =~ $handles }
|
||||
grep { !exists $Lmo::Object::{$_} && $target_class->can($_) }
|
||||
grep { !$export_for{$target_class}->{$_} }
|
||||
keys %{ _stash_for $target_class }
|
||||
};
|
||||
}
|
||||
else {
|
||||
Carp::confess("handles for $ref not yet implemented");
|
||||
}
|
||||
|
||||
while ( my ($method, $target) = each %{$kv} ) {
|
||||
my $name = _glob_for "${caller}::$method";
|
||||
Carp::confess("You cannot overwrite a locally defined method ($method) with a delegation")
|
||||
if defined &$name;
|
||||
|
||||
my ($target, @curried_args) = ref($target) ? @$target : $target;
|
||||
*$name = sub {
|
||||
my $self = shift;
|
||||
my $delegate_to = $self->$attribute();
|
||||
my $error = "Cannot delegate $method to $target because the value of $attribute";
|
||||
Carp::confess("$error is not defined") unless $delegate_to;
|
||||
Carp::confess("$error is not an object (got '$delegate_to')")
|
||||
unless Scalar::Util::blessed($delegate_to) || (!ref($delegate_to) && $delegate_to->can($target));
|
||||
return $delegate_to->$target(@curried_args, @_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub _set_package_isa {
|
||||
my ($package, @new_isa) = @_;
|
||||
my $package_isa = \*{ _glob_for "${package}::ISA" };
|
||||
@{*$package_isa} = @new_isa;
|
||||
}
|
||||
|
||||
sub _set_inherited_metadata {
|
||||
my $class = shift;
|
||||
my $class_metadata = Lmo::Meta->metadata_for($class);
|
||||
my $linearized_isa = mro::get_linear_isa($class);
|
||||
my %new_metadata;
|
||||
|
||||
for my $isa_class (reverse @$linearized_isa) {
|
||||
my $isa_metadata = Lmo::Meta->metadata_for($isa_class);
|
||||
%new_metadata = (
|
||||
%new_metadata,
|
||||
%$isa_metadata,
|
||||
);
|
||||
}
|
||||
%$class_metadata = %new_metadata;
|
||||
}
|
||||
|
||||
sub unimport {
|
||||
my $caller = scalar caller();
|
||||
my $target = caller;
|
||||
_unimport_coderefs($target, keys %{$export_for{$caller}});
|
||||
}
|
||||
|
||||
sub Dumper {
|
||||
require Data::Dumper;
|
||||
local $Data::Dumper::Indent = 0;
|
||||
local $Data::Dumper::Sortkeys = 0;
|
||||
local $Data::Dumper::Quotekeys = 0;
|
||||
local $Data::Dumper::Terse = 1;
|
||||
|
||||
Data::Dumper::Dumper(@_)
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
if ($] >= 5.010) {
|
||||
{ local $@; require mro; }
|
||||
}
|
||||
else {
|
||||
local $@;
|
||||
eval {
|
||||
require MRO::Compat;
|
||||
} or do {
|
||||
*mro::get_linear_isa = *mro::get_linear_isa_dfs = sub {
|
||||
no strict 'refs';
|
||||
|
||||
my $classname = shift;
|
||||
|
||||
my @lin = ($classname);
|
||||
my %stored;
|
||||
foreach my $parent (@{"$classname\::ISA"}) {
|
||||
my $plin = mro::get_linear_isa_dfs($parent);
|
||||
foreach (@$plin) {
|
||||
next if exists $stored{$_};
|
||||
push(@lin, $_);
|
||||
$stored{$_} = 1;
|
||||
}
|
||||
}
|
||||
return \@lin;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub override {
|
||||
my ($methods, $code) = @_;
|
||||
my $caller = scalar caller;
|
||||
|
||||
for my $method ( ref($methods) ? @$methods : $methods ) {
|
||||
my $full_method = "${caller}::${method}";
|
||||
*{_glob_for $full_method} = $code;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1;
|
||||
}
|
||||
# ###########################################################################
|
||||
# End Lmo package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# VersionParser package
|
||||
# This package is a copy without comments from the original. The original
|
||||
|
@@ -465,6 +465,7 @@ sub is_cluster_node {
|
||||
sub can_load_data {
|
||||
my ($self, $server) = @_;
|
||||
my $output = $self->use($server, q{-e "SELECT * FROM percona_test.load_data"});
|
||||
#die(0 =~ /1/);
|
||||
return ($output || '') =~ /1/;
|
||||
}
|
||||
|
||||
|
@@ -40,3 +40,6 @@ binlog_format = STATEMENT
|
||||
#performance-schema-instrument='wait/lock/metadata/sql/mdl=ON'
|
||||
#performance-schema-instrument='transaction=ON'
|
||||
secure-file-priv =
|
||||
|
||||
# wait_for_replica buggy on multi-threaded replica
|
||||
slave-parallel-workers=0
|
||||
|
@@ -40,3 +40,6 @@ binlog_format = STATEMENT
|
||||
#performance-schema-instrument='wait/lock/metadata/sql/mdl=ON'
|
||||
#performance-schema-instrument='transaction=ON'
|
||||
secure-file-priv =
|
||||
|
||||
# wait_for_replica buggy on multi-threaded replica
|
||||
replica-parallel-workers=0
|
||||
|
@@ -251,6 +251,7 @@ like(
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_DELAY=0");
|
||||
$source_dbh->do("RESET ${source_reset}");
|
||||
$replica1_dbh->do("RESET ${replica_name}");
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
|
@@ -398,6 +398,7 @@ $replica_dbh2 = $sb->get_dbh_for('replica2');
|
||||
diag("Setting replica delay to 0 seconds");
|
||||
$replica_dbh1->do("STOP ${replica_name}");
|
||||
$replica_dbh2->do("STOP ${replica_name}");
|
||||
$replica_dbh1->do("CHANGE ${source_change} TO ${source_name}_DELAY=0");
|
||||
$source_dbh->do("RESET ${source_reset}");
|
||||
$replica_dbh1->do("RESET ${source_reset}");
|
||||
$replica_dbh1->do("RESET ${replica_name}");
|
||||
|
@@ -162,6 +162,7 @@ $replica_dbh2 = $sb->get_dbh_for('replica2');
|
||||
diag("Setting replica delay to 0 seconds");
|
||||
$replica_dbh1->do("STOP ${replica_name}");
|
||||
$replica_dbh2->do("STOP ${replica_name}");
|
||||
$replica_dbh1->do("CHANGE ${source_change} TO ${source_name}_DELAY=0");
|
||||
$source_dbh->do("RESET ${source_reset}");
|
||||
$replica_dbh1->do("RESET ${replica_name}");
|
||||
$replica_dbh2->do("RESET ${replica_name}");
|
||||
|
@@ -328,6 +328,7 @@ $replica_dbh2 = $sb->get_dbh_for('replica2');
|
||||
diag("Setting replica delay to 0 seconds");
|
||||
$replica_dbh1->do("STOP ${replica_name}");
|
||||
$replica_dbh2->do("STOP ${replica_name}");
|
||||
$replica_dbh1->do("CHANGE ${source_change} TO ${source_name}_DELAY=0");
|
||||
$source_dbh->do("RESET ${source_reset}");
|
||||
$replica_dbh1->do("RESET ${replica_name}");
|
||||
$replica_dbh2->do("RESET ${replica_name}");
|
||||
|
@@ -98,6 +98,8 @@ unlike(
|
||||
diag("Setting replica delay to 0 seconds");
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica2_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_DELAY=0");
|
||||
$replica2_dbh->do("CHANGE ${source_change} TO ${source_name}_DELAY=0");
|
||||
$source_dbh->do("RESET ${source_reset}");
|
||||
$replica1_dbh->do("RESET ${replica_name}");
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
|
@@ -354,6 +354,7 @@ $sb->do_as_root("source", q/FLUSH TABLES/);
|
||||
|
||||
diag("Setting replica delay to 0 seconds");
|
||||
$replica_dbh->do("STOP ${replica_name}");
|
||||
$replica_dbh->do("CHANGE ${source_change} TO ${source_name}_DELAY=0");
|
||||
$source_dbh->do("RESET ${source_reset}");
|
||||
$replica_dbh->do("RESET ${replica_name}");
|
||||
$replica_dbh->do("START ${replica_name}");
|
||||
|
@@ -104,7 +104,7 @@ unlike(
|
||||
$output,
|
||||
qr/Cannot checksum table/,
|
||||
"Very small --chunk-time doesn't cause zero --chunk-size"
|
||||
);
|
||||
) or diag($output);
|
||||
}
|
||||
# #############################################################################
|
||||
# Bug 921700: pt-table-checksum doesn't add --where to chunk-oversize test
|
||||
|
@@ -12,7 +12,7 @@ use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
#if ( !$ENV{SLOW_TESTS} ) {
|
||||
# plan skip_all => "pt-table-checksum/replication_filters.t is one of the top slowest files; set SLOW_TESTS=1 to enable it.";
|
||||
# plan skip_all => "pt-table-checksum/pt-1616.t is one of the top slowest files; set SLOW_TESTS=1 to enable it.";
|
||||
#}
|
||||
|
||||
use PerconaTest;
|
||||
@@ -23,6 +23,8 @@ require "$trunk/bin/pt-table-checksum";
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $dbh = $sb->get_dbh_for('source');
|
||||
my $replica1_dbh = $sb->get_dbh_for('replica1');
|
||||
my $replica2_dbh = $sb->get_dbh_for('replica2');
|
||||
|
||||
if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox source';
|
||||
@@ -104,6 +106,18 @@ unlike(
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
diag("Resetting replicas, because this test sporadically fails");
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica2_dbh->do("STOP ${replica_name}");
|
||||
$dbh->do("RESET ${source_reset}");
|
||||
$replica1_dbh->do("RESET ${replica_name}");
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
$replica2_dbh->do("RESET ${replica_name}");
|
||||
$replica2_dbh->do("START ${replica_name}");
|
||||
|
||||
diag("Replicas reset, syncing");
|
||||
$sb->wait_for_replicas();
|
||||
diag("Cleaning up");
|
||||
$sb->wipe_clean($dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
exit;
|
||||
|
@@ -127,7 +127,7 @@ is_deeply(
|
||||
[qw( sakila city )],
|
||||
],
|
||||
"Checksum results for 1/4 of sakila singles"
|
||||
);
|
||||
) or diag(Dumper($row));
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args, qw(-d sakila --resume --chunk-size 10000)) },
|
||||
|
@@ -49,7 +49,7 @@ like(
|
||||
$output,
|
||||
qr/#\s+0\s+4\s+0\s+0\s+Chunk\s+/,
|
||||
"Chunks char col"
|
||||
);
|
||||
) or diag($output);
|
||||
like(
|
||||
$output,
|
||||
qr/FORCE INDEX \(`c`\)/,
|
||||
|
@@ -61,7 +61,7 @@ is(
|
||||
REPLACE INTO `issue_375`.`t`(`id`, `updated_at`, `foo`) VALUES ('100', '2009-09-06 15:01:23', 'cv');
|
||||
",
|
||||
'Simple --replicate'
|
||||
);
|
||||
) or diag($output);
|
||||
|
||||
# Note how the columns are out of order (tbl order is: id, updated_at, foo).
|
||||
# This is issue http://code.google.com/p/maatkit/issues/detail?id=371
|
||||
|
@@ -10,6 +10,7 @@ use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
use POSIX ":sys_wait_h";
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
@@ -38,26 +39,36 @@ else {
|
||||
plan tests => 3;
|
||||
}
|
||||
|
||||
diag("OK\n");
|
||||
|
||||
$sb->load_file('source', "t/pt-table-sync/samples/pt-1205.sql");
|
||||
diag("OK 2\n");
|
||||
$sb->wait_for_replicas();
|
||||
|
||||
diag("OK 3\n");
|
||||
|
||||
# Setting up tunnels
|
||||
my $pid1 = fork();
|
||||
|
||||
if ( !$pid1 ) {
|
||||
setpgrp;
|
||||
system('ncat -k -l localhost 3333 --sh-exec "ncat 127.0.0.1 12345"');
|
||||
system('ncat -k -l localhost 33333 --sh-exec "ncat 127.0.0.1 12345"');
|
||||
diag("OK 4\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
diag("OK 5\n");
|
||||
|
||||
my $pid2 = fork();
|
||||
|
||||
if ( !$pid2 ) {
|
||||
setpgrp;
|
||||
system('ncat -k -l localhost 3334 --sh-exec "ncat 127.0.0.1 12346"');
|
||||
system('ncat -k -l localhost 33334 --sh-exec "ncat 127.0.0.1 12346"');
|
||||
diag("OK 6\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
diag("OK 7\n");
|
||||
my $o = new OptionParser();
|
||||
my $q = new Quoter();
|
||||
my $ms = new MasterSlave(
|
||||
@@ -67,28 +78,35 @@ my $ms = new MasterSlave(
|
||||
);
|
||||
my $ss = $ms->get_replica_status($replica1_dbh);
|
||||
|
||||
diag("OK 8\n");
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_PORT=3333, ${source_name}_LOG_POS=" . $ss->{"exec_${source_name}_log_pos"});
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_PORT=33333, ${source_name}_LOG_POS=" . $ss->{"exec_${source_name}_log_pos"});
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
|
||||
my $output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=3334,u=msandbox,p=msandbox --database=test --table=t1 --sync-to-source --execute --verbose 2>&1`;
|
||||
diag("OK 9\n");
|
||||
my $output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=33334,u=msandbox,p=msandbox --database=test --table=t1 --sync-to-source --execute --verbose 2>&1`;
|
||||
|
||||
diag("OK 10\n");
|
||||
unlike(
|
||||
$output,
|
||||
qr/The replica is connected to \d+ but the source's port is/,
|
||||
'No error for redirected replica'
|
||||
) or diag($output);
|
||||
|
||||
diag("OK 11\n");
|
||||
kill -1, getpgrp($pid1);
|
||||
kill -1, getpgrp($pid2);
|
||||
|
||||
diag("OK 12\n");
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$ss = $ms->get_replica_status($replica1_dbh);
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_PORT=12347, ${source_name}_LOG_POS=" . $ss->{"exec_${source_name}_log_pos"});
|
||||
$replica1_dbh->do("START ${replica_name} SQL_THREAD");
|
||||
|
||||
diag("OK 13\n");
|
||||
$output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=12346,u=msandbox,p=msandbox --database=test --table=t1 --sync-to-source --execute --verbose 2>&1`;
|
||||
|
||||
diag("OK 14\n");
|
||||
like(
|
||||
$output,
|
||||
qr/The server specified as a source has no connected replicas/,
|
||||
@@ -98,9 +116,12 @@ like(
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_PORT=12345, ${source_name}_LOG_POS=" . $ss->{"exec_${source_name}_log_pos"});
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
diag("OK 15\n");
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($source_dbh);
|
||||
diag("OK 16\n");
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
diag("OK 17\n");
|
||||
exit;
|
||||
|
@@ -146,9 +146,8 @@ like(
|
||||
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_port=12345, ${source_name}_user='msandbox'");
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_port=12345, ${source_name}_user='msandbox'");
|
||||
$source_dbh->do("RESET ${source_reset}");
|
||||
$replica1_dbh->do("RESET ${replica_name}");
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
|
||||
# #############################################################################
|
||||
|
@@ -60,7 +60,7 @@ my $t = time - $t0;
|
||||
|
||||
ok(
|
||||
$t >= 3 && $t <= ($ENV{PERCONA_SLOW_BOX} ? 8 : 6),
|
||||
"Exec queries: ran for roughly --run-time seconds"
|
||||
"Exec queries: ran for roughly 3 seconds"
|
||||
) or diag($output, 'Actual run time:', $t);
|
||||
|
||||
# Exit status 8 = --run-time expired (an no other errors/problems)
|
||||
|
Reference in New Issue
Block a user