]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-client: Pass through transaction timestamp to dict-server
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 9 Jan 2017 17:16:04 +0000 (19:16 +0200)
committerGitLab <gitlab@git.dovecot.net>
Mon, 9 Jan 2017 23:07:49 +0000 (01:07 +0200)
src/dict/dict-commands.c
src/lib-dict/dict-client.c
src/lib-dict/dict-client.h

index d7973d12d0ac699fb8d79d334c6464bd365bdb5c..c4f2e8216fdf56daabc38878044e7faba03e4ec8 100644 (file)
@@ -520,6 +520,33 @@ static int cmd_atomic_inc(struct dict_connection_cmd *cmd, const char *line)
        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 },
@@ -530,6 +557,7 @@ static const struct dict_cmd_func cmds[] = {
        { DICT_PROTOCOL_CMD_SET, cmd_set },
        { DICT_PROTOCOL_CMD_UNSET, cmd_unset },
        { DICT_PROTOCOL_CMD_ATOMIC_INC, cmd_atomic_inc },
+       { DICT_PROTOCOL_CMD_TIMESTAMP, cmd_timestamp },
 
        { 0, NULL }
 };
index 36a306c0ec86b8946ab71318ec71141d14bdeb6f..a283a35f6e3e03d1dec84d98a59123146c0bb103 100644 (file)
@@ -1449,6 +1449,20 @@ static void client_dict_atomic_inc(struct dict_transaction_context *_ctx,
        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",
 
@@ -1467,6 +1481,7 @@ struct dict dict_driver_client = {
                .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,
        }
 };
index f9b760ac964cdc3c2c41680b6e4973c21a5c93d4..47028342ba3fcb7a7bdeb8b142d1fcb072af51bf 100644 (file)
@@ -24,7 +24,8 @@ enum dict_protocol_cmd {
 
        DICT_PROTOCOL_CMD_SET = 'S', /* <id> <key> <value> */
        DICT_PROTOCOL_CMD_UNSET = 'U', /* <id> <key> */
-       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 {