Mercurial > dovecot > original-hg > dovecot-1.2
changeset 2760:9ad220ac86c3 HEAD
Write transactions into index at the beginning of syncing if there's appends
or external changes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 17 Oct 2004 19:39:58 +0300 |
parents | 19b9266f720e |
children | f96a7b2d1c52 |
files | src/lib-index/mail-index-sync-update.c src/lib-index/mail-index-sync.c src/lib-index/mail-transaction-log.c |
diffstat | 3 files changed, 37 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-sync-update.c Sun Oct 17 18:15:27 2004 +0300 +++ b/src/lib-index/mail-index-sync-update.c Sun Oct 17 19:39:58 2004 +0300 @@ -786,6 +786,7 @@ buffer_append(map->hdr_copy_buf, map->hdr, map->hdr->header_size); map->hdr = map->hdr_copy_buf->data; + index->hdr = map->hdr; } mail_index_unmap(index, view->map); @@ -876,7 +877,9 @@ ret = -1; } map->hdr = map->mmap_base; + index->hdr = map->hdr; } + i_assert(view->map == index->map); mail_index_view_unlock(view); return ret;
--- a/src/lib-index/mail-index-sync.c Sun Oct 17 18:15:27 2004 +0300 +++ b/src/lib-index/mail-index-sync.c Sun Oct 17 19:39:58 2004 +0300 @@ -210,11 +210,14 @@ } static int -mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx, int sync_recent) +mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx, int sync_recent, + int *update_index_now_r) { size_t size; int ret; + *update_index_now_r = FALSE; + if ((ctx->view->map->hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) && ctx->sync_dirty) { /* show dirty flags as flag updates */ @@ -230,8 +233,21 @@ while ((ret = mail_transaction_log_view_next(ctx->view->log_view, &ctx->hdr, &ctx->data, NULL)) > 0) { - if ((ctx->hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0) + if ((ctx->hdr->type & MAIL_TRANSACTION_EXTERNAL) != 0) { + /* last sync was written to transaction log, + but it wasn't committed to index. do it now so + the next sync won't do things wrong (especially + duplicate appends). */ + *update_index_now_r = TRUE; + } else if ((ctx->hdr->type & MAIL_TRANSACTION_TYPE_MASK) == + MAIL_TRANSACTION_APPEND) { + /* we appended new message, and now we're committing + it into indexes. do it immediately so that we don't + break if we have to sync the mailbox too */ + *update_index_now_r = TRUE; + } else { mail_index_sync_sort_transaction(ctx); + } } ctx->expunges = buffer_get_data(ctx->expunges_buf, &size); @@ -268,6 +284,7 @@ uint32_t seq; uoff_t offset; unsigned int lock_id; + int update_now; if (mail_transaction_log_sync_lock(index->log, &seq, &offset) < 0) return -1; @@ -311,11 +328,25 @@ caller's mailbox access patterns */ ctx->expunges_buf = buffer_create_dynamic(default_pool, 1024); ctx->updates_buf = buffer_create_dynamic(default_pool, 1024); - if (mail_index_sync_read_and_sort(ctx, sync_recent) < 0) { + if (mail_index_sync_read_and_sort(ctx, sync_recent, &update_now) < 0) { mail_index_sync_rollback(ctx); return -1; } + if (update_now) { + if (mail_transaction_log_view_set(ctx->view->log_view, + index->hdr->log_file_seq, + index->hdr->log_file_offset, + seq, offset, MAIL_TRANSACTION_TYPE_MASK) < 0) { + mail_index_sync_rollback(ctx); + return -1; + } + if (mail_index_sync_update_index(ctx) < 0) { + mail_index_sync_rollback(ctx); + return -1; + } + } + *ctx_r = ctx; *view_r = ctx->view; return 1;
--- a/src/lib-index/mail-transaction-log.c Sun Oct 17 18:15:27 2004 +0300 +++ b/src/lib-index/mail-transaction-log.c Sun Oct 17 19:39:58 2004 +0300 @@ -922,55 +922,6 @@ } static void -mail_transaction_log_append_fix(struct mail_index_transaction *t, - const struct mail_transaction_header *hdr, - const void *data) -{ - const struct mail_index_record *old, *old_end; - struct mail_index_record *appends, *end, *rec, *dest; - size_t size; - int deleted = FALSE; - - if (t->appends == NULL) - return; - - appends = buffer_get_modifyable_data(t->appends, &size); - end = PTR_OFFSET(appends, size); - - if (appends == end) - return; - - /* we'll just check that none of the appends are already in - transaction log. this could happen if we crashed before we had - a chance to update index file */ - old_end = CONST_PTR_OFFSET(data, hdr->size); - for (old = data; old != old_end; old++) { - /* appends are sorted */ - for (rec = appends; rec != end; rec++) { - if (rec->uid >= old->uid) { - if (rec->uid == old->uid) { - rec->uid = 0; - deleted = TRUE; - } - break; - } - } - } - - if (deleted) { - /* compress deleted appends away */ - for (rec = dest = appends; rec != end; rec++) { - if (rec->uid != 0) - dest++; - else if (rec != dest) - *rec = *dest; - } - buffer_set_used_size(t->appends, - (char *)dest - (char *)appends); - } -} - -static void transaction_save_ext_intro(struct mail_index_transaction *t, const struct mail_transaction_ext_intro *intro) { @@ -1019,9 +970,6 @@ while ((ret = mail_transaction_log_view_next(sync_view, &hdr, &data, NULL)) == 1) { switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) { - case MAIL_TRANSACTION_APPEND: - mail_transaction_log_append_fix(t, hdr, data); - break; case MAIL_TRANSACTION_CACHE_RESET: { const struct mail_transaction_cache_reset *reset = data;