Skip to content

quota completely broken #5509

Closed
Closed

Description

@michael-dev

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

  1. install owncloud in linux using the root partition
  2. 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)
  3. 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

  1. DeepDiver1975 commented on Oct 27, 2013

    @DeepDiver1975
    Contributor
  2. neebski commented on Oct 27, 2013

    @neebski

    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 https://github.com/karlitschek oc6 ?

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/5509#issuecomment-27180711
    .

  3. karlitschek commented on Oct 28, 2013

    @karlitschek
    Contributor

    I think this something that we have to fix in oc6. Perhaps make the behavior configurable

  4. PVince81 commented on Oct 30, 2013

    @PVince81
    Contributor

    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.

  5. PVince81 commented on Oct 30, 2013

    @PVince81
    Contributor

    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

  6. neebski commented on Oct 30, 2013

    @neebski

    I didn't start getting this until I installed OC6 :(
    On Oct 30, 2013 6:24 AM, "Vincent Petry" [email protected] wrote:

    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 https://github.com/icewind1991

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/5509#issuecomment-27378153
    .

  7. PVince81 commented on Oct 31, 2013

    @PVince81
    Contributor

    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!

  8. PVince81 commented on Oct 31, 2013

    @PVince81
    Contributor

    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.

  9. PVince81 commented on Oct 31, 2013

    @PVince81
    Contributor

    And the sync client suddenly syncs properly again.

    @michael-dev do you happen to have set another language in your personal settings ?

  10. PVince81 commented on Oct 31, 2013

    @PVince81
    Contributor

    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.

  11. PVince81 commented on Oct 31, 2013

    @PVince81
    Contributor

    Ok, I think I'm onto something which I can reproduce consistently. Not sure whether it's the same quota issue.

    Steps:

    1. Log in as admin
    2. Create a new user, set a quota directly (the value doesn't matter)
    3. Log in as that user
    4. Check the "Upload" button. It will show "0 B".
    5. Go to the user's personal page
    6. Go back to the files list
    7. Check the "Upload" button. It will show "512 MB".

    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.

  12. neebski commented on Oct 31, 2013

    @neebski

    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:

    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.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/5509#issuecomment-27473996
    .

  13. PVince81 commented on Oct 31, 2013

    @PVince81
    Contributor

    @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.

  14. PVince81 commented on Oct 31, 2013

    @PVince81
    Contributor

    @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.

  15. PVince81 commented on Oct 31, 2013

    @PVince81
    Contributor

    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.

  16. 14 remaining items

  17. PVince81 commented on Nov 4, 2013

    @PVince81
    Contributor

    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*filecache WHERE parent = ? AND storage = ?
    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.

  18. ghost assigned on Nov 4, 2013
  19. PVince81 commented on Nov 4, 2013

    @PVince81
    Contributor

    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.

  20. PVince81 commented on Nov 4, 2013

    @PVince81
    Contributor

    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.

  21. PVince81 commented on Nov 4, 2013

    @PVince81
    Contributor

    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.

  22. neebski commented on Nov 4, 2013

    @neebski

    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:

    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.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/5509#issuecomment-27678868
    .

  23. PVince81 commented on Nov 4, 2013

    @PVince81
    Contributor

    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)

  24. PVince81 commented on Nov 4, 2013

    @PVince81
    Contributor

    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:

    1. how to use another method for flagging unscanned folders and not use the "-1" value
      or
    2. Try and find a way to store/cache or ignore the last known free space value to not prevent uploading.
  25. PVince81 commented on Nov 4, 2013

    @PVince81
    Contributor

    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:

      SELECT sum(size) FROM oc_filecache
      WHERE mimetype <> (SELECT id FROM oc_mimetypes WHERE mimetype='httpd/unix-directory') AND storage=2 and size > 0;
      
    • 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.

  26. added a commit that references this issue on Nov 4, 2013
    67c6067
  27. PVince81 commented on Nov 4, 2013

    @PVince81
    Contributor

    @michael-dev @neebski if you feel adventurous, you can also help test the above PR. (as you wish)

  28. added a commit that references this issue on Nov 7, 2013
    121646b
  29. MorrisJobke commented on Nov 13, 2013

    @MorrisJobke
    Contributor

    Closed in #5768

  30. locked as resolved and limited conversation to collaborators on Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions