dovecot-1.2: dict proxy: Handle async commits better.

dovecot at dovecot.org dovecot at dovecot.org
Tue Jan 20 18:28:51 EET 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/446775a31754
changeset: 8664:446775a31754
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jan 20 11:28:48 2009 -0500
description:
dict proxy: Handle async commits better.

diffstat:

3 files changed, 27 insertions(+), 14 deletions(-)
src/dict/dict-server.c     |   19 +++++++++++++++++++
src/lib-dict/dict-client.c |   21 +++++++--------------
src/lib-dict/dict-client.h |    1 +

diffs (96 lines):

diff -r 011a1fb49cfd -r 446775a31754 src/dict/dict-server.c
--- a/src/dict/dict-server.c	Mon Jan 19 17:38:21 2009 -0500
+++ b/src/dict/dict-server.c	Tue Jan 20 11:28:48 2009 -0500
@@ -240,6 +240,24 @@ static int cmd_commit(struct dict_client
 	return 0;
 }
 
+static int
+cmd_commit_async(struct dict_client_connection *conn, const char *line)
+{
+	struct dict_server_transaction *trans;
+
+	if (conn->iter_ctx != NULL) {
+		i_error("dict client: COMMIT: Can't commit while iterating");
+		return -1;
+	}
+
+	if (dict_server_transaction_lookup_parse(conn, line, &trans) < 0)
+		return -1;
+
+	dict_transaction_commit_async(&trans->ctx);
+	dict_server_transaction_array_remove(conn, trans);
+	return 0;
+}
+
 static int cmd_rollback(struct dict_client_connection *conn, const char *line)
 {
 	struct dict_server_transaction *trans;
@@ -319,6 +337,7 @@ static struct dict_client_cmd cmds[] = {
 	{ DICT_PROTOCOL_CMD_ITERATE, cmd_iterate },
 	{ DICT_PROTOCOL_CMD_BEGIN, cmd_begin },
 	{ DICT_PROTOCOL_CMD_COMMIT, cmd_commit },
+	{ DICT_PROTOCOL_CMD_COMMIT_ASYNC, cmd_commit_async },
 	{ DICT_PROTOCOL_CMD_ROLLBACK, cmd_rollback },
 	{ DICT_PROTOCOL_CMD_SET, cmd_set },
 	{ DICT_PROTOCOL_CMD_UNSET, cmd_unset },
diff -r 011a1fb49cfd -r 446775a31754 src/lib-dict/dict-client.c
--- a/src/lib-dict/dict-client.c	Mon Jan 19 17:38:21 2009 -0500
+++ b/src/lib-dict/dict-client.c	Tue Jan 20 11:28:48 2009 -0500
@@ -25,7 +25,6 @@ struct client_dict {
 	struct istream *input;
 	struct ostream *output;
 
-	unsigned int skip_lines;
 	unsigned int connect_counter;
 	unsigned int transaction_id_counter;
 
@@ -225,12 +224,8 @@ static char *client_dict_read_line(struc
 
 	while ((ret = i_stream_read(dict->input)) > 0) {
 		line = i_stream_next_line(dict->input);
-		if (line != NULL) {
-			if (dict->skip_lines == 0)
-				return line;
-			/* ignore this reply and wait for the next line */
-			dict->skip_lines--;
-		}
+		if (line != NULL)
+			return line;
 	}
 	i_assert(ret < 0);
 
@@ -471,17 +466,15 @@ static int client_dict_transaction_commi
 	if (ctx->sent_begin) T_BEGIN {
 		const char *query, *line;
 
-		query = t_strdup_printf("%c%u\n", !ctx->failed ?
-					DICT_PROTOCOL_CMD_COMMIT :
-					DICT_PROTOCOL_CMD_ROLLBACK, ctx->id);
+		query = t_strdup_printf("%c%u\n", ctx->failed ?
+					DICT_PROTOCOL_CMD_ROLLBACK :
+					(!async ? DICT_PROTOCOL_CMD_COMMIT :
+					 DICT_PROTOCOL_CMD_COMMIT_ASYNC),
+					ctx->id);
 		if (client_dict_send_transaction_query(ctx, query) < 0)
 			ret = -1;
 		else if (ret < 0) {
 			/* rollback sent, it has no reply */
-		} else if (async) {
-			/* don't wait for the reply. if we read it later,
-			   ignore it. */
-			dict->skip_lines++;
 		} else {
 			/* read reply */
 			line = client_dict_read_line(dict);
diff -r 011a1fb49cfd -r 446775a31754 src/lib-dict/dict-client.h
--- a/src/lib-dict/dict-client.h	Mon Jan 19 17:38:21 2009 -0500
+++ b/src/lib-dict/dict-client.h	Tue Jan 20 11:28:48 2009 -0500
@@ -19,6 +19,7 @@ enum {
 
 	DICT_PROTOCOL_CMD_BEGIN = 'B', /* <id> */
 	DICT_PROTOCOL_CMD_COMMIT = 'C', /* <id> */
+	DICT_PROTOCOL_CMD_COMMIT_ASYNC = 'D', /* <id> */
 	DICT_PROTOCOL_CMD_ROLLBACK = 'R', /* <id> */
 
 	DICT_PROTOCOL_CMD_SET = 'S', /* <id> <key> <value> */


More information about the dovecot-cvs mailing list