# HG changeset patch # User Timo Sirainen # Date 1138528472 -7200 # Node ID 8f0ff62befd37d8459909faebd13731d4c13d924 # Parent a52c36c51ff2d82e9ad543f52856889816f61bb9 When appending, update sync_stamp in index so that dbox won't get a full resync. diff -r a52c36c51ff2 -r 8f0ff62befd3 src/lib-storage/index/dbox/dbox-save.c --- a/src/lib-storage/index/dbox/dbox-save.c Sun Jan 29 00:05:48 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-save.c Sun Jan 29 11:54:32 2006 +0200 @@ -195,12 +195,15 @@ struct dbox_mail_header hdr; struct dbox_file *file; struct mail_index_view *view; + const struct mail_index_header *idx_hdr; uint32_t seq, uid, last_uid, file_seq; + time_t old_mtime, new_mtime; uoff_t offset; int ret; /* we want the index file to be locked from here until the appends - have been written to transaction log */ + have been written to transaction log. this is so that the + transaction log gets locked before uidlist, not after */ if (mail_index_sync_begin(ctx->mbox->ibox.index, &ctx->index_sync_ctx, &view, (uint32_t)-1, (uoff_t)-1, FALSE, FALSE) < 0) { @@ -211,7 +214,8 @@ /* uidlist gets locked here. do it after starting index syncing to avoid deadlocks */ - if (dbox_uidlist_append_get_first_uid(ctx->append_ctx, &uid) < 0) { + if (dbox_uidlist_append_get_first_uid(ctx->append_ctx, + &uid, &old_mtime) < 0) { ctx->failed = TRUE; dbox_transaction_save_rollback(ctx); return -1; @@ -241,11 +245,23 @@ } } - if (dbox_uidlist_append_commit(ctx->append_ctx) < 0) { + if (dbox_uidlist_append_commit(ctx->append_ctx, &new_mtime) < 0) { mail_index_sync_rollback(&ctx->index_sync_ctx); i_free(ctx); return -1; } + + idx_hdr = mail_index_get_header(view); + if ((uint32_t)old_mtime == idx_hdr->sync_stamp && + old_mtime != new_mtime) { + /* index was fully synced. keep it that way. */ + uint32_t sync_stamp = new_mtime; + + mail_index_update_header(ctx->trans, + offsetof(struct mail_index_header, sync_stamp), + &sync_stamp, sizeof(sync_stamp), TRUE); + } + return 0; } diff -r a52c36c51ff2 -r 8f0ff62befd3 src/lib-storage/index/dbox/dbox-transaction.c --- a/src/lib-storage/index/dbox/dbox-transaction.c Sun Jan 29 00:05:48 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-transaction.c Sun Jan 29 11:54:32 2006 +0200 @@ -17,7 +17,7 @@ } int dbox_transaction_commit(struct mailbox_transaction_context *_t, - enum mailbox_sync_flags flags) + enum mailbox_sync_flags flags __attr_unused__) { struct dbox_transaction_context *t = (struct dbox_transaction_context *)_t; @@ -49,24 +49,11 @@ dbox_transaction_save_commit_post(save_ctx); } -#if 0 - if (lock_id != 0 && dbox->dbox_lock_type != F_WRLCK) { - /* unlock before writing any changes */ - (void)dbox_unlock(dbox, lock_id); - lock_id = 0; - } -#endif if (ret == 0) { if (dbox_sync(dbox, FALSE) < 0) ret = -1; } -#if 0 - if (lock_id != 0) { - if (dbox_unlock(dbox, lock_id) < 0) - ret = -1; - } -#endif return ret; } @@ -74,12 +61,9 @@ { struct dbox_transaction_context *t = (struct dbox_transaction_context *)_t; - struct dbox_mailbox *dbox = (struct dbox_mailbox *)t->ictx.ibox; if (t->save_ctx != NULL) dbox_transaction_save_rollback(t->save_ctx); - /*if (t->dbox_lock_id != 0) - (void)dbox_unlock(dbox, t->dbox_lock_id);*/ index_transaction_rollback(_t); } diff -r a52c36c51ff2 -r 8f0ff62befd3 src/lib-storage/index/dbox/dbox-uidlist.c --- a/src/lib-storage/index/dbox/dbox-uidlist.c Sun Jan 29 00:05:48 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-uidlist.c Sun Jan 29 11:54:32 2006 +0200 @@ -106,6 +106,7 @@ uidlist = i_new(struct dbox_uidlist, 1); uidlist->mbox = mbox; uidlist->fd = -1; + uidlist->mtime = -1; uidlist->lock_fd = -1; uidlist->entry_pool = pool_alloconly_create("uidlist entry pool", 10240); @@ -311,6 +312,7 @@ } } + uidlist->mtime = -1; if (uidlist->fd != -1) { if (close(uidlist->fd) < 0) i_error("close(%s) failed: %m", uidlist->path); @@ -390,11 +392,13 @@ } if (ret == 0) { + /* broken file */ (void)unlink(uidlist->path); if (close(uidlist->fd) < 0) i_error("close(%s) failed: %m", uidlist->path); uidlist->fd = -1; + uidlist->mtime = -1; } i_stream_unref(&input); @@ -716,13 +720,15 @@ return ret; } -int dbox_uidlist_append_commit(struct dbox_uidlist_append_ctx *ctx) +int dbox_uidlist_append_commit(struct dbox_uidlist_append_ctx *ctx, + time_t *mtime_r) { int ret; if (ctx->mail_count == 0) { /* nothing actually appended */ dbox_uidlist_append_rollback(ctx); + *mtime_r = ctx->uidlist->mtime; return 0; } @@ -741,6 +747,7 @@ } } + *mtime_r = ctx->uidlist->mtime; dbox_uidlist_append_rollback(ctx); return ret; } @@ -1007,7 +1014,7 @@ } int dbox_uidlist_append_get_first_uid(struct dbox_uidlist_append_ctx *ctx, - uint32_t *uid_r) + uint32_t *uid_r, time_t *mtime_r) { int ret; @@ -1027,6 +1034,7 @@ } } + *mtime_r = ctx->uidlist->mtime; *uid_r = ctx->uidlist->last_uid + 1; return 0; } diff -r a52c36c51ff2 -r 8f0ff62befd3 src/lib-storage/index/dbox/dbox-uidlist.h --- a/src/lib-storage/index/dbox/dbox-uidlist.h Sun Jan 29 00:05:48 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-uidlist.h Sun Jan 29 11:54:32 2006 +0200 @@ -23,7 +23,8 @@ struct dbox_uidlist_append_ctx * dbox_uidlist_append_init(struct dbox_uidlist *uidlist); -int dbox_uidlist_append_commit(struct dbox_uidlist_append_ctx *ctx); +int dbox_uidlist_append_commit(struct dbox_uidlist_append_ctx *ctx, + time_t *mtime_r); void dbox_uidlist_append_rollback(struct dbox_uidlist_append_ctx *ctx); /* Open/create a file for appending a new message and lock it. @@ -40,7 +41,7 @@ uint32_t dbox_uidlist_get_new_file_seq(struct dbox_uidlist *uidlist); int dbox_uidlist_append_get_first_uid(struct dbox_uidlist_append_ctx *ctx, - uint32_t *uid_r); + uint32_t *uid_r, time_t *mtime_r); int dbox_uidlist_sync_init(struct dbox_uidlist *uidlist, struct dbox_uidlist_sync_ctx **ctx_r,