当前位置: 首页>>代码示例>>Golang>>正文


Golang PaxosMessage.Phase2Request方法代码示例

本文整理汇总了Golang中proto-ascent/paxos/classic.PaxosMessage.Phase2Request方法的典型用法代码示例。如果您正苦于以下问题:Golang PaxosMessage.Phase2Request方法的具体用法?Golang PaxosMessage.Phase2Request怎么用?Golang PaxosMessage.Phase2Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在proto-ascent/paxos/classic.PaxosMessage的用法示例。


在下文中一共展示了PaxosMessage.Phase2Request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: doPhase2

// doPhase2 performs classic paxos phase2 steps.
func (this *Paxos) doPhase2(ctxHeader *msgpb.Header, ballot int64,
	value []byte, acceptorList []string) error {

	phase2request := thispb.Phase2Request{}
	phase2request.BallotNumber = proto.Int64(ballot)
	phase2request.ProposedValue = value
	message := thispb.PaxosMessage{}
	message.Phase2Request = &phase2request

	header := msg.NewNestedRequest(this.msn, ctxHeader, this.namespace, this.uid,
		"ClassicPaxos.Phase2")
	defer this.msn.CloseMessage(header)

	count, errSend := msg.SendAllProto(this.msn, acceptorList, header, &message)
	if errSend != nil && count < this.MajoritySize() {
		this.Errorf("could not send phase2 request to majority acceptors: %v",
			errSend)
		return errSend
	}
	this.Infof("send phase2 request %s to acceptors: %v", header, acceptorList)

	responseMap := make(map[string]*thispb.Phase2Response)
	for ii := 0; ii < count && len(responseMap) < this.MajoritySize(); ii++ {
		message := thispb.PaxosMessage{}
		resHeader, errRecv := msg.ReceiveProto(this.msn, header, &message)
		if errRecv != nil {
			break
		}

		acceptor := resHeader.GetMessengerId()
		if _, ok := responseMap[acceptor]; ok {
			this.Warningf("duplicate phase2 response from %s (ignored)", acceptor)
			continue
		}

		if message.Phase2Response == nil {
			this.Warningf("phase2 response data is empty from %s (ignored)",
				acceptor)
			continue
		}
		response := message.GetPhase2Response()
		promisedBallot := response.GetPromisedBallot()

		if promisedBallot < ballot {
			this.Errorf("as per phase2 response, acceptor %s seems to have rolled "+
				"back on his phase1 promise to ballot %d", acceptor, ballot)
			continue
		}

		if promisedBallot > ballot {
			this.Warningf("acceptor %s has moved on to higher ballot %d", acceptor,
				promisedBallot)
			break
		}

		responseMap[acceptor] = response
	}

	if len(responseMap) < this.MajoritySize() {
		this.Warningf("could not get majority phase2 votes %v for value [%s] "+
			"ballot %d", responseMap, value, ballot)
		return errs.ErrRetry
	}

	this.Infof("value [%s] is chosen by phase2 responses %v", value, responseMap)
	return nil
}
开发者ID:bvk,项目名称:ascent,代码行数:68,代码来源:paxos.go


注:本文中的proto-ascent/paxos/classic.PaxosMessage.Phase2Request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。