]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict proxy: Handle async commits better.
authorTimo Sirainen <tss@iki.fi>
Tue, 20 Jan 2009 16:28:48 +0000 (11:28 -0500)
committerTimo Sirainen <tss@iki.fi>
Tue, 20 Jan 2009 16:28:48 +0000 (11:28 -0500)
--HG--
branch : HEAD

src/dict/dict-server.c
src/lib-dict/dict-client.c
src/lib-dict/dict-client.h

index da1a15da02ba533f4f87ef914a8cf98a3d6d4dfe..a4a3a6c6aec56b3562af38d0007845d0d2349af9 100644 (file)
@@ -240,6 +240,24 @@ static int cmd_commit(struct dict_client_connection *conn, const char *line)
        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 },
index d1738e042bf95f700e8e9062d069311ba32bc47c..a32681f491257ccb35ad9316dd47453f38310419 100644 (file)
@@ -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(struct client_dict *dict)
 
        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_commit(struct dict_transaction_context *_ctx,
        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);
index 94064f85a4a354ea889dfac744ebe523e801a8a9..334483792a0f74fc97320b159372993c9ec2f6fd 100644 (file)
@@ -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> */