|NO.Z.00024|——————————|BigDataEnd|——|Hadoop&HDFS.V09|——|Hadoop.v09|HDFS元数据管理机制|NN和2NN.v02|
一、Fsimage文件内容
### --- 官方地址:
https://hadoop.apache.org/docs/r2.9.2/hadoop-project-dist/hadoop-hdfs/HdfsImageViewer.html
### --- 查看oiv和oev命令
[root@linux121 current]$ hdfs oiv Offline Image Viewer View a Hadoop fsimage INPUTFILE using the specified
PROCESSOR,saving the results in OUTPUTFILE.
oev Offline edits viewer Parse a Hadoop edits log file INPUT_FILE and save results in
OUTPUT_FILE
### --- 基本语法
hdfs oiv -p 文件类型(xml) -i 镜像文件 -o 转换后文件输出路径
### --- 案例实操
[root@linux121 ~]# cd /opt/yanqi/servers/hadoop-2.9.2/data/tmp/dfs/name/current
[root@linux121 current]# hdfs oiv -p XML -i fsimage_0000000000000000507 -o /opt/yanqi/servers/image0507.xml
21/08/13 18:46:11 INFO offlineImageViewer.FSImageHandler: Loading 5 strings
[root@linux121 current]# cat /opt/yanqi/servers/image0507.xml
### --- 格式化流程
~~~ 格式化工具地址:https://tool.oschina.net/codeformat/xml
### --- 输出内容
<?xml version="1.0"?>
<fsimage>
<version>
<layoutVersion>-63</layoutVersion>
<onDiskVersion>1</onDiskVersion>
<oivRevision>826afbeae31ca687bc2f8471dc841b66ed2c6704</oivRevision>
</version>
<NameSection>
<namespaceId>1393381414</namespaceId>
<genstampV1>1000</genstampV1>
<genstampV2>1024</genstampV2>
<genstampV1Limit>0</genstampV1Limit>
<lastAllocatedBlockId>1073741848</lastAllocatedBlockId>
<txid>265</txid>
</NameSection>
<INodeSection>
<inode>
<id>16398</id>
<type>DIRECTORY</type>
<name>history</name>
<mtime>1592376391028</mtime>
<permission>root:supergroup:0777</permission>
<nsquota>-1</nsquota>
<dsquota>-1</dsquota>
</inode>
<inode>
<id>16399</id>
<type>DIRECTORY</type>
<name>done_intermediate</name>
<mtime>1592375256896</mtime>
<permission>root:supergroup:1777</permission>
<nsquota>-1</nsquota>
<dsquota>-1</dsquota>
</inode>
<inode>
<id>16400</id>
<type>DIRECTORY</type>
<name>root</name>
<mtime>1592378079208</mtime>
<permission>root:supergroup:0777</permission>
<nsquota>-1</nsquota>
<dsquota>-1</dsquota>
</inode>
<inode>
<id>16413</id>
<type>FILE</type>
<name>job_1592375222804_0001-1592375231176-root-word+count-1592375281926-1-1-SUCCEEDED-default-1592375261492.jhist</name>
<replication>3</replication>
<mtime>1592375282039</mtime>
<atime>1592375281980</atime>
<preferredBlockSize>134217728</preferredBlockSize>
<permission>root:supergroup:0777</permission>
<blocks>
<block>
<id>1073741834</id>
<genstamp>1010</genstamp>
<numBytes>33584</numBytes>
</block>
</blocks>
<storagePolicyId>0</storagePolicyId>
</inode>
<inode>
<id>16414</id>
<type>FILE</type>
<name>job_1592375222804_0001_conf.xml</name>
<replication>3</replication>
<mtime>1592375282121</mtime>
<atime>1592375282053</atime>
<preferredBlockSize>134217728</preferredBlockSize>
<permission>root:supergroup:0777</permission>
<blocks>
<block>
<id>1073741835</id>
<genstamp>1011</genstamp>
<numBytes>196027</numBytes>
</block>
</blocks>
<storagePolicyId>0</storagePolicyId>
</inode>
<inode>
<id>16415</id>
<type>DIRECTORY</type>
<name>done</name>
<mtime>1592376776670</mtime>
<permission>root:supergroup:0777</permission>
<nsquota>-1</nsquota>
<dsquota>-1</dsquota>
</inode>
<inode>
<id>16427</id>
<type>DIRECTORY</type>
<name>logs</name>
<mtime>1592378009623</mtime>
<permission>root:root:0770</permission>
<nsquota>-1</nsquota>
<dsquota>-1</dsquota>
</inode>
<inode>
<id>16428</id>
<type>DIRECTORY</type>
<name>application_1592376944601_0001</name>
<mtime>1592378045481</mtime>
<permission>root:root:0770</permission>
<nsquota>-1</nsquota>
<dsquota>-1</dsquota>
</inode>
<inode>
<id>16430</id>
<type>DIRECTORY</type>
<name>wcoutput</name>
<mtime>1592378037463</mtime>
<permission>root:supergroup:0755</permission>
<nsquota>-1</nsquota>
<dsquota>-1</dsquota>
</inode>
<inode>
<id>16436</id>
<type>FILE</type>
<name>part-r-00000</name>
<replication>3</replication>
<mtime>1592378037264</mtime>
<atime>1592378037074</atime>
<preferredBlockSize>134217728</preferredBlockSize>
<permission>root:supergroup:0644</permission>
<blocks>
<block>
<id>1073741842</id>
<genstamp>1018</genstamp>
<numBytes>43</numBytes>
</block>
</blocks>
<storagePolicyId>0</storagePolicyId>
</inode>
<inode>
<id>16445</id>
<type>FILE</type>
<name>linux123_39919</name>
<replication>3</replication>
<mtime>1592378045469</mtime>
<atime>1592378045331</atime>
<preferredBlockSize>134217728</preferredBlockSize>
<permission>root:root:0640</permission>
<blocks>
<block>
<id>1073741848</id>
<genstamp>1024</genstamp>
<numBytes>56910</numBytes>
</block>
</blocks>
<storagePolicyId>0</storagePolicyId>
</inode>
<inode>
<id>16446</id>
<type>DIRECTORY</type>
<name>0617</name>
<mtime>1592387393490</mtime>
<permission>root:supergroup:0755</permission>
<nsquota>-1</nsquota>
<dsquota>-1</dsquota>
</inode>
<inode>
<id>16449</id>
<type>FILE</type>
<name>banzhang.txt</name>
<replication>1</replication>
<mtime>1592388309046</mtime>
<atime>1592388309026</atime>
<preferredBlockSize>134217728</preferredBlockSize>
<permission>root:supergroup:0644</permission>
<storagePolicyId>0</storagePolicyId>
</inode>
</INodeSection>
</fsimage>
二、问题:Fsimage中为什么没有记录块所对应DataNode?
### --- 问题:Fsimage中为什么没有记录块所对应DataNode?
~~~ 在内存元数据中是有记录块所对应的dn信息,但是fsimage中就剔除了这个信息;
~~~ HDFS集群在启动的时候会加载image以及edits文件,block对应的dn信息都没有记录,
~~~ 集群启动时会有一个安全模式(safemode),
~~~ 安全模式就是为了让dn汇报自己当前所持有的block信息给nn来补全元数据。
~~~ 后续每隔一段时间dn都要汇报自己持有的block信息。
三、 Edits文件内容
### --- 基本语法
~~~ hdfs oev -p 文件类型 -i编辑日志 -o 转换后文件输出路径
### --- 案例实操
[root@linux121 ~]# hdfs dfs -mkdir /edits_test1
[root@linux121 ~]# hdfs dfs -mkdir /edits_test2
[root@linux121 ~]# hdfs dfs -mkdir /edits_test3
[root@linux121 current]# hdfs oev -p XML -i edits_inprogress_0000000000000000508 -o /opt/yanqi/servers/edits0508.xml
### --- edits文件内容
<?xml version="1.0" encoding="UTF-8"?>
<EDITS>
<EDITS_VERSION>-63</EDITS_VERSION>
<RECORD>
<OPCODE>OP_START_LOG_SEGMENT</OPCODE>
<DATA>
<TXID>113</TXID>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>114</TXID>
<SRC>/wcoutput/_SUCCESS</SRC>
<MODE>493</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>115</TXID>
<SRC>/wcoutput/part-r-00000</SRC>
<MODE>493</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>116</TXID>
<SRC>/wcoutput</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>117</TXID>
<SRC>/wcoutput/_SUCCESS</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>118</TXID>
<SRC>/wcoutput/part-r-00000</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_DELETE</OPCODE>
<DATA>
<TXID>119</TXID>
<LENGTH>0</LENGTH>
<PATH>/wcoutput/part-r-00000</PATH>
<TIMESTAMP>1592377324171</TIMESTAMP>
<RPC_CLIENTID></RPC_CLIENTID>
<RPC_CALLID>-2</RPC_CALLID>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>120</TXID>
<SRC>/</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>121</TXID>
<SRC>/tmp</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>122</TXID>
<SRC>/tmp/hadoop-yarn</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>123</TXID>
<SRC>/tmp/hadoop-yarn/staging</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>124</TXID>
<SRC>/tmp/hadoop-yarn/staging/history</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>125</TXID>
<SRC>/tmp/hadoop-yarn/staging/history/done</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
<OPCODE>OP_SET_PERMISSIONS</OPCODE>
<DATA>
<TXID>126</TXID>
<SRC>/tmp/hadoop-yarn/staging/history/done/2020</SRC>
<MODE>511</MODE>
</DATA>
</RECORD>
<RECORD>
### --- 备注:Edits中只记录了更新相关的操作,查询或者下载文件并不会记录在内!!
~~~ # 问题:
~~~ NameNode启动时如何确定加载哪些Edits文件呢?
~~~ nn启动时需要加载fsimage文件以及那些没有被2nn进行合并的edits文件,
~~~ nn如何判断哪些edits已经被合并了呢?
~~~ 可以通过fsimage文件自身的编号来确定哪些已经被合并。
四、checkpoint周期
### --- [hdfs-default.xml]
<!-- 定时一小时 -->
<property>
<name>dfs.namenode.checkpoint.period</name>
<value>3600</value>
</property>
<!-- 一分钟检查一次操作次数,当操作次数达到1百万时,SecondaryNameNode执行一次 -->
<property>
<name>dfs.namenode.checkpoint.txns</name>
<value>1000000</value>
<description>操作动作次数</description>
</property>
<property>
<name>dfs.namenode.checkpoint.check.period</name>
<value>60</value>
<description> 1分钟检查一次操作次数</description>
</property >
一、[HDFS元数据管理机制之NN故障处理]
### --- NN故障处理
~~~ NameNode故障后,HDFS集群就无法正常工作,
~~~ 因为HDFS文件系统的元数据需要由NameNode来管理维护并与Client交互,
~~~ 如果元数据出现损坏和丢失同样会导致NameNode无法正常
~~~ 工作进而HDFS文件系统无法正常对外提供服务。
### --- 如果元数据出现丢失损坏如何恢复呢?
~~~ 将2NN的元数据拷贝到NN的节点下
~~~ 此种方式会存在元数据的丢失。
~~~ 搭建HDFS的HA(高可用)集群,解决NN的单点故障问题!!
~~~ (借助Zookeeper实现HA,一个Active的NameNode,一个是Standby的NameNode)
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm’d both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
版权声明:本文为yanqi_vip原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。