]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fixed mail_index_modseq_get_next_log_offset() when accessing .log.2
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 8 Sep 2016 21:59:53 +0000 (00:59 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 9 Sep 2016 06:49:55 +0000 (09:49 +0300)
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.

src/lib-index/mail-transaction-log-file.c

index bf4ff94e6d037dab6f22c41eee31f63196710f00..9c252c6185a1d01f956db14e25bb64fd700b734f 100644 (file)
@@ -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)