-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cli.md client.md and example/README.md
Change-Id: Ibf9dc3cef49c923bd4ac62700a8b3871e082d4ba
- Loading branch information
1 parent
73a6d84
commit 80a83a2
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
braft提供了一系列API用来控制复制主或者具体节点, 可以选择在程序了调用[API](../../src/braft/cli.h)或者使用[braft_cli](../../tools/braft_cli.cpp)来给节点发远程控制命令 | ||
|
||
#API | ||
|
||
```cpp | ||
// Add a new peer into the replicating group which consists of |conf|. | ||
// Returns OK on success, error infomation otherwise. | ||
butil::Status add_peer(const GroupId& group_id, const Configuration& conf, | ||
const PeerId& peer_id, const CliOptions& options); | ||
|
||
// Remove the peer from the replicating group which consists of |conf|. | ||
// Returns OK on success, error infomation otherwise. | ||
butil::Status remove_peer(const GroupId& group_id, const Configuration& conf, | ||
const PeerId& peer_id, const CliOptions& options); | ||
|
||
// Reset the configuration of the given peer | ||
butil::Status set_peer(const GroupId& group_id, const PeerId& peer_id, | ||
const Configuration& new_conf, const CliOptions& options); | ||
|
||
// Trigger snapshot of the peer | ||
butil::Status snapshot(const GroupId& group_id, const PeerId& peer_id, | ||
const CliOptions& options); | ||
``` | ||
# braft_cli | ||
braft_cli提供了命令行工具, 作用和API类似 | ||
```shell | ||
braft_cli: Usage: braft_cli [Command] [OPTIONS...] | ||
Command: | ||
add_peer --group=$group_id --peer=$adding_peer --conf=$current_conf | ||
remove_peer --group=$group_id --peer=$removing_peer --conf=$current_conf | ||
set_peer --group=$group_id --peer==$target_peer --conf=$target_conf | ||
snapshot --group=$group_id --peer=$target_peer | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
braft并不能直接被任何client访问, 本文主要是说明一个能访问braft节点的client需要那些要素。 | ||
|
||
# Example | ||
|
||
[client side code](../../example/counter/client.cpp) of Counter | ||
|
||
# 总体流程 | ||
|
||
要访问braft的主节点,需要做这么一些事情: | ||
|
||
* 需要知道这个复制组有哪些节点, 这个可以通过配置列表,记录在dns,或者提供某些naming service如集群的master,redis, zookeeper, etcd等。 | ||
* 查询Leader位置 | ||
* 感知Leader变化 | ||
* 向Leader发起RPC. | ||
|
||
##RouteTable | ||
|
||
braft提供了[RouteTable](../../src/braft/route_table.h)功能,命名空间在braft::rtb, 可以帮助你的进程记录和追踪某个节点的主节点位置, 包含以下功能 | ||
|
||
```cpp | ||
// Update configuration of group in route table | ||
int update_configuration(const GroupId& group, const Configuration& conf); | ||
int update_configuration(const GroupId& group, const std::string& conf_str); | ||
// Get the cached leader of group. | ||
// Returns: | ||
// 0 : success | ||
// 1 : Not sure about the leader | ||
// -1, otherwise | ||
int select_leader(const GroupId& group, PeerId* leader); | ||
// Update leader | ||
int update_leader(const GroupId& group, const PeerId& leader); | ||
int update_leader(const GroupId& group, const std::string& leader_str); | ||
// Blocking the thread until query_leader finishes | ||
butil::Status refresh_leader(const GroupId& group, int timeout_ms); | ||
// Remove this group from route table | ||
int remove_group(const GroupId& group); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Brief introduction of examples: | ||
|
||
* Counter: A integer which can be added to by a given number in each request. | ||
* Atomic: : A integer thats supports exchange and compare_exchange operation. | ||
* Block: A block device supports random read/write from multiple threaded. | ||
|
||
# Build steps | ||
|
||
```shell | ||
example=counter|atomic|block | ||
cd $example && cmake . && make | ||
``` | ||
|
||
# Run Server | ||
|
||
```sh | ||
sh run_server.sh | ||
``` | ||
|
||
* Default number of servers in the group is `3`, changed by `--server_num` | ||
* Servers run on `./runtime/` which is resued, add --clean to cleanup storage | ||
|
||
# Run Client | ||
|
||
```sh | ||
sh run_client.sh | ||
``` | ||
|
||
* Default concurrency of client is 1, changed by `--thread_num` | ||
* If server_num of run_server.sh has been changed, specify run_client to make it consistent. | ||
* Add `--log_each_request` if you want detailed information of each request. | ||
|