本文整理汇总了Golang中dlog.Printf函数的典型用法代码示例。如果您正苦于以下问题:Golang Printf函数的具体用法?Golang Printf怎么用?Golang Printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Printf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
}
示例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
}
}
}
}
示例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])
}
示例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
}
示例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)*/
}
示例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)
}
示例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)
}
}
}
}
示例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)
}
}
示例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)
}
}
}
示例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)
}
示例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)
}
示例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()
}
示例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])
}
示例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)
//.........这里部分代码省略.........