Skip to content

Commit

Permalink
lib-index: Fixed mail_index_modseq_get_next_log_offset() when accessi…
Browse files Browse the repository at this point in the history
…ng .log.2

file->sync_offset was set only after header, so sync_highest_modseq was also
same as initial_modseq. The previous code then just returned offset pointing
to sync_offset, which was too early.
  • Loading branch information
sirainen authored and GitLab committed Sep 9, 2016
1 parent 1ff03d2 commit 2485e31
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib-index/mail-transaction-log-file.c
Expand Up @@ -1207,7 +1207,7 @@ int mail_transaction_log_file_get_modseq_next_offset(
uint64_t cur_modseq;
int ret;

if (modseq >= file->sync_highest_modseq) {
if (modseq == file->sync_highest_modseq) {
*next_offset_r = file->sync_offset;
return 0;
}
Expand All @@ -1231,8 +1231,10 @@ int mail_transaction_log_file_get_modseq_next_offset(
cur_modseq = cache->highest_modseq;
}

ret = mail_transaction_log_file_map(file, cur_offset,
file->sync_offset);
/* make sure we've read until end of file. this is especially important
with non-head logs which might only have been opened without being
synced. */
ret = mail_transaction_log_file_map(file, cur_offset, (uoff_t)-1);
if (ret <= 0) {
if (ret < 0)
return -1;
Expand All @@ -1242,6 +1244,12 @@ int mail_transaction_log_file_get_modseq_next_offset(
return -1;
}

/* check sync_highest_modseq again in case sync_offset was updated */
if (modseq >= file->sync_highest_modseq) {
*next_offset_r = file->sync_offset;
return 0;
}

i_assert(cur_offset >= file->buffer_offset);
while (cur_offset < file->sync_offset) {
if (log_get_synced_record(file, &cur_offset, &hdr) < 0)
Expand Down

0 comments on commit 2485e31

Please sign in to comment.