Code Monkey home page Code Monkey logo

distraft's Introduction

distraft

Raft implementation in a distributed fashion

Installation:

To install distraft you need to follow the steps below:

Pre-reqs

Install steps:

  • (Optional) Create and activate a virtual environment: virtalenv ./venv/ && source ./venv/bin/activate
  • Install dependencies: pip install -r requirements.txt

Run server:

All server configuration is done via environment variables, before running the server, modify the file: distraft-config.env to configure your server then to start the server run the following commands:

# Apply the environmental configurations:
source ./distraft-config.env

# Move to the distraft server:
cd ./distraft

# Start the server:
python server.py

Run in Docker

Running in docker makes the bootstrapping of a 5-node cluster extremely easy, just make sure you have docker and docker-compose installed then run the following command:

# Start the 5-node cluster:
docker-compose up -d

Using the Server:

Once the server is running here are some of the HTTP requests/commands you can use to interact with the server:

  • Get the status of a specific node (e.g. 127.0.0.1:5001)

    • curl http://127.0.0.1:5001/
    • Returns a json message like the following:
    {
      "ok": true,
      "status": {
        "commit_index": 0,
        "id": "server1",
        "is_leader": false,
        "last_applied": 0,
        "last_log_index": 0,
        "last_log_term": 0,
        "leader": "default",
        "match_index": {},
        "members": {
          "default": [
            "127.0.0.1",
            9000,
            "127.0.0.1",
            5000
          ],
          "server1": [
            "127.0.0.1",
            9001,
            "127.0.0.1",
            5001
          ],
          "server2": [
            "127.0.0.1",
            9002,
            "127.0.0.1",
            5002
          ]
        },
        "next_index": {},
        "state": "Follower",
        "term": 1,
        "up": true
      }
    }
    
  • Get the value of a key:

    • curl -L http://127.0.0.1:5001/<key>
    • Returns a json message like the following:
    {
        "ok": true,
        "key": "<key>",
        "value": "<value>"
    }
    
  • Set the value of a key:

    • curl -L -XPOST --data 'value=<new_value>' http://127.0.0.1:5001/<key>
    • Returns a json message like the following:
    {
        "ok": true,
        "key": "<key>",
        "value": "<new_value>"
    }
    
  • Stop a node (for testing purposes):

    • curl http://127.0.0.1:5001/stop
    • Returns a json message like the following:
    {"ok": true}
    
  • Start a node (for testing purposes):

    • curl http://127.0.0.1:5001/start
    • Returns a json message like the following:
    {"ok": true}
    

distraft's People

Contributors

itomaldonado avatar

Stargazers

 avatar

Watchers

 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.