Skip to content

lib/db: Recover sequence number and metadata on startup (fixes #6335) - #6336

Merged
calmh merged 7 commits into
syncthing:masterfrom
calmh:recoverseq
Feb 13, 2020
Merged

calmh merged 7 commits into
syncthing:masterfrom
calmh:recoverseq

Conversation

@calmh

@calmh calmh commented Feb 13, 2020

Copy link
Copy Markdown
Member

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. :/

…ing#6335)

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.

@imsodin imsodin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 imsodin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My review comment disappeared, mean. Here we go again:

Comment thread lib/db/set.go Resolved
Comment thread lib/db/set.go Resolved
Comment thread lib/db/set.go Outdated
goto recalcMeta
}

return &s

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@AudriusButkevicius

Copy link
Copy Markdown
Member

Orthogonal question. Should metadata updates happen in the same "transaction" as the entries landing? Or is that too gnarly to push through?

@calmh

calmh commented Feb 13, 2020

Copy link
Copy Markdown
Member Author

We should, it's doable, and there is another bug on precisely that, so hang tight a moment...

@calmh

calmh commented Feb 13, 2020

Copy link
Copy Markdown
Member Author

Actually that can be a separate one

@calmh
calmh merged commit 51fa36d into syncthing:master Feb 13, 2020
@calmh calmh added this to the v1.4.0 milestone Feb 13, 2020
@calmh
calmh deleted the recoverseq branch February 13, 2020 14:40
@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