consul/website/content/api-docs/operator/raft.mdx

182 lines
6.1 KiB
Plaintext
Raw Normal View History

2017-04-04 16:33:22 +00:00
---
layout: api
page_title: Raft - Operator - HTTP API
description: |-
The /operator/raft endpoints provide tools for management of Raft the
consensus subsystem and cluster quorum.
---
# Raft Operator HTTP API
The `/operator/raft` endpoints provide tools for management of Raft the
consensus subsystem and cluster quorum.
Please see the [Consensus Protocol Guide](/docs/architecture/consensus) for
2017-04-04 16:33:22 +00:00
more information about Raft consensus protocol and its use.
## Read Configuration
This endpoint reads the current raft configuration.
2020-04-06 20:27:35 +00:00
| Method | Path | Produces |
| ------ | ------------------------------ | ------------------ |
| `GET` | `/operator/raft/configuration` | `application/json` |
2017-04-04 16:33:22 +00:00
The table below shows this endpoint's support for
[blocking queries](/api-docs/features/blocking),
[consistency modes](/api-docs/features/consistency),
[agent caching](/api-docs/features/caching), and
2022-10-18 19:49:07 +00:00
[required ACLs](/api-docs/api-structure#authentication).
2017-04-04 16:33:22 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | --------------------- | ------------- | --------------- |
| `NO` | `default` and `stale` | `none` | `operator:read` |
2017-04-04 16:33:22 +00:00
### Query Parameters
2017-04-04 16:33:22 +00:00
- `dc` `(string: "")` - Specifies the datacenter to query.
This parameter defaults to the datacenter of the agent being queried.
2017-04-04 16:33:22 +00:00
- `stale` `(bool: false)` - If the cluster does not currently have a leader an
error will be returned. You can use the `?stale` query parameter to read the
2017-10-06 21:38:21 +00:00
Raft configuration from any of the Consul servers. Not setting this will choose
the default consistency mode which will forward the request to the leader for
2017-10-06 21:38:21 +00:00
processing but not re-confirm the server is still the leader before returning
results. See [default consistency](/api-docs/features/consistency#default) for more details.
2017-04-04 16:33:22 +00:00
### Sample Request
2020-05-19 18:32:38 +00:00
```shell-session
2017-04-04 16:33:22 +00:00
$ curl \
http://127.0.0.1:8500/v1/operator/raft/configuration
2017-04-04 16:33:22 +00:00
```
### Sample Response
```json
{
"Servers": [
{
"ID": "127.0.0.1:8300",
"Node": "alice",
"Address": "127.0.0.1:8300",
"Leader": true,
"Voter": true
},
{
"ID": "127.0.0.2:8300",
"Node": "bob",
"Address": "127.0.0.2:8300",
"Leader": false,
"Voter": true
},
{
"ID": "127.0.0.3:8300",
"Node": "carol",
"Address": "127.0.0.3:8300",
"Leader": false,
"Voter": true
}
],
"Index": 22
}
```
- `Servers` is has information about the servers in the Raft peer configuration:
- `ID` is the ID of the server. This is the same as the `Address` in Consul
0.7 but may be upgraded to a GUID in a future version of Consul.
- `Node` is the node name of the server, as known to Consul, or "(unknown)" if
the node is stale and not known.
- `Address` is the IP:port for the server.
- `Leader` is either "true" or "false" depending on the server's role in the
Raft configuration.
- `Voter` is "true" or "false", indicating if the server has a vote in the
Raft configuration. Future versions of Consul may add support for non-voting
servers.
- `Index` is the Raft corresponding to this configuration. The latest
configuration may not yet be committed if changes are in flight.
## Delete Raft Peer
This endpoint removes the Consul server with given address from the Raft
configuration.
There are rare cases where a peer may be left behind in the Raft configuration
even though the server is no longer present and known to the cluster. This
endpoint can be used to remove the failed server so that it is no longer affects
the Raft quorum.
If ACLs are enabled, the client will need to supply an ACL Token with `operator`
write privileges.
2020-04-06 20:27:35 +00:00
| Method | Path | Produces |
| -------- | --------------------- | ------------------ |
| `DELETE` | `/operator/raft/peer` | `application/json` |
2017-04-04 16:33:22 +00:00
The table below shows this endpoint's support for
[blocking queries](/api-docs/features/blocking),
[consistency modes](/api-docs/features/consistency),
[agent caching](/api-docs/features/caching), and
2022-10-18 19:49:07 +00:00
[required ACLs](/api-docs/api-structure#authentication).
2017-04-04 16:33:22 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | ------------- | ---------------- |
| `NO` | `none` | `none` | `operator:write` |
2017-04-04 16:33:22 +00:00
The corresponding CLI command is [`consul operator raft remove-peer`](/commands/operator/raft#remove-peer).
2022-01-10 19:21:32 +00:00
### Query Parameters
2017-04-04 16:33:22 +00:00
- `id|address` `(string: <required>)` - Specifies the ID or address (IP:port) of the raft peer to remove.
- `dc` `(string: "")` - Specifies the datacenter to query. This will default to
the datacenter of the agent being queried.
2017-04-04 16:33:22 +00:00
### Sample Request
2020-05-19 18:32:38 +00:00
```shell-session
2017-04-04 16:33:22 +00:00
$ curl \
--request DELETE \
"http://127.0.0.1:8500/v1/operator/raft/peer?address=1.2.3.4:5678"
2017-04-04 16:33:22 +00:00
```
Leadership transfer cmd (#14132) * add leadership transfer command * add RPC call test (flaky) * add missing import * add changelog * add command registration * Apply suggestions from code review Co-authored-by: Matt Keeler <mkeeler@users.noreply.github.com> * add the possibility of providing an id to raft leadership transfer. Add few tests. * delete old file from cherry pick * rename changelog filename to PR # * rename changelog and fix import * fix failing test * check for OperatorWrite Co-authored-by: Matt Keeler <mkeeler@users.noreply.github.com> * rename from leader-transfer to transfer-leader * remove version check and add test for operator read * move struct to operator.go * first pass * add code for leader transfer in the grpc backend and tests * wire the http endpoint to the new grpc endpoint * remove the RPC endpoint * remove non needed struct * fix naming * add mog glue to API * fix comment * remove dead code * fix linter error * change package name for proto file * remove error wrapping * fix failing test * add command registration * add grpc service mock tests * fix receiver to be pointer * use defined values Co-authored-by: Matt Keeler <mkeeler@users.noreply.github.com> * reuse MockAclAuthorizer * add documentation * remove usage of external.TokenFromContext * fix failing tests * fix proto generation * Apply suggestions from code review Co-authored-by: Jared Kirschner <85913323+jkirschner-hashicorp@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jared Kirschner <85913323+jkirschner-hashicorp@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jared Kirschner <85913323+jkirschner-hashicorp@users.noreply.github.com> * Apply suggestions from code review * add more context in doc for the reason * Apply suggestions from docs code review Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com> * regenerate proto * fix linter errors Co-authored-by: github-team-consul-core <github-team-consul-core@hashicorp.com> Co-authored-by: Matt Keeler <mkeeler@users.noreply.github.com> Co-authored-by: Jared Kirschner <85913323+jkirschner-hashicorp@users.noreply.github.com> Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com>
2022-11-14 20:35:12 +00:00
## Transfer Raft Leadership
This endpoint transfers the Raft leadership from the current leader to a different Raft peer.
The new leader is selected at random unless explicitly specified with the `id` parameter.
| Method | Path | Produces |
| -------- | ------------------------------- | ------------------ |
| `POST` | `/operator/raft/transfer-leader` | `application/json` |
The table below shows this endpoint's support for
[blocking queries](/api-docs/features/blocking),
[consistency modes](/api-docs/features/consistency),
[agent caching](/api-docs/features/caching), and
[required ACLs](/api-docs#authentication).
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | ------------- | ---------------- |
| `NO` | `none` | `none` | `operator:write` |
The corresponding CLI command is [`consul operator raft transfer-leader`](/commands/operator/raft#transfer-leader).
### Query Parameters
- `id` `(string: "")` - Specifies the node ID of the Raft peer to transfer leadership to.
If empty, leadership transfers to a random server agent.
### Sample Request
```shell-session
$ curl \
--request POST \
"http://127.0.0.1:8500/v1/operator/raft/transfer-leader?id=09cfc046-e74a-ad49-1aad-c2161b7fe677"
```