raft-rs icon indicating copy to clipboard operation
raft-rs copied to clipboard

How to use this lib?

Open HichuYamichu opened this issue 3 years ago • 8 comments

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.

HichuYamichu avatar Oct 08 '20 11:10 HichuYamichu

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.

BusyJay avatar Oct 09 '20 06:10 BusyJay

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

chen-zhuohan avatar Dec 29 '20 07:12 chen-zhuohan

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.

PsiACE avatar May 16 '21 03:05 PsiACE

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

BusyJay avatar May 17 '21 05:05 BusyJay

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.

Fomalhauthmj avatar Sep 02 '21 10:09 Fomalhauthmj

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.

sp1ff avatar Feb 18 '22 22:02 sp1ff

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.

BusyJay avatar Feb 21 '22 08:02 BusyJay

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

jopemachine avatar Jun 16 '23 08:06 jopemachine