Inconsistent file quota usage
Bug #1606749 reported by
Ghada El-Zoghbi
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 |
To post a comment you must log in.
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
artefact_ file_files aff
SET quotaused = (
SELECT sum(aff.size)
FROM
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).