]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Always write tail offset the same as head offset
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 8 Apr 2022 12:59:59 +0000 (15:59 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 14 Apr 2022 06:47:55 +0000 (09:47 +0300)
The mail_index_write() must not be called unless this is safe to do.
This prevents unnecessarily reading through dovecot.index.log between
tail..head offsets, which can be expensive due to modseq calculation.

src/lib-index/mail-index-write.c

index 9fb5784480bf140dec91264f7ab16d02a96170a6..689cb9cdc1508cc4f41bc2838c44c91679bb9bd5 100644 (file)
@@ -78,12 +78,18 @@ static int mail_index_recreate(struct mail_index *index)
        output = o_stream_create_fd_file(fd, 0, FALSE);
        o_stream_cork(output);
 
-       base_size = I_MIN(map->hdr.base_header_size, sizeof(map->hdr));
-       o_stream_nsend(output, &map->hdr, base_size);
+       struct mail_index_header hdr = map->hdr;
+       /* Write tail_offset the same as head_offset. This function must not
+          be called unless it's safe to do this. See the explanations in
+          mail_index_sync_commit(). */
+       hdr.log_file_tail_offset = hdr.log_file_head_offset;
+
+       base_size = I_MIN(hdr.base_header_size, sizeof(hdr));
+       o_stream_nsend(output, &hdr, base_size);
        o_stream_nsend(output, MAIL_INDEX_MAP_HDR_OFFSET(map, base_size),
-                      map->hdr.header_size - base_size);
+                      hdr.header_size - base_size);
        o_stream_nsend(output, map->rec_map->records,
-                      map->rec_map->records_count * map->hdr.record_size);
+                      map->rec_map->records_count * hdr.record_size);
        if (o_stream_finish(output) < 0) {
                mail_index_file_set_syscall_error(index, path, "write()");
                ret = -1;