Mercurial > dovecot > core-2.2
changeset 19212:168ca81df3fe
quota: Avoid triggering quota recalc in dict transaction commit callback.
This mainly causes trouble if it again does more dict accesses.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 24 Sep 2015 18:41:48 +0300 |
parents | 68dd32223db7 |
children | 3599f7b9ea09 |
files | src/plugins/quota/quota-dict.c |
diffstat | 1 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 = {