Skip to content

Commit 124e4eb

Browse files
committed
add cluster_reroute.md
1 parent 36e3908 commit 124e4eb

File tree

4 files changed

+234
-61
lines changed

4 files changed

+234
-61
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ npm run docs:dev
897897
- :heavy_check_mark: 集群获取设置 API [:link:](https://elasticsearch.bookhub.techrest_apis/cluster_apis/cluster_get_settings)
898898
- :heavy_check_mark: 集群健康 API [:link:](https://elasticsearch.bookhub.techrest_apis/cluster_apis/cluster_health)
899899
- :heavy_check_mark: 健康 API [:link:](https://elasticsearch.bookhub.techrest_apis/cluster_apis/health)
900-
- Cluster reroute
900+
- :heavy_check_mark: 集群重路由 API [:link:](https://elasticsearch.bookhub.techrest_apis/cluster_apis/cluster_reroute)
901901
- Cluster state
902902
- Cluster stats
903903
- Cluster update settings
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# 集群重路由 API
2+
3+
:::info 新 API 参考
4+
有关最新 API 的详细信息,参阅[集群 API](https://www.elastic.co/docs/api/doc/elasticsearch/v8/group/endpoint-cluster)
5+
:::
6+
7+
更改集群中分片的分配。
8+
9+
## 请求
10+
11+
```bash
12+
POST /_cluster/reroute?metric=none
13+
```
14+
15+
## 前置条件
16+
17+
- 如果 Elasticsearch 安全特性启用,你必须有 `manage`[集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)以使用此 API。
18+
19+
## 描述
20+
21+
重路由命令允许手动更改集群中各个分片的分配。例如,可以显式地将分片从一个节点移动到另一个节点,可以取消分配,并且可以将未分配的分片显式分配给特定节点。
22+
23+
需要注意的是,在处理任何重新路由命令后,Elasticsearch 将正常执行重新平衡(尊重 `cluster.routing.rebalance.enable` 等设置的值),以保持平衡状态。例如,如果请求的分配包括将分片从 `node1` 移动到 `node2`,则这可能会导致分片从 `node2` 移回 `node1` 以平衡情况。
24+
25+
可以使用 `cluster.routing.allocation.enable` 设置将集群设置为禁用分配。如果禁用了分配,则将执行的唯一分配是使用重路由命令给出的显式分配,以及由于重新平衡而产生的随之而来的分配。
26+
27+
可以通过使用 `?dry_run` URI 查询参数或在请求正文中传递 `"dry_run":true` 在“试运行”模式下运行 `reroute` 命令。这将计算将命令应用于当前集群状态的结果,并在应用命令(和重新平衡)后返回生成的集群状态,但实际上不会执行请求的更改。
28+
29+
如果包含 `?explain` URI 查询参数,则响应中将包含命令可以执行或无法执行的原因的详细说明。
30+
31+
集群将尝试连续分配分片最多 `index.allocation.max_retries` 次数(默认为 `5`),然后放弃并让分片未分配。这种情况可能是由结构问题引起的,例如分析器引用并非所有节点上都存在的停用词文件。
32+
33+
问题得到纠正后,可以通过使用 `?retry_failed` URI 查询参数调用重新路由 API 来手动重试分配,这将尝试对这些分片进行单轮重试。
34+
35+
## 查询参数
36+
37+
- `dry_run`
38+
39+
(可选,布尔值)如果为 `true`,则请求仅模拟作并返回结果状态。
40+
41+
- `explain`
42+
43+
(可选,布尔值)如果为 `true`,则响应包含命令可以执行或不能执行的原因的说明。
44+
45+
- `metric`
46+
47+
(可选,字符串)将返回的信息限制为指定的指标。除 `none` 之外的所有选项均已弃用,应避免用于此参数。默认为除元数据之外的所有数据。以下选项可用:
48+
49+
- `metric` 选项
50+
51+
- `_all`
52+
53+
展示所有指标。
54+
55+
- `blocks`
56+
57+
展示响应的块部分。
58+
59+
- `master_node`
60+
61+
展示响应的当选 `master_node` 部分。
62+
63+
- `metadata`
64+
65+
展示响应的 `metadata` 部分。如果提供逗号分隔的索引列表,则返回的输出将仅包含这些索引的元数据。
66+
67+
- `nodes`
68+
69+
展示响应的 `nodes` 部分。
70+
71+
- `none`
72+
73+
从响应中排除整个 `state` 字段。
74+
75+
- `routing_table`
76+
77+
展示响应的 `routing_table` 部分。
78+
79+
- `version`
80+
81+
展示集群状态版本。
82+
83+
- `retry_failed`
84+
85+
(可选,布尔值)如果为 `true`,则重试分配由于后续分配失败过多而被阻止的分片。
86+
87+
- `master_timeout`
88+
89+
(可选,[时间单位](/rest_apis/api_convention/common_options.html#时间单位))等待主节点的时间段。如果主节点在超时到期之前不可用,则请求将失败并返回错误。默认为 `30s`。也可以设置为 `-1` 以指示请求永远不会超时。
90+
91+
- `timeout`
92+
93+
(可选,[时间单位](/rest_apis/api_convention/common_options.html#时间单位))更新集群元数据后等待集群中所有相关节点响应的时间段。如果在超时到期之前未收到响应,则集群元数据更新仍适用,但响应将指示未完全确认。默认为 `30s`。也可以设置为 `-1` 以指示请求永远不会超时。
94+
95+
## 请求体
96+
97+
- `commands`
98+
99+
(必需,对象数组)定义要执行的命令。支持的命令包括:
100+
101+
- `commands` 属性
102+
103+
- `move`
104+
105+
将已启动的分片从一个节点移动到另一个节点。接受 `index``shard` 的索引名称和分片编号,节点的 `from_node`,以及将分片移动到的节点的 `to_node`
106+
107+
- `cancel`
108+
109+
取消分片(或恢复)的分配。接受索引名称和分片编号的 `index``shard`,以及要取消分片分配的节点的 `node`。这可用于通过取消现有副本并允许通过标准恢复过程重新初始化它们来强制从主分片重新同步现有副本。默认情况下,只能取消副本分片分配。如果需要取消主分片的分配,则请求中还必须包含 `allow_primary` 标志。
110+
111+
- `allocate_replica`
112+
113+
将未分配的副本分片分配给节点。接受索引名称和分片编号的`index``shard`,以及要将分片分配给的 `node`。把[分配决策器](/set_up_elasticsearch/configuration_elasticsearch/cluster_level_shard_allocation_and_routing_settings)纳入考虑。
114+
115+
还有两个命令可用于将主分片分配给节点。但是,应格外小心使用这些命令,因为主分片分配通常由 Elasticsearch 完全自动处理。无法自动分配主分片的原因包括:
116+
117+
- 创建了新索引,但没有满足分配决策器的节点。
118+
- 在集群中的当前数据节点上找不到数据的最新分片副本。为防止数据丢失,系统不会自动将过时的分片副本提升为主副本。
119+
120+
以下两个命令很危险,可能会导致数据丢失。它们旨在用于无法恢复原始数据且集群管理员接受丢失的情况。如果您遇到可以修复的临时问题,请参阅上述 `retry_failed` 标志。需要强调的是:如果执行这些命令,然后节点加入保存受影响分片副本的集群,则新加入的节点上的副本将被删除或覆盖。
121+
122+
- `allocate_stale_primary`
123+
124+
将主分片分配给保存过时副本的节点。接受索引名称和分片编号的索引和分片,以及要将分片分配给的节点。使用此命令可能会导致提供的分片 ID 的数据丢失。如果具有良好数据副本的节点稍后重新加入集群,则该数据将被删除或覆盖为使用此命令强制分配的过时副本的数据。为了确保这些含义得到充分理解,此命令要求将标志 `accept_data_loss` 显式设置为 `true`
125+
126+
- `allocate_empty_primary`
127+
128+
将空主分片分配给节点。接受索引名称和分片编号的索引和分片,以及要将分片分配给的节点。使用此命令会导致完全丢失索引到此分片中的所有数据(如果之前已启动)。如果具有数据副本的节点稍后重新加入集群,则该数据将被删除。为了确保这些含义得到充分理解,此命令要求将标志 `accept_data_loss` 显式设置为 `true`
129+
130+
## 示例
131+
132+
这是一个简单的重新路由 API 调用的简短示例:
133+
134+
```bash
135+
POST /_cluster/reroute?metric=none
136+
{
137+
"commands": [
138+
{
139+
"move": {
140+
"index": "test", "shard": 0,
141+
"from_node": "node1", "to_node": "node2"
142+
}
143+
},
144+
{
145+
"allocate_replica": {
146+
"index": "test", "shard": 1,
147+
"node": "node3"
148+
}
149+
}
150+
]
151+
}
152+
```
153+
154+
> [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/cluster-reroute.html)

docusaurus.config.js

Lines changed: 78 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,168 @@
11
// @ts-check
22
// Note: type annotations allow type checking and IDEs autocompletion
33

4-
const lightCodeTheme = require('prism-react-renderer/themes/github');
5-
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
4+
const lightCodeTheme = require("prism-react-renderer/themes/github");
5+
const darkCodeTheme = require("prism-react-renderer/themes/dracula");
66

77
/** @type {import('@docusaurus/types').Config} */
88
const config = {
9-
title: 'Elasticsearch 中文文档',
10-
tagline: 'Elasticsearch 中文文档',
11-
favicon: 'img/favicon.ico',
9+
title: "Elasticsearch 中文文档",
10+
tagline: "Elasticsearch 中文文档",
11+
favicon: "img/favicon.ico",
1212

1313
// Set the production url of your site here
14-
url: 'https://elasticsearch.bookhub.tech',
14+
url: "https://elasticsearch.bookhub.tech",
1515
// Set the /<baseUrl>/ pathname under which your site is served
1616
// For GitHub pages deployment, it is often '/<projectName>/'
17-
baseUrl: '/',
17+
baseUrl: "/",
1818

1919
// GitHub pages deployment config.
2020
// If you aren't using GitHub pages, you don't need these.
21-
organizationName: 'dev2007', // Usually your GitHub org/user name.
22-
projectName: 'elasticsearch-doc', // Usually your repo name.
21+
organizationName: "dev2007", // Usually your GitHub org/user name.
22+
projectName: "elasticsearch-doc", // Usually your repo name.
2323

24-
onBrokenLinks: 'warn',
25-
onBrokenMarkdownLinks: 'warn',
24+
onBrokenLinks: "warn",
25+
onBrokenMarkdownLinks: "warn",
2626

2727
// Even if you don't use internalization, you can use this field to set useful
2828
// metadata like html lang. For example, if your site is Chinese, you may want
2929
// to replace "en" with "zh-Hans".
3030
i18n: {
31-
defaultLocale: 'zh',
32-
locales: ['zh'],
31+
defaultLocale: "zh",
32+
locales: ["zh"],
3333
},
3434

3535
presets: [
3636
[
37-
'classic',
37+
"classic",
3838
/** @type {import('@docusaurus/preset-classic').Options} */
3939
({
4040
docs: {
41-
routeBasePath: '/',
42-
sidebarPath: require.resolve('./sidebars.js'),
41+
routeBasePath: "/",
42+
sidebarPath: require.resolve("./sidebars.js"),
4343
},
4444
blog: false,
4545
theme: {
46-
customCss: require.resolve('./src/css/custom.css'),
46+
customCss: require.resolve("./src/css/custom.css"),
4747
},
4848
}),
4949
],
5050
],
5151

5252
scripts: [
5353
{
54-
src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8380975615223941',
55-
crossorigin: 'anonymous'
54+
src: "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8380975615223941",
55+
crossorigin: "anonymous",
5656
},
5757
{
58-
src: 'https://hm.baidu.com/hm.js?085b01fdb8056cdc09e3d19350818e33',
59-
async: true
60-
}
58+
src: "https://hm.baidu.com/hm.js?085b01fdb8056cdc09e3d19350818e33",
59+
async: true,
60+
},
6161
],
6262

6363
themeConfig:
6464
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
6565
({
6666
// Replace with your project's social card
67-
docs:{
67+
docs: {
6868
sidebar: {
6969
hideable: true,
7070
},
7171
},
72-
metadata: [{ name: 'keywords', content: 'Elastic,Elasticsearch,ElasticStack,ELK,Document,docs,文档,中文文档,入门' }],
72+
metadata: [
73+
{
74+
name: "keywords",
75+
content:
76+
"Elastic,Elasticsearch,Elasticsearch api,ElasticStack,ELK,Document,docs,文档,中文文档,入门",
77+
},
78+
],
7379
navbar: {
74-
title: 'Elasticsearch 中文文档',
80+
title: "Elasticsearch 中文文档",
7581
logo: {
76-
alt: 'elasticsearch Logo',
77-
src: 'img/favicon.ico',
82+
alt: "elasticsearch Logo",
83+
src: "img/favicon.ico",
7884
},
7985
items: [
8086
{
81-
href: 'https://www.bookhub.tech',
82-
label: 'BookHub 首页',
83-
position: 'right',
87+
href: "https://www.bookhub.tech",
88+
label: "BookHub 首页",
89+
position: "right",
8490
},
8591
{
86-
href: 'https://docs.bookhub.tech',
87-
label: '中文文档',
88-
position: 'right',
92+
href: "https://docs.bookhub.tech",
93+
label: "中文文档",
94+
position: "right",
8995
},
9096
{
91-
href: 'https://github.com/dev2007/elasticsearch-doc',
92-
position: 'right',
93-
className: 'header-github-link',
94-
'aria-label': 'GitHub 仓库',
97+
href: "https://github.com/dev2007/elasticsearch-doc",
98+
position: "right",
99+
className: "header-github-link",
100+
"aria-label": "GitHub 仓库",
95101
},
96102
{
97-
type: 'search',
98-
position: 'right',
103+
type: "search",
104+
position: "right",
99105
},
100106
],
101107
},
102108
footer: {
103-
style: 'dark',
109+
style: "dark",
104110
links: [
105111
{
106-
title: 'BookHub',
112+
title: "BookHub",
107113
items: [
108114
{
109-
label: '首页',
110-
href: 'https://www.bookhub.tech'
115+
label: "首页",
116+
href: "https://www.bookhub.tech",
111117
},
112118
{
113-
label: '中文文档',
114-
href: 'https://docs.bookhub.tech',
119+
label: "中文文档",
120+
href: "https://docs.bookhub.tech",
115121
},
116122
],
117123
},
118124
{
119-
title: '其他文档',
125+
title: "其他文档",
120126
items: [
121127
{
122-
label: 'Micronaut',
123-
href: 'https://micronaut.bookhub.tech',
128+
label: "Micronaut",
129+
href: "https://micronaut.bookhub.tech",
124130
},
125131
{
126-
label: 'MySQL',
127-
href: 'https://mysql.bookhub.tech',
132+
label: "Pac4j",
133+
href: "https://pac4j.bookhub.tech",
128134
},
129-
{
130-
label: 'Pac4j',
131-
href: 'https://pac4j.bookhub.tech',
132-
}
133135
],
134-
}
136+
},
135137
],
136138
copyright: `Copyright © ${new Date().getFullYear()} bookHub.tech`,
137139
},
138140
prism: {
139141
theme: lightCodeTheme,
140142
darkTheme: darkCodeTheme,
141-
additionalLanguages: ['bash', 'java', 'yaml', 'json', 'groovy', 'kotlin', 'graphql', 'properties', 'toml', 'hoon']
143+
additionalLanguages: [
144+
"bash",
145+
"java",
146+
"yaml",
147+
"json",
148+
"groovy",
149+
"kotlin",
150+
"graphql",
151+
"properties",
152+
"toml",
153+
"hoon",
154+
],
142155
},
143156
}),
144-
145-
plugins: [[ require.resolve('docusaurus-lunr-search'), {
146-
languages: ['en', 'zh'] // language codes
147-
}]],
157+
158+
plugins: [
159+
[
160+
require.resolve("docusaurus-lunr-search"),
161+
{
162+
languages: ["en", "zh"], // language codes
163+
},
164+
],
165+
],
148166
};
149167

150168
module.exports = config;

0 commit comments

Comments
 (0)