cloudstack VM的高可用(HighAvailability)

cloudstackVM的高可用有两种方式
1VM ha:由cloudstack management间隔发送pingTask收集host机器上VMstate信息,更新数据库表vm_instancepower_state字段,之后通过消息通知机制
MessageBusBase发行该主题,订阅者比较数据库表vm_instancepower_statestate字段,若果power_statePowerOffPowerReportMissing,而stateStarting|Stopping|Running|Stopped|Migrating中一种,则调用HighAvailabilityManagerImpl
scheduleRestart(VMInstanceVO vm, boolean investigate)方法来重启VM

2hostha:由cloudstack management间隔发送MonitorTaskping超时的host,查询其状态,如果状态不为DisabledMaintenance
ErrorInMaintenance(异常断开连接),调用HighAvailabilityManagerImplscheduleRestartForVmsOnHost(final
HostVO host, boolean investigate)来重启该host上的所有VM



AgentManagerImpl类中有一个
private final ConcurrentHashMap<Long, Long>
_pingMap = new ConcurrentHashMap<Long, Long>(10007);
在处理host的主动连接时,对于host类型不为TrafficMonitorSecondaryStoragehost
_pingMap中保存着hostid和连接时的当前时间
_pingMap.put(host.getId(),InaccurateClock.getTimeInSeconds());
在处理host的主动断开连接时
_pingMap.remove(agentId);
AgentManagerImpl组件启动时(start方法)
_monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), PingInterval.value(), PingInterval.value(),TimeUnit.SECONDS);
_monitorExecutor间隔指定时间调度执行MonitorTask任务
 MonitorTask任务内容为
1)根据当前时间计算出需要进行ping检测的hostid
 List<Long> agentsBehind = new ArrayList<Long>();
 long cutoffTime = InaccurateClock.getTimeInSeconds() - getTimeout();
 for (Map.Entry<Long, Long> entry : _pingMap.entrySet()) {
   if (entry.getValue() < cutoffTime) {
       agentsBehind.add(entry.getKey());
       }
   }
 if (agentsBehind.size() > 0) {
     s_logger.info("Found the following agents behind on ping: " + agentsBehind);
     }
 return agentsBehind;
2)对于每一个需要进行ping检测的hostid,从host数据库表查询其state
2.1 若状态为DisabledMaintenanceErrorInMaintenance,则断开host的连接
if (resourceState == ResourceState.Disabled ||resourceState == ResourceState.Maintenance || resourceState ==ResourceState.ErrorInMaintenance) {
              
 status_logger.debug("Ping timeout but host" + agentId + " is in resource state of " +resourceState + ", so no investigation");
   disconnectWithoutInvestigation(agentId,Event.ShutdownRequested);
}
2.2
如果state不为上述三种(异常断开连接),但host类型为ConsoleProxySecondaryStorageVMSecondaryStorageCmdExecutor,不调查检测,关闭连接
2.3host调查检测,并发出告警事件。并对hostVM生成调用HighAvailabilityManagerImplscheduleRestartForVmsOnHost来重启host上的VMscheduleRestartForVmsOnHost对每一个VM调用scheduleRestart
HighAvailabilityManagerImplscheduleRestart会在数据库表op_ha_work中插入一条VMha类型的记录,然后唤醒WorkerThread来处理。
HighAvailabilityManagerImpl组件在configure根据数据库表configuration的记录ha.workers的值(5)来构建5WorkerThreadWorkerThread
op_ha_work表的记录,对WorkType.HA类型的记录执行restart(work)该函数会重启VM

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值