Merge pull request #11135 from uberbrady/improve_restore_erroring

Do some better erroring if you can't launch the mysql binary
This commit is contained in:
snipe 2022-05-17 18:16:40 -07:00 committed by GitHub
commit 11db243514
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -227,6 +227,9 @@ class RestoreFromBackup extends Command
return $this->error('Unable to invoke mysql via CLI');
}
stream_set_blocking($pipes[1], false); // use non-blocking reads for stdout
stream_set_blocking($pipes[2], false); // use non-blocking reads for stderr
// $this->info("Stdout says? ".fgets($pipes[1])); //FIXME: I think we might need to set non-blocking mode to use this properly?
// $this->info("Stderr says? ".fgets($pipes[2])); //FIXME: ditto, same.
// should we read stdout?
@ -247,18 +250,25 @@ class RestoreFromBackup extends Command
}
$bytes_read = 0;
while (($buffer = fgets($sql_contents, self::$buffer_size)) !== false) {
$bytes_read += strlen($buffer);
// \Log::debug("Buffer is: '$buffer'");
$bytes_written = fwrite($pipes[0], $buffer);
try {
while (($buffer = fgets($sql_contents, self::$buffer_size)) !== false) {
$bytes_read += strlen($buffer);
// \Log::debug("Buffer is: '$buffer'");
$bytes_written = fwrite($pipes[0], $buffer);
if ($bytes_written === false) {
$stdout = fgets($pipes[1]);
$this->info($stdout);
$stderr = fgets($pipes[2]);
$this->info($stderr);
return false;
if ($bytes_written === false) {
throw new Exception("Unable to write to pipe");
}
}
} catch (\Exception $e) {
\Log::error("Error during restore!!!! ".$e->getMessage());
$err_out = fgets($pipes[1]);
$err_err = fgets($pipes[2]);
\Log::error("Error OUTPUT: ".$err_out);
$this->info($err_out);
\Log::error("Error ERROR : ".$err_err);
$this->error($err_err);
throw $e;
}
if (!feof($sql_contents) || $bytes_read == 0) {