设为首页 收藏本站
查看: 1273|回复: 0

[经验分享] hadoop分析之一HDFS元数据解析

[复制链接]

尚未签到

发表于 2016-12-11 08:40:14 | 显示全部楼层 |阅读模式
1、元数据(Metadata):维护HDFS文件系统中文件和目录的信息,分为内存元数据和元数据文件两种。NameNode维护整个元数据。

DSC0000.png

HDFS实现时,没有采用定期导出元数据的方法,而是采用元数据镜像文件(FSImage)+日子文件(edits)的备份机制。

2、Block:文件内容而言。

寻路径流程:

     路径信息             bocks[]                  triplets[]     

Client ------------》INode---------------------》BlockInfo --------------------------》DataNode。



INode:文件的基本元素:文件和目录

BlockInfo: 文件内容对象

DatanodeDescriptor:具体存储对象。

3 、 FSImage和edits的checkPoint。FSImage有2个状态,分别是FsImage和FsImage.ckpt,后者表示正在checkpoint的过程中,上传后将会修改为FSImage文件,同理edits也有两个状态,edits和edits.new。

4、NameNode format情景分析:


  • 遍历元数据存储目录,提示用户是否格式化?(NameNode.java里format函数)

private static boolean format( Configuration conf ,
boolean isConfirmationNeeded )
throws IOException {
Collection<URI > dirsToFormat = FSNamesystem. getNamespaceDirs(conf );
Collection<URI > editDirsToFormat =
FSNamesystem .getNamespaceEditsDirs (conf );
for( Iterator< URI> it = dirsToFormat.iterator (); it. hasNext() ;) {
File curDir = new File (it .next (). getPath()) ;
if (! curDir. exists())
continue;
if (isConfirmationNeeded ) {
System .err .print ("Re-format filesystem in " + curDir + " ? (Y or N) ");
if (! (System .in .read () == 'Y')) {
System .err .println ("Format aborted in " + curDir );
return true ;
}
while(System .in .read () != '\n') ; // discard the enter-key
}
}
FSNamesystem nsys = new FSNamesystem (new FSImage(dirsToFormat ,
editDirsToFormat ), conf) ;
nsys.dir.fsImage .format ();
return false;
}




  • 创建元数据内存镜像,包括类FSNamesystem实例化对象,类FSDirectory实例化对象,类FSImage对象,类Edits对象。创建FsNameSystem对象主要完成:BlockManager,FSDirectory对象以及初始化成员变量。FSImage对象主要完成对layoutVersion、namespaceID,CTime赋值为0,实例化FSEditLog。在类FSDirectory,创建了HDFS根目录节点rootDir。

FSNamesystem( FSImage fsImage, Configuration conf ) throws IOException {
this. blockManager = new BlockManager (this, conf) ;
setConfigurationParameters (conf );
this. dir = new FSDirectory(fsImage , this, conf );
dtSecretManager = createDelegationTokenSecretManager (conf );
}
FSImage( Collection< URI> fsDirs , Collection< URI> fsEditsDirs )
throws IOException {
this() ;
setStorageDirectories( fsDirs, fsEditsDirs );
}
void setStorageDirectories(Collection <URI > fsNameDirs,
Collection< URI> fsEditsDirs ) throws IOException {
this. storageDirs = new ArrayList <StorageDirectory >() ;
this. removedStorageDirs = new ArrayList <StorageDirectory >() ;
// Add all name dirs with appropriate NameNodeDirType
for (URI dirName : fsNameDirs ) {
checkSchemeConsistency (dirName );
boolean isAlsoEdits = false;
for (URI editsDirName : fsEditsDirs) {
if (editsDirName .compareTo (dirName ) == 0) {
isAlsoEdits = true;
fsEditsDirs .remove (editsDirName );
break;
}
}
NameNodeDirType dirType = (isAlsoEdits ) ?
NameNodeDirType .IMAGE_AND_EDITS :
NameNodeDirType .IMAGE ;
// Add to the list of storage directories, only if the
// URI is of type file://
if(dirName .getScheme (). compareTo( JournalType.FILE .name (). toLowerCase())
== 0){
this.addStorageDir (new StorageDirectory(new File(dirName. getPath()) ,
dirType ));
}
}
// Add edits dirs if they are different from name dirs
for (URI dirName : fsEditsDirs ) {
checkSchemeConsistency (dirName );
// Add to the list of storage directories, only if the
// URI is of type file://
if(dirName .getScheme (). compareTo( JournalType.FILE .name (). toLowerCase())
== 0)
this.addStorageDir (new StorageDirectory(new File(dirName. getPath()) ,
NameNodeDirType .EDITS ));
}
}



  • 对内存镜像数据中的数据结构进行初始化:主要有FSImage的format函数完成,layoutVersion:软件所处的版本。namespaceID:在Format时候产生,当data node注册到Name Node后,会获得该NameNode的NameSpaceID,并作为后续与NameNode通讯的身份标识。对于未知身份的Data Node,NameNode拒绝通信。CTime:表示FSimage产生的时间。checkpointTime:表示NameSpace第一次checkpoint的时间。

public void format () throws IOException {
this. layoutVersion = FSConstants .LAYOUT_VERSION ;
this. namespaceID = newNamespaceID ();
this. cTime = 0L ;
this. checkpointTime = FSNamesystem .now ();
for (Iterator <StorageDirectory > it =
dirIterator (); it. hasNext() ;) {
StorageDirectory sd = it .next ();
format (sd );
}
}


  • 对内存镜像写入元数据备份目录。FSImage的format方法会遍历所有的目录进行备份。如果是FSImage的文件目录,则调用saveFSImage保存FSImage,如果是Edits,则调用editLog.createEditLogFile,最后调用sd.write方法创建fstime和VERSION文件。VERSION文件通常最后写入。

void format(StorageDirectory sd ) throws IOException {
sd.clearDirectory (); // create currrent dir
sd.lock ();
try {
saveCurrent (sd );
} finally {
sd .unlock ();
}
LOG.info ("Storage directory " + sd. getRoot()
+ " has been successfully formatted.");
}





最后分析一下元数据应用的场景:

1、格式化时。

2、Hadoop启动时。

3、元数据更新操作时。

4、如果NameNode与Secondary NameNode、Backup Node或checkpoint Node配合使用时,会进行checkPoint操作。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-312557-1-1.html 上篇帖子: Hadoop 中使用DistributedCache遇到的问题 下篇帖子: HBase如何从Hadoop读取数据,DFSInputStream
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表