Giter VIP home page Giter VIP logo

raftd's Introduction

raftd

unmaintained

NOTE: This project is unmaintained. If you are using goraft in a project and want to carry the project forward please file an issue with your ideas and intentions. The original project authors have created new raft implementations now used in etcd and InfluxDB.

If you want to see a simple raft key-value store see the etcd/raft example.

Overview

The raftd server is a reference implementation for using the goraft library. This library provides a distributed consensus protocol based on the Raft protocol as described by Diego Ongaro and John Ousterhout in their paper, In Search of an Understandable Consensus Algorithm. This protocol is based on Paxos but is architected to be more understandable. It is similar to other log-based distributed consensus systems such as Google's Chubby or Heroku's doozerd.

This reference implementation is very simple. It is a key/value database with the following HTTP API:

# Set the value of a key.
$ curl -X POST http://localhost:4001/db/my_key -d 'FOO'
# Retrieve the value for a given key.
$ curl http://localhost:4001/db/my_key
FOO

All the values sent to the leader will be propagated to the other servers in the cluster. This reference implementation does not support command forwarding. If you try to send a change to a follower then it will simply be denied.

Running

First, install raftd:

$ go get github.com/goraft/raftd

To start the first node in your cluster, simply specify a port and a directory where the data will be stored:

$ raftd -p 4001 ~/node.1

To add nodes to the cluster, you'll need to start on a different port and use a different data directory. You'll also need to specify the host/port of the leader of the cluster to join:

$ raftd -p 4002 -join localhost:4001 ~/node.2

When you restart the node, it's already been joined to the cluster so you can remove the -join argument.

Finally, you can add one more node:

$ raftd -p 4003 -join localhost:4001 ~/node.3

Now when you set values to the leader:

$ curl -XPOST localhost:4001/db/foo -d 'bar'

The values will be propagated to the followers:

$ curl localhost:4001/db/foo
bar
$ curl localhost:4002/db/foo
bar
$ curl localhost:4003/db/foo
bar

Killing the leader will automatically elect a new leader. If you kill and restart the first node and try to set a value you'll receive:

$ curl -XPOST localhost:4001/db/foo -d 'bar'
raft.Server: Not current leader

Leader forwarding is not implemented in the reference implementation.

FAQ

Why is command forwarding not implemented?

Command forwarding is a nice feature to have because it allows a client to send a command to any server and have it pushed to the current leader. This lets your client code stay simple. However, now you have an additional point of failure in your remote call. If the intermediate server crashes while delivering the command then your client will still need to know how to retry its command. Since this retry logic needs to be in your client code, adding command forwarding doesn't provide any benefit.

Why isn't feature X implemented?

Raftd is meant to be a basic reference implementation. As such, it's aim is to provide the smallest, simplest implementation required to get someone off the ground and using go-raft in their project. If you have questions on how to implement a given feature, please add a Github Issue and we can provide instructions in this README.

Debugging

If you want to see more detail then you can specify several options for logging:

-v       Enables verbose raftd logging.
-debug   Enables debug-level raft logging.
-trace   Enables trace-level raft logging.

If you're having an issue getting raftd running, the -debug and -trace options can be really useful.

Caveats

One issue with running a 2-node distributed consensus protocol is that we need both servers operational to make a quorum and to perform an actions on the server. So if we kill one of the servers at this point, we will not be able to update the system (since we can't replicate to a majority). You will need to add additional nodes to allow failures to not affect the system. For example, with 3 nodes you can have 1 node fail. With 5 nodes you can have 2 nodes fail.

raftd's People

Contributors

andybons avatar benbjohnson avatar cenkalti avatar jensrantil avatar ongardie avatar philips avatar rockymadden avatar xiang90 avatar zhengjia 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raftd's Issues

Error running multiple instances

When starting a simple 3 node cluster, after about 5-10 minutes, the "leader" dies throwing this error:

Accept error: accept tcp [::]:4001: too many open files

Using debug output, the only thing it shows is a sudden stop when doing:

[raft]01:28:53.821293 peer.heartbeat.flush

I'm not sure where to look. I'm experiencing the same issue in a separate Raft based project and wanted to try the reference implementation which appears to be doing the same thing.

Any ideas?

node panics when cannot connect to leader

This is the panic, caused by resp.Body.Close() after the HTTP connection fails (resp.Body is nil).

2014/01/06 15:24:36 Initializing Raft Server: node.2
2014/01/06 15:24:36 Attempting to join leader: localhost:9001
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x40 pc=0x446d12]

goroutine 1 [running]:
runtime.panic(0x69e6c0, 0xa05e68)
/usr/local/go/src/pkg/runtime/panic.c:266 +0xb6
github.com/goraft/raftd/server.(_Server).Join(0xc210062280, 0x7fff1c62aa32, 0xe, 0x6289e0, 0xc210038aa0)
/usr/local/gopath/src/github.com/goraft/raftd/server/server.go:138 +0x2b2
github.com/goraft/raftd/server.(_Server).ListenAndServe(0xc210062280, 0x7fff1c62aa32, 0xe, 0x9, 0x238d)
/usr/local/gopath/src/github.com/goraft/raftd/server/server.go:84 +0x521
main.main()
/usr/local/gopath/src/github.com/goraft/raftd/main.go:60 +0x471

goroutine 3 [select]:
github.com/goraft/raft.(_server).followerLoop(0xc21006c000)
/usr/local/gopath/src/github.com/goraft/raft/server.go:590 +0x934
github.com/goraft/raft.(_server).loop(0xc21006c000)
/usr/local/gopath/src/github.com/goraft/raft/server.go:544 +0x2cf
created by github.com/goraft/raft.(*server).Start
/usr/local/gopath/src/github.com/goraft/raft/server.go:458 +0x7af

goroutine 6 [syscall]:
runtime.goexit()
/usr/local/go/src/pkg/runtime/proc.c:1394

You should move the close after checking the error:

--- a/server/server.go
+++ b/server/server.go
@@ -135,11 +135,11 @@ func (s *Server) Join(leader string) error {
var b bytes.Buffer
json.NewEncoder(&b).Encode(command)
resp, err := http.Post(fmt.Sprintf("http://%s/join", leader), "application/json", &b)

  •   resp.Body.Close()
    if err != nil {
            return err
    }
    
  •   resp.Body.Close()
    return nil
    

    }

Error in Multiple Instances

Hi,
I am not able to start the multiple instances i.e nodes which will follow the leader.
Please help or you can post video of how you are instantiating multiple servers so that we can also do the same.

Error :

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0xb0 pc=0x4a7962]

goroutine 1 [running]:
github.com/goraft/raftd/server.(*Server).Join(0xc820082080, 0x86d2e0, 0x15, 0x0, 0x0)
    /~/newraft/src/github.com/goraft/raftd/server/server.go:132 +0x62
main.main()
    ~/newraft/src/github.com/goraft/node/raftd/main.go:66 +0x5e8

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
exit status 2

go get fails

$ go get github.com/goraft/raftd

github.com/goraft/raft/protobuf

go/src/github.com/goraft/raft/protobuf/append_entries_request.pb.go:113: undefined: "code.google.com/p/goprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_request.pb.go:130: undefined: "code.google.com/p/goprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_request.pb.go:147: undefined: "code.google.com/p/goprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_request.pb.go:164: undefined: "code.google.com/p/goprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_request.pb.go:181: undefined: "code.google.com/p/goprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_request.pb.go:204: undefined: "code.google.com/p/goprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_responses.pb.go:97: undefined: "code.google.com/p/gogoprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_responses.pb.go:114: undefined: "code.google.com/p/gogoprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_responses.pb.go:131: undefined: "code.google.com/p/gogoprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_responses.pb.go:148: undefined: "code.google.com/p/gogoprotobuf/proto".ErrWrongType
go/src/github.com/goraft/raft/protobuf/append_entries_responses.pb.go:148: too many errors

too many open files

This might be me doing something wrong, but I was attempting to follow the instructions in the README and I get each system spitting out the "too many open files" error. It looks like each heartbeat is opening a new TCP connection and that is maxing it out. Any idea why this would be happening?

Build failed

I tried to build raftd but failed with following errors.

raftd ✘╹◡╹✘ go get github.com/goraft/raftd
# github.com/goraft/raftd/server
src/github.com/goraft/raftd/server/server.go:68: not enough arguments in call to raft.NewHTTPTransporter

raft.NewHTTPTransporter takes 2nd argument timeout time.Duration, but raftd doesn't pass it. I tried to pass the 2nd argument, building was successful.

http.Post error handling

resp.Body.Close()

Should resp.Body.Close() be done even when there's an error?

I ran this with no leader running:

$ raftd -join="localhost:4000" /tmp/d2
2014/01/28 23:32:48 Initializing Raft Server: /tmp/d2
2014/01/28 23:32:48 Attempting to join leader: localhost:4000
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x40 pc=0x45ce12]

goroutine 1 [running]:
runtime.panic(0x6c44a0, 0xa5ee68)
/usr/lib/go/src/pkg/runtime/panic.c:266 +0xb6
github.com/goraft/raftd/server.(_Server).Join(0xc210058280, 0x7fff7165f776, 0xe, 0x64bc60, 0xc210036ba0)
/home/ongardie/code/gopath/src/github.com/goraft/raftd/server/server.go:138 +0x2b2
github.com/goraft/raftd/server.(_Server).ListenAndServe(0xc210058280, 0x7fff7165f776, 0xe, 0x9, 0xfa1)
/home/ongardie/code/gopath/src/github.com/goraft/raftd/server/server.go:84 +0x521
main.main()
/home/ongardie/code/gopath/src/github.com/goraft/raftd/main.go:66 +0x47e

goroutine 3 [select]:
github.com/goraft/raft.(_server).followerLoop(0xc2100525a0)
/home/ongardie/code/gopath/src/github.com/goraft/raft/server.go:605 +0x934
github.com/goraft/raft.(_server).loop(0xc2100525a0)
/home/ongardie/code/gopath/src/github.com/goraft/raft/server.go:548 +0x2cf
created by github.com/goraft/raft.(*server).Start
/home/ongardie/code/gopath/src/github.com/goraft/raft/server.go:461 +0x7af

goroutine 6 [syscall]:
runtime.goexit()
/usr/lib/go/src/pkg/runtime/proc.c:1394

Go get command not working.

Hi,

I have done setting GOPATH and installed git also. But after giving command
go get github.com/goraft/raftd

It gives Error and installtion fails. Here is error.

package code.google.com/p/gogoprotobuf/proto: unable to detect version control system for code.google.com/ path package code.google.com/p/goprotobuf/proto: unable to detect version control system for code.google.com/ path

404 page not found

when i add a new url request in line 114 of "raftd/sever/server.go", like s.router.HandleFunc("/nodeState", s.readStateHandle).Method("GET") it went wrong, shows "404 page not found", it is strange.

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.