chiark / gitweb /
journal: make skipping of exhausted journal files effective again
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 24 Feb 2015 18:45:17 +0000 (19:45 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Wed, 25 Feb 2015 16:32:27 +0000 (17:32 +0100)
Commit 668c965af "journal: skipping of exhausted journal files is bad if
direction changed" fixed a correctness issue, but it also significantly
limited the cases where the optimization that skips exhausted journal
files could apply.
As a result, some journalctl queries are much slower in v219 than in v218.
(e.g. queries where a "--since" cutoff should have quickly eliminated
older journal files from consideration, but didn't.)

If already in the initial iteration find_location_with_matches() finds
no entry, the journal file's location is not updated. This is fine,
except that:
 - We must update at least f->last_direction. The optimization relies on
   it. Let's separate that from journal_file_save_location() and update
   it immediately after the direction checks.
 - The optimization was conditional on "f->current_offset > 0", but it
   would always be 0 in this scenario. This check is unnecessary for the
   optimization.

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

index 9b4967fb3216b739bde0a9ab6b9c5984885716eb..9c9a5483be550b84cf6095bc0850e40dbe283be5 100644 (file)
@@ -2013,8 +2013,7 @@ void journal_file_reset_location(JournalFile *f) {
         f->current_xor_hash = 0;
 }
 
-void journal_file_save_location(JournalFile *f, direction_t direction, Object *o, uint64_t offset) {
-        f->last_direction = direction;
+void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset) {
         f->location_type = LOCATION_SEEK;
         f->current_offset = offset;
         f->current_seqnum = le64toh(o->entry.seqnum);
index 2526e14d650f3ab7cec8599d84b72e285bf8a9e0..403c8f760c8541a5f0b6478d38a08f44c9a2d4ad 100644 (file)
@@ -199,7 +199,7 @@ int journal_file_find_field_object(JournalFile *f, const void *field, uint64_t s
 int journal_file_find_field_object_with_hash(JournalFile *f, const void *field, uint64_t size, uint64_t hash, Object **ret, uint64_t *offset);
 
 void journal_file_reset_location(JournalFile *f);
-void journal_file_save_location(JournalFile *f, direction_t direction, Object *o, uint64_t offset);
+void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset);
 int journal_file_compare_locations(JournalFile *af, JournalFile *bf);
 int journal_file_next_entry(JournalFile *f, uint64_t p, direction_t direction, Object **ret, uint64_t *offset);
 
index 94891cdf35b16b6aad570e2150fa81fb2c7a4643..9b57e5945dd385f1863f2b2be449b8f6e9b167dc 100644 (file)
@@ -723,13 +723,17 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
         assert(j);
         assert(f);
 
-        if (f->last_direction == direction && f->current_offset > 0) {
-                /* 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;
+        n_entries = le64toh(f->header->n_entries);
+
+        /* If we hit EOF before, we don't need to look into this file again
+         * unless direction changed or new entries appeared. */
+        if (f->last_direction == direction && 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) {
                 /* LOCATION_SEEK here means we did the work in a previous
                  * iteration and the current location already points to a
                  * candidate entry. */
@@ -738,14 +742,16 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
                         if (r <= 0)
                                 return r;
 
-                        journal_file_save_location(f, direction, c, cp);
+                        journal_file_save_location(f, c, cp);
                 }
         } else {
+                f->last_direction = direction;
+
                 r = find_location_with_matches(j, f, direction, &c, &cp);
                 if (r <= 0)
                         return r;
 
-                journal_file_save_location(f, direction, c, cp);
+                journal_file_save_location(f, c, cp);
         }
 
         /* OK, we found the spot, now let's advance until an entry
@@ -773,7 +779,7 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
                 if (r <= 0)
                         return r;
 
-                journal_file_save_location(f, direction, c, cp);
+                journal_file_save_location(f, c, cp);
         }
 }