您的位置:首页 > Web前端 > Node.js

HDFS1.0源代码解析—DataNode状态切换

2012-05-11 09:40 309 查看
Hadoop支持软件升级,对于Hadoop这样一个分布式的系统,升级将是一件很复杂的事情。下面介绍升级过程中DataNode的状态切换

首先来看DataNode可能存在的各种状态:

FORMAT  ("-format"),//格式化,用于系统第一次启动,必须先进行格式
REGULAR ("-regular"),//用于正常启动
UPGRADE ("-upgrade"),//进行升级的命令
ROLLBACK("-rollback"),//升级过程中出现错误,进行回滚
FINALIZE("-finalize"),//升级稳定后,进行提交
IMPORT  ("-importCheckpoint");//将系统恢复到某个checkpoint




该图摘在别人博客(感觉画的很透彻)

上图描述了各状态之间的切换流程。

1、DataNoe的具体升级流程如下:见DataStorage.java的doUpgrade方法

File curDir = sd.getCurrentDir();
File prevDir = sd.getPreviousDir();
assert curDir.exists() : "Current directory must exist.";
// delete previous dir before upgrading
if (prevDir.exists())
deleteDir(prevDir);
File tmpDir = sd.getPreviousTmp();//获取previous.tmp
assert !tmpDir.exists() : "previous.tmp directory must not exist.";
// rename current to tmp
rename(curDir, tmpDir);//将当前的current目录,重命名为previous.tmp
// hardlink blocks
linkBlocks(tmpDir, curDir, this.getLayoutVersion(), hardLink);
// write version file
this.layoutVersion = FSConstants.LAYOUT_VERSION;
assert this.namespaceID == nsInfo.getNamespaceID() :
"Data-node and name-node layout versions must be the same.";
this.cTime = nsInfo.getCTime();
sd.write();
// rename tmp to previous
rename(tmpDir, prevDir);


获取当前的current和previous目录,如果previous目录存在先删除,将当前current目录重命名为previous.tmp,建立current到previous.tmp的硬链接,在current里写入新的VERSION文件,将previous.tmp改名为previous,完成升级。其实整个升级的过程只是对VERSION文件的改写,对原先的数据文件只是建立了硬链接。

2、DataNode的回滚流程:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: