PT-1205 - LP #1275034: pt-table-sync reports 'wide character in print' and terminates

- Added binmode :utf8 for STDERR
- Added test case for PT-1205
- Run update-modules
This commit is contained in:
Sveta Smirnova
2024-03-22 00:37:07 +03:00
parent 1ad44e04da
commit 37ca3d2d49
23 changed files with 124 additions and 2 deletions

View File

@@ -2604,6 +2604,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2150,6 +2150,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2494,6 +2494,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -991,6 +991,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -382,6 +382,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -1648,6 +1648,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -3029,6 +3029,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -392,6 +392,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2154,6 +2154,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2404,6 +2404,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -1060,6 +1060,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -1426,6 +1426,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2147,6 +2147,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2082,6 +2082,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2493,6 +2493,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -1695,6 +1695,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2315,6 +2315,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -1057,6 +1057,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -2151,6 +2151,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -370,6 +370,8 @@ sub get_dbh {
if ( $charset && $charset =~ m/^utf8/ ) {
binmode(STDOUT, ':utf8')
or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR";
binmode(STDERR, ':utf8')
or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR";
}
else {
binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR";

View File

@@ -53,13 +53,13 @@ like(
$output,
qr/😜/,
'Smiley character successfully printed in the output'
);
) or diag($output);
unlike(
$output,
qr/Wide character in print at/,
'Smiley character did not cause error'
);
) or diag($output);
# #############################################################################
# Done.

70
t/pt-table-sync/pt-1205.t Normal file
View File

@@ -0,0 +1,70 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;
use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-table-sync";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $master_dbh = $sb->get_dbh_for('master');
my $slave1_dbh = $sb->get_dbh_for('slave1');
my $slave2_dbh = $sb->get_dbh_for('slave2');
if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
elsif ( !$slave1_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave1';
}
elsif ( !$slave1_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave2';
}
else {
plan tests => 3;
}
$sb->load_file('master', "t/pt-table-sync/samples/pt-1205.sql");
$sb->wait_for_slaves();
$slave1_dbh->do("DELETE FROM test.t1 LIMIT 3");
# Save original PTDEBUG env because we modify it below.
my $dbg = $ENV{PTDEBUG};
$ENV{PTDEBUG} = 1;
my $output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=t1,A=utf8 --sync-to-master --execute --verbose --function=MD5 2>&1`;
unlike(
$output,
qr/Wide character in print at/,
'Error "Wide character in print at" is not printed for the smiley character'
) or diag($output);
like(
$output,
qr/😜/,
'Smiley character succesfully printed to STDERR'
) or diag($output);
# Restore PTDEBUG env.
delete $ENV{PTDEBUG};
$ENV{PTDEBUG} = $dbg || 0;
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;

View File

@@ -0,0 +1,12 @@
DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;
create table t1(
id int not null auto_increment primary key,
f1 varchar(10)
);
insert into t1(f1) values('😜');
insert into t1(f1) select f1 from t1;
insert into t1(f1) select f1 from t1;
insert into t1(f1) select f1 from t1;