Repository navigation
Description
It's somewhat rare in the grand scheme of things, but there are setups with hundreds of devices in a cluster. In some cases this results in files with hundreds of entries in the version vector. This is fine and expected. In our global version list we keep for each file an array of (version vector, device, invalid). In the case where there are many devices and a long version vector we get that vector repeated for every device and this global entry can grow to hundreds of kilobytes for a single file entry.
Thing is though, in the steady state all these hundreds of version vectors are actually the same. So if we grouped the version list by version vector, with each item being (version vector, (device, invalid)...) we'd cut that by a factor hundreds.
In one database I'm looking at, the change would be from
0x00: 1169574 items, 70491 KB keys + 5506325 KB data, 60 B + 4707 B avg, 7634 B max
0x01: 52634 items, 3004 KB keys + 5412346 KB data, 57 B + 102829 B avg, 517727 B max
0x02: 259848 items, 23082 KB keys + 1039 KB data, 88 B + 4 B avg, 256 B max
...
Total 1581101 items, 98761 KB keys + 10935349 KB data.
to
0x00: 1169574 items, 70491 KB keys + 5506325 KB data, 60 B + 4707 B avg, 7634 B max
0x01: 52634 items, 3004 KB keys + 818664 KB data, 57 B + 15553 B avg, 56103 B max
0x02: 259848 items, 23082 KB keys + 1039 KB data, 88 B + 4 B avg, 256 B max
...
Total 1581101 items, 98761 KB keys + 6341667 KB data.
or about a 40% reduction in database size. Smaller setups aren't going to gain that, but it won't hurt either.
The actual file entries still contain all the copies of the version vectors, so class 0x00 is large. Theoretically we could do the same there as with the block lists and bring that down too, but that would actually hurt small setups with the extra indirection. Although we could just skip the indirection (storing it like we do now) if the version list is smaller than x, and have getFile handle both the version list being already in place or there being a hash pointer to it.
Activity
lib/db: Add version vector indirection (ref syncthing#6372)
lib/db: Add version vector indirection (ref syncthing#6372)
lib/db: Slightly improve indirection (ref syncthing#6372)
lib/db: Slightly improve indirection (ref syncthing#6372)
lib/db: Slightly improve indirection (ref #6372) (#6373)
lib/db: Slightly improve indirection (ref #6372) (#6373)
Merge branch 'release'
Merge branch 'master' into indirectversions
Merge branch 'master' into encryption
Merge branch 'master' into badgermerge
imsodin commentedon May 7, 2020
I implemented a prototype to restructure the global list to save a list of versions, and devices that have that version, instead of one long list of devices (duplicating lots of versions). I didn't fully consider the implications of a change in the proto structures: It means unmarshalling global lists now fails with the new code on old databases, and that can happen during a few of the old transitions. One option is to convert to the new format before all the existing transitions, but that obviously might have unintended side-effects. A second one is duplicating a lot of code using the old proto types just for db transitions. A (possible) third to reimplement existing transitions doing "everything by hand", i.e. direct db interaction not using methods like
updateGlobal(we should probably always do that in future transitions). And a fourth to make a hard version break without db transitions. But the gain of this change seems quite small compared to such a cost. I'll look into the feasibility of options 1-3 tomorrow - any general thoughts on it?The new structures are:
The invalid handling might seem a bit random: It's due to the fact that now a version can be mixed between invalid and valid entries or have just invalid ones. Currently we just sort invalid devices behind valid ones, and that distinction is now no longer there -> account them separately. I'll try to write it up better later when I have more time (and found solution to the practicalities) :)
AudriusButkevicius commentedon May 7, 2020
The double invalid stuff looks fishy.
6 remaining items
imsodin commentedon May 8, 2020
On the naming side of things: I will have an old and new variant respectively. In proto the requirements are clear: Old names aren't renamed. Thus I'd go with
V2suffix (e.g.FileVersionV2) for the new variant. On the go side I could usegogoproto.customnameto name the new variant without any suffix (e.g.FileVersion) and the old one with a suffix (e.g.FileVersionOld1orFileVersionDepr1). I like not having suffixes in the code, however switching around names between proto and go is a source of confusion. Then again I'd say proto stuff is hardly ever looked at. Opinions?AudriusButkevicius commentedon May 8, 2020
Sorry, whats the issue with renaming stuff to old/deprecated?
imsodin commentedon May 8, 2020
Never mind, it's anyway not possible:
gogoproto.customnameis only available on message members, not on the name of messages themselves.If I change the name of the old/deprecated messages in proto, the unmarshalling of old proto data (dbs on migration, json test data) won't work anymore.
AudriusButkevicius commentedon May 8, 2020
Unmarshalling is done on the field id, not field name. And message names are completely meaningless in proto, as you pass the bytes to some deserializer and that's it.
imsodin commentedon May 8, 2020
... argh - yeah of course, thanks for insisting.
I was wrapping my head around proto the wrong way: I was thinking we tell it to look up
FileVersionin some data structure... which doesn't exists, we pass the serialized data to a specific type to deserialize. Basic stuff...At least that means there wasn't a naming problem in the first place.
lib/db: Add version vector indirection (ref syncthing#6372)
imsodin commentedon May 13, 2020
I implemented a new global list with version vectors stored once only. The whole diff is a monster - I'll probably put it up for review in step-by-step PRs to a feature branch in the Syncthing repo. The branch lives on top of PR #6635, so that's the first thing to happen.
https://github.com/imsodin/syncthing/tree/indirectversions
One high-level bit for feedback without jumping into the deep end are db migrations:
They needed a fair bit of code duplication and adjustments to the 0to1 migration. Everything starting with line 751 are old methods: master...imsodin:indirectversions#diff-59e58e2c68f4fbad47386d8ccbaee68cR751
I haven't looked into Jakobs suggestion above to convert global lists on load and using "the new global list handling" for the old migrations. Given the current amount of duplication, do you think it is worth investing time to give that a try?
lib/db: Add version vector indirection (ref syncthing#6372)
lib/db: Refactor to use global list by version (ref syncthing#6372)
lib/db: Refactor to use global list by version (ref syncthing#6372)
lib/db: Refactor to use global list by version (ref syncthing#6372)