Skip to content

Fix quota calc by preventing root folder size to be overwritten by -1 - #5684

Closed
PVince81 wants to merge 2 commits into
masterfrom
quota-workaroundwhenmissingrootsize
Closed

PVince81 wants to merge 2 commits into
masterfrom
quota-workaroundwhenmissingrootsize

Conversation

@PVince81

@PVince81 PVince81 commented Nov 4, 2013

Copy link
Copy Markdown
Contributor

In some cases when a scan process is in progress (or not started yet),
the root folder might have a size of -1.

To make sure that the quota can still be calculated correctly, an
special SQL query is used to pre-calculate the root folder size by
summing the size of all known files, which is better than no value at
all.

Fixes #5509

Please review @DeepDiver1975 @icewind1991 @karlitschek

This shouldn't happen too often, only when some race condition occurs.
If it is not acceptable to select that way (in case it still happens too often), we can replace it with an UPDATE that writes the value into the DB, which might have some other side effects related to scanners (but unlikely)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

` missing on PREFIXmimetypes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and on mimetype

@PVince81

PVince81 commented Nov 4, 2013

Copy link
Copy Markdown
Contributor Author

I've added the missing backticks.

@PVince81

PVince81 commented Nov 4, 2013

Copy link
Copy Markdown
Contributor Author

Good point. I'll make it default to -1 (the original result) if an exception occurs, and log the exception.

@PVince81

PVince81 commented Nov 4, 2013

Copy link
Copy Markdown
Contributor Author

Ok done, see last commit.

@bantu

bantu commented Nov 4, 2013

Copy link
Copy Markdown

Can we get test coverage for this?

@bantu

bantu commented Nov 4, 2013

Copy link
Copy Markdown

SQLite does not support subqueries to my knowledge. Consider using joins.

@PVince81

PVince81 commented Nov 4, 2013

Copy link
Copy Markdown
Contributor Author

Good point, I was just considering testing it with SQLite.
I'll look into writing tests.

@bantu

bantu commented Nov 4, 2013

Copy link
Copy Markdown

Could probably also just extract the queries.

@PVince81

PVince81 commented Nov 5, 2013

Copy link
Copy Markdown
Contributor Author

Note to self: also check that this works correctly when "/Shared" is present. The calculation might currently differ from the real value because it seems that shared files are currently counted in the "used space" while scanning (inferred from #5688)

@PVince81

PVince81 commented Nov 5, 2013

Copy link
Copy Markdown
Contributor Author

It looks like OC 6 doesn't count the contents of "/Shared" in the actual quota, which means the calculation done in this PR is indeed correct.

@PVince81

PVince81 commented Nov 5, 2013

Copy link
Copy Markdown
Contributor Author

But it does seem that the root dir takes into account the size of files that have been uploaded into other user's shared dir. This needs to be cleared out in #2796 first.

@PVince81

PVince81 commented Nov 5, 2013

Copy link
Copy Markdown
Contributor Author

I'm not sure whether this PR is the best fix. I had the issue again on my private ownCloud and tried applying this PR as patch. The sync client works again, but in the DB I see that the "-1" of the root never gets updated.
This is due to all the other folders which seemingly will never update themselves.
So far I have the following in my data root:

  • / : -1
  • /cache: -1
  • /contacts: -1
  • /documents: -1
  • /files: 128109572
  • /gallery: -1
  • /thumbnails: -1

As you can see, only the "files" dir has a size set. The root is the sum of all, but if a -1 is found, it stays -1.

The fix in this PR just bypasses this wrong value and sums up all files every time, which might have a performance impact if it stays that way. 😦

@PVince81

PVince81 commented Nov 5, 2013

Copy link
Copy Markdown
Contributor Author

I think I'll have a try changing that SELECT to an UPDATE to prevent future calls to need to do the sum many times. The "real" size should overwrite that value whenever Cache::correctFolderSize() is called at some point by a watcher.

@ghost ghost assigned PVince81 Nov 6, 2013
In some cases when a scan process is in progress (or not started yet),
the root folder might have subfolder with the size of -1.

Since the quota is calculated based on the root folder size, it is not
good to let that size be overwritten. In such case, the size will be
calculated by ignoring the non-scanned subfolders.

At some point, the scan process in these subfolders will update the root
size again eventually.

Fixes #5509
@PVince81

PVince81 commented Nov 7, 2013

Copy link
Copy Markdown
Contributor Author

I decided to go with another approach, and rebased/removed all commits into that one.

Before the fix, we sometimes get a situation like this (sometimes even while syncing)):

/ : 128109572
/cache: -1
/contacts: -1
/documents: -1
/files: 128109572
/gallery: -1
/thumbnails: -1

At this point, if you upload a file into /files, the method Cache::calculateFolderSize() is called on all parents up to the root. When calculating the root size, it would see the "-1" and decide that the root size is unknown and write a "-1" there, which breaks the quota.

This fix fixes the logic for the root folder and makes it ignore "-1" subdirs to prevent such situation.

Normally, the "-1" subdirs should only be there initially, maybe at the time where some app has inited its subdir. Once the scan has run, the real size will appear there and add itself to the root total.

Please review @bantu @icewind1991 @DeepDiver1975 @karlitschek

@PVince81

PVince81 commented Nov 7, 2013

Copy link
Copy Markdown
Contributor Author

Ok ok Oracle, I get it. I'll add the backticks...

@ghost

ghost commented Nov 7, 2013

Copy link
Copy Markdown

@PVince81

PVince81 commented Nov 8, 2013

Copy link
Copy Markdown
Contributor Author

Please review @DeepDiver1975 @karlitschek @bantu @icewind1991 @schiesbn
Explanation is here: #5684 (comment)

@karlitschek

Copy link
Copy Markdown
Contributor

👍

@icewind1991

Copy link
Copy Markdown
Contributor

👎 this will effect the root for every storage, including external ones

@icewind1991

Copy link
Copy Markdown
Contributor

see #5768 instead

@PVince81

PVince81 commented Nov 8, 2013

Copy link
Copy Markdown
Contributor Author

Good catch.

@PVince81

PVince81 commented Nov 9, 2013

Copy link
Copy Markdown
Contributor Author

@icewind1991 just thought maybe it isn't that bad to have this "don't overwrite root size with -1" for other storages as well. In the future we might want to know how much space is used there as well (or have storage based quotas which would also need this fix).

Or would this PR break something related to ext storage that I am not aware of ?

@MorrisJobke

Copy link
Copy Markdown
Contributor

@icewind1991 @PVince81 So this can be closed?

@PVince81

Copy link
Copy Markdown
Contributor Author

Yes, closing.

@PVince81 PVince81 closed this Nov 13, 2013
@PVince81
PVince81 deleted the quota-workaroundwhenmissingrootsize branch November 13, 2013 13:31
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quota completely broken

6 participants