跨集群复制 API
使用这些复制操作以编程方式管理跨集群复制。
目录
启动复制
于 1.1 引入
从领导集群向跟随集群启动索引复制。将此请求发送到跟随集群。
请求
PUT /_plugins/_replication/<follower-index>/_start
{
"leader_alias":"<connection-alias-name>",
"leader_index":"<index-name>",
"use_roles":{
"leader_cluster_role":"<role-name>",
"follower_cluster_role":"<role-name>"
}
}
指定以下选项
选项 | 描述 | 类型 | 必需 |
---|---|---|---|
leader_alias | 跨集群连接的名称。您在设置跨集群连接时定义此别名。 | 字符串 | 是 |
leader_index | 您希望复制的领导集群上的索引。 | 字符串 | 是 |
use_roles | 用于所有后续索引之间后端复制任务的角色。指定 leader_cluster_role 和 follower_cluster_role 。请参阅映射领导集群和跟随集群角色。 | 字符串 | 如果安全插件已启用 |
示例响应
{
"acknowledged": true
}
停止复制
于 1.1 引入
终止复制并将跟随索引转换为标准索引。将此请求发送到跟随集群。
请求
POST /_plugins/_replication/<follower-index>/_stop
{}
示例响应
{
"acknowledged": true
}
暂停复制
于 1.1 引入
暂停领导索引的复制。将此请求发送到跟随集群。
请求
POST /_plugins/_replication/<follower-index>/_pause
{}
如果复制暂停超过 12 小时,则无法恢复。您必须停止复制,删除跟随索引,然后重新启动领导索引的复制。
示例响应
{
"acknowledged": true
}
恢复复制
于 1.1 引入
恢复领导索引的复制。将此请求发送到跟随集群。
请求
POST /_plugins/_replication/<follower-index>/_resume
{}
示例响应
{
"acknowledged": true
}
获取复制状态
于 1.1 引入
获取索引复制的状态。可能的状态包括 SYNCING
(正在同步)、BOOTSTRAPING
(正在引导)、PAUSED
(已暂停)和 REPLICATION NOT IN PROGRESS
(复制未进行)。使用同步详情来衡量复制延迟。将此请求发送到跟随集群。
请求
GET /_plugins/_replication/<follower-index>/_status
示例响应
{
"status" : "SYNCING",
"reason" : "User initiated",
"leader_alias" : "my-connection-name",
"leader_index" : "leader-01",
"follower_index" : "follower-01",
"syncing_details" : {
"leader_checkpoint" : 19,
"follower_checkpoint" : 19,
"seq_no" : 0
}
}
要在响应中包含分片复制详情,请添加参数 &verbose=true
。
领导和跟随检查点值以负整数开头,反映分片计数(一个分片为 -1,五个分片为 -5,依此类推)。这些值会随着您的每次更改而向正整数递增。例如,当您在领导索引上进行更改时,leader_checkpoint
变为 0
。follower_checkpoint
最初仍为 -1
,直到跟随索引从领导索引拉取更改,此时它递增到 0
。如果值相同,则表示索引已完全同步。
获取领导集群统计信息
于 1.1 引入
获取指定集群上复制的领导索引的信息。
请求
GET /_plugins/_replication/leader_stats
示例响应
{
"num_replicated_indices": 2,
"operations_read": 15,
"translog_size_bytes": 1355,
"operations_read_lucene": 0,
"operations_read_translog": 15,
"total_read_time_lucene_millis": 0,
"total_read_time_translog_millis": 659,
"bytes_read": 1000,
"index_stats":{
"leader-index-1":{
"operations_read": 7,
"translog_size_bytes": 639,
"operations_read_lucene": 0,
"operations_read_translog": 7,
"total_read_time_lucene_millis": 0,
"total_read_time_translog_millis": 353,
"bytes_read":466
},
"leader-index-2":{
"operations_read": 8,
"translog_size_bytes": 716,
"operations_read_lucene": 0,
"operations_read_translog": 8,
"total_read_time_lucene_millis": 0,
"total_read_time_translog_millis": 306,
"bytes_read": 534
}
}
}
获取跟随集群统计信息
于 1.1 引入
获取指定集群上跟随(同步中)索引的信息。
请求
GET /_plugins/_replication/follower_stats
示例响应
{
"num_syncing_indices": 2,
"num_bootstrapping_indices": 0,
"num_paused_indices": 0,
"num_failed_indices": 0,
"num_shard_tasks": 2,
"num_index_tasks": 2,
"operations_written": 3,
"operations_read": 3,
"failed_read_requests": 0,
"throttled_read_requests": 0,
"failed_write_requests": 0,
"throttled_write_requests": 0,
"follower_checkpoint": 1,
"leader_checkpoint": 1,
"total_write_time_millis": 2290,
"index_stats":{
"follower-index-1":{
"operations_written": 2,
"operations_read": 2,
"failed_read_requests": 0,
"throttled_read_requests": 0,
"failed_write_requests": 0,
"throttled_write_requests": 0,
"follower_checkpoint": 1,
"leader_checkpoint": 1,
"total_write_time_millis": 1355
},
"follower-index-2":{
"operations_written": 1,
"operations_read": 1,
"failed_read_requests": 0,
"throttled_read_requests": 0,
"failed_write_requests": 0,
"throttled_write_requests": 0,
"follower_checkpoint": 0,
"leader_checkpoint": 0,
"total_write_time_millis": 935
}
}
}
获取自动跟随统计信息
于 1.1 引入
获取指定集群上自动跟随活动和任何已配置复制规则的信息。
请求
GET /_plugins/_replication/autofollow_stats
示例响应
{
"num_success_start_replication": 2,
"num_failed_start_replication": 0,
"num_failed_leader_calls": 0,
"failed_indices":[
],
"autofollow_stats":[
{
"name":"my-replication-rule",
"pattern":"movies*",
"num_success_start_replication": 2,
"num_failed_start_replication": 0,
"num_failed_leader_calls": 0,
"failed_indices":[
]
}
]
}
更新设置
于 1.1 引入
更新跟随索引上的设置。
请求
PUT /_plugins/_replication/<follower-index>/_update
{
"settings":{
"index.number_of_shards": 4,
"index.number_of_replicas": 2
}
}
示例响应
{
"acknowledged": true
}
创建复制规则
于 1.1 引入
自动开始对匹配指定模式的索引进行复制。如果领导集群上的新索引匹配该模式,OpenSearch 会自动创建一个跟随索引并开始复制。您也可以使用此 API 更新现有复制规则。
将此请求发送到跟随集群。
创建后务必记下所有自动跟随模式的名称。复制插件目前不包括检索现有模式列表的 API 操作。
请求
POST /_plugins/_replication/_autofollow
{
"leader_alias" : "<connection-alias-name>",
"name": "<auto-follow-pattern-name>",
"pattern": "<pattern>",
"use_roles":{
"leader_cluster_role": "<role-name>",
"follower_cluster_role": "<role-name>"
}
}
指定以下选项
选项 | 描述 | 类型 | 必需 |
---|---|---|---|
leader_alias | 跨集群连接的名称。您在设置跨集群连接时定义此别名。 | 字符串 | 是 |
名称 | 自动跟随模式的名称。 | 字符串 | 是 |
模式 | 一个索引模式数组,用于匹配指定领导集群中的索引。支持通配符。例如,leader-* 。 | 字符串 | 是 |
use_roles | 用于所有后续索引之间后端复制任务的角色。指定 leader_cluster_role 和 follower_cluster_role 。请参阅映射领导集群和跟随集群角色。 | 字符串 | 如果安全插件已启用 |
示例响应
{
"acknowledged": true
}
删除复制规则
于 1.1 引入
删除指定的复制规则。此操作会阻止任何新索引被复制,但不会停止该规则已启动的现有复制。复制的索引在您停止复制之前保持只读状态。
将此请求发送到跟随集群。
请求
DELETE /_plugins/_replication/_autofollow
{
"leader_alias" : "<connection-alias-name>",
"name": "<auto-follow-pattern-name>",
}
指定以下选项
选项 | 描述 | 类型 | 必需 |
---|---|---|---|
leader_alias | 跨集群连接的名称。您在设置跨集群连接时定义此别名。 | 字符串 | 是 |
名称 | 模式名称。 | 字符串 | 是 |
示例响应
{
"acknowledged": true
}