[dovecot-cvs] dovecot/src/lib-storage/index index-search.c, 1.121, 1.122 index-storage.h, 1.110, 1.111

tss at dovecot.org tss at dovecot.org
Wed Dec 20 19:23:47 UTC 2006


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

Modified Files:
	index-search.c index-storage.h 
Log Message:
Dovecot is now able to execute multiple commands at the same time.
Practically this means commands: FETCH, LIST, SEARCH and syncing output for
all commands. For example it's possible that doing two FETCH commands at the
same time makes their output mixed together.

Non-blocking SEARCH is done by doing search for 20 mails at a time, and then
checking if another command is pending.

Also added X-CANCEL <tag> command to cancel running commands.



Index: index-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- index-search.c	15 Dec 2006 18:38:20 -0000	1.121
+++ index-search.c	20 Dec 2006 19:23:44 -0000	1.122
@@ -21,6 +21,8 @@
 #define TXT_UNKNOWN_CHARSET "[BADCHARSET] Unknown charset"
 #define TXT_INVALID_SEARCH_KEY "Invalid search key"
 
+#define SEARCH_NONBLOCK_COUNT 20
+
 struct index_search_context {
         struct mail_search_context mail_ctx;
 	struct mail_index_view *view;
@@ -952,15 +954,21 @@
 	return TRUE;
 }
 
-int index_storage_search_next(struct mail_search_context *_ctx,
-			      struct mail *mail)
+int index_storage_search_next_nonblock(struct mail_search_context *_ctx,
+				       struct mail *mail, bool *tryagain_r)
 {
         struct index_search_context *ctx = (struct index_search_context *)_ctx;
 	struct mailbox *box = _ctx->transaction->box;
+	unsigned int count = 0;
 	int ret;
 
-	if (ctx->sorted)
+	*tryagain_r = FALSE;
+
+	if (ctx->sorted) {
+		/* everything searched at this point already. just returning
+		   matches from sort list */
 		return index_sort_list_next(ctx->mail_ctx.sort_program, mail);
+	}
 
 	ctx->mail = mail;
 	ctx->imail = (struct index_mail *)mail;
@@ -989,6 +997,11 @@
 				break;
 			}
 		}
+
+		if (++count == SEARCH_NONBLOCK_COUNT) {
+			*tryagain_r = TRUE;
+			return 0;
+		}
 	}
 	if (ret < 0)
 		ctx->failed = TRUE;
@@ -996,10 +1009,13 @@
 	ctx->imail = NULL;
 
 	if (ctx->mail_ctx.sort_program != NULL && ret == 0) {
+		/* finished searching the messages. now sort them and start
+		   returning the messages. */
 		ctx->sorted = TRUE;
 		if (index_sort_list_finish(ctx->mail_ctx.sort_program) < 0)
 			return -1;
-		return index_sort_list_next(ctx->mail_ctx.sort_program, mail);
+		return index_storage_search_next_nonblock(_ctx, mail,
+							  tryagain_r);
 	}
 
 	return ret;

Index: index-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -d -r1.110 -r1.111
--- index-storage.h	17 Dec 2006 16:35:32 -0000	1.110
+++ index-storage.h	20 Dec 2006 19:23:44 -0000	1.111
@@ -179,6 +179,8 @@
 int index_storage_search_deinit(struct mail_search_context *ctx);
 int index_storage_search_next(struct mail_search_context *ctx,
 			      struct mail *mail);
+int index_storage_search_next_nonblock(struct mail_search_context *ctx,
+				       struct mail *mail, bool *tryagain_r);
 int index_storage_search_next_update_seq(struct mail_search_context *ctx);
 
 void index_transaction_init(struct index_transaction_context *t,



More information about the dovecot-cvs mailing list