Hadoop学习二十四:Hadoop-Hdfs FSEditLog 源码
一. FSEditLog类图
二. FSEditLog
- FSEditLog提供了对editlog文件的操作方法。简单的类,方法一个个看。
- editStreams保存着一个fsimage下所有的editlog文件对应的输出流EditLogOutputStream。
三. FSEditLog方法
- void open():Create empty edit log files.Initialize the output stream for logging.当open方法被都调用时,会把fsimage下所有的editlog文件流加到editStreams中。
public synchronized void open() throws IOException { Iterator<StorageDirectory> it = fsimage.dirIterator(NameNodeDirType.EDITS); while (it.hasNext()) { StorageDirectory sd = it.next(); File eFile = getEditFile(sd); EditLogOutputStream eStream = new EditLogFileOutputStream(eFile); editStreams.add(eStream); }
- int loadFSEdits(EditLogInputStream edits,MetaRecoveryContext recovery):Load an edit log, and apply the changes to the in-memory structure.加载硬盘上的editlog,应用到内存文件树中。从硬盘中读取editlog后,根据每个opcode来构建文件树。
- void logEdit(byte op, Writable ... writables):从editStreams里取出所有输出流,写editlog到硬盘。
- log*(...):对应每个操作日志。
- void rollEditLog():Closes the current edit log and opens edits.new. 对应着http://zy19982004.iteye.com/admin/blogs/1870624三.2
- void purgeEditLog():Removes the old edit log and renamed edits.new as edits. Reopens the edits file. 对应着http://zy19982004.iteye.com/admin/blogs/1870624三.6的Roll edit.new
四. log*记录哪些信息
- logOpenFile(OP_ADD):申请lease path(路径)/replication(副本数,文本形式)/modificationTime(修改时间,文本形式)/accessTime(访问时间,文本形式)/preferredBlockSize(块大小,文本形式)/BlockInfo[](增强的数据块信息,数组)/permissionStatus(访问控制信息)/clientName(客户名)/clientMachine(客户机器名)
- logCloseFile(OP_CLOSE):归还lease path/replication/modificationTime/accessTime/preferredBlockSize/BlockInfo[]/permissionStatus
- logMkDir(OP_MKDIR):创建目录 path/modificationTime/accessTime/permissionStatus
- logRename(OP_RENAME):改文件名 src(原文件名)/dst(新文件名)/timestamp(时间戳)
- logSetReplication(OP_SET_REPLICATION):更改副本数 src/replication
- logSetQuota(OP_SET_QUOTA):设置空间额度 path/nsQuota(文件空间额度)/dsQuota(磁盘空间额度)
- logSetPermissions(OP_SET_PERMISSIONS):设置文件权限位 src/permissionStatus
- logSetOwner(OP_SET_OWNER):设置文件组和主 src/username(所有者)/groupname(所在组)
- logDelete(OP_DELETE):删除文件 src/timestamp
- logGenerationStamp(OP_SET_GENSTAMP):文件版本*** genstamp(***)
- logTimes(OP_TIMES):更改文件更新/访问时间 src/modificationTime/accessTime