From: Timo Sirainen Date: Thu, 8 Sep 2016 21:59:53 +0000 (+0300) Subject: lib-index: Fixed mail_index_modseq_get_next_log_offset() when accessing .log.2 X-Git-Tag: 2.3.0.rc1~3052 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2485e31c7ef8ac6656dd8b9def439fc6cf6f7598;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Fixed mail_index_modseq_get_next_log_offset() when accessing .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. --- diff --git a/src/lib-index/mail-transaction-log-file.c b/src/lib-index/mail-transaction-log-file.c index bf4ff94e6d..9c252c6185 100644 --- a/src/lib-index/mail-transaction-log-file.c +++ b/src/lib-index/mail-transaction-log-file.c @@ -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; } @@ -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; @@ -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)