【Elasticsearch】迁出节点”≠“恢复源节点

复制代码
ShardRouting source = startedShard.relocate(nodeId, expectedShardSize);
ShardRouting target = source.getTargetRelocatingShard();
updateAssigned(startedShard, source);
node(target.currentNodeId()).add(target);
assignedShardsAdd(target);
addRecovery(target); //找恢复源(这里用到的恢复源不一定是迁出节点的)
changes.relocationStarted(startedShard, target);
复制代码
@Nullable //给一个副本分片,返回一条“可以用来当恢复源”的主分片路由。
private ShardRouting findAssignedPrimaryIfPeerRecovery(ShardRouting routing) {
    ShardRouting primary = null;
    if (routing.recoverySource() != null && routing.recoverySource().getType() == RecoverySource.Type.PEER) {
        List<ShardRouting> shardRoutings = assignedShards.get(routing.shardId());
        if (shardRoutings != null) {
            for (ShardRouting shardRouting : shardRoutings) {
                if (shardRouting.primary()) {   //这里只选主分片
                    if (shardRouting.active()) {
                        return shardRouting;
                    } else if (primary == null) {
                        primary = shardRouting;
                    } else if (primary.relocatingNodeId() != null) { //如果当前这个shardRouting还没active,并且旧的主分片正在作为迁移源往外迁移,
                        primary = shardRouting;
                    }
                }
            }
        }
    }
    return primary;
}

完全正确 ------ **"迁出节点"≠"恢复源节点"**:

  1. `startedShard.relocate(...)` 只是**生成两条路由记录**:
  • **源**:状态 `RELOCATING`,仍在**原节点**;

  • **目标**:状态 `INITIALIZING`,在**新节点**。

  1. 后续副本做 **PEER 恢复**时,**选源逻辑只看"哪条主分片路由当前能提供数据"**(通常就是那条 `RELOCATING` 源记录),**不管它物理上在哪个节点**;

因此恢复流量走向是:

**"选中的主分片路由所在节点" → 副本节点**

  1. 如果主分片本身也在 relocating,**旧节点**上的 `RELOCATING` 源分片仍处于 `STARTED` 状态,**照样能当数据源**;

一旦旧主分片关闭、新主分片 `STARTED`,恢复源会自动切换到新节点。

**结论:**

**"迁出节点"只是路由表里的一个中间状态,真正的恢复源由 `findAssignedPrimaryIfPeerRecovery` 动态选择,两者没有绑定关系。**

相关推荐
大大大大晴天2 天前
Hudi Metadata Table 与 Hive Sync (HMS)怎么选?
大数据
手可摘星辰7772 天前
一次线上FlinkCDC异常排查复盘
大数据·flink
大大大大晴天2 天前
Hudi技术内幕:Metadata Table原理与实践
大数据
武子康3 天前
调查研究-197 FAISS vs Elasticsearch 全面对比:从向量检索、全文搜索到 RAG 选型指南
人工智能·elasticsearch·agent
大大大大晴天3 天前
Hudi技术内幕:深入解析Index索引机制
大数据
阿里云大数据AI技术3 天前
Flink Forward Asia 2026 深圳启幕:Agentic Streaming for AI,开启实时智能新范式
大数据·flink
SelectDB4 天前
阶跃星辰基于 SelectDB 构建 PB 级 Agent 可观测平台
大数据·数据库·aigc
Elasticsearch4 天前
Elasticsearch ES|QL:现已支持视图、子查询和读取时模式定义
elasticsearch
Elasticsearch7 天前
Kibana 中的 SNMP 拓扑数据:从采集到 Canvas
elasticsearch
大大大大晴天7 天前
Hudi技术内幕:RecordPayload到RecordMerger
大数据