本文整理匯總了Golang中github.com/docker/swarmkit/api.InternalRaftRequest.Marshal方法的典型用法代碼示例。如果您正苦於以下問題:Golang InternalRaftRequest.Marshal方法的具體用法?Golang InternalRaftRequest.Marshal怎麽用?Golang InternalRaftRequest.Marshal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarmkit/api.InternalRaftRequest
的用法示例。
在下文中一共展示了InternalRaftRequest.Marshal方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processInternalRaftRequest
// processInternalRaftRequest sends a message to nodes participating
// in the raft to apply a log entry and then waits for it to be applied
// on the server. It will block until the update is performed, there is
// an error or until the raft node finalizes all the proposals on node
// shutdown.
func (n *Node) processInternalRaftRequest(ctx context.Context, r *api.InternalRaftRequest, cb func()) (proto.Message, error) {
n.stopMu.RLock()
if !n.canSubmitProposal() {
n.stopMu.RUnlock()
return nil, ErrStopped
}
n.waitProp.Add(1)
defer n.waitProp.Done()
n.stopMu.RUnlock()
r.ID = n.reqIDGen.Next()
ch := n.wait.register(r.ID, cb)
// Do this check after calling register to avoid a race.
if atomic.LoadUint32(&n.signalledLeadership) != 1 {
n.wait.cancel(r.ID)
return nil, ErrLostLeadership
}
data, err := r.Marshal()
if err != nil {
n.wait.cancel(r.ID)
return nil, err
}
if len(data) > store.MaxTransactionBytes {
n.wait.cancel(r.ID)
return nil, ErrRequestTooLarge
}
// This must use the context which is cancelled by stop() to avoid a
// deadlock on shutdown.
err = n.Propose(n.Ctx, data)
if err != nil {
n.wait.cancel(r.ID)
return nil, err
}
select {
case x, ok := <-ch:
if ok {
res := x.(*applyResult)
return res.resp, res.err
}
return nil, ErrLostLeadership
case <-n.Ctx.Done():
n.wait.cancel(r.ID)
return nil, ErrStopped
case <-ctx.Done():
n.wait.cancel(r.ID)
return nil, ctx.Err()
}
}