Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

server loads old snapshots #235

Open
bcwaldon opened this issue Oct 7, 2014 · 6 comments
Open

server loads old snapshots #235

bcwaldon opened this issue Oct 7, 2014 · 6 comments

Comments

@bcwaldon
Copy link
Contributor

bcwaldon commented Oct 7, 2014

I have the following snapshot files:

1007_79443860.ss
101073_272975458.ss
103852_275330228.ss
11166_165394546.ss
1136_85946380.ss
12466_171438525.ss
1336_94077876.ss
22734_195564716.ss
3111_127284971.ss
3276_130008173.ss
3440_132650609.ss
579_44459558.ss
59456_237259277.ss
651_50350829.ss
68876_245043430.ss
8128_151960757.ss
88589_262075601.ss
9787_159118266.ss

On startup, the server picks the "latest" snapshot as a starting point. The "latest" snapshot is determined by first sorting all the snapshot files in alphabetical order (as they are above), then choosing the last one [0] . The format of these file names is <lastTerm>_<lastIndex>.ss. The intention here is to grab the snapshot from the highest term, falling back to the highest index in case two snapshots were created within the same term. Looking at the sort order above, the last one is clearly not the one with the highest term or highest index.

[0]

raft/server.go

Line 1339 in 510993e

snapshotPath := path.Join(s.path, "snapshot", filenames[len(filenames)-1])

@philips
Copy link
Member

philips commented Oct 7, 2014

This is a somewhat dangerous bug if people have been using rsync or something to backup their snapshot directory. But, in the common case there is only ever one snapshot file on disk and this is managed by go-raft.

@otoolep
Copy link
Contributor

otoolep commented Oct 7, 2014

Wow. Something as simple as this should fix it.

otoolep/raft@ffe3da0

@bcwaldon
Copy link
Contributor Author

bcwaldon commented Oct 8, 2014

@otoolep You actually need to pad both fields, as you need to be able to sort by the last index in the event that the term appears more than once.

@bcwaldon
Copy link
Contributor Author

bcwaldon commented Oct 8, 2014

...and we need to deal with snapshots that are already out there.

@otoolep
Copy link
Contributor

otoolep commented Oct 8, 2014

Check the PR -- it pads both fields.

@bcwaldon
Copy link
Contributor Author

bcwaldon commented Oct 8, 2014

Ah, I didn't realize there was a PR.

#237

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants