All Projects → vision9527 → Raft Demo

vision9527 / Raft Demo

通过hashicorp-raft库手把手调试raft协议

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Raft Demo

huffleraft
Replicated key-value store driven by the raft consensus protocol 🚵
Stars: ✭ 32 (-55.56%)
Mutual labels:  raft, hashicorp
Leto
A key value storage example powered by hashicorp raft and BadgerDB
Stars: ✭ 73 (+1.39%)
Mutual labels:  hashicorp, raft
Terraform Best Practices
Terraform Best Practices for AWS users
Stars: ✭ 931 (+1193.06%)
Mutual labels:  hashicorp
Rqlite
The lightweight, distributed relational database built on SQLite
Stars: ✭ 9,147 (+12604.17%)
Mutual labels:  raft
Consensus Yaraft
consensus-yaraft is a library for distributed, strong consistent, highly replicated log storage. It's based on yaraft, which is an implementation of the Raft protocol.
Stars: ✭ 30 (-58.33%)
Mutual labels:  raft
Blast
Blast is a full text search and indexing server, written in Go, built on top of Bleve.
Stars: ✭ 934 (+1197.22%)
Mutual labels:  raft
Raftlog
A Rust implementation of distributed replicated log based on the Raft algorithm
Stars: ✭ 44 (-38.89%)
Mutual labels:  raft
Packer Post Processor Ami Copy
Packer post-processor plugin for copying, encrypting, tagging a built AMI into other accounts.
Stars: ✭ 17 (-76.39%)
Mutual labels:  hashicorp
Zanredisdb
Yet another distributed kvstore support redis data and index. moved to: https://github.com/youzan/ZanRedisDB
Stars: ✭ 64 (-11.11%)
Mutual labels:  raft
Hcloud Okd4
Deploy OKD4 (OpenShift) on Hetzner Cloud
Stars: ✭ 29 (-59.72%)
Mutual labels:  hashicorp
Vaulted
nodejs based wrapper for HashiCorp's Vault HTTP API
Stars: ✭ 47 (-34.72%)
Mutual labels:  hashicorp
Javaok
必看!java后端,亮剑诛仙。java发展路线技术要点。
Stars: ✭ 867 (+1104.17%)
Mutual labels:  raft
Trek
Trek is a CLI/ncurses explorer for HashiCorp Nomad clusters.
Stars: ✭ 26 (-63.89%)
Mutual labels:  hashicorp
Atlantis On Gke
A set of @HashiCorp Terraform configurations for running Atlantis on @GoogleCloud GKE
Stars: ✭ 44 (-38.89%)
Mutual labels:  hashicorp
Blog
my blog, using markdown
Stars: ✭ 25 (-65.28%)
Mutual labels:  raft
6.824 2018
MIT 6.824 2018 lab. MIT6.824分布式系统(2018秋)
Stars: ✭ 59 (-18.06%)
Mutual labels:  raft
Cli
a lightweight, security focused, BDD test framework against terraform.
Stars: ✭ 918 (+1175%)
Mutual labels:  hashicorp
Raft.github.io
website at https://raft.github.io
Stars: ✭ 844 (+1072.22%)
Mutual labels:  raft
Dister
dister(Distribution Cluster)是一款轻量级高性能的分布式集群管理软件,实现了分布式软件架构中的常用核心组件,包括:服务配置管理中心、服务注册与发现、服务健康检查、服务负载均衡。dister的灵感来源于ZooKeeper、Consul、Etcd,它们都实现了类似的分布式组件,但是dister更加的轻量级、低成本、易维护、架构清晰、简单实用、性能高效,这也是dister设计的初衷。
Stars: ✭ 41 (-43.06%)
Mutual labels:  raft
Molecule Vagrant
Molecule Vangrant Driver
Stars: ✭ 69 (-4.17%)
Mutual labels:  hashicorp

另外一篇关于paxos协议的分享地址:https://github.com/vision9527/paxos

一、Raft协议简介

二、Raft选举过程

  • 选举过程图1(单个节点视角)

选举流程

  • 选举过程图2(整体视角)

选举流程2

三、Raft日志复制流程

  • 日志格式:term + index + cmd + type

日志流程

  • 请求处理整体流程

日志流程

  • 请求处理详细流程(重点)

日志流程

注:这里7. commit log 应该是在5. commit之后,但是因为commit策略的原因有一定延迟,所以从日志上看是在回复客户端以后

四、Raft协议动画演示

五、hashicorp/raft源码讲解

六、运行hashicorp/raft库搭建的简单kv服务

  • 编译:go build -mod vendor

  • 启动node1: ./raft-demo --http_addr=127.0.0.1:7001 --raft_addr=127.0.0.1:7000 --raft_id=1 --raft_cluster=1/127.0.0.1:7000,2/127.0.0.1:8000,3/127.0.0.1:9000

  • 启动node2: ./raft-demo --http_addr=127.0.0.1:8001 --raft_addr=127.0.0.1:8000 --raft_id=2 --raft_cluster=1/127.0.0.1:7000,2/127.0.0.1:8000,3/127.0.0.1:9000

  • 启动node3: ./raft-demo --http_addr=127.0.0.1:9001 --raft_addr=127.0.0.1:9000 --raft_id=3 --raft_cluster=1/127.0.0.1:7000,2/127.0.0.1:8000,3/127.0.0.1:9000

  • set请求:curl http://127.0.0.1:7001/set?key=test_key&value=test_value

  • get请求:curl http://127.0.0.1:7001/get?key=test_key

七、调试场景

选举变化相关
  1. 集群启动后,follower等待一个随机election timeout时间变成candidate,然后发起投票,如果不能获得majority票数,则任期term会一直增加(未pre-vote情况)(branch: election-1)

  2. 集群启动后,follower等待一个随机election timeout时间变成candidate,然后发起投票,获得majority票数的节点变成leader (branch: election-2)

  3. leader选举成功后发送heartbeat保持leader的地位(branch: election-3)

  4. leader失去majority节点的heartbeat响应,退回到follower(branch: election-4)

日志复制相关
  1. leader接收客户端请求,向集群内所有节点发送复制RPC,所有都正常响应 -> 正常commit,然后apply到状态机,最后返回客户端处理成功(branch: replicate-log-1)

  2. leader接收客户端请求,向集群内所有节点发送复制RPC,majority正常响应 -> 正常commit,然后apply到状态机,最后返回客户端处理成功(branch: replicate-log-2)

  3. leader接收客户端请求,向集群内所有节点发送复制RPC,少于majority正常响应 -> 不能commit(branch: replicate-log-3)

八、收获

  • hashicorp/raft源码

  • raft选举与日志复制

九、QA

纠正:3个节点宕机2个,剩下一个不可用,怎么处理请求的强一致?

答:这个时候服务应该是不可用的,当然如果要强行提供查询的服务,强一致肯定是无法保证的。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].