Skip to content

Commit

Permalink
journald: remove triplicate logging about failure to write log lines
Browse files Browse the repository at this point in the history
Let's log exactly at one place about failed writing of log lines to
journal file: in shall_try_append_again().

Then, if we decide to suppress a retry-after-vacuum because we already
vacuumed anyway then say this explicitly as "supressed rotation",
because that's what we do here.

This removes triplicate logging about the same error, and logs exactly
once, plus optional one "suppressed rotation" message. (plus more debug
output). The triplicate logging was bad in particular because it had no
understanding of the actual error codes and just showed generic UNIX
error strings ("Not a XENIX named type file"). By relying on
shall_try_append_again() to do all logging we now get very clean error
strings for all conditions.

Fixes: systemd#26496
  • Loading branch information
poettering committed Feb 28, 2023
1 parent 32b0678 commit 0631aab
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/journal/journald-server.c
Expand Up @@ -969,20 +969,16 @@ static void server_write_to_journal(
return;
}

if (vacuumed || !shall_try_append_again(f->file, r)) {
log_ratelimit_error_errno(r, FAILED_TO_WRITE_ENTRY_RATELIMIT,
"Failed to write entry (%zu items, %zu bytes), ignoring: %m",
n, IOVEC_TOTAL_SIZE(iovec, n));
log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->file->path, n, IOVEC_TOTAL_SIZE(iovec, n));

if (!shall_try_append_again(f->file, r))
return;
if (vacuumed) {
log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
"Suppressing rotation, as we already rotated immediately before write attempt. Giving up.");
return;
}

if (r == -E2BIG)
log_debug("Journal file %s is full, rotating to a new file", f->file->path);
else
log_ratelimit_info_errno(r, FAILED_TO_WRITE_ENTRY_RATELIMIT,
"Failed to write entry to %s (%zu items, %zu bytes), rotating before retrying: %m",
f->file->path, n, IOVEC_TOTAL_SIZE(iovec, n));

server_rotate(s);
server_vacuum(s, false);

Expand Down

0 comments on commit 0631aab

Please sign in to comment.