Skip to content

Commit

Permalink
lib-dict: Add dict_transaction_set_timestamp()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed Jan 9, 2017
1 parent 788810a commit e28b4fc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib-dict/dict-private.h
@@ -1,6 +1,7 @@
#ifndef DICT_PRIVATE_H
#define DICT_PRIVATE_H

#include <time.h>
#include "dict.h"

struct dict_vfuncs {
Expand Down Expand Up @@ -40,6 +41,8 @@ struct dict_vfuncs {
void (*lookup_async)(struct dict *dict, const char *key,
dict_lookup_callback_t *callback, void *context);
bool (*switch_ioloop)(struct dict *dict);
void (*set_timestamp)(struct dict_transaction_context *ctx,
const struct timespec *ts);
};

struct dict {
Expand All @@ -62,6 +65,8 @@ struct dict_iterate_context {
struct dict_transaction_context {
struct dict *dict;

struct timespec timestamp;

bool changed:1;
bool no_slowness_warning:1;
};
Expand Down
16 changes: 16 additions & 0 deletions src/lib-dict/dict.c
Expand Up @@ -222,6 +222,22 @@ void dict_transaction_no_slowness_warning(struct dict_transaction_context *ctx)
ctx->no_slowness_warning = TRUE;
}

void dict_transaction_set_timestamp(struct dict_transaction_context *ctx,
const struct timespec *ts)
{
/* These asserts are mainly here to guarantee a possibility in future
to change the API to support multiple timestamps within the same
transaction, so this call would apply only to the following
changes. */
i_assert(!ctx->changed);
i_assert(ctx->timestamp.tv_sec == 0);
i_assert(ts->tv_sec > 0);

ctx->timestamp = *ts;
if (ctx->dict->v.set_timestamp != NULL)
ctx->dict->v.set_timestamp(ctx, ts);
}

struct dict_commit_sync_result {
int ret;
char *error;
Expand Down
5 changes: 5 additions & 0 deletions src/lib-dict/dict.h
Expand Up @@ -129,6 +129,11 @@ struct dict_transaction_context *dict_transaction_begin(struct dict *dict);
finish up anytime soon. Mainly useful for transactions which aren't
especially important whether they finish or not. */
void dict_transaction_no_slowness_warning(struct dict_transaction_context *ctx);
/* Set write timestamp for the entire transaction. This must be set before
any changes are done and can't be changed afterwards. Currently only
dict-sql with Cassandra backend does anything with this. */
void dict_transaction_set_timestamp(struct dict_transaction_context *ctx,
const struct timespec *ts);
/* Commit the transaction. Returns 1 if ok, 0 if dict_atomic_inc() was used
on a nonexistent key, -1 if failed. */
int dict_transaction_commit(struct dict_transaction_context **ctx,
Expand Down

0 comments on commit e28b4fc

Please sign in to comment.