Offline Image Viewer Guide

来源:互联网 发布:手机淘宝买家秀在哪里 编辑:程序博客网 时间:2024/05/21 17:45

Overview

离线Image查看器是一个将HDFS FsImage文件的内容以人类可读的格式输出以允许离线的分析和检查一个Hadoop集群的命名空间。这个工具能够相当快速地处理非常大的image文件,将其转换为几个输出格式中的一个。这个工具在Hadoop版本16之后被增加以处理布局格式。如果此工具不能够处理一个image文件,它将干净地退出。离线Image查看器不需要Hadoop集群正在运行,它的操作完全离线。

离线Image查看器提供几个输出格式:

1.      Ls是默认的输出处理器。它模仿lsr命令的格式。它包含lsr命令的输出相同的字段,相同的顺序打印,字段包括目录/文件标识,权限,副本个数,文件所有者,组,文件大小,修改时间,全路径。不像lsr命令,这是包含根路径的。Lsr命令和此处理器输出的一个重要的不同是,处理器的输出不会被目录名和内容保存。而是,文件以它们存储在FsImage文件中的顺序被列出。因此,不可能直接比较lsr命令和此工具的输出。Ls处理器使用包含在Inode Block中的信息来计算文件大小,按-skipBlocks的条件忽略。

2.      Indented提供一个FsImage内容的完整的视图,包括所有在Image文件中包含的信息,像Image的版本,生成的时间戳,特定的inode和Block的列表。处理器用缩进来分层地组织输出。Lsr格式近适用于简单的理解Image内容。

3.      Delimited为每个文件保存一行数据,包括路径,副本信息,修改时间,访问时间,Block大小,Block个数,文件大小,命名空间配额,磁盘空间配额,权限,用户名和用户组名。如果不加字段中的一个对一个FsImage文件运行此处理器,这个字段的列将会出现,但是不会有记录的数据。默认记录分隔符是tab键,但这可以通过 -delimiter命令行参数来改变。这个处理器被设计为输出一个容易被其他工具分析的输出,比如Pig。可以查看 Analyzing Results部分获取更多如何使用这个处理器来分析FsImage文件中的数据的信息。

4.      XML创建一个FsImage的XML文档,其中包含FsImage中所有的信息,与lsr处理器相似。这个处理器的输出可被XML工具自动处理和分析。由于XML语法的冗长,这个处理器生成的输出最大。

5.      FileDistribution是一个分析命名空间镜像中的文件大小的工具。为了运行这个工具,你应该通过指定maxSize定义一个整数范围[0,maxSize]和一个step。

Usage

Basic

离线Image查看器最简单的用法是提供一个输入文件和一个输出文件:

bash$ bin/hdfs oiv -ifsimage -o fsimage.txt

这将使用Ls输出处理器在当前目录中创建一个名叫FsImage.txt的文件。对于大的Image文件,这个过程可能花费几分钟。

你可以指定输出处理器,例如:

bash$ bin/hdfs oiv -i fsimage -o fsimage.xml -p XML

或者

bash$ bin/hdfs oiv -i fsimage -o fsimage.txt -p Indented

这将各自使用XML或者Indented输出处理器运行工具。

一个值得考虑的命令行选项是-skipBlocks。这防止工具明确的列出命名空间中组成一个文件的所有的Block。这对有非常大的文件的文件系统是非常有用的。开启这个选项将极大的减少输出结果的大小。因为不包括单独的块的信息。注意,Ls处理器需要遍历所有的Block,所以它重载了这个选项。

Example

考虑下面虚构的命名空间:

drwxr-xr-x   - theuser supergroup          0 2009-03-16 21:17 /anotherDir-rw-r--r--   3 theuser supergroup  286631664 2009-03-16 21:15 /anotherDir/biggerfile-rw-r--r--   3 theuser supergroup       8754 2009-03-16 21:17 /anotherDir/smallFiledrwxr-xr-x   - theuser supergroup          0 2009-03-16 21:11 /mapredsystemdrwxr-xr-x   - theuser supergroup          0 2009-03-16 21:11 /mapredsystem/theuserdrwxr-xr-x   - theuser supergroup          0 2009-03-16 21:11 /mapredsystem/theuser/mapredsystemdrwx-wx-wx   - theuser supergroup          0 2009-03-16 21:11 /mapredsystem/theuser/mapredsystem/ip.redacted.comdrwxr-xr-x   - theuser supergroup          0 2009-03-16 21:12 /onedrwxr-xr-x   - theuser supergroup          0 2009-03-16 21:12 /one/twodrwxr-xr-x   - theuser supergroup          0 2009-03-16 21:16 /userdrwxr-xr-x   - theuser supergroup          0 2009-03-16 21:19 /user/theuser

用默认的选项对这个文件应用离线Image处理器将会产生下面的输出:

machine:hadoop-0.21.0-dev theuser$ bin/hdfs oiv -i fsimagedemo -o fsimage.txtdrwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:16 /drwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:17 /anotherDirdrwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:11 /mapredsystemdrwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:12 /onedrwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:16 /user-rw-r--r--  3   theuser supergroup    286631664 2009-03-16 14:15 /anotherDir/biggerfile-rw-r--r--  3   theuser supergroup         8754 2009-03-16 14:17 /anotherDir/smallFiledrwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:11 /mapredsystem/theuserdrwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:11 /mapredsystem/theuser/mapredsystemdrwx-wx-wx  -   theuser supergroup            0 2009-03-16 14:11 /mapredsystem/theuser/mapredsystem/ip.redacted.comdrwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:12 /one/twodrwxr-xr-x  -   theuser supergroup            0 2009-03-16 14:19 /user/theuser

类似的,用Indented处理器将生成以下面的输出开始的输出:

machine:hadoop-0.21.0-dev theuser$ bin/hdfs oiv -i fsimagedemo -p Indented -o fsimage.txtFSImage     ImageVersion = -19     NamespaceID = 2109123098     GenerationStamp = 1003     INodes [NumInodes = 12]       Inode         INodePath =         Replication = 0         ModificationTime = 2009-03-16 14:16         AccessTime = 1969-12-31 16:00         BlockSize = 0         Blocks [NumBlocks = -1]         NSQuota = 2147483647         DSQuota = -1         Permissions           Username = theuser           GroupName = supergroup           PermString = rwxr-xr-x   ...remaining output omitted...

Options

Flag

Description

-i|--inputFileinput file

Specify the input fsimage file to process. Required.

-o|--outputFileoutput file

Specify the output filename, if the specified output processor generates one. If the specified file already exists, it is silently overwritten. Required.

-p|--processorprocessor

Specify the image processor to apply against the image file. Currently valid options are Ls (default), XML and Indented..

-skipBlocks

Do not enumerate individual blocks within files. This may save processing time and outfile file space on namespaces with very large files. The Ls processor reads the blocks to correctly determine file sizes and ignores this option.

-printToScreen

Pipe output of processor to console as well as specified file. On extremely large namespaces, this may increase processing time by an order of magnitude.

-delimiterarg

When used in conjunction with the Delimited processor, replaces the default tab delimiter with the string specified by arg.

-h|--help

Display the tool usage and help information and exit.

Analyzing Results

离线Image查看器使得收集关于HDFS命名空间的大量信息非常容易。这些信息可被用来探索文件系统的使用模式或者找到符合任意标准的特殊类型文件,与其他类型的命名空间分析写作。尤其是Delimited Image处理器创建一个可以被像Pig这样的工具进一步处理的输出。Pig为分析这些数据提供了一个特别好的方式,因为它能处理一个小的FsImage文件生成的输出,也能够消费极大的文件系统。

Delimited Image处理器生成一行一行的文本,默认情况下,用tab分隔,一行文本包含所有的字段,这些字段在已经构建的文件和当Fsimage生成时还在构建的文件之间是共同的。提供的例子脚本描述了如何使用这个输出来完成3个任务:判断文件系统中每个用户已经创建的文件个数,找出创建过后从没被访问过的文件,通过比较每个文件的大小找出大文件的副本。

下面的脚本假设你已经用Delimited处理器生成了一个叫做foo的输出文件,同时,你将会存储Pig的分析文件到一个叫Results的文件中。

Total Number of Files for Each User

这个脚本处理每一个命名空间中的路径,按文件所有者分组,计算每一个文件拥有者的总文件数。

   
numFilesOfEachUser.pig:   -- This script determines the total number of files each user has in   -- the namespace. Its output is of the form:   --   username, totalNumFiles    -- Load all of the fields from the file   A = LOAD '$inputFile' USING PigStorage('\t') AS (path:chararray,                                                    replication:int,                                                    modTime:chararray,                                                    accessTime:chararray,                                                    blockSize:long,                                                    numBlocks:int,                                                    fileSize:long,                                                    NamespaceQuota:int,                                                    DiskspaceQuota:int,                                                    perms:chararray,                                                    username:chararray,                                                    groupname:chararray);     -- Grab just the path and username   B = FOREACH A GENERATE path, username;    -- Generate the sum of the number of paths for each user   C = FOREACH (GROUP B BY username) GENERATE group, COUNT(B.path);    -- Save results   STORE C INTO '$outputFile';

这个脚本可以用下面的命令运行:

bin/pig -x local -param inputFile=../foo -param outputFile=../results ../numFilesOfEachUser.pig

输出文件的内容与下面类似:

bart 1lisa 16homer 28marge 2456

Files That Have Never Been Accessed

这个脚本找出文件自创建后访问时间从没改变的文件,意味着它们从没被打开或者查看。

   
neverAccessed.pig:   -- This script generates a list of files that were created but never   -- accessed, based on their AccessTime    -- Load all of the fields from the file   A = LOAD '$inputFile' USING PigStorage('\t') AS (path:chararray,                                                    replication:int,                                                    modTime:chararray,                                                    accessTime:chararray,                                                    blockSize:long,                                                    numBlocks:int,                                                    fileSize:long,                                                    NamespaceQuota:int,                                                    DiskspaceQuota:int,                                                    perms:chararray,                                                    username:chararray,                                                    groupname:chararray);    -- Grab just the path and last time the file was accessed   B = FOREACH A GENERATE path, accessTime;    -- Drop all the paths that don't have the default assigned last-access time   C = FILTER B BY accessTime == '1969-12-31 16:00';    -- Drop the accessTimes, since they're all the same   D = FOREACH C GENERATE path;    -- Save results   STORE D INTO '$outputFile';

这个脚本用下面的命令运行,它的输出文件的内容将会是一个文件列表:

bin/pig -x local -param inputFile=../foo -param outputFile=../results ../neverAccessed.pig

Probable Duplicated Files Based on File Size

这个脚本根据文件的大小分组,丢掉所有小于100MB的文件,返回一个文件大小,文件数量和一个文件路径的元组。这可被用来找出文件系统命名空间可能的副本。

  
 probableDuplicates.pig:   -- This script finds probable duplicate files greater than 100 MB by   -- grouping together files based on their byte size. Files of this size   -- with exactly the same number of bytes can be considered probable   -- duplicates, but should be checked further, either by comparing the   -- contents directly or by another proxy, such as a hash of the contents.   -- The scripts output is of the type:   --    fileSize numProbableDuplicates {(probableDup1), (probableDup2)}    -- Load all of the fields from the file   A = LOAD '$inputFile' USING PigStorage('\t') AS (path:chararray,                                                    replication:int,                                                    modTime:chararray,                                                    accessTime:chararray,                                                    blockSize:long,                                                    numBlocks:int,                                                    fileSize:long,                                                    NamespaceQuota:int,                                                    DiskspaceQuota:int,                                                    perms:chararray,                                                    username:chararray,                                                    groupname:chararray);    -- Grab the pathname and filesize   B = FOREACH A generate path, fileSize;    -- Drop files smaller than 100 MB   C = FILTER B by fileSize > 100L  * 1024L * 1024L;    -- Gather all the files of the same byte size   D = GROUP C by fileSize;    -- Generate path, num of duplicates, list of duplicates   E = FOREACH D generate group AS fileSize, COUNT(C) as numDupes, C.path AS files;    -- Drop all the files where there are only one of them   F = FILTER E by numDupes > 1L;    -- Sort by the size of the files   G = ORDER F by fileSize;    -- Save results   STORE G INTO '$outputFile';

这个脚本可以用下面的命令运行:

bin/pig -x local -param inputFile=../foo -param outputFile=../results ../probableDuplicates.pig

输出文件的内容将会像下面这样:

1077288632 2 {(/user/tennant/work1/part-00501),(/user/tennant/work1/part-00993)}1077288664 4 {(/user/tennant/work0/part-00567),(/user/tennant/work0/part-03980),(/user/tennant/work1/part-00725),(/user/eccelston/output/part-03395)}1077288668 3 {(/user/tennant/work0/part-03705),(/user/tennant/work0/part-04242),(/user/tennant/work1/part-03839)}1077288698 2 {(/user/tennant/work0/part-00435),(/user/eccelston/output/part-01382)}1077288702 2 {(/user/tennant/work0/part-03864),(/user/eccelston/output/part-03234)}

每一行包括文件的大小,单位bytes,副本的个数,所有副本的路径的列表。小于100MB的文件被忽略了,提供一个合理的确切大小的文件可被复制的可能。

0 0