本文整理汇总了Golang中dlog.Printf函数的典型用法代码示例。如果您正苦于以下问题:Golang Printf函数的具体用法?Golang Printf怎么用?Golang Printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Printf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: handlePropose
func (r *Replica) handlePropose(propose *genericsmr.Propose) {
//TODO!! Handle client retries
batchSize := len(r.ProposeChan) + 1
if batchSize > MAX_BATCH {
batchSize = MAX_BATCH
}
instNo := r.crtInstance[r.Id]
r.crtInstance[r.Id]++
dlog.Printf("Starting instance %d\n", instNo)
dlog.Printf("Batching %d\n", batchSize)
cmds := make([]state.Command, batchSize)
proposals := make([]*genericsmr.Propose, batchSize)
cmds[0] = propose.Command
proposals[0] = propose
for i := 1; i < batchSize; i++ {
prop := <-r.ProposeChan
cmds[i] = prop.Command
proposals[i] = prop
}
r.startPhase1(r.Id, instNo, 0, proposals, cmds, batchSize)
}
开发者ID:nunezro2,项目名称:yarnHA,代码行数:26,代码来源:epaxos.go
示例2: handlePropose
func (r *Replica) handlePropose(propose *genericsmr.Propose) {
if !r.IsLeader {
preply := &genericsmrproto.ProposeReplyTS{FALSE, -1, state.NIL, 0}
r.ReplyProposeTS(preply, propose.Reply)
return
}
for r.instanceSpace[r.crtInstance] != nil {
r.crtInstance++
}
instNo := r.crtInstance
r.crtInstance++
batchSize := len(r.ProposeChan) + 1
if batchSize > MAX_BATCH {
batchSize = MAX_BATCH
}
dlog.Printf("Batched %d\n", batchSize)
cmds := make([]state.Command, batchSize)
proposals := make([]*genericsmr.Propose, batchSize)
cmds[0] = propose.Command
proposals[0] = propose
for i := 1; i < batchSize; i++ {
prop := <-r.ProposeChan
cmds[i] = prop.Command
proposals[i] = prop
}
if r.defaultBallot == -1 {
r.instanceSpace[instNo] = &Instance{
cmds,
r.makeUniqueBallot(0),
PREPARING,
&LeaderBookkeeping{proposals, 0, 0, 0, 0}}
r.bcastPrepare(instNo, r.makeUniqueBallot(0), true)
dlog.Printf("Classic round for instance %d\n", instNo)
} else {
r.instanceSpace[instNo] = &Instance{
cmds,
r.defaultBallot,
PREPARED,
&LeaderBookkeeping{proposals, 0, 0, 0, 0}}
r.recordInstanceMetadata(r.instanceSpace[instNo])
r.recordCommands(cmds)
r.sync()
r.bcastAccept(instNo, r.defaultBallot, cmds)
dlog.Printf("Fast round for instance %d\n", instNo)
}
}
开发者ID:nunezro2,项目名称:yarnHA,代码行数:56,代码来源:paxos.go
示例3: updateBlocking
func (r *Replica) updateBlocking(instance int32) {
if instance != r.blockingInstance {
return
}
for r.blockingInstance = r.blockingInstance; true; r.blockingInstance++ {
if r.blockingInstance <= r.skippedTo[int(r.blockingInstance)%r.N] {
continue
}
if r.instanceSpace[r.blockingInstance] == nil {
return
}
inst := r.instanceSpace[r.blockingInstance]
if inst.status == COMMITTED && inst.skipped {
r.skippedTo[int(r.blockingInstance)%r.N] = r.blockingInstance + int32((inst.nbInstSkipped-1)*r.N)
continue
}
if inst.status == ACCEPTED && inst.skipped {
return
}
if r.blockingInstance%int32(r.N) == r.Id || inst.lb != nil {
if inst.status == READY {
//commit my instance
dlog.Printf("Am about to commit instance %d\n", r.blockingInstance)
inst.status = COMMITTED
if inst.lb.clientProposal != nil && !r.Dreply {
// give client the all clear
dlog.Printf("Sending ACK for req. %d\n", inst.lb.clientProposal.CommandId)
r.ReplyProposeTS(&genericsmrproto.ProposeReplyTS{TRUE, inst.lb.clientProposal.CommandId, state.NIL, inst.lb.clientProposal.Timestamp},
inst.lb.clientProposal.Reply)
}
skip := FALSE
if inst.skipped {
skip = TRUE
}
r.recordInstanceMetadata(inst)
r.sync()
r.bcastCommit(r.blockingInstance, skip, int32(inst.nbInstSkipped), *inst.command)
} else if inst.status != COMMITTED && inst.status != EXECUTED {
return
}
if inst.skipped {
r.skippedTo[int(r.blockingInstance)%r.N] = r.blockingInstance + int32((inst.nbInstSkipped-1)*r.N)
}
} else {
if inst.status == PREPARING || (inst.status == ACCEPTED && inst.skipped) {
return
}
}
}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:54,代码来源:mencius.go
示例4: handleCommitShort
func (r *Replica) handleCommitShort(commit *paxosproto.CommitShort) {
inst := r.instanceSpace[commit.Instance]
dlog.Printf("Committing instance %d\n", commit.Instance)
if inst == nil {
r.instanceSpace[commit.Instance] = &Instance{nil,
commit.Ballot,
COMMITTED,
nil}
} else {
r.instanceSpace[commit.Instance].status = COMMITTED
r.instanceSpace[commit.Instance].ballot = commit.Ballot
if inst.lb != nil && inst.lb.clientProposals != nil {
for i := 0; i < len(inst.lb.clientProposals); i++ {
r.ProposeChan <- inst.lb.clientProposals[i]
}
inst.lb.clientProposals = nil
}
}
r.updateCommittedUpTo()
r.recordInstanceMetadata(r.instanceSpace[commit.Instance])
}
开发者ID:nunezro2,项目名称:yarnHA,代码行数:25,代码来源:paxos.go
示例5: handlePreAcceptOK
func (r *Replica) handlePreAcceptOK(pareply *epaxosproto.PreAcceptOK) {
dlog.Printf("Handling PreAccept reply\n")
inst := r.InstanceSpace[r.Id][pareply.Instance]
if inst.Status != epaxosproto.PREACCEPTED {
// we've moved on, this is a delayed reply
return
}
if !isInitialBallot(inst.ballot) {
return
}
inst.lb.preAcceptOKs++
allCommitted := true
for q := 0; q < r.N; q++ {
if inst.lb.committedDeps[q] < inst.lb.originalDeps[q] {
inst.lb.committedDeps[q] = inst.lb.originalDeps[q]
}
if inst.lb.committedDeps[q] < r.CommittedUpTo[q] {
inst.lb.committedDeps[q] = r.CommittedUpTo[q]
}
if inst.lb.committedDeps[q] < inst.Deps[q] {
allCommitted = false
}
}
//can we commit on the fast path?
if inst.lb.preAcceptOKs >= r.N/2 && inst.lb.allEqual && allCommitted && isInitialBallot(inst.ballot) {
happy++
r.InstanceSpace[r.Id][pareply.Instance].Status = epaxosproto.COMMITTED
r.updateCommitted(r.Id)
if inst.lb.clientProposals != nil && !r.Dreply {
// give clients the all clear
for i := 0; i < len(inst.lb.clientProposals); i++ {
r.ReplyProposeTS(
&genericsmrproto.ProposeReplyTS{
TRUE,
inst.lb.clientProposals[i].CommandId,
state.NIL,
inst.lb.clientProposals[i].Timestamp},
inst.lb.clientProposals[i].Reply)
}
}
r.recordInstanceMetadata(inst)
r.sync() //is this necessary here?
r.bcastCommit(r.Id, pareply.Instance, inst.Cmds, inst.Seq, inst.Deps)
} else if inst.lb.preAcceptOKs >= r.N/2 {
if !allCommitted {
weird++
}
slow++
inst.Status = epaxosproto.ACCEPTED
r.bcastAccept(r.Id, pareply.Instance, inst.ballot, int32(len(inst.Cmds)), inst.Seq, inst.Deps)
}
//TODO: take the slow path if messages are slow to arrive
}
开发者ID:nunezro2,项目名称:yarnHA,代码行数:60,代码来源:epaxos.go
示例6: handleCommit
func (r *Replica) handleCommit(commit *lpaxosproto.Commit) {
inst := r.InstanceSpace[commit.Instance]
dlog.Printf("Committing instance %d\n", commit.Instance)
if inst == nil {
r.InstanceSpace[commit.Instance] = &Instance{
commit.LeaseUpdate,
commit.Ballot,
COMMITTED,
nil}
} else {
r.InstanceSpace[commit.Instance].Updates = commit.LeaseUpdate
r.InstanceSpace[commit.Instance].Status = COMMITTED
r.InstanceSpace[commit.Instance].ballot = commit.Ballot
//try to propose in a different instance or just give up?
}
if r.LatestCommitted < commit.Instance {
r.LatestCommitted = commit.Instance
}
/*r.recordInstanceMetadata(r.InstanceSpace[commit.Instance])
r.recordUpdates(commit.Updates)*/
}
开发者ID:pombredanne,项目名称:qlease,代码行数:25,代码来源:lpaxos.go
示例7: handleCommit
func (r *Replica) handleCommit(commit *paxosproto.Commit) {
inst := r.instanceSpace[commit.Instance]
dlog.Printf("Committing instance %d\n", commit.Instance)
if inst == nil {
r.instanceSpace[commit.Instance] = &Instance{
commit.Command,
commit.Ballot,
COMMITTED,
nil,
0, false}
r.addUpdatingKeys(commit.Command)
} else {
r.instanceSpace[commit.Instance].cmds = commit.Command
r.instanceSpace[commit.Instance].status = COMMITTED
r.instanceSpace[commit.Instance].ballot = commit.Ballot
if inst.lb != nil && inst.lb.clientProposals != nil {
for i := 0; i < len(inst.lb.clientProposals); i++ {
r.ProposeChan <- inst.lb.clientProposals[i]
}
inst.lb.clientProposals = nil
}
}
if commit.Instance > r.latestAcceptedInst {
r.latestAcceptedInst = commit.Instance
}
r.updateCommittedUpTo()
r.recordInstanceMetadata(r.instanceSpace[commit.Instance])
r.recordCommands(commit.Command)
}
开发者ID:pombredanne,项目名称:qlease,代码行数:34,代码来源:paxos.go
示例8: handleAcceptReply
func (r *Replica) handleAcceptReply(areply *menciusproto.AcceptReply) {
dlog.Printf("AcceptReply for instance %d\n", areply.Instance)
inst := r.instanceSpace[areply.Instance]
if areply.OK == TRUE {
inst.lb.acceptOKs++
if areply.SkippedStartInstance > -1 {
r.instanceSpace[areply.SkippedStartInstance] = &Instance{true,
int(areply.SkippedEndInstance-areply.SkippedStartInstance)/r.N + 1,
nil,
0,
COMMITTED,
nil}
r.updateBlocking(areply.SkippedStartInstance)
}
if inst.status == COMMITTED || inst.status == EXECUTED { //TODO || aargs.Ballot != inst.ballot {
// we've moved on, these are delayed replies, so just ignore
return
}
if inst.lb.acceptOKs+1 > r.N>>1 {
if inst.skipped {
//TODO what if
}
inst.status = READY
if !inst.skipped && areply.Instance > r.latestInstReady {
r.latestInstReady = areply.Instance
}
r.updateBlocking(areply.Instance)
}
} else {
// TODO: there is probably another active leader
inst.lb.nacks++
if areply.Ballot > inst.lb.maxRecvBallot {
inst.lb.maxRecvBallot = areply.Ballot
}
if (areply.Ballot&0x0F)%int32(r.N) == areply.Instance%int32(r.N) {
// the owner of the instance is trying to commit something, I should give up
}
if inst.lb.nacks >= r.N>>1 {
// TODO
if inst.lb.clientProposal != nil {
// I'm the owner of the instance, I'll try again with a higher ballot number
inst.ballot = r.makeBallotLargerThan(inst.lb.maxRecvBallot)
r.bcastPrepare(areply.Instance, inst.ballot)
}
}
}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:51,代码来源:mencius.go
示例9: handleProposeLease
func (r *Replica) handleProposeLease(propose *lpaxosproto.ProposeLease) {
if !r.IsLeader {
//TODO: should notify sender? not necessary, but may speed things up
return
}
for r.InstanceSpace[r.crtInstance] != nil {
r.crtInstance++
}
instNo := r.crtInstance
r.crtInstance++
if r.defaultBallot == -1 {
r.InstanceSpace[instNo] = &Instance{
propose.Updates,
r.makeUniqueBallot(0),
PREPARING,
&LeaderBookkeeping{0, 0, 0, 0}}
r.bcastPrepare(instNo, r.makeUniqueBallot(0), true)
dlog.Printf("Classic round for instance %d\n", instNo)
} else {
r.InstanceSpace[instNo] = &Instance{
propose.Updates,
r.defaultBallot,
PREPARED,
&LeaderBookkeeping{0, 0, 0, 0}}
/*r.recordInstanceMetadata(r.InstanceSpace[instNo])
r.recordCommands(cmds)
r.sync()*/
r.bcastAccept(instNo, r.defaultBallot, propose.Updates)
dlog.Printf("Fast round for instance %d\n", instNo)
}
}
开发者ID:pombredanne,项目名称:qlease,代码行数:36,代码来源:lpaxos.go
示例10: handlePrepareReply
func (r *Replica) handlePrepareReply(preply *menciusproto.PrepareReply) {
dlog.Printf("PrepareReply for instance %d\n", preply.Instance)
inst := r.instanceSpace[preply.Instance]
if inst.status != PREPARING {
// we've moved on -- these are delayed replies, so just ignore
return
}
if preply.OK == TRUE {
inst.lb.prepareOKs++
if preply.Ballot > inst.lb.maxRecvBallot {
inst.command = &preply.Command
inst.skipped = false
if preply.Skip == TRUE {
inst.skipped = true
}
inst.nbInstSkipped = int(preply.NbInstancesToSkip)
inst.lb.maxRecvBallot = preply.Ballot
}
if inst.lb.prepareOKs+1 > r.N>>1 {
inst.status = ACCEPTED
inst.lb.nacks = 0
skip := FALSE
if inst.skipped {
skip = TRUE
}
r.bcastAccept(preply.Instance, inst.ballot, skip, int32(inst.nbInstSkipped), *inst.command)
}
} else {
// TODO: there is probably another active leader
inst.lb.nacks++
if preply.Ballot > inst.lb.maxRecvBallot {
inst.lb.maxRecvBallot = preply.Ballot
}
if inst.lb.nacks >= r.N>>1 && inst.lb != nil {
// TODO: better to wait a while
// some other replica is trying to commit skips for our instance
// increase ballot number and try again
inst.ballot = r.makeBallotLargerThan(inst.lb.maxRecvBallot)
r.bcastPrepare(preply.Instance, inst.ballot)
}
}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:47,代码来源:mencius.go
示例11: handlePropose
func (r *Replica) handlePropose(propose *genericsmr.Propose) {
instNo := r.crtInstance
r.crtInstance += int32(r.N)
r.instanceSpace[instNo] = &Instance{false,
0,
&propose.Command,
r.makeBallotLargerThan(0),
ACCEPTED,
&LeaderBookkeeping{propose, 0, 0, 0, 0}}
r.recordInstanceMetadata(r.instanceSpace[instNo])
r.recordCommand(&propose.Command)
r.sync()
r.bcastAccept(instNo, r.instanceSpace[instNo].ballot, FALSE, 0, propose.Command)
dlog.Printf("Choosing req. %d in instance %d\n", propose.CommandId, instNo)
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:19,代码来源:mencius.go
示例12: handleCommit
func (r *Replica) handleCommit(commit *menciusproto.Commit) {
inst := r.instanceSpace[commit.Instance]
dlog.Printf("Committing instance %d\n", commit.Instance)
if inst == nil {
skip := false
if commit.Skip == TRUE {
skip = true
}
r.instanceSpace[commit.Instance] = &Instance{skip,
int(commit.NbInstancesToSkip),
nil, //&commit.Command,
0,
COMMITTED,
nil}
} else {
//inst.command = &commit.Command
inst.status = COMMITTED
inst.skipped = false
if commit.Skip == TRUE {
inst.skipped = true
}
inst.nbInstSkipped = int(commit.NbInstancesToSkip)
if inst.lb != nil && inst.lb.clientProposal != nil {
// try command in the next available instance
r.ProposeChan <- inst.lb.clientProposal
inst.lb.clientProposal = nil
}
}
r.recordInstanceMetadata(r.instanceSpace[commit.Instance])
if commit.Instance%int32(r.N) == r.Id%int32(r.N) {
if r.crtInstance < commit.Instance+commit.NbInstancesToSkip*int32(r.N) {
r.crtInstance = commit.Instance + commit.NbInstancesToSkip*int32(r.N)
}
}
// Try to commit instances waiting for this one
r.updateBlocking(commit.Instance)
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:42,代码来源:mencius.go
示例13: handle2b
func (r *Replica) handle2b(msg *gpaxosproto.M_2b) {
if msg.Balnum != r.crtBalnum {
dlog.Println("2b from a different ballot")
return
}
crtbal := r.ballotArray[r.crtBalnum]
if r.isLeader && crtbal.status != PHASE2 {
log.Println("2b before its time")
return
}
crtbal.lb.cstructs[msg.ReplicaId] = msg.Cstruct
dlog.Printf("Replica %d 2b msg.Cstruct: ", msg.ReplicaId)
dlog.Println(msg.Cstruct)
dlog.Println("my cstruct:", crtbal.cstruct)
crtbal.lb.cstructs[r.Id] = crtbal.cstruct
r.tryToLearn()
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:22,代码来源:gpaxos.go
示例14: handleCommitShort
func (r *Replica) handleCommitShort(commit *lpaxosproto.CommitShort) {
inst := r.InstanceSpace[commit.Instance]
if inst != nil && inst.Updates != nil {
log.Printf("Lease update commit at replica %d\n", r.Id)
}
dlog.Printf("Committing instance %d\n", commit.Instance)
if inst == nil {
r.InstanceSpace[commit.Instance] = &Instance{nil,
commit.Ballot,
COMMITTED,
nil}
} else {
r.InstanceSpace[commit.Instance].Status = COMMITTED
r.InstanceSpace[commit.Instance].ballot = commit.Ballot
if r.LatestCommitted < commit.Instance {
r.LatestCommitted = commit.Instance
}
//try to propose in a different instance or just give up?
}
//r.recordInstanceMetadata(r.InstanceSpace[commit.Instance])
}
开发者ID:pombredanne,项目名称:qlease,代码行数:24,代码来源:lpaxos.go
示例15: run
func (r *Replica) run() {
r.ConnectToPeers()
dlog.Println("Waiting for client connections")
go r.WaitForClientConnections()
if r.Exec {
go r.executeCommands()
}
if r.Id == 0 {
r.IsLeader = true
}
clockChan = make(chan bool, 1)
go r.clock()
clockRang := false
for !r.Shutdown {
select {
case <-clockChan:
clockRang = true
break
case prepareS := <-r.prepareChan:
prepare := prepareS.(*paxosproto.Prepare)
//got a Prepare message
dlog.Printf("Received Prepare from replica %d, for instance %d\n", prepare.LeaderId, prepare.Instance)
r.handlePrepare(prepare)
break
case acceptS := <-r.acceptChan:
accept := acceptS.(*paxosproto.Accept)
//got an Accept message
dlog.Printf("Received Accept from replica %d, for instance %d\n", accept.LeaderId, accept.Instance)
r.handleAccept(accept)
break
case commitS := <-r.commitChan:
commit := commitS.(*paxosproto.Commit)
//got a Commit message
dlog.Printf("Received Commit from replica %d, for instance %d\n", commit.LeaderId, commit.Instance)
r.handleCommit(commit)
break
case commitS := <-r.commitShortChan:
commit := commitS.(*paxosproto.CommitShort)
//got a Commit message
dlog.Printf("Received Commit from replica %d, for instance %d\n", commit.LeaderId, commit.Instance)
r.handleCommitShort(commit)
break
case prepareReplyS := <-r.prepareReplyChan:
prepareReply := prepareReplyS.(*paxosproto.PrepareReply)
//got a Prepare reply
dlog.Printf("Received PrepareReply for instance %d\n", prepareReply.Instance)
r.handlePrepareReply(prepareReply)
break
case acceptReplyS := <-r.acceptReplyChan:
acceptReply := acceptReplyS.(*paxosproto.AcceptReply)
//got an Accept reply
dlog.Printf("Received AcceptReply for instance %d\n", acceptReply.Instance)
r.handleAcceptReply(acceptReply)
break
}
if clockRang {
select {
case propose := <-r.ProposeChan:
//got a Propose from a client
dlog.Printf("Proposal with op %d\n", propose.Command.Op)
r.handlePropose(propose)
clockRang = false
break
case prepareS := <-r.prepareChan:
prepare := prepareS.(*paxosproto.Prepare)
//got a Prepare message
dlog.Printf("Received Prepare from replica %d, for instance %d\n", prepare.LeaderId, prepare.Instance)
r.handlePrepare(prepare)
break
case acceptS := <-r.acceptChan:
accept := acceptS.(*paxosproto.Accept)
//got an Accept message
dlog.Printf("Received Accept from replica %d, for instance %d\n", accept.LeaderId, accept.Instance)
r.handleAccept(accept)
break
case commitS := <-r.commitChan:
commit := commitS.(*paxosproto.Commit)
//got a Commit message
dlog.Printf("Received Commit from replica %d, for instance %d\n", commit.LeaderId, commit.Instance)
//.........这里部分代码省略.........
开发者ID:nunezro2,项目名称:yarnHA,代码行数:101,代码来源:paxos.go
示例16: executeCommands
func (r *Replica) executeCommands() {
execedUpTo := int32(-1)
skippedTo := make([]int32, r.N)
skippedToOrig := make([]int32, r.N)
conflicts := make(map[state.Key]int32, 60000)
for q := 0; q < r.N; q++ {
skippedToOrig[q] = -1
}
for !r.Shutdown {
executed := false
jump := false
copy(skippedTo, skippedToOrig)
for i := execedUpTo + 1; i < r.crtInstance; i++ {
if i < skippedTo[i%int32(r.N)] {
continue
}
if r.instanceSpace[i] == nil {
break
}
if r.instanceSpace[i].status == EXECUTED {
continue
}
if r.instanceSpace[i].status != COMMITTED {
if !r.instanceSpace[i].skipped {
confInst, present := conflicts[r.instanceSpace[i].command.K]
if present && r.instanceSpace[confInst].status != EXECUTED {
break
}
conflicts[r.instanceSpace[i].command.K] = i
jump = true
continue
} else {
break
}
}
if r.instanceSpace[i].skipped {
skippedTo[i%int32(r.N)] = i + int32(r.instanceSpace[i].nbInstSkipped*r.N)
if !jump {
skippedToOrig[i%int32(r.N)] = skippedTo[i%int32(r.N)]
}
continue
}
inst := r.instanceSpace[i]
for inst.command == nil {
time.Sleep(1000 * 1000)
}
confInst, present := conflicts[inst.command.K]
if present && confInst < i && r.instanceSpace[confInst].status != EXECUTED && state.Conflict(r.instanceSpace[confInst].command, inst.command) {
break
}
inst.command.Execute(r.State)
if r.Dreply && inst.lb != nil && inst.lb.clientProposal != nil {
dlog.Printf("Sending ACK for req. %d\n", inst.lb.clientProposal.CommandId)
r.ReplyProposeTS(&genericsmrproto.ProposeReplyTS{TRUE, inst.lb.clientProposal.CommandId, state.NIL, inst.lb.clientProposal.Timestamp},
inst.lb.clientProposal.Reply)
}
inst.status = EXECUTED
executed = true
if !jump {
execedUpTo = i
}
}
if !executed {
time.Sleep(1000 * 1000)
}
}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:78,代码来源:mencius.go
示例17: run
func (r *Replica) run() {
r.ConnectToPeers()
dlog.Println("Waiting for client connections")
go r.WaitForClientConnections()
if r.Exec {
go r.executeCommands()
}
if r.Id == 0 {
//init quorum read lease
quorum := make([]int32, r.N/2+1)
for i := 0; i <= r.N/2; i++ {
quorum[i] = int32(i)
}
r.UpdatePreferredPeerOrder(quorum)
}
slowClockChan = make(chan bool, 1)
fastClockChan = make(chan bool, 1)
go r.slowClock()
//Enabled when batching for 5ms
if MAX_BATCH > 100 {
go r.fastClock()
}
if r.Beacon {
go r.stopAdapting()
}
for !r.Shutdown {
handleNewProposals := true
// Enabled when batching for 5ms
if MAX_BATCH > 100 {
handleNewProposals = false
}
select {
case <-fastClockChan:
handleNewProposals = true
break
case prepareS := <-r.prepareChan:
prepare := prepareS.(*epaxosproto.Prepare)
//got a Prepare message
dlog.Printf("Received Prepare for instance %d.%d\n", prepare.Replica, prepare.Instance)
r.handlePrepare(prepare)
break
case preAcceptS := <-r.preAcceptChan:
preAccept := preAcceptS.(*epaxosproto.PreAccept)
//got a PreAccept message
dlog.Printf("Received PreAccept for instance %d.%d\n", preAccept.LeaderId, preAccept.Instance)
r.handlePreAccept(preAccept)
break
case acceptS := <-r.acceptChan:
accept := acceptS.(*epaxosproto.Accept)
//got an Accept message
dlog.Printf("Received Accept for instance %d.%d\n", accept.LeaderId, accept.Instance)
r.handleAccept(accept)
break
case commitS := <-r.commitChan:
commit := commitS.(*epaxosproto.Commit)
//got a Commit message
dlog.Printf("Received Commit for instance %d.%d\n", commit.LeaderId, commit.Instance)
r.handleCommit(commit)
break
case commitS := <-r.commitShortChan:
commit := commitS.(*epaxosproto.CommitShort)
//got a Commit message
dlog.Printf("Received Commit for instance %d.%d\n", commit.LeaderId, commit.Instance)
r.handleCommitShort(commit)
break
case prepareReplyS := <-r.prepareReplyChan:
prepareReply := prepareReplyS.(*epaxosproto.PrepareReply)
//got a Prepare reply
dlog.Printf("Received PrepareReply for instance %d.%d\n", prepareReply.Replica, prepareReply.Instance)
r.handlePrepareReply(prepareReply)
break
case preAcceptReplyS := <-r.preAcceptReplyChan:
preAcceptReply := preAcceptReplyS.(*epaxosproto.PreAcceptReply)
//got a PreAccept reply
dlog.Printf("Received PreAcceptReply for instance %d.%d\n", preAcceptReply.Replica, preAcceptReply.Instance)
r.handlePreAcceptReply(preAcceptReply)
break
case preAcceptOKS := <-r.preAcceptOKChan:
preAcceptOK := preAcceptOKS.(*epaxosproto.PreAcceptOK)
//got a PreAccept reply
//.........这里部分代码省略.........
开发者ID:nunezro2,项目名称:yarnHA,代码行数:101,代码来源:epaxos.go
示例18: run
func (r *Replica) run() {
r.ConnectToPeers()
dlog.Println("Waiting for client connections")
go r.WaitForClientConnections()
if r.Exec {
go r.executeCommands()
}
go r.clock()
for !r.Shutdown {
select {
case propose := <-r.ProposeChan:
//got a Propose from a client
dlog.Printf("Proposal with id %d\n", propose.CommandId)
r.handlePropose(propose)
break
case skipS := <-r.skipChan:
skip := skipS.(*menciusproto.Skip)
//got a Skip from another replica
dlog.Printf("Skip for instances %d-%d\n", skip.StartInstance, skip.EndInstance)
r.handleSkip(skip)
case prepareS := <-r.prepareChan:
prepare := prepareS.(*menciusproto.Prepare)
//got a Prepare message
dlog.Printf("Received Prepare from replica %d, for instance %d\n", prepare.LeaderId, prepare.Instance)
r.handlePrepare(prepare)
break
case acceptS := <-r.acceptChan:
accept := acceptS.(*menciusproto.Accept)
//got an Accept message
dlog.Printf("Received Accept from replica %d, for instance %d\n", accept.LeaderId, accept.Instance)
r.handleAccept(accept)
break
case commitS := <-r.commitChan:
commit := commitS.(*menciusproto.Commit)
//got a Commit message
dlog.Printf("Received Commit from replica %d, for instance %d\n", commit.LeaderId, commit.Instance)
r.handleCommit(commit)
break
case prepareReplyS := <-r.prepareReplyChan:
prepareReply := prepareReplyS.(*menciusproto.PrepareReply)
//got a Prepare reply
dlog.Printf("Received PrepareReply for instance %d\n", prepareReply.Instance)
r.handlePrepareReply(prepareReply)
break
case acceptReplyS := <-r.acceptReplyChan:
acceptReply := acceptReplyS.(*menciusproto.AcceptReply)
//got an Accept reply
dlog.Printf("Received AcceptReply for instance %d\n", acceptReply.Instance)
r.handleAcceptReply(acceptReply)
break
case delayedSkip := <-r.delayedSkipChan:
r.handleDelayedSkip(delayedSkip)
break
case <-r.clockChan:
if lastSeenInstance == r.blockingInstance {
r.noCommitFor++
} else {
r.noCommitFor = 0
lastSeenInstance = r.blockingInstance
}
if r.noCommitFor >= 50+int(r.Id) && r.crtInstance >= r.blockingInstance+int32(r.N) {
r.noCommitFor = 0
dlog.Printf("Doing force commit\n")
r.forceCommit()
}
break
}
}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:84,代码来源:mencius.go
示例19: handlePreAcceptReply
func (r *Replica) handlePreAcceptReply(pareply *epaxosproto.PreAcceptReply) {
dlog.Printf("Handling PreAccept reply\n")
inst := r.InstanceSpace[pareply.Replica][pareply.Instance]
if inst.Status != epaxosproto.PREACCEPTED {
// we've moved on, this is a delayed reply
return
}
if inst.ballot != pareply.Ballot {
return
}
if pareply.OK == FALSE {
// TODO: there is probably another active leader
inst.lb.nacks++
if pareply.Ballot > inst.lb.maxRecvBallot {
inst.lb.maxRecvBallot = pareply.Ballot
}
if inst.lb.nacks >= r.N/2 {
// TODO
}
return
}
inst.lb.preAcceptOKs++
var equal bool
inst.Seq, inst.Deps, equal = r.mergeAttributes(inst.Seq, inst.Deps, pareply.Seq, pareply.Deps)
if (r.N <= 3 && !r.Thrifty) || inst.lb.preAcceptOKs > 1 {
inst.lb.allEqual = inst.lb.allEqual && equal
if !equal {
conflicted++
}
}
allCommitted := true
for q := 0; q < r.N; q++ {
if inst.lb.committedDeps[q] < pareply.CommittedDeps[q] {
inst.lb.committedDeps[q] = pareply.CommittedDeps[q]
}
if inst.lb.committedDeps[q] < r.CommittedUpTo[q] {
inst.lb.committedDeps[q] = r.CommittedUpTo[q]
}
if inst.lb.committedDeps[q] < inst.Deps[q] {
allCommitted = false
}
}
//can we commit on the fast path?
if inst.lb.preAcceptOKs >= r.N/2 && inst.lb.allEqual && allCommitted && isInitialBallot(inst.ballot) {
happy++
dlog.Printf("Fast path for instance %d.%d\n", pareply.Replica, pareply.Instance)
r.InstanceSpace[pareply.Replica][pareply.Instance].Status = epaxosproto.COMMITTED
r.updateCommitted(pareply.Replica)
if inst.lb.clientProposals != nil && !r.Dreply {
// give clients the all clear
for i := 0; i < len(inst.lb.clientProposals); i++ {
r.ReplyProposeTS(
&genericsmrproto.ProposeReplyTS{
TRUE,
inst.lb.clientProposals[i].CommandId,
state.NIL,
inst.lb.clientProposals[i].Timestamp},
inst.lb.clientProposals[i].Reply)
}
}
r.recordInstanceMetadata(inst)
r.sync() //is this necessary here?
r.bcastCommit(pareply.Replica, pareply.Instance, inst.Cmds, inst.Seq, inst.Deps)
} else if inst.lb.preAcceptOKs >= r.N/2 {
if !allCommitted {
weird++
}
slow++
inst.Status = epaxosproto.ACCEPTED
r.bcastAccept(pareply.Replica, pareply.Instance, inst.ballot, int32(len(inst.Cmds)), inst.Seq, inst.Deps)
}
//TODO: take the slow path if messages are slow to arrive
}
开发者ID:nunezro2,项目名称:yarnHA,代码行数:82,代码来源:epaxos.go
示例20: handleAccept
func (r *Replica) handleAccept(accept *menciusproto.Accept) {
flush := true
inst := r.instanceSpace[accept.Instance]
if inst != nil && inst.ballot > accept.Ballot {
r.replyAccept(accept.LeaderId, &menciusproto.AcceptReply{accept.Instance, FALSE, inst.ballot, -1, -1})
return
}
skipStart := int32(-1)
skipEnd := int32(-1)
if accept.Skip == FALSE && r.crtInstance < accept.Instance {
skipStart = r.crtInstance
skipEnd = accept.Instance/int32(r.N)*int32(r.N) + r.Id
if skipEnd > accept.Instance {
skipEnd -= int32(r.N)
}
if r.skipsWaiting < MAX_SKIPS_WAITING {
//start a timer, waiting for a propose to arrive and fill this hole
go r.timerHelper(&DelayedSkip{skipEnd})
//r.delayedSkipChan <- &DelayedSkip{accept, skipStart}
r.skipsWaiting++
flush = false
}
r.instanceSpace[r.crtInstance] = &Instance{true,
int(skipEnd-r.crtInstance)/r.N + 1,
nil,
-1,
COMMITTED,
nil}
r.recordInstanceMetadata(r.instanceSpace[r.crtInstance])
r.sync()
r.crtInstance = skipEnd + int32(r.N)
}
if inst == nil {
skip := false
if accept.Skip == TRUE {
skip = true
}
r.instanceSpace[accept.Instance] = &Instance{skip,
int(accept.NbInstancesToSkip),
&accept.Command,
accept.Ballot,
ACCEPTED,
nil}
r.recordInstanceMetadata(r.instanceSpace[accept.Instance])
r.recordCommand(&accept.Command)
r.sync()
r.replyAccept(accept.LeaderId, &menciusproto.AcceptReply{accept.Instance, TRUE, -1, skipStart, skipEnd})
} else {
if inst.status == COMMITTED || inst.status == EXECUTED {
if inst.command == nil {
inst.command = &accept.Command
}
dlog.Printf("ATTENTION! Reordered Commit\n")
} else {
inst.command = &accept.Command
inst.ballot = accept.Ballot
inst.status = ACCEPTED
inst.skipped = false
if accept.Skip == TRUE {
inst.skipped = true
}
inst.nbInstSkipped = int(accept.NbInstancesToSkip)
r.recordInstanceMetadata(inst)
r.replyAccept(accept.LeaderId, &menciusproto.AcceptReply{accept.Instance, TRUE, inst.ballot, skipStart, skipEnd})
}
}
if skipStart >= 0 {
dlog.Printf("Skipping!!\n")
r.bcastSkip(skipStart, skipEnd, accept.LeaderId)
r.updateBlocking(skipStart)
if flush {
for _, w := range r.PeerWriters {
if w != nil {
w.Flush()
}
}
}
} else {
r.updateBlocking(accept.Instance)
}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:88,代码来源:mencius.go
注:本文中的dlog.Printf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论