hadoop2.4源码分析
发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,本篇内容介绍了"hadoop2.4源码分析"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!ZKFail
千家信息网最后更新 2026年10月31日hadoop2.4源码分析
本篇内容介绍了"hadoop2.4源码分析"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
ZKFailoverController是整个HA的协调者。下面我们将分析几个实际的问题。
1.怎么协调选举的?怎么选举出来active的?
2.active宕机后,做了什么事情,如何切换的?
下面,我们来分析第一个问题 怎么协调选举的?怎么选举出来active的?
步骤1:参看NameNode源码,可以看出,对于使用HA的NN来说,进入Standby是必须的。 升级除外
protected HAState createHAState(StartupOption startOpt) { if (!haEnabled || startOpt == StartupOption.UPGRADE) { return ACTIVE_STATE; } else { return STANDBY_STATE; //standby状态 } }步骤2:此时的HealthMonitor监控NN,发现是HEALTH的状态,会执行:
if (healthy) { //设置状态,用于通知回调函数 enterState(State.SERVICE_HEALTHY); }enterState会通知回调函数,进行处理。对于HEALTH状态的开始执行选举方法。
elector.joinElection(targetToData(localTarget));
通过创建零时节点,来抢占节点,获取Active
createLockNodeAsync();
对于创建节点,会触发ZK的EVENT时间。
对于事件的处理,见源码部分:
public synchronized void processResult(int rc, String path, Object ctx, String name) { if (isStaleClient(ctx)) return; LOG.debug("CreateNode result: " + rc + " for path: " + path + " connectionState: " + zkConnectionState + " for " + this); Code code = Code.get(rc);//为了方便使用,这里自定义了一组状态 if (isSuccess(code)) {//成功返回,成功创建zklocakpath节点 // we successfully created the znode. we are the leader. start monitoring if (becomeActive()) {//要将本节点上的NN变成active monitorActiveStatus();//继续监控节点状态 } else { reJoinElectionAfterFailureToBecomeActive();//失败,继续选举尝试 } return; } if (isNodeExists(code)) {//节点存在,说明已经有active,wait即可 if (createRetryCount == 0) { // znode exists and we did not retry the operation. so a different // instance has created it. become standby and monitor lock. becomeStandby(); } // if we had retried then the znode could have been created by our first // attempt to the server (that we lost) and this node exists response is // for the second attempt. verify this case via ephemeral node owner. this // will happen on the callback for monitoring the lock. monitorActiveStatus();//不过努力成为active的动作不能停 return; } String errorMessage = "Received create error from Zookeeper. code:" + code.toString() + " for path " + path; LOG.debug(errorMessage); if (shouldRetry(code)) { if (createRetryCount < maxRetryNum) { LOG.debug("Retrying createNode createRetryCount: " + createRetryCount); ++createRetryCount; createLockNodeAsync(); return; } errorMessage = errorMessage + ". Not retrying further znode create connection errors."; } else if (isSessionExpired(code)) { // This isn't fatal - the client Watcher will re-join the election LOG.warn("Lock acquisition failed because session was lost"); return; } fatalError(errorMessage); }对于获取Active的机器,调用becomeActive()方法
private synchronized void becomeActive() throws ServiceFailedException { LOG.info("Trying to make " + localTarget + " active..."); try { HAServiceProtocolHelper.transitionToActive(localTarget.getProxy( conf, FailoverController.getRpcTimeoutToNewActive(conf)), createReqInfo()); String msg = "Successfully transitioned " + localTarget + " to active state"; LOG.info(msg); serviceState = HAServiceState.ACTIVE; recordActiveAttempt(new ActiveAttemptRecord(true, msg)); } catch (Throwable t) { String msg = "Couldn't make " + localTarget + " active"; LOG.fatal(msg, t); recordActiveAttempt(new ActiveAttemptRecord(false, msg + "\n" + StringUtils.stringifyException(t))); if (t instanceof ServiceFailedException) { throw (ServiceFailedException)t; } else { throw new ServiceFailedException("Couldn't transition to active", t); }通过对RPC进过一系列的调用,最终执行NameNode的
synchronized void transitionToActive() throws ServiceFailedException, AccessControlException { namesystem.checkSuperuserPrivilege(); if (!haEnabled) { throw new ServiceFailedException("HA for namenode is not enabled"); } state.setState(haContext, ACTIVE_STATE); }OVER
2.active宕机后,做了什么事情,如何切换的?
active宕机后或者异常会导致ZK节点的消失或监控状态的UNHEALTH,这些都会导致新一轮的选举,原理同上。
"hadoop2.4源码分析"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
节点
状态
选举
源码
分析
监控
成功
事情
内容
函数
实际
方法
更多
步骤
知识
问题
切换
处理
实用
学有所成
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
百单网互联网科技有限公司怎么样
亿人帮互联网科技有限公司
广州淘业互联网络科技
广州万易互联网科技有限公司
互联网科技活动banner
科技企业和互联网企业
朗涯互联网科技
左右互联网络科技
博兴的互联网电子科技公司
成都玖崟互联网科技有限公司乐商圈怎么样
小米互联网科技园设置
常德市电业局互联网科技部
移动互联网科技股
语蝶互联网科技有限公司
西安小鹰速贷互联网科技有限公司
明优互联网科技有限公司
江苏互联网智能科技软件
安徽零酒互联网科技有限公司
科技互联网专业工作会议发言稿
互联网科技创新创业项目
万易互联网科技有限公司
亿策互联网科技
岳阳华臻互联网科技有限公司
互联网科技大奖都有哪些公司
济南有互联网科技公司吗
厦门江牛科技互联网
广东鹅鹅鹅互联网科技有限公司
互联网科技大佬云集
前海云享互联网科技
每日互联网科技新闻