Repository navigation
lib/db: Recover sequence number and metadata on startup (fixes #6335) - #6336
Conversation
imsodin
left a comment
There was a problem hiding this comment.
Great find!
My initial idea was to put local sequence directly into the db and live with metadata being potentially crap after crashes. This nicely kills two birds with one stone (wow, English is a bit harsher on this proverb, we German-speakers just hit two flies with a single swat :D ).
imsodin
left a comment
There was a problem hiding this comment.
My review comment disappeared, mean. Here we go again:
| goto recalcMeta | ||
| } | ||
|
|
||
| return &s |
There was a problem hiding this comment.
This just made me blink, then think about the goto, think again, and then get it. Personally I'd rather use a function variable defined above like
recalc := func() *FileSet {
if err := s.recalcMeta(); backend.IsClosed(err) {
return nil
} else if err != nil {
panic(err)
}
return &s
}
and replace the gotos with calling and returning that.
|
Orthogonal question. Should metadata updates happen in the same "transaction" as the entries landing? Or is that too gnarly to push through? |
|
We should, it's doable, and there is another bug on precisely that, so hang tight a moment... |
|
Actually that can be a separate one |
Purpose
If we crashed after writing new file entries but before updating metadata in the database the sequence number and metadata will be wrong. This fixes that.
Testing
I have an elegant stress test for this, but it's too large to fit in the margins of this PR. I'm going to improve that a bit more (still bug hunting) and then commit it separately.
Testing it separately is annoying as we need to reach in and mess up the metadata which is tricky. :/