MESSAGE quota resource implemention

Greg Banks gnb at
Mon Sep 5 00:32:40 EDT 2011

On 01/09/11 22:22, Bron Gondwana wrote:
> On Thu, Sep 01, 2011 at 01:27:00PM +0200, Julien Coloos wrote:
>> Le 01/09/2011 03:03, Greg Banks a écrit :
>>> I'm thinking that there's now three places in the code which take
>>> a mailbox* and fill out an array of quota diffs, interpreting the
>>> contents of the struct mailbox.  That should really be
>>> centralised.
>> I'm not sure to see what you have in mind here.
>> Are you talking about the places where the QUOTA_STORAGE and
>> QUOTA_MESSAGE entries of the quota diff array are computed
>> relatively to the 'quota_mailbox_used' and 'exists' index fields of
>> the struct mailbox ? If so I guess some of the code could indeed be
>> centralised.
> One place please :)  Ideally I'd like to absorb more of the quota
> stuff into mailbox.c.  Greg and I have some debate about this - how
> much is too much for that file to be doing.  Probably it should be
> abstracted into a couple of layers of stuff - but I really do like
> the consistency of having just a couple of function calls:
> mailbox_append_index_record; and
> mailbox_update_index_record
> which do all the consistency checking and counter updating inside.
> Plus of course a mailbox_check_quota thing that takes a set of
> quota checks to do and sees if there will be space for the
> planned changes!

Ok, I'm now convinced my first attempt at annotation quotas sucked too
hard, here's how I want to re-implement it.  Let me know what you think.

 - rejig the annotation code to always have an open and locked mailbox*
before opening any annotations db (for per-mailbox and per-message

 - add a 32b mailbox index header entry to track the storage in bytes
used by all annotations for the mailbox itself or for messages in the

 - at header upgrade time, write the special value ~0 into this field,
meaning "unknown"

 - when setting or clearing annotations, if the field's value is ~0 then
recalculate it by scanning the annotations databases

 - when setting or clearing annotations, after the field is no longer in
it's "unknown" state, increment or decrement the field by the size of
the annotation

 - in mailbox_commit_quota(), if the field is not "unknown", then
calculate the delta in usage and apply to the quota db.

 - make reconstruct scan the annotations db to figure out the correct
value for this new field.

This means that the annotation STORE and SETMETADATA paths will be
updating the quota db in the same place that APPEND et al do,
mailbox_commit_quota().  This should work around Bug #3529 and also make
the code neater.


More information about the Cyrus-devel mailing list