美文网首页
关于RAFT后续的一些思考(二)

关于RAFT后续的一些思考(二)

作者: fooboo | 来源:发表于2020-01-12 09:38 被阅读0次

这篇是关于优化的snapshot。从连接中2.6小节快照管理Raft 算法原理及其在 CMQ 中的应用(上)中描述的那样,在floyd中实现也比较简单:

313     } else if (res.append_entries_res().success() == true) {
314       if (num_entries > 0) {
315         match_index_ = prev_log_index + num_entries;
316         // only log entries from the leader's current term are committed
317         // by counting replicas
318         if (append_entries->entries(num_entries - 1).term() == context_->current_term) {
319           AdvanceLeaderCommitIndex();
320           apply_->ScheduleApply();
321         }
322         next_index_ = prev_log_index + num_entries + 1;
323       }

194 // only leader will call AdvanceCommitIndex
195 // follower only need set commit as leader's
196 void Peer::AdvanceLeaderCommitIndex() {
197   Entry entry;
198   uint64_t new_commit_index = QuorumMatchIndex();
199   if (context_->commit_index < new_commit_index) {
200     context_->commit_index = new_commit_index;
201     raft_meta_->SetCommitIndex(context_->commit_index);
202   }
203   return;
204 }

 62 void FloydApply::ApplyStateMachine() {
 63   uint64_t last_applied = context_->last_applied;
 64   // Apply as more entry as possible
 65   uint64_t commit_index;
 66   commit_index = context_->commit_index;
 67 
 70   Entry log_entry;
 71   if (last_applied >= commit_index) {
 72     return;
 73   }
 74   // TODO: use batch commit to optimization
 75   while (last_applied < commit_index) {
 76     last_applied++;
 77     raft_log_->GetEntry(last_applied, &log_entry);
 78     // TODO: we need change the s type
 79     // since the Apply may not operate rocksdb
 80     rocksdb::Status s = Apply(log_entry);
 81     if (!s.ok()) {
 84       usleep(1000000);
 85       ScheduleApply();  // try once more
 86       return;
 87     }
 88   }
 89   context_->apply_mu.Lock();
 90   context_->last_applied = last_applied;
 91   raft_meta_->SetLastApplied(last_applied); ///持久化applyindex
 92   context_->apply_mu.Unlock();
 93   context_->apply_cond.SignalAll();
 94 }

参考资料
Raft 算法原理及其在 CMQ 中的应用(下

相关文章

  • 关于RAFT后续的一些思考(二)

    这篇是关于优化的snapshot。从连接中2.6小节快照管理Raft 算法原理及其在 CMQ 中的应用(上)[ht...

  • 关于RAFT后续的一些思考(一)

    这段时间也在总结之前分析过的源码和记录的文章内容,为了加深理解,需要结合具体需求和业务,去思考更多可能。 之前分析...

  • RocketMQ主从切换

    本文主要是记录raft协议的学习过程,包括如下几个方面 raft协议一些基本概念 raft协议场景 raft协议在...

  • 航海日志02--有人记得你年少时的梦想吗?

    嘿!欢迎回来! 这是第二篇关于《RAFT》的航海日志,因为上周末打完全部的任务岛,《RAFT》还没更新第三章(我们...

  • raft协议-集群成员变化处理

    raft协议,关于集群成员变化的一点个人理解,纯粹是根据论文分析的,不一定正确。后续看下etcd, braft的实...

  • 好玩的Raft动画演示,原理秒懂

    关于Raft原理,许多朋友也许不是很明白原理,下面的地址是一个好玩的Raft动画,看完后能够很快的掌握Raft原理...

  • Raft 配置变更 Configuration changes

    背景 仔细思考了 Raft 关于配置变更的内容,发现论文中的搞法用代码根本无法实现.......然后开始了 sea...

  • 关于小说后续的创作思考

    处女作《来世愿做你肩上的星》已经写到了第22章,女主杜菁菁到了部队探亲,克服了“高反”之后在联欢晚会上表演了节目,...

  • 关于一些思考(二)

    午后的图书馆,暖洋洋的太阳透过窗户照在我们的发梢和脸庞,慵懒又安逸。大概最近老王的课程听多了,逐渐开始形成自己的...

  • 【raft】关于raft算法原理

    raft 是什么? Replicated And Fault Tolerant,复制和容错 raft算法的动画演示...

网友评论

      本文标题:关于RAFT后续的一些思考(二)

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