]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: dsync shouldn't trigger quota warnings
authorTimo Sirainen <tss@iki.fi>
Mon, 8 Apr 2013 12:13:39 +0000 (15:13 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 8 Apr 2013 12:13:39 +0000 (15:13 +0300)
They would probably just be duplicates that were already triggered by the
other replica.

src/plugins/quota/quota-private.h
src/plugins/quota/quota-storage.c
src/plugins/quota/quota.c

index ba73d5380df263037c4a50c7ba88b507de7f390e..285534082f5a6c512299d9017a3c1952a01a7001 100644 (file)
@@ -156,6 +156,7 @@ struct quota_transaction_context {
        unsigned int limits_set:1;
        unsigned int failed:1;
        unsigned int recalculate:1;
+       unsigned int sync_transaction:1;
 };
 
 /* Register storage to all user's quota roots. */
index d5a31e2082f1da4e64e4f8e4f634161cc4527ab2..880a1553c3ec89878dae6deaffe595486fb95ceb 100644 (file)
@@ -32,6 +32,7 @@ struct quota_mailbox {
        ARRAY(uoff_t) expunge_sizes;
 
        unsigned int recalculate:1;
+       unsigned int sync_transaction_expunge:1;
 };
 
 struct quota_user_module quota_user_module =
@@ -61,6 +62,14 @@ static void quota_mail_expunge(struct mail *_mail)
                }
                array_append(&qbox->expunge_uids, &_mail->uid, 1);
                array_append(&qbox->expunge_sizes, &size, 1);
+               if ((_mail->transaction->flags & MAILBOX_TRANSACTION_FLAG_SYNC) != 0) {
+                       /* we're running dsync. if this brings the quota below
+                          a negative quota warning, don't execute it, because
+                          it probably was already executed by the replica. */
+                       qbox->sync_transaction_expunge = TRUE;
+               } else {
+                       qbox->sync_transaction_expunge = FALSE;
+               }
        }
 
        qmail->super.expunge(_mail);
@@ -106,6 +115,7 @@ quota_mailbox_transaction_begin(struct mailbox *box,
 
        t = qbox->module_ctx.super.transaction_begin(box, flags);
        qt = quota_transaction_begin(box);
+       qt->sync_transaction = (flags & MAILBOX_TRANSACTION_FLAG_SYNC) != 0;
 
        MODULE_CONTEXT_SET(t, quota_storage_module, qt);
        return t;
@@ -285,6 +295,7 @@ static void quota_mailbox_sync_cleanup(struct quota_mailbox *qbox)
                mail_free(&qbox->expunge_qt->tmp_mail);
                mailbox_transaction_rollback(&qbox->expunge_trans);
        }
+       qbox->sync_transaction_expunge = FALSE;
 }
 
 static void quota_mailbox_sync_commit(struct quota_mailbox *qbox)
@@ -330,8 +341,11 @@ static void quota_mailbox_sync_notify(struct mailbox *box, uint32_t uid,
                }
        }
 
-       if (qbox->expunge_qt == NULL)
+       if (qbox->expunge_qt == NULL) {
                qbox->expunge_qt = quota_transaction_begin(box);
+               qbox->expunge_qt->sync_transaction =
+                       qbox->sync_transaction_expunge;
+       }
 
        if (i != count) {
                /* we already know the size */
index 656f412e297a020573ef48575e66db6e3d3c0b15..806d66362b8154159339c93b7b8ccc0ce8690dc2 100644 (file)
@@ -1210,12 +1210,15 @@ int quota_transaction_commit(struct quota_transaction_context **_ctx)
 
                        if (roots[i]->backend.v.update(roots[i], ctx) < 0)
                                ret = -1;
-                       else
+                       else if (!ctx->sync_transaction)
                                array_append(&warn_roots, &roots[i], 1);
                }
                /* execute quota warnings after all updates. this makes it
                   work correctly regardless of whether backend.get_resource()
-                  returns updated values before backend.update() or not */
+                  returns updated values before backend.update() or not.
+                  warnings aren't executed when dsync bring the user over,
+                  because the user probably already got the warning on the
+                  other replica. */
                array_foreach(&warn_roots, roots)
                        quota_warnings_execute(ctx, *roots);
        } T_END;