Skip to content

Commit

Permalink
dict-client: Pass through transaction timestamp to dict-server
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed Jan 9, 2017
1 parent e28b4fc commit 345fcea
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/dict/dict-commands.c
Expand Up @@ -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 },
Expand All @@ -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 }
};
Expand Down
17 changes: 16 additions & 1 deletion src/lib-dict/dict-client.c
Expand Up @@ -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",

Expand All @@ -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,
}
};
3 changes: 2 additions & 1 deletion src/lib-dict/dict-client.h
Expand Up @@ -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 {
Expand Down

0 comments on commit 345fcea

Please sign in to comment.