Skip to content

lib/db: Keep metadata better in sync (ref #6335) - #6337

Merged
calmh merged 3 commits into
syncthing:masterfrom
calmh:bettermeta
Feb 13, 2020
Merged

calmh merged 3 commits into
syncthing:masterfrom
calmh:bettermeta

Conversation

@calmh

@calmh calmh commented Feb 13, 2020

Copy link
Copy Markdown
Member

This adds metadata updates to the same write batch as the underlying
file change. The odds of a metadata update going missing is greatly
reduced.

Bonus change: actually commit the transaction in recalcMeta.

This now makes the previous recovery thing not kick in during my stress testing...

This adds metadata updates to the same write batch as the underlying
file change. The odds of a metadata update going missing is greatly
reduced.

Bonus change: actually commit the transaction in recalcMeta.
@imsodin

imsodin commented Feb 13, 2020 •

Copy link
Copy Markdown
Member

That's a bit wasteful, as in a batch of 1000 items (the amount we use in model) we do 1000 writes to the db on the meta key, but only the last one is actually effective (at least that's how I understand goleveldb's Batch, as a "stupid" list of db operations to be performed sequentially).

Maybe it's a non-issue, but if there is a noticeable performance impact, I'd just rely on #6336 cleaning up afterwards.

@calmh

calmh commented Feb 13, 2020 •

Copy link
Copy Markdown
Member Author

Yes that's stupid, this is better. For large batches we may still get Checkpoint() writes without metadata, for reasonably small batches it will just be included in the same batch.

We can still crash in the middle of a batch of course, but reduces the window from previous.

@calmh

calmh commented Feb 13, 2020

Copy link
Copy Markdown
Member Author

This does in fact trigger the recalc about as often as we did previously. Would it be over engineering it to add a "pre-flush" hook to Checkpoint() so that we could say

t.Checkpoint(func (t readWriteTransaction) error {
  return meta.toDB(t, ...)
})

and have that only run on actual checkpoints?

@imsodin

imsodin commented Feb 13, 2020 •

Copy link
Copy Markdown
Member

I like the interface :)
However it does indeed smell a bit like over-engineering, or better fells like more complexity than gain (I don't consider having to recalc metadata after a crash a particularly high cost). Then again, Checkpoint itself already has that smell.

@AudriusButkevicius Wanna give a comment on your favorite topic: database-stuff™ ;)

@calmh

calmh commented Feb 13, 2020

Copy link
Copy Markdown
Member Author

The cost is actually fairly high, on the order of 45 minutes to an hour in some setups. It just hopefully shouldn't kick in that often, and there is also a cost to doing a thousand unnecessary writes.

Comment thread lib/db/set.go Resolved
Comment thread lib/db/set.go Resolved
@calmh
calmh merged commit 6a840a0 into syncthing:master Feb 13, 2020
@calmh calmh added this to the v1.4.0 milestone Feb 13, 2020
@calmh
calmh deleted the bettermeta branch February 13, 2020 14:40
imsodin added a commit to imsodin/syncthing that referenced this pull request Feb 13, 2020
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Feb 13, 2021
@syncthing syncthing locked and limited conversation to collaborators Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants