journald: close runtime journal earlier
Then, we can use SD_JOURNAL_ASSUME_IMMUTABLE flag, and the performance of reading runtime journal should be improved.
This commit is contained in:
@@ -1321,6 +1321,10 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
|
||||
if (!s->system_journal)
|
||||
return 0;
|
||||
|
||||
/* Offline and close the 'main' runtime journal file to allow the runtime journal to be opened with
|
||||
* the SD_JOURNAL_ASSUME_IMMUTABLE flag in the below. */
|
||||
s->runtime_journal = journal_file_offline_close(s->runtime_journal);
|
||||
|
||||
/* Reset current seqnum data to avoid unnecessary rotation when switching to system journal.
|
||||
* See issue #30092. */
|
||||
zero(*s->seqnum);
|
||||
@@ -1329,7 +1333,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
|
||||
|
||||
start = now(CLOCK_MONOTONIC);
|
||||
|
||||
r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY);
|
||||
r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY | SD_JOURNAL_ASSUME_IMMUTABLE);
|
||||
if (r < 0)
|
||||
return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
|
||||
"Failed to read runtime journal: %m");
|
||||
@@ -1405,9 +1409,6 @@ finish:
|
||||
/* First, close all runtime journals opened in the above. */
|
||||
sd_journal_close(j);
|
||||
|
||||
/* Offline and close the 'main' runtime journal file. */
|
||||
s->runtime_journal = journal_file_offline_close(s->runtime_journal);
|
||||
|
||||
/* Remove the runtime directory if the all entries are successfully flushed to /var/. */
|
||||
if (r >= 0) {
|
||||
(void) rm_rf(s->runtime_storage.path, REMOVE_ROOT);
|
||||
|
||||
Reference in New Issue
Block a user