[dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-save.c, 1.3, 1.4 dbox-transaction.c, 1.1, 1.2 dbox-uidlist.c, 1.14, 1.15 dbox-uidlist.h, 1.3, 1.4

cras at dovecot.org cras at dovecot.org
Sun Jan 29 11:54:35 EET 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index/dbox
In directory talvi:/tmp/cvs-serv30720

Modified Files:
	dbox-save.c dbox-transaction.c dbox-uidlist.c dbox-uidlist.h 
Log Message:
When appending, update sync_stamp in index so that dbox won't get a full
resync.



Index: dbox-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-save.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbox-save.c	14 Jan 2006 18:47:46 -0000	1.3
+++ dbox-save.c	29 Jan 2006 09:54:32 -0000	1.4
@@ -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;
 }
 

Index: dbox-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-transaction.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbox-transaction.c	27 Nov 2005 23:05:29 -0000	1.1
+++ dbox-transaction.c	29 Jan 2006 09:54:32 -0000	1.2
@@ -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);
 }

Index: dbox-uidlist.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-uidlist.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- dbox-uidlist.c	28 Jan 2006 22:05:48 -0000	1.14
+++ dbox-uidlist.c	29 Jan 2006 09:54:32 -0000	1.15
@@ -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;
 }

Index: dbox-uidlist.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-uidlist.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbox-uidlist.h	5 Jan 2006 01:10:46 -0000	1.3
+++ dbox-uidlist.h	29 Jan 2006 09:54:32 -0000	1.4
@@ -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,



More information about the dovecot-cvs mailing list