GithubHelp home page GithubHelp logo

consensus's Introduction

consensus算法的学习&实现

参考资料

raft作者讲解paxos&raft

basic paxos

basic paxos是纯粹的共识算法,其目的是解决一个问题:让所有进程都认可一个值

实现

系统中有多个proposer 多个acceptor.proposer发出提案,acceptor接收提案.为了解决问题,需要

  1. 让proposer知道目前是否有已经被选中的值
  2. 老的提案不能覆盖新的提案

为了做到这两点,所以引入两阶段提交

  1. prepare1,proposer将一个独一无二的number广播给acceptor,acceptor接收到以后如果这个number大于接收过最大的number,将记录下来,并且返回已经接收的提案和接收提案的number(如果没有返回nil)
  2. prepare2, proposer收到大部分的回应以后.如果回应中包含已经存在的提案,那么选中acceptNumber最大的提案 并覆盖自己的提案
  3. commit1 proposer将(number,提案)广播给acceptor,accetpor接收到以后如果number>=接收过最大的提案,那么将number设置为acceptNumber和minNumber(接收过最大number) 并选中提案,返回minNumber
  4. commit2 proposer收到大部分的响应后,如果回应中的minNumber> number那么说明提案失败,需要再次propose,反之则说明提案已经通过

consensus's People

Watchers

 avatar  avatar  avatar

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.