dovecot-2.0: dict quota: When updating quota, recalculate it whe...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Sep 7 03:56:00 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/a521d09c3ab9
changeset: 9891:a521d09c3ab9
user: Timo Sirainen <tss at iki.fi>
date: Sun Sep 06 20:45:21 2009 -0400
description:
dict quota: When updating quota, recalculate it when necessary.
diffstat:
1 file changed, 22 insertions(+), 9 deletions(-)
src/plugins/quota/quota-dict.c | 31 ++++++++++++++++++++++---------
diffs (72 lines):
diff -r 54813ca63b26 -r a521d09c3ab9 src/plugins/quota/quota-dict.c
--- a/src/plugins/quota/quota-dict.c Sun Sep 06 20:51:58 2009 -0400
+++ b/src/plugins/quota/quota-dict.c Sun Sep 06 20:45:21 2009 -0400
@@ -81,8 +81,10 @@ static void dict_quota_deinit(struct quo
{
struct dict_quota_root *root = (struct dict_quota_root *)_root;
- if (root->dict != NULL)
+ if (root->dict != NULL) {
+ (void)dict_wait(root->dict);
dict_deinit(&root->dict);
+ }
i_free(root);
}
@@ -112,7 +114,7 @@ dict_quota_count(struct dict_quota_root
dict_set(dt, DICT_QUOTA_CURRENT_COUNT_PATH, dec2str(count));
} T_END;
- dict_transaction_commit_async(&dt);
+ dict_transaction_commit_async(&dt, NULL, NULL);
*value_r = want_bytes ? bytes : count;
return 1;
}
@@ -157,19 +159,30 @@ dict_quota_get_resource(struct quota_roo
return ret;
}
+static void dict_quota_update_callback(int ret, void *context)
+{
+ struct dict_quota_root *root = context;
+ uint64_t value;
+
+ if (ret == 0) {
+ /* row doesn't exist, need to recalculate it */
+ (void)dict_quota_count(root, TRUE, &value);
+ }
+}
+
static int
dict_quota_update(struct quota_root *_root,
struct quota_transaction_context *ctx)
{
struct dict_quota_root *root = (struct dict_quota_root *) _root;
struct dict_transaction_context *dt;
-
- dt = dict_transaction_begin(root->dict);
+ uint64_t value;
if (ctx->recalculate) {
- dict_unset(dt, DICT_QUOTA_CURRENT_BYTES_PATH);
- dict_unset(dt, DICT_QUOTA_CURRENT_COUNT_PATH);
+ if (dict_quota_count(root, TRUE, &value) < 0)
+ return -1;
} else {
+ dt = dict_transaction_begin(root->dict);
if (ctx->bytes_used != 0) {
dict_atomic_inc(dt, DICT_QUOTA_CURRENT_BYTES_PATH,
ctx->bytes_used);
@@ -178,9 +191,9 @@ dict_quota_update(struct quota_root *_ro
dict_atomic_inc(dt, DICT_QUOTA_CURRENT_COUNT_PATH,
ctx->count_used);
}
- }
-
- dict_transaction_commit_async(&dt);
+ dict_transaction_commit_async(&dt, dict_quota_update_callback,
+ root);
+ }
return 0;
}
More information about the dovecot-cvs
mailing list