1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-01-09 14:45:47 +02:00

Issue 56: be more lenient to .rotation file been empty or containing garbage: issue WARNING instead of ERROR and rotate file immediately. Also issue WARNING if .rotation file is missing, previously such condition was ignored

This commit is contained in:
Grigory Smolkin 2019-04-19 17:11:58 +03:00
parent ec2d74dbbe
commit fc8453b6c7

View File

@ -565,11 +565,18 @@ open_logfile(FILE **file, const char *filename_format)
{ {
struct stat control_st; struct stat control_st;
if (stat(control, &control_st) == -1) if (stat(control, &control_st) < 0)
{ {
if (errno != ENOENT) if (errno != ENOENT)
elog_stderr(ERROR, "cannot stat rotation file \"%s\": %s", elog_stderr(ERROR, "cannot stat rotation file \"%s\": %s",
control, strerror(errno)); control, strerror(errno));
else
{
/* file not found, force rotation */
elog_stderr(WARNING, "missing rotation file: \"%s\"",
control);
rotation_requested = true;
}
} }
else else
{ {
@ -585,18 +592,28 @@ open_logfile(FILE **file, const char *filename_format)
time_t creation_time; time_t creation_time;
if (!parse_int64(buf, (int64 *) &creation_time, 0)) if (!parse_int64(buf, (int64 *) &creation_time, 0))
elog_stderr(ERROR, "rotation file \"%s\" has wrong " {
/* Inability to parse value from .rotation file is
* concerning but not a critical error
*/
elog_stderr(WARNING, "rotation file \"%s\" has wrong "
"creation timestamp \"%s\"", "creation timestamp \"%s\"",
control, buf); control, buf);
/* Parsed creation time */ rotation_requested = true;
}
rotation_requested = (cur_time - creation_time) > else
/* convert to seconds from milliseconds */ /* Parsed creation time */
logger_config.log_rotation_age / 1000; rotation_requested = (cur_time - creation_time) >
/* convert to seconds from milliseconds */
logger_config.log_rotation_age / 1000;
} }
else else
elog_stderr(ERROR, "cannot read creation timestamp from " {
/* truncated .rotation file is not a critical error */
elog_stderr(WARNING, "cannot read creation timestamp from "
"rotation file \"%s\"", control); "rotation file \"%s\"", control);
rotation_requested = true;
}
fclose(control_file); fclose(control_file);
} }