Skip to content

Commit

Permalink
Add basic instruction for the raft engine in README (#233)
Browse files Browse the repository at this point in the history
Co-authored-by: Twice <[email protected]>
  • Loading branch information
git-hulk and PragmaTwice authored Dec 18, 2024
1 parent 83355d5 commit 25030c6
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 13 deletions.
59 changes: 54 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,74 @@ Apache Kvrocks Controller is a cluster management tool for [Apache Kvrocks](http
$ git clone https://github.com/apache/kvrocks-controller
$ cd kvrocks-controller
$ make # You can find the binary file in the `_build` dir if all goes good
# ---
# If you do not have a suitable Golang compilation environment locally, you can also use 'make BUILDER_IMAGE=<golang:version>' to choose a Golang image for compilation.
# $ make BUILDER_IMAGE=golang:1.20.3
```
### Overview
![image](docs/images/overview.png)
For the storage, the ETCD is used as the default storage now. Welcome to contribute other storages like MySQL, Redis, Consul and so on. And what you need to do is to implement the [Engine interface](https://github.com/apache/kvrocks-controller/blob/unstable/store/engine/engine.go).

### 1. Run the controller server
### Supported Storage Engine

- [x] ETCD
- [x] Zookeeper
- [x] Embedded Storage based on Raft (experimental)

### Run the controller server

```shell
# Use docker-compose to setup the etcd or zookeeper
$ make setup
# Run the controller server
$ ./_build/kvctl-server -c config/config.yaml
```

![image](docs/images/server.gif)

### 2. Use the terminal client to interact with the controller server
### Run server with the raft embedding engine

> Note: The embedded Raft engine is still in the experimental stage, and it's not recommended to use it in the production environment.
Change the storage type to `raft` in the configuration file.

```yaml
storage_type: raft

raft:
id: 1
data_dir: "/data/kvrocks/raft/1"
cluster_state: "new"
peers:
- "http://127.0.0.1:6001"
- "http://127.0.0.1:6002"
- "http://127.0.0.1:6003"
```
- id: the node id for the raft node, it's also an index in the peers list
- data_dir: the directory to store the raft data
- cluster_state: the state of the raft cluster, it should be `new` when the cluster is initialized. And it should be `existing` when the cluster is already bootstrapped.
- peers: the list of the raft peers, it should include all the nodes in the cluster.

And then you can run the controller server with the configuration file.

```shell
$ ./_build/kvctl-server -c config/config-raft.yaml
```

#### Add/Remove a raft peer node

We now support adding and removing via the HTTP API.

```shell
# Add a new peer node
curl -XPOST -d '{"id":4,"peer":"http://127.0.0.1:6004","operation":"add"}' http://127.0.0.1:9379/api/v1/raft/peers
# Remove a peer node
curl -XPOST -d '{"id":4, "operation":"remove"}' http://127.0.0.1:9379/api/v1/raft/peers
# List all the peer nodes
curl http://127.0.0.1:9379/api/v1/raft/peers
```

### Use client to interact with the controller server

```shell
# Show help
Expand Down
44 changes: 44 additions & 0 deletions config/config-raft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

addr: "127.0.0.1:9379"


# Which store engine should be used by controller
# options: etcd, zookeeper, raft
# Note: the raft engine is an experimental feature and is not recommended for production use.
#
# default: etcd
storage_type: raft

raft:
id: 1
data_dir: "/data/kvrocks/raft"
# Cluster state must be 'new' or 'existing'.
# For a new cluster, its initial cluster state must be set to 'new'.
# And you would like to join an existing cluster, its initial cluster state must be set to 'existing'.
cluster_state: "new"
peers:
- "http://127.0.0.1:6001"
- "http://127.0.0.1:6002"
- "http://127.0.0.1:6003"

controller:
failover:
ping_interval_seconds: 3
min_alive_size: 5
39 changes: 39 additions & 0 deletions config/config-zk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

addr: "127.0.0.1:9379"


# Which store engine should be used by controller
# options: etcd, zookeeper, raft
# Note: the raft engine is an experimental feature and is not recommended for production use.
#
# default: etcd
storage_type: zookeeper

zookeeper:
addrs:
- "127.0.0.1:2181"
scheme:
auth:
elect_path:

controller:
failover:
ping_interval_seconds: 3
min_alive_size: 5
11 changes: 3 additions & 8 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ addr: "127.0.0.1:9379"


# Which store engine should be used by controller
# options: etcd, zookeeper
# options: etcd, zookeeper, raft
# Note: the raft engine is an experimental feature and is not recommended for production use.
#
# default: etcd
storage_type: etcd

Expand All @@ -36,13 +38,6 @@ etcd:
key_file:
ca_file:

zookeeper:
addrs:
- "127.0.0.1:2181"
scheme:
auth:
elect_path:

controller:
failover:
ping_interval_seconds: 3
Expand Down

0 comments on commit 25030c6

Please sign in to comment.