Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6880:724c8f12eed2 HEAD
maildir_storage_sync_force(): Don't wait on trying to lock uidlist. Just try
once and if it fails, find the changed filenames and do nothing else.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 01 Dec 2007 09:23:21 +0200 |
parents | fed2843b4ab8 |
children | b1554dea8ee8 |
files | src/lib-storage/index/maildir/maildir-sync.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/maildir/maildir-uidlist.h |
diffstat | 3 files changed, 36 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-sync.c Sat Dec 01 09:09:47 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-sync.c Sat Dec 01 09:23:21 2007 +0200 @@ -208,12 +208,14 @@ struct maildir_sync_context { struct maildir_mailbox *mbox; const char *new_dir, *cur_dir; - bool partial; time_t last_touch, last_notify; struct maildir_uidlist_sync_ctx *uidlist_sync_ctx; - struct maildir_index_sync_context *index_sync_ctx; + struct maildir_index_sync_context *index_sync_ctx; + + unsigned int partial:1; + unsigned int locked:1; }; void maildir_sync_notify(struct maildir_sync_context *ctx) @@ -425,7 +427,7 @@ dest = t_str_new(1024); move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) && - !ctx->mbox->ibox.keep_recent; + !ctx->mbox->ibox.keep_recent && ctx->locked; errno = 0; for (; (dp = readdir(dirp)) != NULL; errno = 0) { @@ -754,18 +756,25 @@ problem rarely happens except under high amount of modifications. */ - ctx->partial = !cur_changed; - sync_flags = ctx->partial ? MAILDIR_UIDLIST_SYNC_PARTIAL : 0; + if (!cur_changed || forced) { + ctx->partial = TRUE; + sync_flags = MAILDIR_UIDLIST_SYNC_PARTIAL; + if (forced) + sync_flags |= MAILDIR_UIDLIST_SYNC_FORCE; + } else { + ctx->partial = FALSE; + sync_flags = 0; + } ret = maildir_uidlist_sync_init(ctx->mbox->uidlist, sync_flags, &ctx->uidlist_sync_ctx); if (ret <= 0) { - /* failure / timeout. if forced is TRUE, we could still go - forward and check only for renamed files, but is it worth - the trouble? .. */ + /* failure / timeout */ + i_assert(ret < 0 || !forced); return ret; } + ctx->locked = maildir_uidlist_is_locked(ctx->mbox->uidlist); - if (!ctx->mbox->syncing_commit) { + if (!ctx->mbox->syncing_commit && ctx->locked) { if (maildir_sync_index_begin(ctx->mbox, ctx, &ctx->index_sync_ctx) < 0) return -1; @@ -797,7 +806,7 @@ maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); } - if (!ctx->mbox->syncing_commit) { + if (!ctx->mbox->syncing_commit && ctx->locked) { /* NOTE: index syncing here might cause a re-sync due to files getting lost, so this function might be called re-entrantly. */
--- a/src/lib-storage/index/maildir/maildir-uidlist.c Sat Dec 01 09:09:47 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-uidlist.c Sat Dec 01 09:23:21 2007 +0200 @@ -108,6 +108,7 @@ unsigned int finished:1; unsigned int changed:1; unsigned int failed:1; + unsigned int locked:1; }; struct maildir_uidlist_iter_ctx { @@ -1067,13 +1068,19 @@ struct maildir_uidlist_sync_ctx *ctx; int ret; - if ((ret = maildir_uidlist_lock(uidlist)) <= 0) - return ret; + if ((sync_flags & MAILDIR_UIDLIST_SYNC_FORCE) == 0) { + if ((ret = maildir_uidlist_lock(uidlist)) <= 0) + return ret; + } else { + if ((ret = maildir_uidlist_try_lock(uidlist)) < 0) + return -1; + } *sync_ctx_r = ctx = i_new(struct maildir_uidlist_sync_ctx, 1); ctx->uidlist = uidlist; ctx->sync_flags = sync_flags; ctx->partial = (sync_flags & MAILDIR_UIDLIST_SYNC_PARTIAL) != 0; + ctx->locked = ret > 0; ctx->first_unwritten_pos = (unsigned int)-1; ctx->first_nouid_pos = (unsigned int)-1; @@ -1109,6 +1116,10 @@ if (rec == NULL) { /* doesn't exist in uidlist */ + if (!ctx->locked) { + /* we can't add it, so just ignore it */ + return; + } if (ctx->first_nouid_pos == (unsigned int)-1) ctx->first_nouid_pos = array_count(&uidlist->records); ctx->new_files_count++; @@ -1371,7 +1382,8 @@ t_pop(); } - maildir_uidlist_unlock(ctx->uidlist); + if (ctx->locked) + maildir_uidlist_unlock(ctx->uidlist); if (ctx->files != NULL) hash_destroy(&ctx->files);
--- a/src/lib-storage/index/maildir/maildir-uidlist.h Sat Dec 01 09:09:47 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-uidlist.h Sat Dec 01 09:23:21 2007 +0200 @@ -9,7 +9,8 @@ enum maildir_uidlist_sync_flags { MAILDIR_UIDLIST_SYNC_PARTIAL = 0x01, - MAILDIR_UIDLIST_SYNC_KEEP_STATE = 0x02 + MAILDIR_UIDLIST_SYNC_KEEP_STATE = 0x02, + MAILDIR_UIDLIST_SYNC_FORCE = 0x04 }; enum maildir_uidlist_rec_flag {