Repository navigation
lib/db, lib/model: Keep need stats in metadata (ref #5899) - #6413
Conversation
|
Zomg |
| // it will get recreated later in normal operations. | ||
| meta := newMetadataTracker() | ||
| metaErr := meta.fromDB(db.Lowlevel, []byte(folder)) | ||
| meta.resetAll(protocol.GlobalDeviceID) // Is rewritten in updateGlobal |
There was a problem hiding this comment.
I believe this is wrong: Updating global will do nothing except updating the Deleted field of in global list entries, as the versions won't change (thus no change in need or global counts). I probably need to not touch global and recalc needs only. And I definitely want to write a test for the transition :)
There was a problem hiding this comment.
It is good (wrote the test) - a few lines above I empty the global list (because it wouldn't do anything otherwise, not even update the deleted field as the version doesn't change).
|
Does this transform every file |
|
Database access stays the same, max two: The new and old global file (and usually only one, as the inserted one is already the global one in most cases). What changes is that now the But good point, need to check benchmarks, didn't do that yet. |
|
I added a benchmark for updating with lots of remotes: There's 10 additional remotes with half of them on the old version, the other half on the new version. Then I update another device (local or a remote) between those two sets of files (as in existing benchs). I don't see any relevant change running it for 10s. While I expected no significant change (as db operations should be much costlier than a single loop over all devices with a few comparisons and writes to memory), they seem suspiciously close: master: PR: A benchmark for getting need stats before and now feels pretty pointless: Now it's looking up a struct in memory, before iterating/unmarshalling the entire global prefix of the db doing lots of checks. |
but that's the one that shows the awesomeness 😿 |
Brace for the awesomeness: master: PR: |
calmh
left a comment
There was a problem hiding this comment.
I'm not sure it's humanly possible to review this, the global list juggling code was already one of the more complicated pieces of machinery. Nonetheless I'll give it at an attempt to test and run this a bit :) (hang in there)
|
Most of the global update stuff is optimisations. I thought about in a first step doing a version that just stupidly checks everything and doesn't take any shortcuts - I can look into that again. |
|
I guess this just needs a lonely evening and a large crate of wine? |
|
I could make smaller, functional but on their own useless PRs against a feature branch to make it shorter evenings with smaller creates (or equally sized ones and funnier evenings). Essentially the first few commits here, plus hopefully i can split the last of the first ones up further. |
calmh
left a comment
There was a problem hiding this comment.
Barring the one mistake I happened to find, this seems fine. I mean, there might be a hundred new bugs in the global list juggling / need updates in the db transaction code but I'll never find them. We will have to see by seeing how this plays out and applying STRECHECKDBEVERY=1s when it seems broken.
|
Rerunning with |
|
The migration does not trigger a db check/meta recalc itself, but requires at least a meta recalc. Which on upgrade will happen, as schema upgrades come before the version comparison, leading to the check and recalc part. However that should only cause incorrect metadata, not out of sync - looking into that. |
|
That's it, could reproduce before (d1b13b7), is working correctly now: |
|
Is v1.6.0 rc going out tomorrow, given sudden influx of reviews? |
|
That’s generally the plan yes |
|
Ok, I'll try to wrap up the reorder stuff shortly, given its close. |

This is the "main thing" from which I separated #6411 and #6412 (still in this PR as the first two commits). I also kept the rest as three commits for now, as they address separate issues and thus makes reviewing potentially easier - they should still be merged together in the end.
Purpose
The purpose of this PR is to get rid of the frequent db access due to folder summaries/API completion queries. These require the global list and unmarshalling lots of stuff. I added a new metadata flag for needed files. Thus when a file is added to the db, that flag is updated and the summary/db query can just directly access those values from memory. Only if the actual list of needed files is required (i.e. user opens the list in UI) the db needs to be accessed.
Testing
I extended tests in #6402 to cover more ground on "needs". And I now extended all these tests to look at both the metadata and db when checking needs.
I have also done some manual testing a while ago and before merging want to run this on my main setup.