Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Write some of most important error messages to STDERR
  • Loading branch information
elenst committed Jul 15, 2018
1 parent f668b0a commit 6d5a76e
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 36 deletions.
2 changes: 2 additions & 0 deletions combinations.pl
Expand Up @@ -33,6 +33,8 @@
use File::Basename;
use File::Path qw(make_path);

$| = 1;

if (defined $ENV{RQG_HOME}) {
if (osWindows()) {
$ENV{RQG_HOME} = $ENV{RQG_HOME}.'\\';
Expand Down
23 changes: 22 additions & 1 deletion lib/DBServer/DBServer.pm
Expand Up @@ -19,7 +19,7 @@
package DBServer::DBServer;
use base 'Exporter';

@EXPORT = ('say', 'sayFile', 'tmpdir', 'safe_exit',
@EXPORT = ('say', 'sayError', 'sayFile', 'tmpdir', 'safe_exit',
'osWindows', 'osLinux', 'osSolaris', 'osMac',
'isoTimestamp', 'isoUTCTimestamp',
'DBSTATUS_OK','DBSTATUS_FAILURE');
Expand Down Expand Up @@ -115,6 +115,27 @@ sub say {
}
}

sub sayError {
my $text = shift;
defaultLogging();
if ($text =~ m{[\r\n]}sio) {
foreach my $line (split (m{[\r\n]}, $text)) {
if (defined $logger) {
$logger->error("[$$] ".$line);
} else {
print "# ".isoTimestamp()." [$$][ERROR] $line\n";
}
}
} else {
if (defined $logger) {
$logger->error("[$$] ".$text);
} else {
print "# ".isoTimestamp()." [$$][ERROR] $text\n";
}
}
}


sub sayFile {
my ($file) = @_;

Expand Down
14 changes: 7 additions & 7 deletions lib/DBServer/MySQL/MySQLd.pm
Expand Up @@ -521,7 +521,7 @@ sub startServer {
my $errlog_fh;
my $errlog_last_update_time= (stat($errorlog))[9] || 0;
if ($errlog_last_update_time) {
open($errlog_fh,$errorlog) || ( say("ERROR: could not open the error log " . $errorlog . " for initial read: $!") && return DBSTATUS_FAILURE );
open($errlog_fh,$errorlog) || ( sayError("Could not open the error log " . $errorlog . " for initial read: $!") && return DBSTATUS_FAILURE );
while (!eof($errlog_fh)) { readline $errlog_fh };
seek $errlog_fh, 0, 1;
}
Expand Down Expand Up @@ -557,7 +557,7 @@ sub startServer {
$pid= get_pid_from_file($self->pidfile);
say("Server created pid file with pid $pid");
} elsif (!$errlog_update) {
say("ERROR: server has not started updating the error log withing $start_wait_timeout sec. timeout, and has not created pid file");
sayError("Server has not started updating the error log withing $start_wait_timeout sec. timeout, and has not created pid file");
sayFile($errorlog);
return DBSTATUS_FAILURE;
}
Expand All @@ -573,7 +573,7 @@ sub startServer {

unless ($errlog_fh) {
unless (open($errlog_fh, $errorlog)) {
say("ERROR: could not open the error log " . $errorlog . ": $!");
sayError("Could not open the error log " . $errorlog . ": $!");
return DBSTATUS_FAILURE;
}
}
Expand Down Expand Up @@ -623,12 +623,12 @@ sub startServer {
if (!-f $self->pidfile) {
sayFile($errorlog);
if ($pid and not kill(0, $pid)) {
say("ERROR: server disappeared after having started with pid $pid");
sayError("Server disappeared after having started with pid $pid");
} elsif ($pid) {
say("ERROR: timeout $startup_timeout has passed and the server still has not created the pid file, assuming it has hung, sending final SIGABRT to pid $pid...");
sayError("Timeout $startup_timeout has passed and the server still has not created the pid file, assuming it has hung, sending final SIGABRT to pid $pid...");
kill 'ABRT', $pid;
} else {
say("ERROR: timeout $startup_timeout has passed and the server still has not created the pid file, assuming it has hung, but cannot kill because we don't know the pid");
sayError("Timeout $startup_timeout has passed and the server still has not created the pid file, assuming it has hung, but cannot kill because we don't know the pid");
}
return DBSTATUS_FAILURE;
}
Expand Down Expand Up @@ -890,7 +890,7 @@ sub dbh {
mysql_auto_reconnect => 1});
}
if(!defined $self->[MYSQLD_DBH]) {
say("ERROR: (Re)connect to ".$self->[MYSQLD_PORT]." failed due to ".$DBI::err.": ".$DBI::errstr);
sayError("(Re)connect to ".$self->[MYSQLD_PORT]." failed due to ".$DBI::err.": ".$DBI::errstr);
}
return $self->[MYSQLD_DBH];
}
Expand Down
8 changes: 4 additions & 4 deletions lib/DBServer/MySQL/ReplMySQLd.pm
Expand Up @@ -233,11 +233,11 @@ sub startServer {
sub waitForSlaveSync {
my ($self) = @_;
if (! $self->master->dbh) {
say("ERROR: Could not connect to master");
sayError("Could not connect to master");
return DBSTATUS_FAILURE;
}
if (! $self->slave->dbh) {
say("ERROR: Could not connect to slave");
sayError("Could not connect to slave");
return DBSTATUS_FAILURE;
}

Expand All @@ -247,9 +247,9 @@ sub waitForSlaveSync {
if (not defined $wait_result) {
if ($self->slave->dbh) {
my @slave_status = $self->slave->dbh->selectrow_array("SHOW SLAVE STATUS /* ReplMySQLd::waitForSlaveSync */");
say("ERROR: Slave SQL thread has stopped with error: ".$slave_status[37]);
sayError("Slave SQL thread has stopped with error: ".$slave_status[37]);
} else {
say("ERROR: Lost connection to the slave");
sayError("Lost connection to the slave");
}
return DBSTATUS_FAILURE;
} else {
Expand Down
27 changes: 26 additions & 1 deletion lib/GenTest.pm
Expand Up @@ -19,7 +19,7 @@
package GenTest;
use base 'Exporter';

@EXPORT = ('say', 'sayFile', 'tmpdir', 'safe_exit',
@EXPORT = ('say', 'sayError', 'sayFile', 'tmpdir', 'safe_exit',
'osWindows', 'osLinux', 'osSolaris', 'osMac',
'isoTimestamp', 'isoUTCTimestamp', 'isoUTCSimpleTimestamp',
'rqg_debug', 'unix2winPath',
Expand Down Expand Up @@ -129,6 +129,31 @@ sub say {
}
}

sub sayError {
my $text = shift;

# Suppress warnings "Wide character in print".
# We already know that our UTFs in some grammars are ugly.
no warnings 'layer';

defaultLogging();
if ($text =~ m{[\r\n]}sio) {
foreach my $line (split (m{[\r\n]}, $text)) {
if (defined $logger) {
$logger->error("[$$] ".$line);
} else {
print STDERR "# ".isoTimestamp()." [$$][ERROR] $line\n";
}
}
} else {
if (defined $logger) {
$logger->error("[$$] ".$text);
} else {
print STDERR "# ".isoTimestamp()." [$$][ERROR] $text\n";
}
}
}

sub sayFile {
my ($file) = @_;

Expand Down
10 changes: 5 additions & 5 deletions lib/GenTest/App/GenTest.pm
Expand Up @@ -427,7 +427,7 @@ sub workerProcess {
);

if (not defined $mixer) {
say("GenTest: ERROR: Failed to create a Mixer, status will be set to ENVIRONMENT_FAILURE");
sayError("GenTest failed to create a Mixer, status will be set to ENVIRONMENT_FAILURE");
$self->stopChild(STATUS_ENVIRONMENT_FAILURE);
}

Expand Down Expand Up @@ -563,7 +563,7 @@ sub initGenerator {

if ($generator_name eq 'GenTest::Generator::FromGrammar') {
if (not defined $self->config->grammar) {
say("ERROR: --grammar not specified but Generator is $generator_name, status will be set to ENVIRONMENT_FAILURE");
sayError("Grammar not specified but Generator is $generator_name, status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}

Expand All @@ -573,12 +573,12 @@ sub initGenerator {
) if defined $self->config->grammar;

if (not defined $self->grammar()) {
say("ERROR: Could not initialize the grammar, status will be set to ENVIRONMENT_FAILURE");
sayError("Could not initialize the grammar, status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}

if (not defined $self->grammar()) {
say("ERROR: Could not redefine the grammar, status will be set to ENVIRONMENT_FAILURE");
sayError("Could not redefine the grammar, status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}
}
Expand All @@ -592,7 +592,7 @@ sub initGenerator {
);

if (not defined $self->generator()) {
say("ERROR: Could not initialize the generator, status will be set to ENVIRONMENT_FAILURE");
sayError("Could not initialize the generator, status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/GenTest/App/PopulateSchema.pm
Expand Up @@ -164,7 +164,7 @@ sub run {
say("WARNING: basedir was not defined, relying on MySQL client being on the default path");
}
unless ($mysql_client_path) {
say("ERROR: Could not find MySQL client");
sayError("Could not find MySQL client");
return STATUS_ENVIRONMENT_FAILURE;
}

Expand All @@ -185,7 +185,7 @@ sub run {
my $port = $executor->port();
system("$mysql_client_path --port=$port --protocol=tcp -uroot --force test < $schema_file");
if ($?) {
say("ERROR: failed to load $schema_file through MySQL client");
sayError("Failed to load $schema_file through MySQL client");
return STATUS_ENVIRONMENT_FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GenTest/Reporter/Crash.pm
Expand Up @@ -46,7 +46,7 @@ sub monitor {
return STATUS_OK if $reporter ne $first_reporter;
my $pid = $reporter->serverInfo('pid');
if (!defined $pid) {
say("ERROR: Server PID is not defined, cannot crash the server");
sayError("Server PID is not defined, cannot crash the server");
return STATUS_ENVIRONMENT_FAILURE;
} elsif (time() > $reporter->testEnd() - 19) {
say("Sending SIGKILL to server with pid $pid...");
Expand Down
10 changes: 5 additions & 5 deletions lib/GenTest/Reporter/CrashRestart.pm
Expand Up @@ -58,13 +58,13 @@ sub monitor {
my $dbh = DBI->connect($reporter->dsn());

unless ($dbh) {
say("CrashRestart reporter: ERROR: Could not connect to the server before shutdown. Status will be set to STATUS_SERVER_CRASHED");
sayError("CrashRestart reporter could not connect to the server before shutdown. Status will be set to STATUS_SERVER_CRASHED");
return STATUS_SERVER_CRASHED;
}

my $pid = $reporter->serverInfo('pid');
if (!defined $pid) {
say("CrashRestart reporter: ERROR: Server PID is not defined, cannot crash the server");
sayError("CrashRestart reporter cannot crash the server: server PID is not defined");
return STATUS_ENVIRONMENT_FAILURE;
} else {
say("CrashRestart reporter: Sending SIGKILL to server with pid $pid...");
Expand All @@ -78,7 +78,7 @@ sub monitor {
sleep(1);
}
if ($dbh) {
say("CrashRestart reporter: ERROR: Still can connect to the server, crash did not work. Status will be set to ENVIRONMENT_FAILURE");
sayError("CrashRestart reporter still can connect to the server, crash did not work. Status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}

Expand All @@ -87,14 +87,14 @@ sub monitor {
my $status = $server->startServer();

if ($status > STATUS_OK) {
say("CrashRestart reporter: ERROR: Server startup finished with an error");
sayError("Server startup finished with an error in CrashRestart reporter");
return $status;
}

$dbh = DBI->connect($reporter->dsn());

unless ($dbh) {
say("CrashRestart reporter: ERROR: Could not connect to the restarted server. Status will be set to ENVIRONMENT_FAILURE");
sayError("CrashRestart reporter could not connect to the restarted server. Status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/GenTest/Reporter/Restart.pm
Expand Up @@ -58,7 +58,7 @@ sub monitor {
my $dbh = DBI->connect($reporter->dsn());

unless ($dbh) {
say("Restart reporter: ERROR: Could not connect to the server before shutdown. Status will be set to STATUS_SERVER_CRASHED");
sayError("Restart reporter could not connect to the server before shutdown. Status will be set to STATUS_SERVER_CRASHED");
return STATUS_SERVER_CRASHED;
}

Expand All @@ -72,22 +72,22 @@ sub monitor {
}
$dbh = DBI->connect($reporter->dsn(),'','',{PrintError=>0}) ;
if ($dbh) {
say("Restart reporter: ERROR: Still can connect to the server, shutdown failed. Status will be set to ENVIRONMENT_FAILURE");
sayError("Restart reporter still can connect to the server, shutdown failed. Status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}

say("Restart reporter: Restarting the server ...");
my $status = $server->startServer();

if ($status > STATUS_OK) {
say("Restart reporter: ERROR: Server startup finished with an error");
sayError("Server startup finished with an error in Restart reporter");
return $status;
}

$dbh = DBI->connect($reporter->dsn());

unless ($dbh) {
say("Restart reporter: ERROR: Could not connect to the restarted server. Status will be set to ENVIRONMENT_FAILURE");
sayError("Restart reporter could not connect to the restarted server. Status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GenTest/ReporterManager.pm
Expand Up @@ -77,7 +77,7 @@ sub addReporter {
eval "use $module" or print $@;
$reporter = $module->new(%$params);
if (not defined $reporter) {
say("ERROR: Reporter could not be added. Status will be set to ENVIRONMENT_FAILURE");
sayError("Reporter could not be added. Status will be set to ENVIRONMENT_FAILURE");
return STATUS_ENVIRONMENT_FAILURE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/GenTest/XML/Transporter.pm
Expand Up @@ -138,7 +138,7 @@ sub sendXML {
$dest = $self->defaultScpDestination if not defined $dest;
return $self->scp($xml, $dest);
} else {
say("[ERROR] XML transport type '".$self->type."' not supported.");
sayError("XML transport type '".$self->type."' not supported.");
return STATUS_ENVIRONMENT_FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion populate-schema.pl
Expand Up @@ -50,7 +50,7 @@
help();
exit(1);
} elsif (!$opt_result) {
say("ERROR: could not parse the command-line options\n");
sayError("Could not parse the command-line options\n");
help();
exit(1);
}
Expand Down
8 changes: 5 additions & 3 deletions runall-new.pl
Expand Up @@ -35,6 +35,7 @@
use DBServer::MySQL::ReplMySQLd;
use DBServer::MySQL::GaleraMySQLd;

$| = 1;
my $logger;
eval
{
Expand Down Expand Up @@ -443,7 +444,7 @@
if ($status > DBSTATUS_OK) {
stopServers($status);

say("ERROR: Could not start Galera cluster");
sayError("Could not start Galera cluster");
exit_test(STATUS_ENVIRONMENT_FAILURE);
}

Expand Down Expand Up @@ -483,7 +484,8 @@
} else {
say(system("ls -l ".$server[$server_id]->datadir));
}
croak("Could not start all servers");
sayError("Could not start all servers");
exit_test(STATUS_CRITICAL_FAILURE);
}

if ( ($server_id == 0) || ($rpl_mode eq '') ) {
Expand Down Expand Up @@ -687,7 +689,7 @@
if ($diff == STATUS_OK) {
say("No differences were found between servers ".($i-1)." and $i.");
} else {
say("ERROR: found differences between servers ".($i-1)." and $i.");
sayError("Found differences between servers ".($i-1)." and $i.");
$diff_result = STATUS_CONTENT_MISMATCH;
}
}
Expand Down

0 comments on commit 6d5a76e

Please sign in to comment.