1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-08 08:58:27 +03:00

journal: keep per-JournalFile location info during iteration

In next_beyond_location() when we find a candidate entry in a journal
file, save its location information in struct JournalFile.

The purpose of remembering the locations of candidate entries is to be
able to save work in the next iteration. This patch does only the
remembering part.

LOCATION_SEEK means the location identifies a candidate entry.
When a winner is picked from among candidates, it becomes
LOCATION_DISCRETE.
LOCATION_TAIL here signifies we've iterated the file to the end (or the
beginning in the case of reversed direction).
This commit is contained in:
Michal Schmidt 2014-12-16 21:03:36 +01:00
parent 1fc605b0e1
commit 6573ef05a3
3 changed files with 33 additions and 1 deletions

View File

@ -1929,7 +1929,24 @@ int journal_file_move_to_entry_by_monotonic(
}
void journal_file_reset_location(JournalFile *f) {
f->location_type = LOCATION_HEAD;
f->current_offset = 0;
f->current_seqnum = 0;
f->current_realtime = 0;
f->current_monotonic = 0;
zero(f->current_boot_id);
f->current_xor_hash = 0;
}
void journal_file_save_location(JournalFile *f, direction_t direction, Object *o, uint64_t offset) {
f->last_direction = direction;
f->location_type = LOCATION_SEEK;
f->current_offset = offset;
f->current_seqnum = le64toh(o->entry.seqnum);
f->current_realtime = le64toh(o->entry.realtime);
f->current_monotonic = le64toh(o->entry.monotonic);
f->current_boot_id = o->entry.boot_id;
f->current_xor_hash = le64toh(o->entry.xor_hash);
}
int journal_file_next_entry(

View File

@ -77,6 +77,7 @@ typedef struct JournalFile {
bool tail_entry_monotonic_valid:1;
direction_t last_direction;
LocationType location_type;
char *path;
struct stat last_stat;
@ -86,6 +87,11 @@ typedef struct JournalFile {
HashItem *field_hash_table;
uint64_t current_offset;
uint64_t current_seqnum;
uint64_t current_realtime;
uint64_t current_monotonic;
sd_id128_t current_boot_id;
uint64_t current_xor_hash;
JournalMetrics metrics;
MMapCache *mmap;
@ -190,6 +196,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);
int journal_file_next_entry(JournalFile *f, Object *o, uint64_t p, direction_t direction, Object **ret, uint64_t *offset);
int journal_file_next_entry_for_data(JournalFile *f, Object *o, uint64_t p, uint64_t data_offset, direction_t direction, Object **ret, uint64_t *offset);

View File

@ -128,6 +128,10 @@ static void set_location(sd_journal *j, LocationType type, JournalFile *f, Objec
f->last_direction = direction;
f->current_offset = offset;
/* Let f know its candidate entry was picked. */
assert(f->location_type == LOCATION_SEEK);
f->location_type = LOCATION_DISCRETE;
}
static int match_is_valid(const void *data, size_t size) {
@ -855,6 +859,8 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
found = true;
if (found) {
journal_file_save_location(f, direction, c, cp);
if (ret)
*ret = c;
if (offset)
@ -887,8 +893,10 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
log_debug_errno(r, "Can't iterate through %s, ignoring: %m", f->path);
remove_file_real(j, f);
continue;
} else if (r == 0)
} else if (r == 0) {
f->location_type = LOCATION_TAIL;
continue;
}
if (!new_file)
found = true;