tikv / raft-rs

Raft distributed consensus algorithm implemented in Rust.
Apache License 2.0
2.93k stars 394 forks source link

How to use this lib? #402

Open HichuYamichu opened 3 years ago

HichuYamichu commented 3 years ago

Or more specifically how does one build transport component?

I'm feeling kind of lost after reading docs, readme and examples as none of them (at least to my knowledge) shows/points to information about transport implementation. Readme mentions gRPC but I couldn't find any further information on the matter besides raft-rs/proto/, which isn't much on its own. TiKv is too big to be a valid reference for starters and etcd raftexample although helpful shows only http api and uses Go implementation.

I believe some information about transport layer should be present either in docs, examples or readme (as it is the case for log and state machine parts). If that's the case and I've simply missed it this can be closed right away.

BusyJay commented 3 years ago

Basically you need to see batch_raft RPC implement:

Receiver: https://github.com/tikv/tikv/blob/master/src/server/service/kv.rs#L628-L664 Sender: https://github.com/tikv/tikv/blob/master/src/server/raft_client.rs

And snapshot handling:

https://github.com/tikv/tikv/blob/master/src/server/snap.rs.

Providing a details and minimal example in raft-rs using gRPC and raft-rs would certainly help.

chen-zhuohan commented 3 years ago

The Example and docs don't show the border in this lib. For example, I spend much time learning how nodes connect to and know each other automatically(I thought the lib has default way to broadcast message, the only things I provided is IP or Host) , finnally I found I should implement broadcasting messages.

On the other hand, seriously, if I did not write the full program including basic raft and upper kv-db, I totally don't know what should do with the lib. "Server gets requests and wait another thread handles these requests message with raft-rs" is not intuitive. It needs docs apart from example.

The example may has somethings wrong. It's another issue: #412

PsiACE commented 3 years ago

You can check and use some frameworks built on top of raft-rs, such as ritedb/riteraft . This hides most of the work details and can help you get a good start. A simple Raft HashStore Service example is written in ~160 lines of code, you can try to run it.

In addition, async-raft has a brief document. Although its design is different from raft-rs, it is still a reference material worth reading.

BusyJay commented 3 years ago

@PsiACE If you can send a PR, we can list it as an item under "Projects using the Raft crate".

Fomalhauthmj commented 3 years ago

I have written a simple example about how to use this lib, dkvrr which use real gRPC framework. My toy project is still under development and need helpful suggestions.

sp1ff commented 2 years ago

I'd like to add to this: not only are @HichuYamichu 's comments reflective of my own experience trying to figure out how to use this crate, I'm not thrilled about being forced to use slog for logging & grpc for network communications. These (especially logging) should be left to the user behind interfaces, perhaps with pluggable implementations.

BusyJay commented 2 years ago

being forced to use slog for logging

@sp1ff You can opt out slog by configuring raft as raft = { version = "0.6", default-features = false, features = ["protobuf-codec"] }.

grpc for network communications.

raft-rs is designed and implemented as simple as possible, there is no RPC logics in the library at all. So you can use any RPC you like to build up network layers.

jopemachine commented 1 year ago

I have ported riteraft, which was originally created by @PsiACE, to riteraft-py.

I think riteraft-py's example code is written in Python instead of Rust, making it easier to read and understand for beginners.

However, the current version of riteraft contains several bugs from the original implementation.

As I am not a distributed system expert, I am facing difficulties in resolving these issues.

I would greatly appreciate it if someone could assist me with this problem by any chance.

1