From 03b10bd68ecd2307c7f505ddbdeee2d40a5d1441 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 20 Jan 2009 11:28:48 -0500 Subject: [PATCH] dict proxy: Handle async commits better. --HG-- branch : HEAD --- src/dict/dict-server.c | 19 +++++++++++++++++++ src/lib-dict/dict-client.c | 21 +++++++-------------- src/lib-dict/dict-client.h | 1 + 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/dict/dict-server.c b/src/dict/dict-server.c index da1a15da02..a4a3a6c6ae 100644 --- a/src/dict/dict-server.c +++ b/src/dict/dict-server.c @@ -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 }, diff --git a/src/lib-dict/dict-client.c b/src/lib-dict/dict-client.c index d1738e042b..a32681f491 100644 --- a/src/lib-dict/dict-client.c +++ b/src/lib-dict/dict-client.c @@ -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); diff --git a/src/lib-dict/dict-client.h b/src/lib-dict/dict-client.h index 94064f85a4..334483792a 100644 --- a/src/lib-dict/dict-client.h +++ b/src/lib-dict/dict-client.h @@ -19,6 +19,7 @@ enum { DICT_PROTOCOL_CMD_BEGIN = 'B', /* */ DICT_PROTOCOL_CMD_COMMIT = 'C', /* */ + DICT_PROTOCOL_CMD_COMMIT_ASYNC = 'D', /* */ DICT_PROTOCOL_CMD_ROLLBACK = 'R', /* */ DICT_PROTOCOL_CMD_SET = 'S', /* */ -- 2.47.3