本文整理汇总了Golang中proto-ascent/paxos/classic.PaxosMessage.ProposeRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang PaxosMessage.ProposeRequest方法的具体用法?Golang PaxosMessage.ProposeRequest怎么用?Golang PaxosMessage.ProposeRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类proto-ascent/paxos/classic.PaxosMessage
的用法示例。
在下文中一共展示了PaxosMessage.ProposeRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Propose
// Propose proposes given value for a consensus.
//
// value: The value to propose for consensus.
//
// timeout: Maximum time duration for the propose operation.
//
// Returns the chosen value on success.
func (this *Paxos) Propose(value []byte, timeout time.Duration) (
[]byte, error) {
// If local instance is not a proposer, find a random proposer.
proposer := this.msn.UID()
if !this.IsProposer() {
proposer = this.proposerList[rand.Intn(len(this.proposerList))]
this.Infof("using %s as the proposer", proposer)
}
// Send the propose request.
request := thispb.ProposeRequest{}
request.ProposedValue = value
message := thispb.PaxosMessage{}
message.ProposeRequest = &request
reqHeader := this.msn.NewRequest(this.namespace, this.uid,
"ClassicPaxos.Propose", timeout)
errSend := msg.SendProto(this.msn, proposer, reqHeader, &message)
if errSend != nil {
this.Errorf("could not send propose request to %s: %v", proposer, errSend)
return nil, errSend
}
// Wait for the response.
_, errRecv := msg.ReceiveProto(this.msn, reqHeader, &message)
if errRecv != nil {
this.Errorf("could not receive propose response from %s: %v", proposer,
errRecv)
return nil, errRecv
}
if message.ProposeResponse == nil {
this.Errorf("propose response from %s is empty", proposer)
return nil, errs.ErrCorrupt
}
response := message.GetProposeResponse()
return response.GetChosenValue(), nil
}