1. 程式人生 > >Hadoop-2.4.1學習之edits和fsimage查看器

Hadoop-2.4.1學習之edits和fsimage查看器

文件的 順序 rup oev 兼容 require aps block mean

在hadoop中edits和fsimage是兩個至關關鍵的文件。當中edits負責保存自最新檢查點後命名空間的變化。起著日誌的作用,而fsimage則保存了最新的檢查點信息。這個兩個文件裏的內容使用普通文本編輯器是無法直接查看的,幸運的是hadoop為此準備了專門的工具用於查看文件的內容。這些工具分別為oev和oiv。能夠使用hdfs調用運行。

oev是offline edits viewer(離線edits查看器)的縮寫,該工具僅僅操作文件因而並不須要hadoop集群處於執行狀態。該工具提供了幾個輸出處理器。用於將輸入文件轉換為相關格式的輸出文件,能夠使用參數-p指定。眼下支持的輸出格式有binary(hadoop使用的二進制格式)、xml(在不使用參數p時的默認輸出格式)和stats(輸出edits文件的統計信息)。該工具支持的輸入格式為binary和xml,當中的xml文件為該工具使用xml處理器的輸出文件。因為沒有與stats格式相應的輸入文件,所以一旦輸出為stats格式將不能夠再轉換為原有格式。比方輸入格式為bianry。輸出格式為xml。能夠通過將輸入文件指定為原來的輸出文件,將輸出文件指定為原來的輸入文件實現binary和xml的轉換,而stats則不能夠。

該工具的詳細使用語法為:

Usage: bin/hdfs oev [OPTIONS] -i INPUT_FILE -o OUTPUT_FILE
Parse a Hadoop edits log file INPUT_FILE and save results
in OUTPUT_FILE.
Required command line arguments:
-i,--inputFile <arg>   edits file to process, xml (case insensitive) extension means XML format, any other filename means binary format
-o,--outputFile <arg>  Name of output file. If the specified file exists, it will be overwritten, format of the file is determined by -p option
Optional command line arguments:
-p,--processor <arg>   Select which type of processor to apply against image file, currently supported processors are: binary (native binary format that Hadoop uses), xml (default, XML format), stats (prints statistics about edits file)
-h,--help            Display usage information and exit
-f,--fix-txids         Renumber the transaction IDs in the input,so that there are no gaps or invalid transaction IDs.
-r,--recover          When reading binary edit logs, use recovery mode.  This will give you the chance to skip corrupt parts of the edit log.
-v,--verbose         More verbose output, prints the input and output filenames, for processors that write to a file, also output to screen. On large image files this will dramatically increase processing time (default is false).

該工具使用的演示樣例及輸出文件的部分文件內容例如以下:

$ hdfs oev -i edits_0000000000000000081-0000000000000000089 -o edits.xml
<?

xml version="1.0" encoding="UTF-8"?

> <EDITS> <EDITS_VERSION>-56</EDITS_VERSION> <RECORD> <OPCODE>OP_DELETE</OPCODE> <DATA> <TXID>88</TXID> <LENGTH>0</LENGTH> <PATH>/user/hive/test</PATH> <TIMESTAMP>1413794973949</TIMESTAMP> <RPC_CLIENTID>a52277d8-a855-41ee-9ca2-a5d0bc7d298a</RPC_CLIENTID> <RPC_CALLID>3</RPC_CALLID> </DATA> </RECORD> </EDITS>

在輸出文件裏。每一個RECORD記錄了一次操作。在該演示樣例中運行的是刪除操作。當edits文件破損進而導致hadoop集群出現故障時。保存edits文件裏正確的部分是可能的,能夠通過將原有的bianry文件轉換為xml文件,並手動編輯xml文件然後轉回bianry文件來實現。

最常見的edits文件破損情況是丟失關閉記錄的部分(OPCODE為-1),關閉記錄例如以下所看到的。

假設在xml文件裏沒有關閉記錄。能夠在最後正確的記錄後面加入關閉記錄。關閉記錄後面的記錄都將被忽略。

<RECORD>
    <OPCODE>-1</OPCODE>
    <DATA>
    </DATA>
</RECORD>

oiv是offline image viewer的縮寫。用於將fsimage文件的內容轉儲到指定文件裏以便於閱讀,該工具還提供了僅僅讀的WebHDFS API以同意離線分析和檢查hadoop集群的命名空間。

oiv在處理很大的fsimage文件時是相當快的,假設該工具不可以處理fsimage。它會直接退出。該工具不具備向後兼容性,比方使用hadoop-2.4版本號的oiv不能處理hadoop-2.3版本號的fsimage,僅僅能使用hadoop-2.3版本號的oiv。同oev一樣。就像它的名稱所提示的(offline),oiv也不須要hadoop集群處於執行狀態。oiv詳細語法可以通過在命令行輸入hdfs oiv查看。

oiv支持三種輸出處理器,分別為Ls、XML和FileDistribution。通過選項-p指定。Ls是默認的處理器,該處理器的輸出與lsr命令的輸出極其相似,以同樣的順序輸出同樣的字段。比方文件夾或文件的標誌、權限、副本數量、全部者、組、文件大小、改動日期和全路徑等。與lsr不同的是,該處理器的輸出包括根路徑/。還有一個重要的不同是該處理器的輸出不是依照文件夾名稱和內容排序的,而是依照在fsimage中的順序顯示。除非命名空間包括較少的信息。否則不太可能直接比較該處理器和lsr命令的輸出。Ls使用INode塊中的信息計算文件大小並忽略-skipBlocks選項。示比例如以下:

[[email protected] current]$ hdfs oiv -i fsimage_0000000000000000115 -o fsimage.ls
[[email protected] current]$ cat fsimage.ls
drwxr-xr-x  -   hadoop supergroup 1412832662162          0 /
drwxr-xr-x  -   hadoop supergroup 1413795010372          0 /user
drwxr-xr-x  -   hadoop supergroup 1414032848858          0 /user/hadoop
drwxr-xr-x  -   hadoop supergroup 1411626881217          0 /user/hadoop/input
drwxr-xr-x  -   hadoop supergroup 1413770138964          0 /user/hadoop/output

XML處理器輸出fsimage的xml文檔,包括了fsimage中的全部信息。比方inodeid等。該處理器的輸出支持XML工具的自己主動化處理和分析,因為XML語法格式的冗長,該處理器的輸出也最大。示比例如以下:

[[email protected] current]$ hdfs oiv -i fsimage_0000000000000000115 -p XML -o fsimage.xml 
[[email protected] current]$ cat fsimage.xml
<?

xml version="1.0"?> <fsimage> <NameSection> <genstampV1>1000</genstampV1> <genstampV2>1004</genstampV2> <genstampV1Limit>0</genstampV1Limit> <lastAllocatedBlockId>1073741828</lastAllocatedBlockId> <txid>115</txid> </NameSection> <INodeSection> <lastInodeId>16418</lastInodeId> <inode> <id>16385</id> <type>DIRECTORY</type> <name></name> <mtime>1412832662162</mtime> <permission>hadoop:supergroup:rwxr-xr-x</permission> <nsquota>9223372036854775807</nsquota> <dsquota>-1</dsquota> </inode> <inode> <id>16386</id> <type>DIRECTORY</type> <name>user</name> <mtime>1413795010372</mtime> <permission>hadoop:supergroup:rwxr-xr-x</permission> <nsquota>-1</nsquota> <dsquota>-1</dsquota> </inode> </INodeSection> </fsimage>

FileDistribution是分析命名空間中文件大小的工具。為了執行該工具須要通過指定最大文件大小和段數定義一個整數範圍[0,maxSize],該整數範圍依據段數切割為若幹段[0, s[1], ..., s[n-1], maxSize],處理器計算有多少文件落入每一個段中([s[i-1], s[i]),大於maxSize的文件總是落入最後的段中。即s[n-1], maxSize。輸出文件被格式化為由tab分隔的包括Size列和NumFiles列的表,當中Size表示段的起始,NumFiles表示文件大小落入該段的文件數量。在使用FileDistribution處理器時還須要指定該處理器的參數maxSize和step。若未指定默覺得0。示比例如以下:

[[email protected] current]$ hdfs oiv -i fsimage_0000000000000000115 -o fsimage.fd -p FileDistribution maxSize 1000 step 5
[[email protected] current]$ cat fsimage.fd
Processed 0 inodes.
Size	NumFiles
2097152	2
totalFiles = 2
totalDirectories = 11
totalBlocks = 2
totalSpace = 4112
maxFileSize = 1366

Hadoop-2.4.1學習之edits和fsimage查看器