dovecot-1.2: dict quota: When updating quota, recalculate it whe...

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 7 03:45:26 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/ea522175c549
changeset: 9362:ea522175c549
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 a1b92a251bb9 -r ea522175c549 src/plugins/quota/quota-dict.c
--- a/src/plugins/quota/quota-dict.c	Sun Sep 06 20:44:00 2009 -0400
+++ b/src/plugins/quota/quota-dict.c	Sun Sep 06 20:45:21 2009 -0400
@@ -83,8 +83,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);
 }
 
@@ -114,7 +116,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;
 }
@@ -159,19 +161,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);
@@ -180,9 +193,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