From 25030c6bd87a148ede5158d6ac2044e0da01ab7f Mon Sep 17 00:00:00 2001 From: hulk Date: Wed, 18 Dec 2024 09:15:46 +0800 Subject: [PATCH] Add basic instruction for the raft engine in README (#233) Co-authored-by: Twice --- README.md | 59 +++++++++++++++++++++++++++++++++++++---- config/config-raft.yaml | 44 ++++++++++++++++++++++++++++++ config/config-zk.yaml | 39 +++++++++++++++++++++++++++ config/config.yaml | 11 +++----- 4 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 config/config-raft.yaml create mode 100644 config/config-zk.yaml diff --git a/README.md b/README.md index 4f10ccce..7975b3f3 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,18 @@ 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=' 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 @@ -37,9 +40,55 @@ $ 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 diff --git a/config/config-raft.yaml b/config/config-raft.yaml new file mode 100644 index 00000000..17973c70 --- /dev/null +++ b/config/config-raft.yaml @@ -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 diff --git a/config/config-zk.yaml b/config/config-zk.yaml new file mode 100644 index 00000000..1bcfbf74 --- /dev/null +++ b/config/config-zk.yaml @@ -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 \ No newline at end of file diff --git a/config/config.yaml b/config/config.yaml index 2bec5dc8..d2e414fa 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -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 @@ -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