Skip to content

Commit

Permalink
lib-index: Fix setting highest_modseq correctly in mail_index_modseq_…
Browse files Browse the repository at this point in the history
…header

The internally counted ctx->highest_modseq wasn't correct if all of the
records weren't synced. This could have happened for various reasons.
Since the view's current log seq/offset is used for the header, we can
also use the current highest_modseq from the view as well and it's
guaranteed to be correct.

This fixes various potential problems with using QRESYNC and CONDSTORE
extensions. It also fixes potential errors with unhibernating imap
clients, including:

Error: .../dovecot.index.log: Transaction log changed unexpectedly, can't get modseq
  • Loading branch information
sirainen authored and villesavolainen committed Aug 14, 2017
1 parent 6eb78e3 commit 85d78d5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib-index/mail-index-modseq.c
Expand Up @@ -490,22 +490,24 @@ mail_index_modseq_sync_begin(struct mail_index_sync_map_ctx *sync_map_ctx)
return ctx;
}

static void mail_index_modseq_update_header(struct mail_index_view *view,
uint64_t highest_modseq)
static void mail_index_modseq_update_header(struct mail_index_modseq_sync *ctx)
{
struct mail_index_view *view = ctx->view;
struct mail_index_map *map = view->map;
const struct mail_index_ext *ext;
const struct mail_index_modseq_header *old_modseq_hdr;
struct mail_index_modseq_header new_modseq_hdr;
uint32_t ext_map_idx, log_seq;
uoff_t log_offset;
uint64_t highest_modseq;

if (!mail_index_map_get_ext_idx(map, view->index->modseq_ext_id,
&ext_map_idx))
return;

mail_transaction_log_view_get_prev_pos(view->log_view,
&log_seq, &log_offset);
highest_modseq = mail_transaction_log_view_get_prev_modseq(view->log_view);

ext = array_idx(&map->extensions, ext_map_idx);
old_modseq_hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
Expand All @@ -532,7 +534,7 @@ void mail_index_modseq_sync_end(struct mail_index_modseq_sync **_ctx)
*_ctx = NULL;
if (ctx->mmap != NULL) {
i_assert(ctx->mmap == ctx->view->map->rec_map->modseq);
mail_index_modseq_update_header(ctx->view, ctx->highest_modseq);
mail_index_modseq_update_header(ctx);
}
i_free(ctx);
}
Expand Down

0 comments on commit 85d78d5

Please sign in to comment.