You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Bash获取Apache Ignite中需重置丢失分区的缓存列表?

获取有丢失分区的缓存列表(Bash实现)

方法1:利用control.sh自带命令检测丢失分区

如果你的缓存系统(比如Apache Ignite)的control.sh支持查询分区状态,可以直接用它筛选出有丢失分区的缓存:

# 获取所有缓存名称
ALL_CACHES=$(./control.sh --cache list | grep -E '^[A-Za-z0-9_-]+$')

# 遍历缓存,检查是否存在丢失分区
LOST_PARTITION_CACHES=""
for CACHE in $ALL_CACHES; do
    PARTITION_STATUS=$(./control.sh --cache partition-state $CACHE | grep -i "lost")
    if [ -n "$PARTITION_STATUS" ]; then
        LOST_PARTITION_CACHES+="$CACHE,"
    fi
done

# 移除末尾多余的逗号
LOST_PARTITION_CACHES=${LOST_PARTITION_CACHES%,}

# 执行重置命令
if [ -n "$LOST_PARTITION_CACHES" ]; then
    ./control.sh --cache reset_lost_partitions $LOST_PARTITION_CACHES
else
    echo "没有检测到有丢失分区的缓存"
fi

方法2:从集群日志/状态文件提取缓存列表

如果control.sh没有直接查询分区状态的命令,可以从集群日志中提取目标缓存:

# 从集群日志过滤含"lost partition"的行,提取缓存名并去重
LOST_PARTITION_CACHES=$(grep -i "lost partition" /var/log/ignite/ignite.log | awk -F'cache=' '{print $2}' | awk '{print $1}' | sort -u | tr '\n' ',')

# 移除末尾逗号
LOST_PARTITION_CACHES=${LOST_PARTITION_CACHES%,}

# 执行重置
if [ -n "$LOST_PARTITION_CACHES" ]; then
    ./control.sh --cache reset_lost_partitions $LOST_PARTITION_CACHES
else
    echo "未找到有丢失分区的缓存"
fi

注意事项

  • 确保control.sh有可执行权限,执行前可通过chmod +x control.sh设置
  • 不同缓存系统的control.sh参数可能有差异,可先执行./control.sh --help查看具体命令
  • 日志提取时,需根据实际日志格式调整awk的分割规则,确保能正确提取缓存名称

内容的提问来源于stack exchange,提问作者Striker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 08:07:42