示例#1
0
func (a *roleAcceptor) stepByMsgAccpt(ins *spaxosInstance, msg pb.Message) (bool, error) {
	assert(nil != ins)
	assert(msg.Index == ins.index)

	rsp := pb.Message{
		Type: pb.MsgAccptResp, Reject: false,
		Index: msg.Index, From: msg.To, To: msg.From,
		Entry: pb.PaxosEntry{PropNum: msg.Entry.PropNum}}

	if msg.Entry.PropNum < a.maxPromisedNum {
		rsp.Reject = true
		ins.append(rsp)
		return true, nil
	}

	a.acceptedCnt += 1
	if msg.Entry.PropNum == a.maxAcceptedNum {
		ins.append(rsp)
		return true, nil // do not repeat produce the same hs
	}

	assert(msg.Entry.PropNum > a.maxAcceptedNum)
	a.maxPromisedNum = msg.Entry.PropNum
	a.maxAcceptedNum = msg.Entry.PropNum
	a.acceptedValue = msg.Entry.Value

	ins.updateAccptHardState(a.maxPromisedNum, a.maxAcceptedNum, a.acceptedValue)
	ins.append(rsp)
	return true, nil
}
示例#2
0
func (a *roleAcceptor) stepByMsgProp(ins *spaxosInstance, msg pb.Message) (bool, error) {
	assert(msg.Index == ins.index)

	rsp := pb.Message{
		Type: pb.MsgPropResp, Reject: false,
		Index: msg.Index, From: msg.To, To: msg.From,
		Entry: pb.PaxosEntry{PropNum: msg.Entry.PropNum}}
	if msg.Entry.PropNum < a.maxPromisedNum {
		rsp.Reject = true
		ins.append(rsp)
		return true, nil
	}

	if 0 != a.maxAcceptedNum {
		rsp.Entry.AccptNum = a.maxAcceptedNum
		rsp.Entry.Value = a.acceptedValue
	}

	a.promisedCnt += 1
	if msg.Entry.PropNum == a.maxPromisedNum {
		ins.append(rsp)
		return true, nil
	}

	a.maxPromisedNum = msg.Entry.PropNum

	ins.updateAccptHardState(a.maxPromisedNum, a.maxAcceptedNum, a.acceptedValue)
	ins.append(rsp)
	return true, nil
}