// 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 }