braft提供了一系列API用来控制复制主或者具体节点, 可以选择在程序了调用API或者使用braft_cli来给节点发远程控制命令

API

  1. // Add a new peer into the replicating group which consists of |conf|.
  2. // Returns OK on success, error information otherwise.
  3. butil::Status add_peer(const GroupId& group_id, const Configuration& conf,
  4. const PeerId& peer_id, const CliOptions& options);
  5. // Remove a peer from the replicating group which consists of |conf|.
  6. // Returns OK on success, error information otherwise.
  7. butil::Status remove_peer(const GroupId& group_id, const Configuration& conf,
  8. const PeerId& peer_id, const CliOptions& options);
  9. // Gracefully change the peers of the replication group.
  10. butil::Status change_peers(const GroupId& group_id, const Configuration& conf,
  11. const Configuration& new_peers,
  12. const CliOptions& options);
  13. // Transfer the leader of the replication group to the target peer
  14. butil::Status transfer_leader(const GroupId& group_id, const Configuration& conf,
  15. const PeerId& peer, const CliOptions& options);
  16. // Reset the peer set of the target peer
  17. butil::Status reset_peer(const GroupId& group_id, const PeerId& peer_id,
  18. const Configuration& new_conf,
  19. const CliOptions& options);
  20. // Ask the peer to dump a snapshot immediately.
  21. butil::Status snapshot(const GroupId& group_id, const PeerId& peer_id,
  22. const CliOptions& options);

braft_cli

braft_cli提供了命令行工具, 作用和API类似

  1. braft_cli: Usage: braft_cli [Command] [OPTIONS...]
  2. Command:
  3. add_peer --group=$group_id --peer=$adding_peer --conf=$current_conf
  4. remove_peer --group=$group_id --peer=$removing_peer --conf=$current_conf
  5. change_peers --group=$group_id --conf=$current_conf --new_peers=$new_peers
  6. reset_peer --group=$group_id --peer==$target_peer --new_peers=$new_peers
  7. snapshot --group=$group_id --peer=$target_peer
  8. transfer_leader --group=$group_id --peer=$target_leader --conf=$current_conf