Git Product home page Git Product logo

afloatdb's Introduction

AfloatDB

This project demonstrates how to build very simple distributed key-value store on top of MicroRaft. Please note that this is not production-ready code.

Code pointers

afloatdb-server directory contains the server code and afloatdb-client directory contains the client code.

Each AfloatDB server runs a RaftNode and the communication between servers and the client-server communication happens through gRPC.

afloatdb-server/src/main/proto/AfloatDBRaft.proto contains the Protobufs definitions for MicroRaft's model and network abstractions, and the key-value operations of AfloatDB's key-value API. AfloatDB servers talk to each other via the RaftService defined in this file. This service is implemented at afloatdb-server/src/main/java/io/afloatdb/internal/rpc/impl/RaftRpcServiceImpl.java.

afloatdb-server/src/main/java/io/afloatdb/internal/raft/model package contains implementing MicroRaft's model abstractions using the Protobufs definitions defined in the above file.

afloatdb-server/src/main/java/io/afloatdb/internal/rpc/RaftRpcService.java implements MicroRaft's Transport abstraction and makes AfloatDB servers talk to each other with gRPC.

afloatdb-server/src/main/java/io/afloatdb/internal/raft/impl/KVStoreStateMachine.java contains the state machine implementation of AfloatDB's key-value API and it implements MicroRaft's StateMachine interface.

afloatdb-commons/src/main/proto/KV.proto defines the protocol between AfloatDB clients and servers. The server side counterpart is at afloatdb-server/src/main/java/io/afloatdb/internal/rpc/impl/KVService.java. It handles requests sent by clients and passes them to RaftNode.

afloatdb-server/src/main/proto/AfloatDBAdmin.proto contains the Protobufs definitions for management operations on AfloatDB clusters, such as adding / removing servers, querying RaftNode reports. Operators can manage AfloatDB clusters by making gRPC calls to the AdminService service defined in this file. Its server side counter part is at afloatdb-server/src/main/java/io/afloatdb/internal/rpc/impl/AdminService.java. It handles requests sent by clients and passes them to RaftNode.

That is enough pointers for curious readers.

MicroRaft provides a SQLite-based RaftStore implementation. AfloatDB injects its SerDe class to persist its Protocol Buffers based implementations of the RaftModel interfaces.

How to start a 3-node AfloatDB cluster

Configuration is built with the Typesafe Config library. You can also create config programmatically. Please see afloatdb-server/src/main/java/io/afloatdb/config/AfloatDBConfig.java.

You need to pass a config to start an AfloatDB server. The config should provide the Raft endpoint (id and address) and the initial member list of the cluster. afloatdb-server/src/test/resources contains example config files to start a 3 node AfloatDB cluster.

mvn clean package

java -jar afloatdb-server/target/afloatdb-server-fat.jar afloatdb-server/src/test/resources/node1.conf &

java -jar afloatdb-server/target/afloatdb-server-fat.jar afloatdb-server/src/test/resources/node2.conf &

java -jar afloatdb-server/target/afloatdb-server-fat.jar afloatdb-server/src/test/resources/node3.conf &

Adding a new server to a running cluster

Once you start your AfloatDB cluster, you can add new servers at runtime. For this, you need to provide address of one of the running servers via the "join-to" config field for the new server.

java -jar afloatdb-server/target/afloatdb-server-fat.jar afloatdb-server/src/test/resources/node4.conf &

Key-value API

afloatdb-client/src/main/java/io/afloatdb/client/kv/KV.java contains the key-value interface. Keys have String type and values can be one of String, long, or byte[].

Client API

You can start a client with AfloatDBClient.newInstance(config) to write and read key-value pairs on the cluster. Please see afloatdb-client/src/main/java/io/afloatdb/client/AfloatDBClientConfig.java for configuration options. You need to pass a server address. If singleConnection is false, which is the default value, the client will discover all servers and connect to them.

Key-value CLI for experimentation

java -jar afloatdb-client-cli/target/afloatdb-client-cli-fat.jar --server localhost:6701 --key name --value basri set

Output: Ordered{commitIndex=2, value=null}

java -jar afloatdb-client-cli/target/afloatdb-client-cli-fat.jar --server localhost:6701 --key name get

Output: Ordered{commitIndex=2, value=basri}

See afloatdb-client-cli/src/main/java/io/afloatdb/client/AfloatDBClientCliRunner.java for more options.

afloatdb's People

Contributors

metanet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bselyes janschzz

afloatdb's Issues

Cannot start cluster

When all node startup, node cannot communication with each other. macOS Ventura , JDK 11
Node 1 log
16:48:44.583 [RaftRpc-17] ERROR io.microraft.afloatdb.internal.rpc.RaftRpcService - node1 Raft RPC stream to node3 has failed. Exception: StatusRuntimeException Message: DEADLINE_EXCEEDED: deadline exceeded after 9.995382590s. [buffered_nanos=48380599, remote_addr=/127.0.0.1:6769] 16:48:53.062 [RaftRpc-25] ERROR io.microraft.afloatdb.internal.rpc.RaftRpcService - node1 Raft RPC stream to node2 has failed. Exception: StatusRuntimeException Message: DEADLINE_EXCEEDED: deadline exceeded after 9.997887682s. [buffered_nanos=35821362, remote_addr=/127.0.0.1:6768]
Node 2 log
16:49:11.524 [Raft-0] INFO - [RaftNode] node2<afloatdb-test-cluster> Pre-vote started for next term: 1, last log index: 0, last log term: 0 16:49:11.526 [Raft-0] INFO - [RaftRpcService] AfloatDBEndpoint{id=node2} initialized stub for AfloatDBEndpoint{id=node3} 16:49:11.528 [RaftRpc-33] ERROR - [RaftRpcService] node2 Raft RPC stream to node3 has failed. Exception: StatusRuntimeException Message: UNKNOWN

Node 3 log
[RaftRpcService] node3 Raft RPC stream to node2 has failed. Exception: StatusRuntimeException Message: UNKNOWN

StatusRuntimeException Message: DEADLINE_EXCEEDED: deadline exceeded after 9.999708256s.

I can build and run the code but I get a lot of these DEADLINE_EXCEEDED exceptions.

[RaftRpcService] node3 Raft RPC stream to node1 has failed. Exception: StatusRuntimeException Message: DEADLINE_EXCEEDED: deadline exceeded after 9.999360207s.

I had to change this change in afloatdb-server/commons to make them discoverable. Oh and I'm running on WSL2/Debian.

    <io.grpc.version>1.30.0</io.grpc.version>

Thanks!

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.