美文网首页
2018-05-24 Raft 代码实现2

2018-05-24 Raft 代码实现2

作者: fairy冉冉 | 来源:发表于2018-05-24 14:28 被阅读0次

    代码:

    package main
    
    import (
        "sync"
        "math/rand"
        "fmt"
        "time"
        "log"
    )
    
    // 设置节点的个数为3
    const raftCount  =3
    // 声明leader
    type AppendEntiresArgs struct {
        Term int// 第几任领导
        leaderId  int//设置领导编号
    }
    // 创建一个领导对象
    var args   =AppendEntiresArgs{0,-1}
    // 声明节点类型
    type Raft struct {
        // 线程锁
        mu  sync.Mutex
        // 节点编号
        me int
        //当前领导期数
        currentTerm int
        // 为哪个节点投票
        votedFor int
        //当前节点的状态
        state int// 0 跟随者 1候选人 2就是领导
        // 厚厚一天发送消息时间
        lastMessageTime  int64
        // 节点间发送消息的通道
        message  chan bool
        // 选举通道
        eclectCh chan bool
        // 心跳信号通道
        heartBeat chan bool
        // 返回心跳信号
        heartBeatRe chan  bool
        // 超时时间
        timeout  int
    
        // 设置当前节点的领导
      currentLeader int
    }
    // 产生随机值
    func  randRange(min,max int64)int64  {
        return  rand.Int63n(max-min)+min
    }
    // 打印当前时间
    func printTime()  {
        fmt.Printf("%s",time.Now().String())
    }
    
    // 获取当前时间的ms
    func millisecond()int64  {
        return  time.Now().UnixNano()/int64(time.Millisecond)
    }
    
    func  main()  {
        // 创建三个节点
        for i:=0;i<raftCount ;i++  {
            // 创建三个raft
            Make(i)
        }
    }
    // 通过make函数创建raft节点的对象
    func Make(me int)*Raft  {
        rf :=&Raft{}
        rf.me = me
        rf.votedFor = -1
        rf.state = 0
        rf.timeout =0
        rf.currentLeader = -1
        rf.setTerm(0)
        // 创建通道对象
        rf.eclectCh = make(chan bool)
        rf.message = make(chan  bool)
        rf.heartBeat = make(chan bool)
        rf.heartBeatRe = make(chan bool)
        rand.Seed(time.Now().UnixNano())
    
        go rf.sendLeaderHeartBeat()
        go rf.election()
    
        return rf
    }
    // 创建raft对象的方法
    func  (rf *Raft) setTerm(term int)  {
        rf.currentTerm = term
    }
    // 设置节点发送心跳信号的方法
    func (rf *Raft)sendLeaderHeartBeat()  {
       for{
        // 其他节点接收到了leader发射的心跳信号
           select {
           case <-rf.heartBeat:
            rf.snedAppendEntriesImpl()
        }
       }
    }
    // 返回给leader确认信号
    func (rf *Raft)snedAppendEntriesImpl()  {
        if rf.currentLeader== rf.me {
            // 返回确认信号的节点个数
            var success_count int  =0i
            //设置返回确认信号的子节点的个数
            for i:=0;i<raftCount ;i++  {
                if i!=rf.me {
                    go func() {
                        rf.heartBeatRe <-true
                    }()
                }
            }
            // 计算返回确信信号子节点的个数大于raftCount/2 才能校验成功
            for i:=0;i<raftCount-1 ;i++  {
                select {
                case ok:= <-rf.heartBeatRe:
                    if ok {
                        success_count ++
                        if success_count>raftCount/2 {
                            fmt.Println("子节点为",rf.me)//0,1,2 循环
                            fmt.Println("投票选举成功,校验心跳信号也成功")
                            log.Fatal("over")// 结束程序进程
                        }
                    }
                }
            }
        }
    }
    //设置节点投票的方法
    func (rf *Raft)election ()  {
        // 设置标签
        var result bool
        for  {
            // 设置超时时间
            timeout := randRange(150,300)
            // 设置每个节点的时间
            rf.lastMessageTime = millisecond()
            select {
            // 延迟等待
            case <-time.After(time.Duration(timeout)*time.Millisecond):
                fmt.Println(rf.state)// 打印当前节点的状态
            }
            result= false
            for !result{
                // 选择谁作为leader
                result = rf.election_one_round(&args)
            }
        }
    }
    // 选择谁为leader
    func (rf *Raft)election_one_round(args *AppendEntiresArgs)bool  {
        var  timeout int64
        var done int
        // 是否开始心跳信号的产生
        var  triggerHeartbeat bool
        last := millisecond()
        timeout = 100
        // 信号变量标签
        success :=false
        // 修改raft节点的状态为candidate候选人状态
        rf.mu.Lock()
        rf.becomeCandidate()
        rf.mu.Unlock()
    
        fmt.Println("start electing leader")
        for  {
            for i:=0;i<raftCount ;i++  {
                if i!= rf.me {
                    //拉选票
                 printTime()
                 go func() {
                     if args.leaderId <0 {
                        // 设置此节点开始选举
                        rf.eclectCh <- true
                     }
                 }()
                }
            }
            // 设置投票数量
            done =0
            triggerHeartbeat = false
            for i:=0;i<raftCount-1 ;i++  {
                // 计算一下投票的数量
                //raftCount-1 把自己去掉
                select {
                case ok:= <-rf.eclectCh:
                    if ok {
                        done ++
                        success = done>raftCount/2
                        if success && !triggerHeartbeat {
                            // 选举成功了
                            triggerHeartbeat = true
                            rf.mu.Lock()
                            rf.brcomeLeader()
                            rf.mu.Unlock()
                            // 由leader向其他节点发送心跳信号
                            rf.heartBeat <- true
                            fmt.Println("leader发送心跳信号")
                        }
                    }
                }
            }
            if(timeout+last <millisecond()||(done>raftCount/2 || rf.currentLeader>-1)) {
                break
            }else {
                select {
                // 延时操作
                case <-time.After(time.Duration(10)*time.Millisecond):
                }
            }
        }
        return success
    }
    func(rf *Raft) becomeCandidate()  {
        rf.state  = 1
        rf.setTerm(rf.currentTerm +1)
        rf.votedFor = rf.me
        rf.currentLeader = -1
    }
    func (rf *Raft)brcomeLeader()  {
        rf.state = 2
        rf.currentLeader = rf.me
    }
    

    结果:
    GOROOT=/usr/local/Cellar/go/1.10.2/libexec #gosetup
    GOPATH=/Users/zhaoran/go #gosetup
    /usr/local/Cellar/go/1.10.2/libexec/bin/go build -i -o /private/var/folders/79/bdczcr4x0z9gkj0mch0ws40r0000gn/T/___1go_build_main_go /Users/zhaoran/go/src/kongyxueyuan.com/RAFT/main.go #gosetup
    /private/var/folders/79/bdczcr4x0z9gkj0mch0ws40r0000gn/T/___1go_build_main_go #gosetup
    0
    start electing leader
    2018-05-24 14:25:41.128198939 +0800 CST m=+0.1807056472018-05-24 14:25:41.128325107 +0800 CST m=+0.180831819leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    0
    start electing leader
    2018-05-24 14:25:41.168998072 +0800 CST m=+0.2215062592018-05-24 14:25:41.169029898 +0800 CST m=+0.221538086leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    0
    start electing leader
    2018-05-24 14:25:41.211408824 +0800 CST m=+0.2639185492018-05-24 14:25:41.211433695 +0800 CST m=+0.263943421leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.346189243 +0800 CST m=+0.3987038552018-05-24 14:25:41.346249553 +0800 CST m=+0.398764167leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.399095146 +0800 CST m=+0.4516116762018-05-24 14:25:41.399113229 +0800 CST m=+0.451629760leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.440504985 +0800 CST m=+0.4930230162018-05-24 14:25:41.440514085 +0800 CST m=+0.493032117leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.509335939 +0800 CST m=+0.5618564662018-05-24 14:25:41.509346254 +0800 CST m=+0.561866782leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.602088573 +0800 CST m=+0.6546124632018-05-24 14:25:41.602106619 +0800 CST m=+0.654630510leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.686427797 +0800 CST m=+0.7389547452018-05-24 14:25:41.686439731 +0800 CST m=+0.738966680leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.689967132 +0800 CST m=+0.7424942092018-05-24 14:25:41.689974101 +0800 CST m=+0.742501178leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.755193742 +0800 CST m=+0.8077231842018-05-24 14:25:41.755207131 +0800 CST m=+0.807736573leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.892227863 +0800 CST m=+0.9447622732018-05-24 14:25:41.892239186 +0800 CST m=+0.944773597leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.978426815 +0800 CST m=+1.0309643512018-05-24 14:25:41.978438503 +0800 CST m=+1.030976039leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:41.978602265 +0800 CST m=+1.0311398072018-05-24 14:25:41.978609516 +0800 CST m=+1.031147059leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.172379456 +0800 CST m=+1.2249240242018-05-24 14:25:42.172396289 +0800 CST m=+1.224940858leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.243653007 +0800 CST m=+1.2962001602018-05-24 14:25:42.243663722 +0800 CST m=+1.296210875leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.261706488 +0800 CST m=+1.3142542952018-05-24 14:25:42.261720425 +0800 CST m=+1.314268233leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.40077404 +0800 CST m=+1.4533268902018-05-24 14:25:42.400789791 +0800 CST m=+1.453342641leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.508422815 +0800 CST m=+1.5609795682018-05-24 14:25:42.508434761 +0800 CST m=+1.560991514leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.522819762 +0800 CST m=+1.5753770372018-05-24 14:25:42.522829195 +0800 CST m=+1.575386470leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.690770726 +0800 CST m=+1.7433340902018-05-24 14:25:42.690782151 +0800 CST m=+1.743345516leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.731889901 +0800 CST m=+1.7844547562018-05-24 14:25:42.731901057 +0800 CST m=+1.784465913leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.803425721 +0800 CST m=+1.8559931702018-05-24 14:25:42.80343658 +0800 CST m=+1.856004030leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.850811931 +0800 CST m=+1.9033810982018-05-24 14:25:42.850833844 +0800 CST m=+1.903403012leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:42.959040737 +0800 CST m=+2.0116138292018-05-24 14:25:42.959072024 +0800 CST m=+2.011645117leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.084948972 +0800 CST m=+2.1375266292018-05-24 14:25:43.084963942 +0800 CST m=+2.137541600leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.091469349 +0800 CST m=+2.1440472432018-05-24 14:25:43.091477456 +0800 CST m=+2.144055350leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.191116578 +0800 CST m=+2.2436980852018-05-24 14:25:43.191131382 +0800 CST m=+2.243712889leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.242519281 +0800 CST m=+2.2951026512018-05-24 14:25:43.242530829 +0800 CST m=+2.295114200leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.375330087 +0800 CST m=+2.4279182732018-05-24 14:25:43.37535798 +0800 CST m=+2.427946167leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.429520329 +0800 CST m=+2.4821104802018-05-24 14:25:43.429553314 +0800 CST m=+2.482143466leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.48893521 +0800 CST m=+2.5415275152018-05-24 14:25:43.488948721 +0800 CST m=+2.541541027leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.653935471 +0800 CST m=+2.7065337592018-05-24 14:25:43.653951695 +0800 CST m=+2.706549983leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.687127187 +0800 CST m=+2.7397266782018-05-24 14:25:43.687140718 +0800 CST m=+2.739740210leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.71352989 +0800 CST m=+2.7661303382018-05-24 14:25:43.713540473 +0800 CST m=+2.766140922leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.816282338 +0800 CST m=+2.8688865122018-05-24 14:25:43.816298007 +0800 CST m=+2.868902182leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.952706646 +0800 CST m=+3.0053157672018-05-24 14:25:43.952717551 +0800 CST m=+3.005326672leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:43.97524748 +0800 CST m=+3.0278574182018-05-24 14:25:43.975265611 +0800 CST m=+3.027875550leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.104335754 +0800 CST m=+3.1569503732018-05-24 14:25:44.104342583 +0800 CST m=+3.156957202leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.172871378 +0800 CST m=+3.2254884822018-05-24 14:25:44.172887119 +0800 CST m=+3.225504223leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.235211658 +0800 CST m=+3.2878310222018-05-24 14:25:44.235222675 +0800 CST m=+3.287842040leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.326000448 +0800 CST m=+3.3786231042018-05-24 14:25:44.326016565 +0800 CST m=+3.378639222leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.399543916 +0800 CST m=+3.4521692392018-05-24 14:25:44.399553868 +0800 CST m=+3.452179191leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.454029271 +0800 CST m=+3.5066565692018-05-24 14:25:44.454041308 +0800 CST m=+3.506668607leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.529484365 +0800 CST m=+3.5821143992018-05-24 14:25:44.529495471 +0800 CST m=+3.582125505leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.654962438 +0800 CST m=+3.7075970222018-05-24 14:25:44.654974992 +0800 CST m=+3.707609576leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.67925223 +0800 CST m=+3.7318876942018-05-24 14:25:44.679272565 +0800 CST m=+3.731908030leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.808082834 +0800 CST m=+3.8607229702018-05-24 14:25:44.808094559 +0800 CST m=+3.860734695leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.823051723 +0800 CST m=+3.8756924012018-05-24 14:25:44.823067183 +0800 CST m=+3.875707862leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:44.92033724 +0800 CST m=+3.9729814462018-05-24 14:25:44.920350019 +0800 CST m=+3.972994226leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.003537919 +0800 CST m=+4.0561851422018-05-24 14:25:45.003548868 +0800 CST m=+4.056196091leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.037222315 +0800 CST m=+4.0898707592018-05-24 14:25:45.037241355 +0800 CST m=+4.089889800leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.112432779 +0800 CST m=+4.1650839502018-05-24 14:25:45.112441884 +0800 CST m=+4.165093056leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.241952581 +0800 CST m=+4.2946084482018-05-24 14:25:45.241968049 +0800 CST m=+4.294623917leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.284941571 +0800 CST m=+4.3375989972018-05-24 14:25:45.284952877 +0800 CST m=+4.337610304leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.398411234 +0800 CST m=+4.4510727742018-05-24 14:25:45.398428521 +0800 CST m=+4.451090062leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.512210254 +0800 CST m=+4.5648759212018-05-24 14:25:45.512236866 +0800 CST m=+4.564902533leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.519860072 +0800 CST m=+4.5725260162018-05-24 14:25:45.519881224 +0800 CST m=+4.572547169leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.60960201 +0800 CST m=+4.6622712082018-05-24 14:25:45.609613281 +0800 CST m=+4.662282479leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.738309018 +0800 CST m=+4.7909828832018-05-24 14:25:45.738325856 +0800 CST m=+4.790999721leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.81894876 +0800 CST m=+4.8716255482018-05-24 14:25:45.818974029 +0800 CST m=+4.871650818leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.867206877 +0800 CST m=+4.9198854152018-05-24 14:25:45.867222951 +0800 CST m=+4.919901490leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.935395526 +0800 CST m=+4.9880765372018-05-24 14:25:45.935406791 +0800 CST m=+4.988087802leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:45.984779779 +0800 CST m=+5.0374625812018-05-24 14:25:45.984795387 +0800 CST m=+5.037478189leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.156310168 +0800 CST m=+5.2089991892018-05-24 14:25:46.156320954 +0800 CST m=+5.209009975leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.192185033 +0800 CST m=+5.2448753552018-05-24 14:25:46.192194486 +0800 CST m=+5.244884808leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.200189691 +0800 CST m=+5.2528803032018-05-24 14:25:46.200216509 +0800 CST m=+5.252907122leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.368274381 +0800 CST m=+5.4209710872018-05-24 14:25:46.368285031 +0800 CST m=+5.420981738leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.428204817 +0800 CST m=+5.4809036962018-05-24 14:25:46.428229074 +0800 CST m=+5.480927954leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.44668818 +0800 CST m=+5.4993877302018-05-24 14:25:46.446699616 +0800 CST m=+5.499399166leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.660469621 +0800 CST m=+5.7131769222018-05-24 14:25:46.660485417 +0800 CST m=+5.713192719leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.681286565 +0800 CST m=+5.7339946212018-05-24 14:25:46.681300203 +0800 CST m=+5.734008259leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.705412186 +0800 CST m=+5.7581211172018-05-24 14:25:46.705423238 +0800 CST m=+5.758132169leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.812235572 +0800 CST m=+5.8649483762018-05-24 14:25:46.812247011 +0800 CST m=+5.864959815leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.895655989 +0800 CST m=+5.9483718172018-05-24 14:25:46.89567265 +0800 CST m=+5.948388479leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.954790244 +0800 CST m=+6.0075082172018-05-24 14:25:46.954802047 +0800 CST m=+6.007520020leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:46.992299132 +0800 CST m=+6.0450184652018-05-24 14:25:46.992308794 +0800 CST m=+6.045028127leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.127173055 +0800 CST m=+6.1798972782018-05-24 14:25:47.127209281 +0800 CST m=+6.179933506leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.158919475 +0800 CST m=+6.2116448492018-05-24 14:25:47.158929631 +0800 CST m=+6.211655006leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.176917878 +0800 CST m=+6.2296439052018-05-24 14:25:47.176930954 +0800 CST m=+6.229656981leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.394333761 +0800 CST m=+6.4470676712018-05-24 14:25:47.394348665 +0800 CST m=+6.447082576leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.40039257 +0800 CST m=+6.4531267002018-05-24 14:25:47.400402639 +0800 CST m=+6.453136769leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.403889235 +0800 CST m=+6.4566234922018-05-24 14:25:47.403898691 +0800 CST m=+6.456632948leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.588570118 +0800 CST m=+6.6413110712018-05-24 14:25:47.588580739 +0800 CST m=+6.641321692leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.639498364 +0800 CST m=+6.6922411632018-05-24 14:25:47.639513242 +0800 CST m=+6.692256042leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.675634085 +0800 CST m=+6.7283781952018-05-24 14:25:47.67566424 +0800 CST m=+6.728408351leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.799578159 +0800 CST m=+6.8523267632018-05-24 14:25:47.799595421 +0800 CST m=+6.852344025leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.87464831 +0800 CST m=+6.9273996362018-05-24 14:25:47.874660079 +0800 CST m=+6.927411405leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:47.954027129 +0800 CST m=+7.0067813332018-05-24 14:25:47.954057194 +0800 CST m=+7.006811399leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.058595933 +0800 CST m=+7.1113539292018-05-24 14:25:48.058608336 +0800 CST m=+7.111366332leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.072588208 +0800 CST m=+7.1253467112018-05-24 14:25:48.072598913 +0800 CST m=+7.125357416leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.209112998 +0800 CST m=+7.2618764512018-05-24 14:25:48.209125549 +0800 CST m=+7.261889003leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.281892948 +0800 CST m=+7.3346590402018-05-24 14:25:48.281900303 +0800 CST m=+7.334666395leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.333612834 +0800 CST m=+7.3863808012018-05-24 14:25:48.333642985 +0800 CST m=+7.386410953leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.409591816 +0800 CST m=+7.4623625382018-05-24 14:25:48.409623975 +0800 CST m=+7.462394698leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.523723371 +0800 CST m=+7.5764982312018-05-24 14:25:48.523739206 +0800 CST m=+7.576514067leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.566993993 +0800 CST m=+7.6197704222018-05-24 14:25:48.567004488 +0800 CST m=+7.619780918leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.589683454 +0800 CST m=+7.6424607062018-05-24 14:25:48.589690754 +0800 CST m=+7.642468006leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.740068877 +0800 CST m=+7.7928515822018-05-24 14:25:48.740078621 +0800 CST m=+7.792861326leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.812645497 +0800 CST m=+7.8654308332018-05-24 14:25:48.812660353 +0800 CST m=+7.865445690leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.817814052 +0800 CST m=+7.8705995762018-05-24 14:25:48.81782671 +0800 CST m=+7.870612234leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.973699741 +0800 CST m=+8.0264909172018-05-24 14:25:48.973713204 +0800 CST m=+8.026504381leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:48.975177663 +0800 CST m=+8.0279688932018-05-24 14:25:48.975187616 +0800 CST m=+8.027978846leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.009742857 +0800 CST m=+8.0625353402018-05-24 14:25:49.009754148 +0800 CST m=+8.062546631leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.132229489 +0800 CST m=+8.1850264132018-05-24 14:25:49.132240198 +0800 CST m=+8.185037123leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.146089854 +0800 CST m=+8.1988872812018-05-24 14:25:49.146098474 +0800 CST m=+8.198895901leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.241092649 +0800 CST m=+8.2938935202018-05-24 14:25:49.241104106 +0800 CST m=+8.293904978leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.402137181 +0800 CST m=+8.4549438922018-05-24 14:25:49.402148553 +0800 CST m=+8.454955264leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.411324567 +0800 CST m=+8.4641316112018-05-24 14:25:49.411337915 +0800 CST m=+8.464144959leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.503693501 +0800 CST m=+8.5565038942018-05-24 14:25:49.503705939 +0800 CST m=+8.556516332leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.612615631 +0800 CST m=+8.6654299732018-05-24 14:25:49.612626951 +0800 CST m=+8.665441294leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.67577314 +0800 CST m=+8.7285897722018-05-24 14:25:49.675786887 +0800 CST m=+8.728603520leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.694389486 +0800 CST m=+8.7472067932018-05-24 14:25:49.694400047 +0800 CST m=+8.747217355leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.773110078 +0800 CST m=+8.8259302402018-05-24 14:25:49.773125715 +0800 CST m=+8.825945877leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.870143178 +0800 CST m=+8.9229668582018-05-24 14:25:49.870155269 +0800 CST m=+8.922978949leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.899453617 +0800 CST m=+8.9522783602018-05-24 14:25:49.899461144 +0800 CST m=+8.952285887leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:49.958835216 +0800 CST m=+9.0116621122018-05-24 14:25:49.958849004 +0800 CST m=+9.011675900leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.10149985 +0800 CST m=+9.1543319192018-05-24 14:25:50.101524081 +0800 CST m=+9.154356151leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.122080883 +0800 CST m=+9.1749136982018-05-24 14:25:50.122091234 +0800 CST m=+9.174924049leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.162930111 +0800 CST m=+9.2157644072018-05-24 14:25:50.162941095 +0800 CST m=+9.215775392leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.297600914 +0800 CST m=+9.3504400932018-05-24 14:25:50.297610944 +0800 CST m=+9.350450123leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.348241544 +0800 CST m=+9.4010825592018-05-24 14:25:50.348260368 +0800 CST m=+9.401101384leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.459981161 +0800 CST m=+9.5128262282018-05-24 14:25:50.460006448 +0800 CST m=+9.512851516leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.514685971 +0800 CST m=+9.5675330212018-05-24 14:25:50.514699899 +0800 CST m=+9.567546950leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.58732826 +0800 CST m=+9.6401779442018-05-24 14:25:50.587339011 +0800 CST m=+9.640188696leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.67389369 +0800 CST m=+9.7267465132018-05-24 14:25:50.673905089 +0800 CST m=+9.726757912leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.743748367 +0800 CST m=+9.7966037232018-05-24 14:25:50.743758569 +0800 CST m=+9.796613925leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.86753376 +0800 CST m=+9.9203936042018-05-24 14:25:50.86754634 +0800 CST m=+9.920406184leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:50.918138116 +0800 CST m=+9.9709997952018-05-24 14:25:50.918153833 +0800 CST m=+9.971015513leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:51.003837812 +0800 CST m=+10.0567025982018-05-24 14:25:51.003853216 +0800 CST m=+10.056718003leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:51.105474416 +0800 CST m=+10.1583428882018-05-24 14:25:51.105485476 +0800 CST m=+10.158353948leader发送心跳信号
    子节点为 1
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:51.129302443 +0800 CST m=+10.1821717792018-05-24 14:25:51.129316747 +0800 CST m=+10.182186083leader发送心跳信号
    子节点为 2
    投票选举成功,校验心跳信号也成功
    2
    start electing leader
    2018-05-24 14:25:51.215080258 +0800 CST m=+10.2679527042018-05-24 14:25:51.215091227 +0800 CST m=+10.267963673leader发送心跳信号
    子节点为 0
    投票选举成功,校验心跳信号也成功

    Process finished with exit code 130 (interrupted by signal 2: SIGINT)

    相关文章

      网友评论

          本文标题:2018-05-24 Raft 代码实现2

          本文链接:https://www.haomeiwen.com/subject/fgajjftx.html