Example #1
0
File: paxos.go Project: bvk/ascent
// RecoverCheckpoint recovers state from a checkpoint record.
func (this *Paxos) RecoverCheckpoint(uid string, data []byte) error {
	if uid != this.uid {
		this.Errorf("checkpoint record doesn't belong to this instance")
		return errs.ErrInvalid
	}

	walRecord := thispb.WALRecord{}
	if err := proto.Unmarshal(data, &walRecord); err != nil {
		this.Errorf("could not parse checkpoint wal record: %v", err)
		return err
	}

	if walRecord.Checkpoint == nil {
		this.Errorf("checkpoint record has no data")
		return errs.ErrInvalid
	}
	checkpoint := walRecord.GetCheckpoint()

	config := checkpoint.GetConfiguration()
	this.doRestoreConfig(config)

	if this.IsProposer() {
		if checkpoint.ProposerState == nil {
			this.Errorf("checkpoint record has no proposer state")
			return errs.ErrInvalid
		}
		this.doRestoreProposer(checkpoint.GetProposerState())
	}

	if this.IsAcceptor() {
		if checkpoint.AcceptorState == nil {
			this.Errorf("checkpoint record has no acceptor state")
			return errs.ErrInvalid
		}
		this.doRestoreAcceptor(checkpoint.GetAcceptorState())
	}

	if this.IsLearner() {
		if checkpoint.LearnerState == nil {
			this.Errorf("checkpoint record has no learner state")
		}
		this.doRestoreLearner(checkpoint.GetLearnerState())
	}
	return nil
}