[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-save.c, 1.54, 1.55 mbox-storage.h, 1.23, 1.24 mbox-sync-rewrite.c, 1.24, 1.25 mbox-sync.c, 1.56, 1.57

cras at procontrol.fi cras at procontrol.fi
Sat Jul 3 21:13:47 EEST 2004


Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv27076/src/lib-storage/index/mbox

Modified Files:
	mbox-save.c mbox-storage.h mbox-sync-rewrite.c mbox-sync.c 
Log Message:
Updated comment about how syncing is done, and s/extra space/padding/



Index: mbox-save.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- mbox-save.c	2 Jul 2004 11:50:46 -0000	1.54
+++ mbox-save.c	3 Jul 2004 18:13:45 -0000	1.55
@@ -221,7 +221,7 @@
 					     const char *const *keywords,
 					     unsigned int count)
 {
-	unsigned char space[MBOX_HEADER_EXTRA_SPACE+1 +
+	unsigned char space[MBOX_HEADER_PADDING+1 +
 			    sizeof("Content-Length: \n")-1 + MAX_INT_STRLEN];
 	unsigned int i;
 

Index: mbox-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- mbox-storage.h	3 Jul 2004 09:47:13 -0000	1.23
+++ mbox-storage.h	3 Jul 2004 18:13:45 -0000	1.24
@@ -1,8 +1,8 @@
 #ifndef __MBOX_STORAGE_H
 #define __MBOX_STORAGE_H
 
-/* Extra space to leave in X-Keywords header when rewriting mbox */
-#define MBOX_HEADER_EXTRA_SPACE 50
+/* Padding to leave in X-Keywords header when rewriting mbox */
+#define MBOX_HEADER_PADDING 50
 
 #define SUBSCRIPTION_FILE_NAME ".subscriptions"
 #define MBOX_INDEX_PREFIX "dovecot.index"

Index: mbox-sync-rewrite.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- mbox-sync-rewrite.c	2 Jul 2004 18:30:17 -0000	1.24
+++ mbox-sync-rewrite.c	3 Jul 2004 18:13:45 -0000	1.25
@@ -411,7 +411,7 @@
 {
 	struct mbox_sync_mail *mails;
 	uoff_t offset, end_offset, dest_offset, space_diff;
-	uint32_t idx, extra_per_mail;
+	uint32_t idx, padding_per_mail;
 	size_t size;
 	int ret = 0;
 
@@ -427,7 +427,7 @@
 	   complexity, we just leave all the rest of the extra space to first
 	   mail */
 	idx = last_seq - first_seq;
-	extra_per_mail = extra_space / (idx + 1);
+	padding_per_mail = extra_space / (idx + 1);
 
 	/* after expunge the next mail must have been missing space, or we
 	   would have moved it backwards already */
@@ -437,20 +437,19 @@
 	do {
 		/* this message's body is always moved space_diff bytes
 		   forward along with next message's headers, so current
-		   message gets temporarily space_diff amount of extra
-		   whitespace.
+		   message gets temporarily space_diff amount of padding.
 
-		   the moving stops at next message's beginning of extra
-		   space. each message gets left extra_per_mail bytes of
-		   space. what gets left over is given to first message */
+		   the moving stops at next message's beginning of padding.
+		   each message gets left padding_per_mail bytes of space.
+		   what gets left over is given to first message */
 		i_assert(mails[idx].space > 0);
 		space_diff = mails[idx].space;
 		end_offset = mails[idx].offset + mails[idx].space;
 
 		if ((mails[idx].flags & MBOX_EXPUNGED) == 0) {
-			space_diff -= extra_per_mail;
-			end_offset -= extra_per_mail;
-			mails[idx].space = extra_per_mail;
+			space_diff -= padding_per_mail;
+			end_offset -= padding_per_mail;
+			mails[idx].space = padding_per_mail;
 		}
 
 		idx--;

Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- mbox-sync.c	2 Jul 2004 18:30:17 -0000	1.56
+++ mbox-sync.c	3 Jul 2004 18:13:45 -0000	1.57
@@ -11,37 +11,24 @@
 
    Here's how we do it:
 
-   - Start reading the mails mail headers from the beginning
-   - X-Keywords and X-UID headers may contain extra spaces at the end of them,
-     remember how much extra each message has and offset to beginning of the
-     spaces
-   - If message flags are dirty and there's enough space to write them, do it
-   - If we didn't have enough space, remember how much was missing and keep
-     the total amount of them
-   - When we encounter expunged message, check if the amount of empty space in
-     previous messages plus size of expunged message is enough to cover the
-     missing space. If yes,
-       - execute the rewrite plan
-       - forget all the messages before the expunged message. only remember
-         how much data we still have to move to cover the expunged message
-   - If we encounter end of file, grow the file and execute the rewrite plan
-
-   Rewrite plan goes:
-
-   - Start from the first message that needs more space
-   - If there's expunged messages before us, we have to write over them.
-       - Move all messages after it backwards to fill it
-       - Each moved message's X-Keywords header should have n bytes extra
-         space, unless there's not enough space to do it.
-   - If there's no expunged messages, we can move data either forward or
-     backward to get it. Calculate which requires less moving. Forward
-     counting may encounter more messages which require extra space, count
-     that too.
-       - If we decide to move forwards and we had to go through dirty
-         messages, do the moving from last to first dirty message
-   - If we encounter end of file, grow the file enough to get the required
-     amount of space plus enough space to fill X-Keywords headers full of
-     spaces.
+   - Start reading the mails from the beginning
+   - X-Keywords, X-UID and X-IMAPbase headers may contain padding at the end
+     of them, remember how much each message has and offset to beginning of the
+     padding
+   - If header needs to be rewritten and there's enough space, do it
+       - If we didn't have enough space, remember how much was missing
+   - Continue reading and counting the padding in each message. If available
+     padding is enough to rewrite all the previous messages needing it, do it
+   - When we encounter expunged message, treat all of it as padding and
+     rewrite previous messages if needed (and there's enough space).
+     Afterwards keep moving messages backwards to fill the expunged space.
+     Moving is done by rewriting each message's headers, with possibly adding
+     missing Content-Length header and padding. Message bodies are moved
+     without modifications.
+   - If we encounter end of file, grow the file and rewrite needed messages
+   - Rewriting is done by moving message body forward, rewriting message's
+     header and doing the same for previous message, until all of them are
+     rewritten.
 */
 
 #include "lib.h"
@@ -149,7 +136,7 @@
 
 	i_assert(grow_size > 0);
 
-	/* put the extra space between last message's header and body */
+	/* put the padding between last message's header and body */
 	file_size = i_stream_get_size(sync_ctx->file_input) + grow_size;
 	if (file_set_size(sync_ctx->fd, file_size) < 0) {
 		mbox_set_syscall_error(sync_ctx->ibox, "file_set_size()");
@@ -683,7 +670,7 @@
 mbox_sync_handle_missing_space(struct mbox_sync_mail_context *mail_ctx)
 {
 	struct mbox_sync_context *sync_ctx = mail_ctx->sync_ctx;
-	uoff_t extra_space;
+	uoff_t padding;
 
 	buffer_append(sync_ctx->mails, &mail_ctx->mail, sizeof(mail_ctx->mail));
 
@@ -692,14 +679,14 @@
 		return 0;
 
 	/* we have enough space now */
-	extra_space = MBOX_HEADER_EXTRA_SPACE *
+	padding = MBOX_HEADER_PADDING *
 		(sync_ctx->seq - sync_ctx->need_space_seq + 1);
 
 	if (mail_ctx->mail.uid == 0 &&
-	    (uoff_t)sync_ctx->space_diff > extra_space) {
-		/* don't waste too much on extra spacing */
-		sync_ctx->expunged_space = sync_ctx->space_diff - extra_space;
-		sync_ctx->space_diff = extra_space;
+	    (uoff_t)sync_ctx->space_diff > padding) {
+		/* don't waste too much on padding */
+		sync_ctx->expunged_space = sync_ctx->space_diff - padding;
+		sync_ctx->space_diff = padding;
 	} else {
 		sync_ctx->expunged_space = 0;
 	}
@@ -929,7 +916,7 @@
 static int mbox_sync_handle_eof_updates(struct mbox_sync_context *sync_ctx,
 					struct mbox_sync_mail_context *mail_ctx)
 {
-	uoff_t offset, extra_space, trailer_size;
+	uoff_t offset, padding, trailer_size;
 	int need_rewrite;
 
 	if (!istream_raw_mbox_is_eof(sync_ctx->input)) {
@@ -943,9 +930,9 @@
 
 	if (sync_ctx->need_space_seq != 0) {
 		i_assert(sync_ctx->space_diff < 0);
-		extra_space = MBOX_HEADER_EXTRA_SPACE *
+		padding = MBOX_HEADER_PADDING *
 			(sync_ctx->seq - sync_ctx->need_space_seq + 1);
-		sync_ctx->space_diff -= extra_space;
+		sync_ctx->space_diff -= padding;
 
 		sync_ctx->space_diff += sync_ctx->expunged_space;
 		if (sync_ctx->expunged_space <= -sync_ctx->space_diff)
@@ -973,7 +960,7 @@
 			buffer_append(sync_ctx->mails, &mail_ctx->mail,
 				      sizeof(mail_ctx->mail));
 
-			if (mbox_sync_rewrite(sync_ctx, extra_space,
+			if (mbox_sync_rewrite(sync_ctx, padding,
 					      sync_ctx->need_space_seq,
 					      sync_ctx->seq) < 0)
 				return -1;



More information about the dovecot-cvs mailing list