dovecot-2.2: quota: Avoid triggering quota recalc in dict transa...

dovecot at dovecot.org dovecot at dovecot.org
Thu Sep 24 15:44:20 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/168ca81df3fe
changeset: 19212:168ca81df3fe
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 24 18:41:48 2015 +0300
description:
quota: Avoid triggering quota recalc in dict transaction commit callback.
This mainly causes trouble if it again does more dict accesses.

diffstat:

 src/plugins/quota/quota-dict.c |  20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diffs (64 lines):

diff -r 68dd32223db7 -r 168ca81df3fe src/plugins/quota/quota-dict.c
--- a/src/plugins/quota/quota-dict.c	Thu Sep 24 16:41:10 2015 +0300
+++ b/src/plugins/quota/quota-dict.c	Thu Sep 24 18:41:48 2015 +0300
@@ -1,6 +1,7 @@
 /* Copyright (c) 2005-2015 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "ioloop.h"
 #include "str.h"
 #include "dict.h"
 #include "mail-user.h"
@@ -15,6 +16,7 @@
 struct dict_quota_root {
 	struct quota_root root;
 	struct dict *dict;
+	struct timeout *to_update;
 };
 
 extern struct quota_backend quota_backend_dict;
@@ -94,6 +96,8 @@
 {
 	struct dict_quota_root *root = (struct dict_quota_root *)_root;
 
+	i_assert(root->to_update == NULL);
+
 	if (root->dict != NULL)
 		dict_deinit(&root->dict);
 	i_free(root);
@@ -175,14 +179,22 @@
 	return ret;
 }
 
+static void dict_quota_recalc_timeout(struct dict_quota_root *root)
+{
+	uint64_t value;
+
+	timeout_remove(&root->to_update);
+	(void)dict_quota_count(root, TRUE, &value);
+}
+
 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);
+		if (root->to_update == NULL)
+			root->to_update = timeout_add_short(0, dict_quota_recalc_timeout, root);
 	} else if (ret < 0) {
 		i_error("dict quota: Quota update failed, it's now desynced");
 	}
@@ -220,6 +232,10 @@
 	struct dict_quota_root *root = (struct dict_quota_root *)_root;
 
 	(void)dict_wait(root->dict);
+	if (root->to_update != NULL) {
+		dict_quota_recalc_timeout(root);
+		(void)dict_wait(root->dict);
+	}
 }
 
 struct quota_backend quota_backend_dict = {


More information about the dovecot-cvs mailing list