HdfsImageViewer.apt.vm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. ~~ Licensed under the Apache License, Version 2.0 (the "License");
  2. ~~ you may not use this file except in compliance with the License.
  3. ~~ You may obtain a copy of the License at
  4. ~~
  5. ~~ http://www.apache.org/licenses/LICENSE-2.0
  6. ~~
  7. ~~ Unless required by applicable law or agreed to in writing, software
  8. ~~ distributed under the License is distributed on an "AS IS" BASIS,
  9. ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. ~~ See the License for the specific language governing permissions and
  11. ~~ limitations under the License. See accompanying LICENSE file.
  12. ---
  13. Offline Image Viewer Guide
  14. ---
  15. ---
  16. ${maven.build.timestamp}
  17. Offline Image Viewer Guide
  18. %{toc|section=1|fromDepth=0}
  19. * Overview
  20. The Offline Image Viewer is a tool to dump the contents of hdfs fsimage
  21. files to human-readable formats in order to allow offline analysis and
  22. examination of an Hadoop cluster's namespace. The tool is able to
  23. process very large image files relatively quickly, converting them to
  24. one of several output formats. The tool handles the layout formats that
  25. were included with Hadoop versions 16 and up. If the tool is not able
  26. to process an image file, it will exit cleanly. The Offline Image
  27. Viewer does not require an Hadoop cluster to be running; it is entirely
  28. offline in its operation.
  29. The Offline Image Viewer provides several output processors:
  30. [[1]] Ls is the default output processor. It closely mimics the format of
  31. the lsr command. It includes the same fields, in the same order, as
  32. lsr : directory or file flag, permissions, replication, owner,
  33. group, file size, modification date, and full path. Unlike the lsr
  34. command, the root path is included. One important difference
  35. between the output of the lsr command this processor, is that this
  36. output is not sorted by directory name and contents. Rather, the
  37. files are listed in the order in which they are stored in the
  38. fsimage file. Therefore, it is not possible to directly compare the
  39. output of the lsr command this this tool. The Ls processor uses
  40. information contained within the Inode blocks to calculate file
  41. sizes and ignores the -skipBlocks option.
  42. [[2]] Indented provides a more complete view of the fsimage's contents,
  43. including all of the information included in the image, such as
  44. image version, generation stamp and inode- and block-specific
  45. listings. This processor uses indentation to organize the output
  46. into a hierarchal manner. The lsr format is suitable for easy human
  47. comprehension.
  48. [[3]] Delimited provides one file per line consisting of the path,
  49. replication, modification time, access time, block size, number of
  50. blocks, file size, namespace quota, diskspace quota, permissions,
  51. username and group name. If run against an fsimage that does not
  52. contain any of these fields, the field's column will be included,
  53. but no data recorded. The default record delimiter is a tab, but
  54. this may be changed via the -delimiter command line argument. This
  55. processor is designed to create output that is easily analyzed by
  56. other tools, such as {{{http://pig.apache.org}Apache Pig}}. See
  57. the {{Analyzing Results}} section for further information on using
  58. this processor to analyze the contents of fsimage files.
  59. [[4]] XML creates an XML document of the fsimage and includes all of the
  60. information within the fsimage, similar to the lsr processor. The
  61. output of this processor is amenable to automated processing and
  62. analysis with XML tools. Due to the verbosity of the XML syntax,
  63. this processor will also generate the largest amount of output.
  64. [[5]] FileDistribution is the tool for analyzing file sizes in the
  65. namespace image. In order to run the tool one should define a range
  66. of integers [0, maxSize] by specifying maxSize and a step. The
  67. range of integers is divided into segments of size step: [0, s[1],
  68. ..., s[n-1], maxSize], and the processor calculates how many files
  69. in the system fall into each segment [s[i-1], s[i]). Note that
  70. files larger than maxSize always fall into the very last segment.
  71. The output file is formatted as a tab separated two column table:
  72. Size and NumFiles. Where Size represents the start of the segment,
  73. and numFiles is the number of files form the image which size falls
  74. in this segment.
  75. * Usage
  76. ** Basic
  77. The simplest usage of the Offline Image Viewer is to provide just an
  78. input and output file, via the -i and -o command-line switches:
  79. ----
  80. bash$ bin/hdfs oiv -i fsimage -o fsimage.txt
  81. ----
  82. This will create a file named fsimage.txt in the current directory
  83. using the Ls output processor. For very large image files, this process
  84. may take several minutes.
  85. One can specify which output processor via the command-line switch -p.
  86. For instance:
  87. ----
  88. bash$ bin/hdfs oiv -i fsimage -o fsimage.xml -p XML
  89. ----
  90. or
  91. ----
  92. bash$ bin/hdfs oiv -i fsimage -o fsimage.txt -p Indented
  93. ----
  94. This will run the tool using either the XML or Indented output
  95. processor, respectively.
  96. One command-line option worth considering is -skipBlocks, which
  97. prevents the tool from explicitly enumerating all of the blocks that
  98. make up a file in the namespace. This is useful for file systems that
  99. have very large files. Enabling this option can significantly decrease
  100. the size of the resulting output, as individual blocks are not
  101. included. Note, however, that the Ls processor needs to enumerate the
  102. blocks and so overrides this option.
  103. Example
  104. Consider the following contrived namespace:
  105. ----
  106. drwxr-xr-x - theuser supergroup 0 2009-03-16 21:17 /anotherDir
  107. -rw-r--r-- 3 theuser supergroup 286631664 2009-03-16 21:15 /anotherDir/biggerfile
  108. -rw-r--r-- 3 theuser supergroup 8754 2009-03-16 21:17 /anotherDir/smallFile
  109. drwxr-xr-x - theuser supergroup 0 2009-03-16 21:11 /mapredsystem
  110. drwxr-xr-x - theuser supergroup 0 2009-03-16 21:11 /mapredsystem/theuser
  111. drwxr-xr-x - theuser supergroup 0 2009-03-16 21:11 /mapredsystem/theuser/mapredsystem
  112. drwx-wx-wx - theuser supergroup 0 2009-03-16 21:11 /mapredsystem/theuser/mapredsystem/ip.redacted.com
  113. drwxr-xr-x - theuser supergroup 0 2009-03-16 21:12 /one
  114. drwxr-xr-x - theuser supergroup 0 2009-03-16 21:12 /one/two
  115. drwxr-xr-x - theuser supergroup 0 2009-03-16 21:16 /user
  116. drwxr-xr-x - theuser supergroup 0 2009-03-16 21:19 /user/theuser
  117. ----
  118. Applying the Offline Image Processor against this file with default
  119. options would result in the following output:
  120. ----
  121. machine:hadoop-0.21.0-dev theuser$ bin/hdfs oiv -i fsimagedemo -o fsimage.txt
  122. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:16 /
  123. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:17 /anotherDir
  124. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:11 /mapredsystem
  125. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:12 /one
  126. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:16 /user
  127. -rw-r--r-- 3 theuser supergroup 286631664 2009-03-16 14:15 /anotherDir/biggerfile
  128. -rw-r--r-- 3 theuser supergroup 8754 2009-03-16 14:17 /anotherDir/smallFile
  129. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:11 /mapredsystem/theuser
  130. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:11 /mapredsystem/theuser/mapredsystem
  131. drwx-wx-wx - theuser supergroup 0 2009-03-16 14:11 /mapredsystem/theuser/mapredsystem/ip.redacted.com
  132. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:12 /one/two
  133. drwxr-xr-x - theuser supergroup 0 2009-03-16 14:19 /user/theuser
  134. ----
  135. Similarly, applying the Indented processor would generate output that
  136. begins with:
  137. ----
  138. machine:hadoop-0.21.0-dev theuser$ bin/hdfs oiv -i fsimagedemo -p Indented -o fsimage.txt
  139. FSImage
  140. ImageVersion = -19
  141. NamespaceID = 2109123098
  142. GenerationStamp = 1003
  143. INodes [NumInodes = 12]
  144. Inode
  145. INodePath =
  146. Replication = 0
  147. ModificationTime = 2009-03-16 14:16
  148. AccessTime = 1969-12-31 16:00
  149. BlockSize = 0
  150. Blocks [NumBlocks = -1]
  151. NSQuota = 2147483647
  152. DSQuota = -1
  153. Permissions
  154. Username = theuser
  155. GroupName = supergroup
  156. PermString = rwxr-xr-x
  157. ...remaining output omitted...
  158. ----
  159. * Options
  160. *-----------------------:-----------------------------------+
  161. | <<Flag>> | <<Description>> |
  162. *-----------------------:-----------------------------------+
  163. | <<<-i>>>\|<<<--inputFile>>> <input file> | Specify the input fsimage file to
  164. | | process. Required.
  165. *-----------------------:-----------------------------------+
  166. | <<<-o>>>\|<<<--outputFile>>> <output file> | Specify the output filename, if the
  167. | | specified output processor generates one. If the specified file already
  168. | | exists, it is silently overwritten. Required.
  169. *-----------------------:-----------------------------------+
  170. | <<<-p>>>\|<<<--processor>>> <processor> | Specify the image processor to apply
  171. | | against the image file. Currently valid options are Ls (default), XML
  172. | | and Indented..
  173. *-----------------------:-----------------------------------+
  174. | <<<-skipBlocks>>> | Do not enumerate individual blocks within files. This may
  175. | | save processing time and outfile file space on namespaces with very
  176. | | large files. The Ls processor reads the blocks to correctly determine
  177. | | file sizes and ignores this option.
  178. *-----------------------:-----------------------------------+
  179. | <<<-printToScreen>>> | Pipe output of processor to console as well as specified
  180. | | file. On extremely large namespaces, this may increase processing time
  181. | | by an order of magnitude.
  182. *-----------------------:-----------------------------------+
  183. | <<<-delimiter>>> <arg>| When used in conjunction with the Delimited processor,
  184. | | replaces the default tab delimiter with the string specified by arg.
  185. *-----------------------:-----------------------------------+
  186. | <<<-h>>>\|<<<--help>>>| Display the tool usage and help information and exit.
  187. *-----------------------:-----------------------------------+
  188. * Analyzing Results
  189. The Offline Image Viewer makes it easy to gather large amounts of data
  190. about the hdfs namespace. This information can then be used to explore
  191. file system usage patterns or find specific files that match arbitrary
  192. criteria, along with other types of namespace analysis. The Delimited
  193. image processor in particular creates output that is amenable to
  194. further processing by tools such as [38]Apache Pig. Pig provides a
  195. particularly good choice for analyzing these data as it is able to deal
  196. with the output generated from a small fsimage but also scales up to
  197. consume data from extremely large file systems.
  198. The Delimited image processor generates lines of text separated, by
  199. default, by tabs and includes all of the fields that are common between
  200. constructed files and files that were still under constructed when the
  201. fsimage was generated. Examples scripts are provided demonstrating how
  202. to use this output to accomplish three tasks: determine the number of
  203. files each user has created on the file system, find files were created
  204. but have not accessed, and find probable duplicates of large files by
  205. comparing the size of each file.
  206. Each of the following scripts assumes you have generated an output file
  207. using the Delimited processor named foo and will be storing the results
  208. of the Pig analysis in a file named results.
  209. ** Total Number of Files for Each User
  210. This script processes each path within the namespace, groups them by
  211. the file owner and determines the total number of files each user owns.
  212. ----
  213. numFilesOfEachUser.pig:
  214. -- This script determines the total number of files each user has in
  215. -- the namespace. Its output is of the form:
  216. -- username, totalNumFiles
  217. -- Load all of the fields from the file
  218. A = LOAD '$inputFile' USING PigStorage('\t') AS (path:chararray,
  219. replication:int,
  220. modTime:chararray,
  221. accessTime:chararray,
  222. blockSize:long,
  223. numBlocks:int,
  224. fileSize:long,
  225. NamespaceQuota:int,
  226. DiskspaceQuota:int,
  227. perms:chararray,
  228. username:chararray,
  229. groupname:chararray);
  230. -- Grab just the path and username
  231. B = FOREACH A GENERATE path, username;
  232. -- Generate the sum of the number of paths for each user
  233. C = FOREACH (GROUP B BY username) GENERATE group, COUNT(B.path);
  234. -- Save results
  235. STORE C INTO '$outputFile';
  236. ----
  237. This script can be run against pig with the following command:
  238. ----
  239. bin/pig -x local -param inputFile=../foo -param outputFile=../results ../numFilesOfEachUser.pig
  240. ----
  241. The output file's content will be similar to that below:
  242. ----
  243. bart 1
  244. lisa 16
  245. homer 28
  246. marge 2456
  247. ----
  248. ** Files That Have Never Been Accessed
  249. This script finds files that were created but whose access times were
  250. never changed, meaning they were never opened or viewed.
  251. ----
  252. neverAccessed.pig:
  253. -- This script generates a list of files that were created but never
  254. -- accessed, based on their AccessTime
  255. -- Load all of the fields from the file
  256. A = LOAD '$inputFile' USING PigStorage('\t') AS (path:chararray,
  257. replication:int,
  258. modTime:chararray,
  259. accessTime:chararray,
  260. blockSize:long,
  261. numBlocks:int,
  262. fileSize:long,
  263. NamespaceQuota:int,
  264. DiskspaceQuota:int,
  265. perms:chararray,
  266. username:chararray,
  267. groupname:chararray);
  268. -- Grab just the path and last time the file was accessed
  269. B = FOREACH A GENERATE path, accessTime;
  270. -- Drop all the paths that don't have the default assigned last-access time
  271. C = FILTER B BY accessTime == '1969-12-31 16:00';
  272. -- Drop the accessTimes, since they're all the same
  273. D = FOREACH C GENERATE path;
  274. -- Save results
  275. STORE D INTO '$outputFile';
  276. ----
  277. This script can be run against pig with the following command and its
  278. output file's content will be a list of files that were created but
  279. never viewed afterwards.
  280. ----
  281. bin/pig -x local -param inputFile=../foo -param outputFile=../results ../neverAccessed.pig
  282. ----
  283. ** Probable Duplicated Files Based on File Size
  284. This script groups files together based on their size, drops any that
  285. are of less than 100mb and returns a list of the file size, number of
  286. files found and a tuple of the file paths. This can be used to find
  287. likely duplicates within the filesystem namespace.
  288. ----
  289. probableDuplicates.pig:
  290. -- This script finds probable duplicate files greater than 100 MB by
  291. -- grouping together files based on their byte size. Files of this size
  292. -- with exactly the same number of bytes can be considered probable
  293. -- duplicates, but should be checked further, either by comparing the
  294. -- contents directly or by another proxy, such as a hash of the contents.
  295. -- The scripts output is of the type:
  296. -- fileSize numProbableDuplicates {(probableDup1), (probableDup2)}
  297. -- Load all of the fields from the file
  298. A = LOAD '$inputFile' USING PigStorage('\t') AS (path:chararray,
  299. replication:int,
  300. modTime:chararray,
  301. accessTime:chararray,
  302. blockSize:long,
  303. numBlocks:int,
  304. fileSize:long,
  305. NamespaceQuota:int,
  306. DiskspaceQuota:int,
  307. perms:chararray,
  308. username:chararray,
  309. groupname:chararray);
  310. -- Grab the pathname and filesize
  311. B = FOREACH A generate path, fileSize;
  312. -- Drop files smaller than 100 MB
  313. C = FILTER B by fileSize > 100L * 1024L * 1024L;
  314. -- Gather all the files of the same byte size
  315. D = GROUP C by fileSize;
  316. -- Generate path, num of duplicates, list of duplicates
  317. E = FOREACH D generate group AS fileSize, COUNT(C) as numDupes, C.path AS files;
  318. -- Drop all the files where there are only one of them
  319. F = FILTER E by numDupes > 1L;
  320. -- Sort by the size of the files
  321. G = ORDER F by fileSize;
  322. -- Save results
  323. STORE G INTO '$outputFile';
  324. ----
  325. This script can be run against pig with the following command:
  326. ----
  327. bin/pig -x local -param inputFile=../foo -param outputFile=../results ../probableDuplicates.pig
  328. ----
  329. The output file's content will be similar to that below:
  330. ----
  331. 1077288632 2 {(/user/tennant/work1/part-00501),(/user/tennant/work1/part-00993)}
  332. 1077288664 4 {(/user/tennant/work0/part-00567),(/user/tennant/work0/part-03980),(/user/tennant/work1/part-00725),(/user/eccelston/output/part-03395)}
  333. 1077288668 3 {(/user/tennant/work0/part-03705),(/user/tennant/work0/part-04242),(/user/tennant/work1/part-03839)}
  334. 1077288698 2 {(/user/tennant/work0/part-00435),(/user/eccelston/output/part-01382)}
  335. 1077288702 2 {(/user/tennant/work0/part-03864),(/user/eccelston/output/part-03234)}
  336. ----
  337. Each line includes the file size in bytes that was found to be
  338. duplicated, the number of duplicates found, and a list of the
  339. duplicated paths. Files less than 100MB are ignored, providing a
  340. reasonable likelihood that files of these exact sizes may be
  341. duplicates.