changeset 8664:446775a31754 HEAD

dict proxy: Handle async commits better.
author Timo Sirainen <tss@iki.fi>
date Tue, 20 Jan 2009 11:28:48 -0500
parents 011a1fb49cfd
children d1954af8aa3b
files src/dict/dict-server.c src/lib-dict/dict-client.c src/lib-dict/dict-client.h
diffstat 3 files changed, 27 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 	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 @@
 	{ 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 },
--- 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 istream *input;
 	struct ostream *output;
 
-	unsigned int skip_lines;
 	unsigned int connect_counter;
 	unsigned int transaction_id_counter;
 
@@ -225,12 +224,8 @@
 
 	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 @@
 	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);
--- 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 @@
 
 	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> */