|
|
763e28 |
From 9c22b31cd639911a2faffad02f2ed9f7cc10b9e1 Mon Sep 17 00:00:00 2001
|
|
|
763e28 |
From: Jiri Vymazal <jvymazal@redhat.com>
|
|
|
763e28 |
Date: Fri, 15 Mar 2019 09:29:04 +0100
|
|
|
763e28 |
Subject: [PATCH] Fetching journal cursor only for valid journal
|
|
|
763e28 |
|
|
|
763e28 |
The sd_journal_get_cursor() got called regradless of previous
|
|
|
763e28 |
retcodes from other jorunal calls which flooded logs with journald
|
|
|
763e28 |
errors. Now skipping the call in case of previous journal call
|
|
|
763e28 |
non-zero result. Fixed success checking of get_cursor() call
|
|
|
763e28 |
to eliminate double-free possibility.
|
|
|
763e28 |
|
|
|
763e28 |
Also, making WorkAroundJournalBug true by default, as there were no
|
|
|
763e28 |
confirmed performance regressions for a quite long time.
|
|
|
763e28 |
---
|
|
|
763e28 |
plugins/imjournal/imjournal.c | 43 ++++++++++++++++++++++------------
|
|
|
763e28 |
1 file changed, 28 insertions(+), 15 deletions(-)
|
|
|
763e28 |
|
|
|
763e28 |
diff --git a/plugins/imjournal/imjournal.c b/plugins/imjournal/imjournal.c
|
|
|
763e28 |
index 7225fae1ab..5419762cf1 100644
|
|
|
763e28 |
--- a/plugins/imjournal/imjournal.c
|
|
|
763e28 |
+++ b/plugins/imjournal/imjournal.c
|
|
|
763e28 |
@@ -135,7 +135,7 @@ static char *last_cursor = NULL;
|
|
|
763e28 |
|
|
|
763e28 |
#define J_PROCESS_PERIOD 1024 /* Call sd_journal_process() every 1,024 records */
|
|
|
763e28 |
|
|
|
763e28 |
-static rsRetVal persistJournalState(void);
|
|
|
763e28 |
+static rsRetVal persistJournalState(int trySave);
|
|
|
763e28 |
static rsRetVal loadJournalState(void);
|
|
|
763e28 |
|
|
|
763e28 |
static rsRetVal openJournal(void) {
|
|
|
763e28 |
@@ -158,9 +158,9 @@ static rsRetVal openJournal(void) {
|
|
|
763e28 |
RETiRet;
|
|
|
763e28 |
}
|
|
|
763e28 |
|
|
|
763e28 |
-static void closeJournal(void) {
|
|
|
763e28 |
+static void closeJournal(int trySave) {
|
|
|
763e28 |
if (cs.stateFile) { /* can't persist without a state file */
|
|
|
763e28 |
- persistJournalState();
|
|
|
763e28 |
+ persistJournalState(trySave);
|
|
|
763e28 |
}
|
|
|
763e28 |
sd_journal_close(j);
|
|
|
763e28 |
j_inotify_fd = 0;
|
|
|
763e28 |
@@ -461,7 +461,7 @@ readjournal(void)
|
|
|
763e28 |
/* This function gets journal cursor and saves it into state file
|
|
|
763e28 |
*/
|
|
|
763e28 |
static rsRetVal
|
|
|
763e28 |
-persistJournalState(void)
|
|
|
763e28 |
+persistJournalState(int trySave)
|
|
|
763e28 |
{
|
|
|
763e28 |
DEFiRet;
|
|
|
763e28 |
FILE *sf; /* state file */
|
|
|
763e28 |
@@ -469,7 +470,7 @@ persistJournalState(void)
|
|
|
763e28 |
if (!last_cursor) {
|
|
|
763e28 |
ABORT_FINALIZE(RS_RET_OK);
|
|
|
763e28 |
}
|
|
|
763e28 |
- } else {
|
|
|
763e28 |
+ } else if (trySave) {
|
|
|
763e28 |
int ret;
|
|
|
763e28 |
free(last_cursor);
|
|
|
763e28 |
if ((ret = sd_journal_get_cursor(j, &last_cursor))) {
|
|
|
763e28 |
@@ -477,6 +478,8 @@ persistJournalState(void)
|
|
|
763e28 |
last_cursor = NULL;
|
|
|
763e28 |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
763e28 |
}
|
|
|
763e28 |
+ } else { /* not trying to get cursor out of invalid journal state */
|
|
|
763e28 |
+ ABORT_FINALIZE(RS_RET_OK);
|
|
|
763e28 |
}
|
|
|
763e28 |
|
|
|
763e28 |
/* we create a temporary name by adding a ".tmp"
|
|
|
763e28 |
@@ -535,14 +535,24 @@ pollJournal(void)
|
|
|
763e28 |
err = sd_journal_wait(j, POLL_TIMEOUT);
|
|
|
763e28 |
if (err == SD_JOURNAL_INVALIDATE) {
|
|
|
763e28 |
STATSCOUNTER_INC(statsCounter.ctrRotations, statsCounter.mutCtrRotations);
|
|
|
763e28 |
- closeJournal();
|
|
|
763e28 |
+ closeJournal(0);
|
|
|
763e28 |
|
|
|
763e28 |
iRet = openJournal();
|
|
|
763e28 |
if (iRet != RS_RET_OK) {
|
|
|
763e28 |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
763e28 |
}
|
|
|
763e28 |
|
|
|
763e28 |
- if (cs.stateFile) {
|
|
|
763e28 |
+ /* If we have locally saved cursor there is no need to read it from state file */
|
|
|
763e28 |
+ if (cs.bWorkAroundJournalBug && last_cursor)
|
|
|
763e28 |
+ {
|
|
|
763e28 |
+ if (sd_journal_seek_cursor(j, last_cursor) != 0) {
|
|
|
763e28 |
+ LogError(0, RS_RET_ERR, "imjournal: "
|
|
|
763e28 |
+ "couldn't seek to cursor `%s'\n", last_cursor);
|
|
|
763e28 |
+ iRet = RS_RET_ERR;
|
|
|
763e28 |
+ }
|
|
|
763e28 |
+ sd_journal_next(j);
|
|
|
763e28 |
+ }
|
|
|
763e28 |
+ else if (cs.stateFile) {
|
|
|
763e28 |
iRet = loadJournalState();
|
|
|
763e28 |
}
|
|
|
763e28 |
LogMsg(0, RS_RET_OK, LOG_NOTICE, "imjournal: journal reloaded...");
|
|
|
763e28 |
@@ -668,10 +680,9 @@ loadJournalState(void)
|
|
|
763e28 |
|
|
|
763e28 |
static void
|
|
|
763e28 |
tryRecover(void) {
|
|
|
763e28 |
- LogMsg(0, RS_RET_OK, LOG_INFO, "imjournal: trying to recover from unexpected "
|
|
|
763e28 |
- "journal error");
|
|
|
763e28 |
+ LogMsg(0, RS_RET_OK, LOG_INFO, "imjournal: trying to recover from journal error");
|
|
|
763e28 |
STATSCOUNTER_INC(statsCounter.ctrRecoveryAttempts, statsCounter.mutCtrRecoveryAttempts);
|
|
|
763e28 |
- closeJournal();
|
|
|
763e28 |
+ closeJournal(0);
|
|
|
763e28 |
srSleep(10, 0); // do not hammer machine with too-frequent retries
|
|
|
763e28 |
openJournal();
|
|
|
763e28 |
}
|
|
|
763e28 |
@@ -768,7 +779,7 @@ CODESTARTrunInput
|
|
|
763e28 |
if (cs.stateFile) { /* can't persist without a state file */
|
|
|
763e28 |
/* TODO: This could use some finer metric. */
|
|
|
763e28 |
if ((count % cs.iPersistStateInterval) == 0) {
|
|
|
763e28 |
- persistJournalState();
|
|
|
763e28 |
+ persistJournalState(1);
|
|
|
763e28 |
}
|
|
|
763e28 |
}
|
|
|
763e28 |
}
|
|
|
763e28 |
@@ -790,7 +801,7 @@ CODESTARTbeginCnfLoad
|
|
|
763e28 |
cs.iDfltFacility = DFLT_FACILITY;
|
|
|
763e28 |
cs.bUseJnlPID = -1;
|
|
|
763e28 |
cs.usePid = NULL;
|
|
|
763e28 |
- cs.bWorkAroundJournalBug = 0;
|
|
|
763e28 |
+ cs.bWorkAroundJournalBug = 1;
|
|
|
763e28 |
cs.dfltTag = NULL;
|
|
|
763e28 |
ENDbeginCnfLoad
|
|
|
763e28 |
|
|
|
763e28 |
@@ -860,7 +871,7 @@ ENDwillRun
|
|
|
763e28 |
/* close journal */
|
|
|
763e28 |
BEGINafterRun
|
|
|
763e28 |
CODESTARTafterRun
|
|
|
763e28 |
- closeJournal();
|
|
|
763e28 |
+ closeJournal(1);
|
|
|
763e28 |
ratelimitDestruct(ratelimiter);
|
|
|
763e28 |
ENDafterRun
|
|
|
763e28 |
|