Mercurial > dovecot > core-2.2
changeset 21380:0082213bce13
dict-client: Pass through transaction timestamp to dict-server
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Mon, 09 Jan 2017 19:16:04 +0200 |
parents | 2efa6abf97df |
children | f22040e335f9 |
files | src/dict/dict-commands.c src/lib-dict/dict-client.c src/lib-dict/dict-client.h |
diffstat | 3 files changed, 46 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dict/dict-commands.c Mon Jan 09 16:55:45 2017 +0200 +++ b/src/dict/dict-commands.c Mon Jan 09 19:16:04 2017 +0200 @@ -526,6 +526,33 @@ return 0; } +static int cmd_timestamp(struct dict_connection_cmd *cmd, const char *line) +{ + struct dict_connection_transaction *trans; + const char *const *args; + long long tv_sec; + unsigned int tv_nsec; + + /* <id> <secs> <nsecs> */ + args = t_strsplit_tabescaped(line); + if (str_array_length(args) != 3 || + str_to_llong(args[1], &tv_sec) < 0 || + str_to_uint(args[2], &tv_nsec) < 0) { + i_error("dict client: ATOMIC_INC: broken input"); + return -1; + } + + if (dict_connection_transaction_lookup_parse(cmd->conn, args[0], &trans) < 0) + return -1; + + struct timespec ts = { + .tv_sec = tv_sec, + .tv_nsec = tv_nsec + }; + dict_transaction_set_timestamp(trans->ctx, &ts); + return 0; +} + static const struct dict_cmd_func cmds[] = { { DICT_PROTOCOL_CMD_LOOKUP, cmd_lookup }, { DICT_PROTOCOL_CMD_ITERATE, cmd_iterate }, @@ -537,6 +564,7 @@ { DICT_PROTOCOL_CMD_UNSET, cmd_unset }, { DICT_PROTOCOL_CMD_APPEND, cmd_append }, { DICT_PROTOCOL_CMD_ATOMIC_INC, cmd_atomic_inc }, + { DICT_PROTOCOL_CMD_TIMESTAMP, cmd_timestamp }, { 0, NULL } };
--- a/src/lib-dict/dict-client.c Mon Jan 09 16:55:45 2017 +0200 +++ b/src/lib-dict/dict-client.c Mon Jan 09 19:16:04 2017 +0200 @@ -1463,6 +1463,20 @@ client_dict_send_transaction_query(ctx, query); } +static void client_dict_set_timestamp(struct dict_transaction_context *_ctx, + const struct timespec *ts) +{ + struct client_dict_transaction_context *ctx = + (struct client_dict_transaction_context *)_ctx; + const char *query; + + query = t_strdup_printf("%c%u\t%s\t%u", + DICT_PROTOCOL_CMD_TIMESTAMP, + ctx->id, dec2str(ts->tv_sec), + (unsigned int)ts->tv_nsec); + client_dict_send_transaction_query(ctx, query); +} + struct dict dict_driver_client = { .name = "proxy", @@ -1481,6 +1495,7 @@ .unset = client_dict_unset, .atomic_inc = client_dict_atomic_inc, .lookup_async = client_dict_lookup_async, - .switch_ioloop = client_dict_switch_ioloop + .switch_ioloop = client_dict_switch_ioloop, + .set_timestamp = client_dict_set_timestamp, } };
--- a/src/lib-dict/dict-client.h Mon Jan 09 16:55:45 2017 +0200 +++ b/src/lib-dict/dict-client.h Mon Jan 09 19:16:04 2017 +0200 @@ -25,7 +25,8 @@ DICT_PROTOCOL_CMD_SET = 'S', /* <id> <key> <value> */ DICT_PROTOCOL_CMD_UNSET = 'U', /* <id> <key> */ DICT_PROTOCOL_CMD_APPEND = 'P', /* <id> <key> <value> */ - DICT_PROTOCOL_CMD_ATOMIC_INC = 'A' /* <id> <key> <diff> */ + DICT_PROTOCOL_CMD_ATOMIC_INC = 'A', /* <id> <key> <diff> */ + DICT_PROTOCOL_CMD_TIMESTAMP = 'T', /* <id> <secs> <nsecs> */ }; enum dict_protocol_reply {