Giter VIP home page Giter VIP logo

simple-raft-py's Introduction

simple-raft-py

这是一个简单的python实现的raft协议,只是为了学习raft而写的代码。 关于raft的资料可以参考: http://thesecretlivesofdata.com/raft/

目前进度:

  1. 完成基本的网络通讯框架,使用python select做多路IO复用
  2. 可以处理定时器事件
  3. 单节点可以进行一些基本的操作(get set del commit)
  4. cluster内节点选举
  5. Leader挂掉,其余节点从新选举出leader
  6. 单个客户端连接Leader节点进行update操作时实现Leader Follower之间数据同步
  7. client关闭后,node内进行资源释放
  8. leader关闭后,释放follower资源
  9. 开始编写简单的coroutine框架,简化异步的编程模型。

目标:

  • 多个客户端连接Leader节点,Leader Follower之间数据同步
  • 新增节点时同步数据(全量同步、增量同步)

新接入节点数据同步方案:

  1. 引入一个新的状态Syncing,表示正在进行数据同步
  2. Leader心跳request带上当前的commit log号
  3. Follower收到leader commit log号后比较自身log号,如果落后,则进入Syncing状态开始同步
  4. 同步完成转为follower

一些问题:

  • 状态转换时,不能自动的处理状态内的定时时间处理函数
  • 异步调用,整个程序的逻辑是分散的,考虑用yield协程重新改写一下事件循环的架构

Usage:

image

目前没有单独的客户端程序,可以使用telnet进行测试

$ telnet 127.0.0.1 2333
> set test 1
> @127.0.0.1:2335@redirect  # 表示写操作被重定向到主节点

$ telnet 127.0.0.1 2335
> set test 1
> success                   # 写成功,事物未提交
> commit
> success                   # 提交成功,写操作同步到Followers
> get test
> 1                         # 返回结果

BLOG: http://aducode.github.io/posts/2015-06-04/simple-raft-py.html

simple-raft-py's People

Contributors

aducode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simple-raft-py's Issues

你的项目怎么进行请求?

@aducode
对于下面的进度6我这里有一些疑问

目前进度
6:单个客户端连接Leader节点进行update操作时实现Leader Follower之间数据同步
  • 如果我们想对node发送一个request请求,该如何进行操作呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.