Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-2378 - extended FP precision in pt-table-sync #863

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bin/pt-archiver
Original file line number Diff line number Diff line change
Expand Up @@ -2993,7 +2993,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-deadlock-logger
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-duplicate-key-checker
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-find
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-fk-error-logger
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-heartbeat
Original file line number Diff line number Diff line change
Expand Up @@ -3564,7 +3564,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-index-usage
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-kill
Original file line number Diff line number Diff line change
Expand Up @@ -4905,7 +4905,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-online-schema-change
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-query-digest
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-replica-restart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-table-checksum
Original file line number Diff line number Diff line change
Expand Up @@ -4134,7 +4134,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-table-sync
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-table-usage
Original file line number Diff line number Diff line change
Expand Up @@ -6680,7 +6680,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion bin/pt-upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,15 @@ sub quote_val {
return $val if $val =~ m/^0x[0-9a-fA-F]+$/ # quote hex data
&& !$args{is_char}; # unless is_char is true

return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

$val =~ s/(['\\])/\\$1/g;
return "'$val'";
Expand Down
10 changes: 9 additions & 1 deletion lib/Quoter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ sub quote_val {
&& !$args{is_char}; # unless is_char is true

# https://bugs.launchpad.net/percona-toolkit/+bug/1229861
return $val if $args{is_float};
if ( $args{is_float} ) {
my $serialization_error = $val - "$val";
if ( $serialization_error != 0 ) {
return sprintf("%.17g", $val);
}
else {
return $val;
}
}

# Quote and return non-numeric vals.
$val =~ s/(['\\])/\\$1/g;
Expand Down
2 changes: 2 additions & 0 deletions t/lib/Quoter.t
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ is( $q->quote_val('0x89504E470', is_char => 0), '0x89504E470', 'hex string, with
is( $q->quote_val('0x89504E470', is_char => 1), "'0x89504E470'", 'hex string, with is_char => 1');
is( $q->quote_val('0x89504I470'), "'0x89504I470'", 'looks like hex string');
is( $q->quote_val('eastside0x3'), "'eastside0x3'", 'looks like hex str (issue 1110');
is( $q->quote_val(969.1 / 360, is_float => 1), "2.6919444444444447", 'float has full precision');
is( $q->quote_val(0.1, is_float => 1), "0.1", 'full precision for float only used when required');

# Splitting DB and tbl apart
is_deeply(
Expand Down
18 changes: 17 additions & 1 deletion t/pt-table-sync/float_precision.t
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ is(
'--float-precision so no more diff (issue 410)'
);

# Although the SQL statement contains serialized values with more than necessary decimal digits
# we produce the expected value on execution
$output = `$trunk/bin/pt-table-sync --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=fl --execute 2>&1`;
is(
$output,
'',
'REPLACE statement can be successfully applied'
);

$sb->wait_for_replicas();
my @rows = $replica_dbh->selectrow_array('SELECT `d` FROM `test`.`fl` WHERE `d` = 2.0000012');
is_deeply(
\@rows,
[2.0000012],
'Floating point values are set correctly in round trip'
);

# #############################################################################
# pt-table-sync quotes floats, prevents syncing
# https://bugs.launchpad.net/percona-toolkit/+bug/1229861
Expand All @@ -86,7 +103,6 @@ is_deeply(
[],
"Sync rows with float values (bug 1229861)"
) or diag(Dumper($rows), $output);

# #############################################################################
# Done.
# #############################################################################
Expand Down
Loading