Skip to content

Commit

Permalink
make vdb server and eraftkv server into docker
Browse files Browse the repository at this point in the history
  • Loading branch information
LLiuJJ committed Jun 18, 2023
1 parent cd28e4c commit 3192cb6
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 59 deletions.
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,27 @@ build-dev:
tests:
chmod +x utils/run-tests.sh
docker run -it --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/utils/run-tests.sh

create-net:
docker network create --subnet=172.18.0.0/16 mytestnetwork

rm-net:
docker network rm mytestnetwork

run-demo:
docker run --name kvserver-node1 --network mytestnetwork --ip 172.18.0.2 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 0 /tmp/kv_db0 /tmp/log_db0 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090
sleep 4s
docker run --name kvserver-node2 --network mytestnetwork --ip 172.18.0.3 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 1 /tmp/kv_db1 /tmp/log_db1 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090
docker run --name kvserver-node3 --network mytestnetwork --ip 172.18.0.4 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 2 /tmp/kv_db2 /tmp/log_db2 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090
sleep 10s
docker run --name vdbserver-node --network mytestnetwork --ip 172.18.0.6 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraft-vdb 172.18.0.6:12306 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090

stop-demo:
docker stop kvserver-node1 kvserver-node2 kvserver-node3 vdbserver-node

run-demo-bench:
docker run --name kvserver-bench --network mytestnetwork --ip 172.18.0.5 --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv-ctl 172.18.0.2:8088 bench 64 64 10

run-vdb-tests:
chmod +x utils/run-vdb-tests.sh
docker run --name vdbserver-node-tests --network mytestnetwork --ip 172.18.0.8 -it --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/utils/run-vdb-tests.sh
68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# ERaftKV
# ERaftVDB

ERaftVDB is a distributed vector database that supports the RESP protocol for vector operations, and uses ERaftKV as the distributed storage layer.

![eraft-vdb](doc/eraft-vdb.png)

## ERaftKV

ERaftKV is a persistent distributed KV storage system, uses the Raft protocol to ensure data consistency, At the same time, it supports sharding to form multi shard large-scale data storage clusters.

# Features
## ERaftKV Features
- Strong and consistent data storage ensures secure and reliable data persistence in distributed systems.
- Support KV data type operations, including PUT, GET, DEL, and SCAN operations on keys. When users operate on cluster data, they must ensure the persistence of the operation and the sequential consistency of reading and writing.
- Dynamically configure the cluster, including adding and deleting nodes, adding and deleting cluster sharding configurations, including which keyrange the cluster sharding is responsible for.
Expand All @@ -14,6 +20,60 @@ ERaftKV is a persistent distributed KV storage system, uses the Raft protocol to

# Getting Started

## Run demo in docker

- step 1, create docker sub net

```
sudo make create-net
```

command output
```
docker network create --subnet=172.18.0.0/16 mytestnetwork
f57ad3d454f27f4b84efca3ce61bf4764bd30ce3d4971b85477daf05c6ae28a3
```

- step 2, run cluster

```
sudo make run-demo
```
command output
```
docker run --name kvserver-node1 --network mytestnetwork --ip 172.18.0.2 -d --rm -v /home/colin/eraft:/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 0 /tmp/kv_db0 /tmp/log_db0 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090
b11928b1281d6693a1fb12d12ab6fbc1f4b13c509d983fb3f04551fdcdff5d32
sleep 4s
docker run --name kvserver-node2 --network mytestnetwork --ip 172.18.0.3 -d --rm -v /home/colin/eraft:/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 1 /tmp/kv_db1 /tmp/log_db1 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090
7588f7ab8176a518ef6100157cfa6cc966ce719401b6f1909f7944230ef4266b
docker run --name kvserver-node3 --network mytestnetwork --ip 172.18.0.4 -d --rm -v /home/colin/eraft:/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 2 /tmp/kv_db2 /tmp/log_db2 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090
8192b50bfc5f00ab0ce43fe95013fa1c80b40a5383ed260333c3032bf7e62203
sleep 10s
docker run --name vdbserver-node --network mytestnetwork --ip 172.18.0.6 -d --rm -v /home/colin/eraft:/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraft-vdb 172.18.0.6:12306 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090
32064172894ca5afb6bc20546121817da8c75438e36c54550b373d8236690653
```

- step 3, run eraft vdb tests

```
sudo make run-vdb-tests
```
command output
```
chmod +x utils/run-vdb-tests.sh
docker run --name vdbserver-node-tests --network mytestnetwork --ip 172.18.0.8 -it --rm -v /home/colin/eraft:/eraft eraft/eraftkv:v0.0.6 /eraft/utils/run-vdb-tests.sh
+ redis-cli -h 172.18.0.6 -p 12306 info
server_id: 0,server_address: 172.18.0.2:8088,status: Running,Role: Leader
server_id: 1,server_address: 172.18.0.3:8089,status: Running,Role: Follower
server_id: 2,server_address: 172.18.0.4:8090,status: Running,Role: Follower
```

- step 4, clean all
```
sudo make run stop-demo
sudo make rm-net
```

## Building and run test using [GitHub Actions](https://github.com/features/actions)

All you need to do is submit a Pull Request to our repository, and all compile, build, and testing will be automatically executed.
Expand Down Expand Up @@ -43,9 +103,9 @@ make image

# Documentation

## Run Demo
## Run ERaftKV server group demo in physical machine

- how to set up demo cluster
- how to set up demo cluster?

```
./build/eraftkv 0 /tmp/kv_db0 /tmp/log_db0 127.0.0.1:8088,127.0.0.1:8089,127.0.0.1:8090
Expand Down
Binary file modified doc/eraft-vdb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions protocol/eraftkv.proto
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ message ShardGroup {
int64 id = 1;
KeyRange key_range = 2;
repeated Server servers = 3;
int64 leader_id = 4;
}

enum ClusterConfigChangeType {
Expand Down
13 changes: 10 additions & 3 deletions src/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ PacketLength Client::_HandlePacket(const char *start, std::size_t bytes) {
eraftkv::ClusterConfigChangeReq req;
req.set_change_type(eraftkv::ClusterConfigChangeType::Query);
eraftkv::ClusterConfigChangeResp resp;
auto status =
stubs_["127.0.0.1:8088"]->ClusterConfigChange(&context, req, &resp);

auto status =
stubs_.begin()->second->ClusterConfigChange(&context, req, &resp);
std::string info_str;
for (int i = 0; i < resp.shard_group(0).servers_size(); i++) {
info_str += "server_id: ";
info_str += std::to_string(resp.shard_group(0).servers(i).id());
info_str += ",server_address: ";
info_str += resp.shard_group(0).servers(i).address();
resp.shard_group(0).servers(i).server_status() ==
eraftkv::ServerStatus::Up
? info_str += ",status: Running"
: info_str += ",status: Down";
resp.shard_group(0).leader_id() == resp.shard_group(0).servers(i).id()
? info_str += ",Role: Leader"
: info_str += ",Role: Follower";
info_str += "\r\n";
}
std::string reply_buf;
Expand All @@ -47,7 +55,6 @@ PacketLength Client::_HandlePacket(const char *start, std::size_t bytes) {
reply_buf += "\r\n";
reply_buf += info_str;
reply_buf += "\r\n";
// std::cout << "reply " << reply_buf << std::endl;
reply_.PushData(reply_buf.c_str(), reply_buf.size());
SendPacket(reply_);

Expand Down
19 changes: 14 additions & 5 deletions src/eraft_vdb_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#include "server.h"
#include "socket.h"

ERaftVdbServer::ERaftVdbServer() : port_(0) {}
ERaftVdbServer::ERaftVdbServer(std::string addr, std::string kv_svr_addrs)
: port_(0), addr_(addr), kv_svr_addrs_(kv_svr_addrs) {}

ERaftVdbServer::~ERaftVdbServer() {}

Expand All @@ -24,14 +25,14 @@ std::shared_ptr<StreamSocket> ERaftVdbServer::_OnNewConnection(int connfd,
SocketAddr peer;
Socket::GetPeerAddr(connfd, peer);

auto cli(std::make_shared<Client>(KV_SERVER_ADDRS));
auto cli(std::make_shared<Client>(kv_svr_addrs_));
if (!cli->Init(connfd, peer))
cli.reset();
return cli;
}

bool ERaftVdbServer::_Init() {
SocketAddr addr("0.0.0.0:12306");
SocketAddr addr(addr_);
if (!Server::TCPBind(addr, 1)) {
return false;
}
Expand All @@ -46,9 +47,17 @@ bool ERaftVdbServer::_Recycle() {
return true;
}

/**
* @brief
*
* @param argc
* @param argv
* @return int
*/
int main(int argc, char *argv[]) {
ERaftVdbServer svr;
std::string addr = std::string(argv[1]);
std::string kv_svr_addrs = std::string(argv[2]);
ERaftVdbServer svr(addr, kv_svr_addrs);
svr.MainLoop(false);

return 0;
}
6 changes: 5 additions & 1 deletion src/eraft_vdb_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class ERaftVdbServer : public Server {
public:
ERaftVdbServer();
ERaftVdbServer(std::string addr, std::string kv_svr_addrs);
~ERaftVdbServer();

private:
Expand All @@ -27,4 +27,8 @@ class ERaftVdbServer : public Server {
bool _Recycle() override;

unsigned short port_;

std::string addr_;

std::string kv_svr_addrs_;
};
Loading

0 comments on commit 3192cb6

Please sign in to comment.