goraft / raft

UNMAINTAINED: A Go implementation of the Raft distributed consensus protocol.
MIT License
2.43k stars 480 forks source link

Broken initialization after loading from a snapshot #207

Closed jvshahid closed 10 years ago

jvshahid commented 10 years ago

Hi everyone, It seems that this commit aa3d8b7dcb9891972a1c8a23d2c1412e827b3a16 has broken the initialization of the raft server when the server is initialized from a snapshot. Unless I misunderstood something, doing the following used to work:

s := raft.NewServer(name, path, transporter, nil, nil, "")
s.LoadSnapsho()

But with the latest release of influxdb (which uses master), we noticed that the followers panic with an invalid argument in appendEntries. Digging in the source code, it turns out that LoadSnapshot() will set the startIndex on this line which is used in isEmpty() here to determine whether the log file is empty or not. This will cause the log file not to be empty on startup, which will cause this line to return and the log file will never be opened. Any subsequent calls to the log file to sync it or write to it will return an error or panic because the log file isn't opened.

xiang90 commented 10 years ago

@jvshahid Thanks for reporting this. It is a bug need to be fixed.