PastLife returns the index of the snapshot before the restart (if any) and whether there was a previous state that should be recovered after a restart.
()
| 290 | // PastLife returns the index of the snapshot before the restart (if any) and whether there was |
| 291 | // a previous state that should be recovered after a restart. |
| 292 | func (n *Node) PastLife() (uint64, bool, error) { |
| 293 | var ( |
| 294 | sp raftpb.Snapshot |
| 295 | idx uint64 |
| 296 | restart bool |
| 297 | rerr error |
| 298 | ) |
| 299 | sp, rerr = n.Store.Snapshot() |
| 300 | if rerr != nil { |
| 301 | return 0, false, rerr |
| 302 | } |
| 303 | if !raft.IsEmptySnap(sp) { |
| 304 | glog.Infof("Found Snapshot.Metadata: %+v\n", sp.Metadata) |
| 305 | restart = true |
| 306 | idx = sp.Metadata.Index |
| 307 | } |
| 308 | |
| 309 | var hd raftpb.HardState |
| 310 | hd, rerr = n.Store.HardState() |
| 311 | if rerr != nil { |
| 312 | return 0, false, rerr |
| 313 | } |
| 314 | if !raft.IsEmptyHardState(hd) { |
| 315 | glog.Infof("Found hardstate: %+v\n", hd) |
| 316 | restart = true |
| 317 | } |
| 318 | |
| 319 | num := n.Store.NumEntries() |
| 320 | glog.Infof("Group %d found %d entries\n", n.RaftContext.Group, num) |
| 321 | // We'll always have at least one entry. |
| 322 | if num > 1 { |
| 323 | restart = true |
| 324 | } |
| 325 | return idx, restart, nil |
| 326 | } |
| 327 | |
| 328 | const ( |
| 329 | messageBatchSoftLimit = 10e6 |
no test coverage detected