let's analyze fsdirectory. In fact, the best place to analyze fsdirectory, should be introduced after inode*, fsdirectory in the Inode* Foundation
, the file directory status of HDFs is saved. When the system loads Fsimage, Fsimage rebuilds the file directory status on the Fsdirectory object, the HDFS file directory
the change of state is also written by Fsdirectory, and at the same time, it preserves the mapping of file name data blocks.
Fsdirectory has only a few member variables, as follows:
finfinal Fsnamesystem Namesystem;
final Inodedirectorywithquota RootDir;
Fsima ge Fsimage;
Boolean ready = false;
where Namesystem,fsimage is a reference to the Fsnamesystem object and Fsimage object, RootDir is the root of the filesystem, and the ready initial value is False,
when the system loads Fsimage successfully, ready becomes the True,fsdirectory user to invoke other fsdirectory functions.
The rest of the fsdirectory is a bunch of methods (we don't discuss the classes, methods, and procedures associated with Mbean).
loadfsimage is used to load the directory tree structure, it will call the Fsimage method, after the persistence of the import of information, it will set the member variable ready to true.
system Call Loadfsimage is the Initialize method in Fsnamesystem.java, which is an important step in system initialization.
AddFile is used to create a file or append data when creating Inodefileunderconstruction, which is its call hierachy graph:
AddFile first attempts to create a path to the file in the system, and if the file is/home/hadoop/hadoop.tar,addfile it calls Mkdirs (creating a path of
/home/hadoop, this will also involve a series of methods), ensure that the file path exists, and then create the Inodefileunderconstruction node, and add the node
to the directory tree (through AddNode, it is also necessary to call a series of methods), if successful, write the operation log (Logopenfile).
Unprotectedaddfile is also used to create a directory or file (not a underconstruction) in the system, and if it is a file, it also establishes a corresponding block.
There are several unprotected* methods in fsdirectory that do not check member variables ready, do not write logs, and they are used extensively in loadfsedits (this
when ready is, of course, false, and because the log is being restored, there is no need to write the log.
Addtoparent adds an inode to the directory tree and returns its top-level directory, and its implementation is similar to Unprotectedaddfile.
Persistblocks is more interesting, used in the past to record the block information of an inode, in fact, there is no corresponding to the persistblocks of the writing log method,
it uses the logopenfile. You can check the information of the Logopenfile record. The closefile corresponds to the logclosefile.
Addblock and Removeblock correspond to add/remove block information, and they also need to update the corresponding information in the Fsnamesystem.java.
Unprotectedrenameto and Renameto implement the UNIX MV command, the main functions are done in the Unprotectedrenameto, the complicated place lies in the
discussion of various situations.
setreplication and unprotectedsetreplication are used to update the number of copies of a block of data, a very simple method, note that changing the resulting deletion of a block of data
/replication is implemented in Fsnamesystem.java.
both Setpermission,unprotectedsetpermission,setowner and Unprotectedsetowner are simple methods.
Delete and Unprotecteddelete are a couple of ways to delete data blocks that will be removed by Fsnamesystem removepathandblocks if necessary.
...... (The following methods are similar to those described earlier, and are some procedural things that are no longer discussed.)
For more highlights, please follow: http://bbs.superwu.cn
Focus on the two-dimensional code of Superman Academy:
Follow the Superman college Java Free Learning Exchange Group:
Hadoop Source Code Analysis (two or three) fsdirectory