<p>The Offline Image Viewer is a tool to dump the contents of hdfs fsimage files to a human-readable format and provide read-only WebHDFS API in order to allow offline analysis and examination of an Hadoop cluster’s namespace. The tool is able to process very large image files relatively quickly. The tool handles the layout formats that were included with Hadoop versions 2.4 and up. If you want to handle older layout formats, you can use the Offline Image Viewer of Hadoop 2.3 or <ahref="#oiv_legacy_Command">oiv_legacy Command</a>. If the tool is not able to process an image file, it will exit cleanly. The Offline Image Viewer does not require a Hadoop cluster to be running; it is entirely offline in its operation.</p>
<p>The Offline Image Viewer provides several output processors:</p>
<olstyle="list-style-type: decimal">
<li>
<p>Web is the default output processor. It launches a HTTP server that exposes read-only WebHDFS API. Users can investigate the namespace interactively by using HTTP REST API. It does not support secure mode, nor HTTPS.</p>
</li>
<li>
<p>XML creates an XML document of the fsimage and includes all of the information within the fsimage. The output of this processor is amenable to automated processing and analysis with XML tools. Due to the verbosity of the XML syntax, this processor will also generate the largest amount of output.</p>
</li>
<li>
<p>FileDistribution is the tool for analyzing file sizes in the namespace image. In order to run the tool one should define a range of integers [0, maxSize] by specifying maxSize and a step. The range of integers is divided into segments of size step: [0, s[1], …, s[n-1], maxSize], and the processor calculates how many files in the system fall into each segment [s[i-1], s[i]). Note that files larger than maxSize always fall into the very last segment. By default, the output file is formatted as a tab separated two column table: Size and NumFiles. Where Size represents the start of the segment, and numFiles is the number of files form the image which size falls in this segment. By specifying the option -format, the output file will be formatted in a human-readable fashion rather than a number of bytes that showed in Size column. In addition, the Size column will be changed to the Size Range column.</p>
</li>
<li>
<p>Delimited (experimental): Generate a text file with all of the elements common to both inodes and inodes-under-construction, separated by a delimiter. The default delimiter is \t, though this may be changed via the -delimiter argument.</p>
</li>
<li>
<p>DetectCorruption (experimental): Detect potential corruption of the image by selectively loading parts of it and actively searching for inconsistencies. Outputs a summary of the found corruptions in a delimited format. Note that the check is not exhaustive, and only catches missing nodes during the namespace reconstruction.</p>
</li>
<li>
<p>ReverseXML (experimental): This is the opposite of the XML processor; it reconstructs an fsimage from an XML file. This processor makes it easy to create fsimages for testing, and manually edit fsimages when there is corruption.</p>
</li>
</ol></section><section>
<h2><aname="Usage"></a>Usage</h2><section>
<h3><aname="Web_Processor"></a>Web Processor</h3>
<p>Web processor launches a HTTP server which exposes read-only WebHDFS API. Users can specify the address to listen by -addr option (default by localhost:5978).</p>
<divclass="source">
<divclass="source">
<pre> bash$ bin/hdfs oiv -i fsimage
14/04/07 13:25:14 INFO offlineImageViewer.WebImageViewer: WebImageViewer
started. Listening on /127.0.0.1:5978. Press Ctrl+C to stop the viewer.
</pre></div></div>
<p>Users can access the viewer and get the information of the fsimage by the following shell command:</p>
<p>XML Processor is used to dump all the contents in the fsimage. Users can specify input and output file via -i and -o command-line.</p>
<divclass="source">
<divclass="source">
<pre> bash$ bin/hdfs oiv -p XML -i fsimage -o fsimage.xml
</pre></div></div>
<p>This will create a file named fsimage.xml contains all the information in the fsimage. For very large image files, this process may take several minutes.</p>
<p>Applying the Offline Image Viewer with XML processor would result in the following output:</p>
<p>FileDistribution processor can analyze file sizes in the namespace image. Users can specify maxSize (128GB by default) and step (2MB by default) in bytes via -maxSize and -step command-line.</p>
<p>The processor will calculate how many files in the system fall into each segment. The output file is formatted as a tab separated two column table showed as the following output:</p>
<divclass="source">
<divclass="source">
<pre> Size NumFiles
4 1
12 1
16 1
20 1
totalFiles = 4
totalDirectories = 2
totalBlocks = 4
totalSpace = 48
maxFileSize = 21
</pre></div></div>
<p>To make the output result look more readable, users can specify -format option in addition.</p>
<p>Delimited processor generates a text representation of the fsimage, with each element separated by a delimiter string (\t by default). Users can specify a new delimiter string by -delimiter option.</p>
<p>If not set, Delimited processor will construct the namespace in memory before outputting text. The output result of this processor should be like the following output:</p>
<p>DetectCorruption processor generates a text representation of the errors of the fsimage, if there’s any. It displays the following cases:</p>
<olstyle="list-style-type: decimal">
<li>
<p>an inode is mentioned in the fsimage but no associated metadata is found (CorruptNode)</p>
</li>
<li>
<p>an inode has at least one corrupt children (MissingChildren)</p>
</li>
</ol>
<p>The delimiter string can be provided with the -delimiter option, and the processor can cache intermediate result using the -t option.</p>
<p>The column CorruptionType can be MissingChild, CorruptNode or the combination of these two. IsSnapshot shows whether the node is kept in a snapshot or not. To the NodeType column either Node, Ref or Unknown can be written depending whether the node is an inode, a reference, or is corrupted and thus unknown. CorruptChildren contains the number of the corrupt children the inode may have.</p></section></section><section>
<tdalign="left"> Specify the output filename, if the specified output processor generates one. If the specified file already exists, it is silently overwritten. (output to stdout by default) If the input file is an XML file, it also creates an <outputFile>.md5. </td></tr>
<tdalign="left"> Specify the image processor to apply against the image file. Currently valid options are <code>Web</code> (default), <code>XML</code>, <code>Delimited</code>, <code>DetectCorruption</code>, <code>FileDistribution</code> and <code>ReverseXML</code>. </td></tr>
<tdalign="left"> Specify the range [0, maxSize] of file sizes to be analyzed in bytes (128GB by default). This option is used with FileDistribution processor. </td></tr>
<tdalign="left"> Specify the granularity of the distribution in bytes (2MB by default). This option is used with FileDistribution processor. </td></tr>
<trclass="b">
<tdalign="left"><code>-format</code></td>
<tdalign="left"> Format the output result in a human-readable fashion rather than a number of bytes. (false by default). This option is used with FileDistribution processor. </td></tr>
<tdalign="left"> Use temporary dir to cache intermediate result to generate Delimited outputs. If not set, Delimited processor constructs the namespace in memory before outputting text. </td></tr>
<p>The Offline Image Viewer makes it easy to gather large amounts of data about the hdfs namespace. This information can then be used to explore file system usage patterns or find specific files that match arbitrary criteria, along with other types of namespace analysis.</p></section><section>
<p>Due to the internal layout changes introduced by the ProtocolBuffer-based fsimage (<aclass="externalLink"href="https://issues.apache.org/jira/browse/HDFS-5698">HDFS-5698</a>), OfflineImageViewer consumes excessive amount of memory and loses some functions such as Indented processor. If you want to process without large amount of memory or use these processors, you can use <code>oiv_legacy</code> command (same as <code>oiv</code> in Hadoop 2.3).</p><section>
<h3><aname="Usage"></a>Usage</h3>
<olstyle="list-style-type: decimal">
<li>
<p>Set <code>dfs.namenode.legacy-oiv-image.dir</code> to an appropriate directory to make standby NameNode or SecondaryNameNode save its namespace in the old fsimage format during checkpointing.</p>
</li>
<li>
<p>Use <code>oiv_legacy</code> command to the old format fsimage.</p>
<tdalign="left"> Specify the output filename, if the specified output processor generates one. If the specified file already exists, it is silently overwritten. Required. </td></tr>
<tdalign="left"> Specify the image processor to apply against the image file. Valid options are Ls (default), XML, Delimited, Indented, FileDistribution and NameDistribution. </td></tr>
<tdalign="left"> Specify the range [0, maxSize] of file sizes to be analyzed in bytes (128GB by default). This option is used with FileDistribution processor. </td></tr>
<tdalign="left"> Specify the granularity of the distribution in bytes (2MB by default). This option is used with FileDistribution processor. </td></tr>
<trclass="a">
<tdalign="left"><code>-format</code></td>
<tdalign="left"> Format the output result in a human-readable fashion rather than a number of bytes. (false by default). This option is used with FileDistribution processor. </td></tr>
<trclass="b">
<tdalign="left"><code>-skipBlocks</code></td>
<tdalign="left"> 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. </td></tr>
<trclass="a">
<tdalign="left"><code>-printToScreen</code></td>
<tdalign="left"> 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. </td></tr>
<tdalign="left"> When used in conjunction with the Delimited processor, replaces the default tab delimiter with the string specified by <i>arg</i>. </td></tr>