Repository navigation
Description
Expected behaviour
A user should be able to upload $Quota Volume as long as the backend storage can take it.
Actual behaviour
OwnCloud uses the Per-User Quota-Value and then subtracks disk usage size of the unix partition (i.e. all owncloud users homes + system installation). So even a user with zero files uploaded cannot upload anything (no matter how small it is) if his quota is set to something smaller than the system installation (i.e. 10MB).
Steps to reproduce
- install owncloud in linux using the root partition
- set quota to something smaller than the installed system size (i.e. smaller than the what "du" shows as used space for your root parition)
- login as user and try to upload a small file (small than quota set). OwnCloud will tell you that there is no space left.
Server configuration
Operating system:
Debian Wheezy
Web server:
Apache 2.2.22
Database:
MySQL 5.5.31
PHP version:
5.3.10
ownCloud version:
Client configuration
Browser:
Mozilla Firefox
Operating system:
Ubuntu LTS
Reason
lib/fileproxy/quota.php line 57ff implements OC_FileProxy_Quota::getFreeSpace .
There you have a
$totalSpace = $this->getQuota($owner);
$view = new \OC\Files\View("/".$owner."/files");
$rootInfo = $view->getFileInfo('/');
$usedSpace = isset($rootInfo['size'])?$rootInfo['size']:0;
return $totalSpace - $usedSpace;
so basically the quota minus the used space is the free space. The used space is extractet from \OC\Files\View::getFileInfo in Field size, which is implemented in lib/files/view.php line 757ff. As mimetype=='httpd/unix-directory' is true, $data["size"] is set to storage size, thus usedSize == storage-size always.
Solution
I think getFileSize is broken or not properly documented. Either getFileSize or getFreeSpace has to be fixed.
Activity
DeepDiver1975 commentedon Oct 27, 2013
@karlitschek oc6 ?
neebski commentedon Oct 27, 2013
Do we think it is related to #5163? If so I'd say this is a big deal. I had
a client yesterday that just endlessly looped uploads on the oc sync client
due to "insufficient storage"
On Oct 27, 2013 6:07 PM, "Thomas Müller" [email protected] wrote:
karlitschek commentedon Oct 28, 2013
I think this something that we have to fix in oc6. Perhaps make the behavior configurable
PVince81 commentedon Oct 30, 2013
I think I had this before and it wasn't related to the quota.
The upload button showed "max size 0B" and I couldn't upload anything.
If I remember well it might be due to permissions / misconfiguration of apache2/htaccess (it was with a fresh install)
I need to look into this and see if I can reproduce it.
PVince81 commentedon Oct 30, 2013
Looks like the quota/free space code has been moved/refactored in OC6.
The code above is from OC5. So there's a little chance that it's fixed in OC6.
Need to check this.
CC @icewind1991
neebski commentedon Oct 30, 2013
I didn't start getting this until I installed OC6 :(
On Oct 30, 2013 6:24 AM, "Vincent Petry" [email protected] wrote:
PVince81 commentedon Oct 31, 2013
Hmmmmm how weird. I've upgraded my personal ownCloud 6 to beta 2 yesterday and syncing worked for a while.
And now out of the blue the sync client starts to say "Insufficient storage".
At least I now have a case that I can debug!
PVince81 commentedon Oct 31, 2013
The only thing I think I changed is setting my personal language to "French".
The upload button says "0B" in the web interface.
So I thought, let's change it back to English.
I refreshed the page and BOOM the upload button was back to "512MB".
Then changed back to "French", it staid on 512MB.
There's something fishy going on.
PVince81 commentedon Oct 31, 2013
And the sync client suddenly syncs properly again.
@michael-dev do you happen to have set another language in your personal settings ?
PVince81 commentedon Oct 31, 2013
Since it doesn't make much sense I think something else might have happened. When I went to the personal page, which happens to show the free space, maybe the internally cached (is it cached?) free space value has been force-refreshed.
PVince81 commentedon Oct 31, 2013
Ok, I think I'm onto something which I can reproduce consistently. Not sure whether it's the same quota issue.
Steps:
Or, at step 4, login as admin and change the quota of that user again. Logging back as the user will show the correct size.
It looks like there is some kind of caching issue. Maybe the available size isn't computed early enough.
I imagine that there might be cases where that cached value is cleared/forgotten which will mess up like it happened to me a few comments ago.
neebski commentedon Oct 31, 2013
I believe you're right that upon opening the personal settings page the
quota is refreshed. Every time I have received "insufficient storage"
errors I was able to fix it by going to personal settings. Unfortunately it
would only work for about 5 file uploads.
On Oct 31, 2013 6:04 AM, "Vincent Petry" [email protected] wrote:
PVince81 commentedon Oct 31, 2013
@neebski thanks, that's valuable information.
What kind of uploads are these ? Over the web interface ?
Small or big files ?
Do you need to log out between the uploads ?
I didn't manage to trigger the bug yet by uploading. I'll try to dive into the code and see what happens there.
PVince81 commentedon Oct 31, 2013
@michael-dev could you try going to the personal settings as described above ? This is to find out whether you're having the same issue or whether it's something completely different.
PVince81 commentedon Oct 31, 2013
It looks like when I refresh the "Files" view in the browser after seeing "Upload size 0B" it will refresh itself correctly.
It actually depends on many files are in the account.
From what I understand now, opening the files view in the web browser will trigger file scanning, which will, once all files were scanned, refresh the root folder's total size in the DB, which is itself used to compute the free size with the quota.
Looking further.
14 remaining items
PVince81 commentedon Nov 4, 2013
Getting a bit closer: lib/private/files/cache/cache.php: calculateFolderSize("files") seems to be the place where the root folder size is overwritten with "-1".
It does a SELECT SUM(
size), MIN(size) FROM*PREFIX*filecacheWHEREparent= ? ANDstorage= ?on the files dir (parent = -1).
For some reason it finds a min size of -1.
The logic in that function makes it favor "-1" over the sum:
{"app":"core","message":"calculateFolderSize: sum=267654662 min=-1 => totalSize=-1","level":0,"time":"2013-11-04T09:00:04+00:00"}
I'm not sure whether this logic is correct. Before I change it, I need to find a way to get a DB snapshot at the time this happens so I can find out what value is pushing the min value down to "-1". This might still be caused by some other process.
Note that this only happens once.
PVince81 commentedon Nov 4, 2013
Aha, GOTCHA: the thumbnail dir is set to -1. Maybe the thumbnail creation process (separate scanner?) has just started and initialized that dir with -1. This causes min(size) to return -1 and -1 to be set to the root.
Looking further.
PVince81 commentedon Nov 4, 2013
It looks like start the scanning process (with force=true) will sometimes reset the size of directories to -1.
This seems to happen as well as soon as thumbnail scanning kicks in (no idea yet when this is supposed to run, seems to start after a few minutes of upload).
And every time the dir is reset to -1, there is a risk (race condition) that the next upload call interprets it as "no more space". Whenever any directory being scanned has "-1", it seems to auto-propagates to the root dir. So this means, if I understand well, that any subdir that is currently being scanned has a chance to trigger the bug.
So far, it seems that when a scan is running at the same time as an upload, the upload usually wins and correctly updates the directory sizes. Occasionally the "-1" update will happen after an upload, which will trigger the issue.
Maybe we shouldn't reset a directory's size to -1 when a size is already present, even when scanning... but there is code in another place that interprets the "-1" as "this directory is currently being scanned".
Complex stuff... I still need some time to understand it better and find a good solution.
PVince81 commentedon Nov 4, 2013
Reload the browser page will call scanFiles(), but that doesn't force a rescan.
So I think the thing that does force it might be the thumbnail generation/scanning/whatever.
Going to look at this next.
neebski commentedon Nov 4, 2013
I installed oc 6 beta 2 the other night and I have not had this issue
since, or at least it's not as obvious.
On Nov 4, 2013 6:28 AM, "Vincent Petry" [email protected] wrote:
PVince81 commentedon Nov 4, 2013
Since it's a race condition, it depends on your server's speed and might not always happen. For me it happens 90% of the times. (hopefully, so I can debug it)
PVince81 commentedon Nov 4, 2013
Not able to reproduce it now 😡
I guess it doesn't matter what triggers the scan. From what I saw in preview.php, there is an isCache() method that will use view->getDirectoryContents() which itself might potentially start a scan. This means that any app that uses this method can potentially trigger a scan.
So I think the thing to focus on is either:
or
PVince81 commentedon Nov 4, 2013
From the things I've seen during testing, I often had the following subdirs in root:
/files 123456
/gallery 789123
/thumbnails -1
where the thumbnails weren't done scanning.
The method calculateFolderSize() would sum these up and find out that there is a -1. The logic would make the root size default to -1.
I'm going to try out the following solution:
use this SQL statement to sum up the size of all files on a given storage:
modify calculateFolderSize() to make a special case of "/", the root dir. The special case would use the above SELECT to compute the total folder size instead of summing up the sizes of the folders inside that root folder, which themselves might contain a "-1" if not fully scanned yet. The size itself might not be 100% accurate as some files/folders might still being uploaded.
Workaround to calculate root folder usage when not in DB
PVince81 commentedon Nov 4, 2013
@michael-dev @neebski if you feel adventurous, you can also help test the above PR. (as you wish)
Do not write -1 as size for root folder
MorrisJobke commentedon Nov 13, 2013
Closed in #5768