// TakeCheckpoint logs a checkpoint record to the wal. func (this *Election) TakeCheckpoint() error { lock := this.ctlr.ReadLockAll() defer lock.Unlock() if this.MajoritySize() <= 0 { this.Errorf("election instance is not yet configured") return errs.ErrInvalid } checkpoint := thispb.Checkpoint{} config := thispb.Configuration{} this.doSaveConfig(&config) checkpoint.Configuration = &config if this.InCommittee() { state := thispb.CommitteeState{} this.doSaveCommittee(&state) checkpoint.CommitteeState = &state } state := thispb.ElectionState{} this.doSaveElection(&state) checkpoint.ElectionState = &state walRecord := thispb.WALRecord{} walRecord.Checkpoint = &checkpoint errAppend := wal.AppendCheckpointProto(this.wal, this.uid, &walRecord) if errAppend != nil { this.Errorf("could not append checkpoint record: %v", errAppend) return errAppend } // Checkpoint recent paxos instances' state. if this.InCommittee() { state := checkpoint.CommitteeState for _, round := range state.ElectionRoundList { if paxos, ok := this.classicPaxosMap[round]; ok { if err := paxos.TakeCheckpoint(); err != nil { this.Errorf("could not take checkpoint of paxos instance for "+ "round %d: %v", err) return err } } } } return nil }
// TakeCheckpoint saves current state into the wal as a checkpoint record. func (this *Paxos) TakeCheckpoint() error { lock := this.ctlr.ReadLockAll() defer lock.Unlock() if !this.IsConfigured() { this.Errorf("classic paxos instance is not yet configured") return errs.ErrInvalid } checkpoint := thispb.Checkpoint{} config := thispb.Configuration{} this.doSaveConfiguration(&config) checkpoint.Configuration = &config if this.IsProposer() { state := thispb.ProposerState{} this.doSaveProposer(&state) checkpoint.ProposerState = &state } if this.IsAcceptor() { state := thispb.AcceptorState{} this.doSaveAcceptor(&state) checkpoint.AcceptorState = &state } if this.IsLearner() { state := thispb.LearnerState{} this.doSaveLearner(&state) checkpoint.LearnerState = &state } walRecord := thispb.WALRecord{} walRecord.Checkpoint = &checkpoint errAppend := wal.AppendCheckpointProto(this.wal, this.uid, &walRecord) if errAppend != nil { this.Errorf("could not append checkpoint record: %v", errAppend) return errAppend } return nil }