journal: optimize iteration by skipping exhausted files
authorMichal Schmidt <mschmidt@redhat.com>
Thu, 18 Dec 2014 13:21:55 +0000 (14:21 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 18 Dec 2014 13:29:46 +0000 (14:29 +0100)
If from a previous iteration we know we are at the end of a journal
file, don't bother looking into the file again. This is complicated by
the fact that the EOF does not have to be permanent (think of
"journalctl -f"). So we also check if the number of entries in the
journal file changed.

This optimization has a similar effect as "journal: optimize iteration:
skip whole files behind current location" had.

src/journal/journal-file.h
src/journal/sd-journal.c

index 8084176..561982f 100644 (file)
@@ -78,6 +78,7 @@ typedef struct JournalFile {
 
         direction_t last_direction;
         LocationType location_type;
+        uint64_t last_n_entries;
 
         char *path;
         struct stat last_stat;
index f3aae9b..0aaf225 100644 (file)
@@ -729,12 +729,18 @@ static int next_with_matches(
 
 static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direction) {
         Object *c;
-        uint64_t cp;
+        uint64_t cp, n_entries;
         int r;
 
         assert(j);
         assert(f);
 
+        /* If we hit EOF before, recheck if any new entries arrived. */
+        n_entries = le64toh(f->header->n_entries);
+        if (f->location_type == LOCATION_TAIL && n_entries == f->last_n_entries)
+                return 0;
+        f->last_n_entries = n_entries;
+
         if (f->last_direction == direction && f->current_offset > 0) {
                 cp = f->current_offset;