From 091d9cf66db72edae5c232faf6661d420244c86f Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 7 Nov 2012 11:38:09 -0700 Subject: [PATCH] Print/save fk errors only if there is one. Fix example --dest table (bug 1075775). --- bin/pt-fk-error-logger | 27 +++++++++++++++------------ t/pt-fk-error-logger/basics.t | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/bin/pt-fk-error-logger b/bin/pt-fk-error-logger index b39fef27..2d71ccc1 100755 --- a/bin/pt-fk-error-logger +++ b/bin/pt-fk-error-logger @@ -3534,20 +3534,23 @@ sub main { { my $text = $dbh->selectrow_hashref("SHOW /*!40100 ENGINE*/ INNODB STATUS")->{Status}; my ($ts, $fk_error) = get_fk_error($text); + PTDEBUG && _d('ts:', $ts, 'fk error:', $fk_error); - # Save and/or print the foreign key error. - if ( $ins_sth ) { - my $fk_ts = parse_timestamp($ts); - PTDEBUG && _d('Saving fk error', $ts, $fk_error); - eval { - $ins_sth->execute($fk_ts, $fk_error); - }; - if ( $EVAL_ERROR ) { - warn $EVAL_ERROR; - PTDEBUG && _d($EVAL_ERROR); + if ( $ts && $fk_error ) { + # Save and/or print the foreign key error. + if ( $ins_sth ) { + my $fk_ts = parse_timestamp($ts); + PTDEBUG && _d('Saving fk error', $ts, $fk_error); + eval { + $ins_sth->execute($fk_ts, $fk_error); + }; + if ( $EVAL_ERROR ) { + warn $EVAL_ERROR; + PTDEBUG && _d($EVAL_ERROR); + } } + print "$ts $fk_error\n\n" if $o->get('print') || !$o->got('dest'); } - print "$ts $fk_error\n\n" if $o->get('print') || !$o->got('dest'); # If there's an --interval argument, run forever or till specified. # Otherwise just run once. @@ -3727,7 +3730,7 @@ The following table is suggested: CREATE TABLE foreign_key_errors ( ts datetime NOT NULL, error text NOT NULL, - PRIMARY KEY (ts), + PRIMARY KEY (ts) ) The only information saved is the timestamp and the foreign key error text. diff --git a/t/pt-fk-error-logger/basics.t b/t/pt-fk-error-logger/basics.t index cce57da3..58cadbdc 100644 --- a/t/pt-fk-error-logger/basics.t +++ b/t/pt-fk-error-logger/basics.t @@ -136,7 +136,7 @@ $output = output( is( $output, "", - "No foreign key errors, no errors and no output (bug 1075773)" + "No foreign key errors, no errors, no output (bug 1075773)" ); diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);