summaryrefslogtreecommitdiff
path: root/src/journal-remote
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-01-23 21:21:21 +0100
committerLennart Poettering <lennart@poettering.net>2023-02-08 13:42:29 +0100
commite5d60d1b3b0c0b229571823c7fdd390a9562982e (patch)
treef46db05768fb62e658f91562088ea01d438e6018 /src/journal-remote
parent2bc70e2e9db13cfbc74e4bf1fd28ecbfef1466c9 (diff)
downloadsystemd-e5d60d1b3b0c0b229571823c7fdd390a9562982e.tar.gz
journald: maintain entry seqnum counter in mmap()ed file in /run/
Let's ensure that entry seqnums remain stable and monotonic across the entire runtime of the system, even if local storage is turned off. Let's do this by maintainer a counter file in /run/ which we mmap() and wherein we maintain the counter from early-boot on till late shutdown. This takes inspiration of the kernel-seqnum file we already maintain like that that tracks which kmsg messages we already processed. In fact, we reuse the same code for maintaining it. This should allow the behaviour entry seqnums to be more predictable, in particular when journal local storage is turned off. Previously, we'd maintain the seqnum simply by always bumping it to the maximum of the last written entry seqnum plus one, and the biggest seqnum so far written to the journal file on disk. If we'd never write a file on disk, or if no journal file was existing during the initrd→seqnum transition we'd completely lose the current seqnum position during daemon restarts (such as the one happening during the switch-root operation). This also will cause a journal file rotation whenever we try to write to a journal file with multiple sequence number IDs, so that we know that from early boot trhough the entire runtime we'll have stable sequence numbers that do not jump, and thus can be used to determine "lost" messages.
Diffstat (limited to 'src/journal-remote')
-rw-r--r--src/journal-remote/journal-remote-write.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c
index f6c3d83732..ace4a1cfad 100644
--- a/src/journal-remote/journal-remote-write.c
+++ b/src/journal-remote/journal-remote-write.c
@@ -99,9 +99,16 @@ int writer_write(Writer *w,
return r;
}
- r = journal_file_append_entry(w->journal->file, ts, boot_id,
- iovw->iovec, iovw->count,
- &w->seqnum, NULL, NULL);
+ r = journal_file_append_entry(
+ w->journal->file,
+ ts,
+ boot_id,
+ iovw->iovec,
+ iovw->count,
+ &w->seqnum,
+ /* seqnum_id= */ NULL,
+ /* ret_object= */ NULL,
+ /* ret_offset= */ NULL);
if (r >= 0) {
if (w->server)
w->server->event_count += 1;
@@ -120,9 +127,15 @@ int writer_write(Writer *w,
return r;
log_debug("Retrying write.");
- r = journal_file_append_entry(w->journal->file, ts, boot_id,
- iovw->iovec, iovw->count,
- &w->seqnum, NULL, NULL);
+ r = journal_file_append_entry(
+ w->journal->file,
+ ts,
+ boot_id,
+ iovw->iovec, iovw->count,
+ &w->seqnum,
+ /* seqnum_id= */ NULL,
+ /* ret_object= */ NULL,
+ /* ret_offset= */ NULL);
if (r < 0)
return r;