Inconsistent file quota usage

Bug #1606749 reported by Ghada El-Zoghbi
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Confirmed
Medium
Unassigned

Bug Description

Mahara: 16.04.2
DB: Postgres
OS: Linux
Browser: various

File quota calculations are not syncing correctly for file upload when using multiple devices at the same time.

This lets users surpass their quota by using different computers at the same time.

I've also been able to replicate it by uploading multiple files at once. The usr.quotaused field doesn't get correctly accumulated after each file as it gets overwritten by the other file getting loaded. Perhaps a transaction is required?

The cron job at the end of the day calculates the quota correctly but by then, the user has uploaded many times more than their quota

For example, we were getting numbers such as 244% of their 500MB quota.

Changed in mahara:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Aaron Wells (u-aaronw) wrote :

We've currently disabled transactions on MySQL because they were causing concurrency problems, so a non-transaction solution would be preferrable.

It looks like currently, we update the user's quota by calling the User::quota_add($bytes) function, which adds a file's size to the usr.quotaused field. We could lessen the impact of this bug if we instead summed up the size of all the user's files. Preferrably in a single query, something like (although I'm not sure if this would be kosher in MySQL):

UPDATE usr u
SET quotaused = (
    SELECT sum(aff.size)
    FROM
        artefact_file_files aff
        INNER JOIN artefact a
            ON a.id = aff.artefact
    WHERE
        a.owner = u.id
)
WHERE
    u.id = ?

Of course you could still get race conditions, but they'd only last until the next pageload when we do "SELECT * FROM usr" (assuming that I am correctly remembering that we do that on each page and don't cache it in the session).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.