理解FSImage,首先需要理解INode。
下面是Hadoop2.6.0下的INode类图。
INode的源码如下
public abstract class
INode
implements
INodeAttributes
,
Diff.Element<
byte
[]>
,
AuthorizationProvider.INodeAuthorizationInfo {
private INode
parent
= null;
final boolean
isRoot
() {
return getLocalNameBytes().
length
==
0
;
}
/**
* Information used for updating the blocksMap when deleting files.
*/
public static class
BlocksMapUpdateInfo {
/**
* The list of blocks that need to be removed from blocksMap
*/
private final
List<Block>
toDeleteList
;
...
}
/**
* INode feature such as {
@link
FileUnderConstructionFeature}
* and {
@link
DirectoryWithQuotaFeature}.
*/
public interface
Feature {
}
}
属性就一个
parent,
它的作用是在快照当中进行版本判断。其余都是与
INode
权限相关方法。最终要的是有一个内部类
BlocksMapUpdateInfo
用来在删除文件的时候更新
blockMap
。还有一个
Feature
接口,这个
Feature
有多个具体实现如下:
可以看出来Feature具体类是用来表现
INode
的特性的,
AclFeature
是用来表示ACL的
DirectoryWithQuotaFeature
是用来记录配额信息的,
FileUnderConstructionFeature
使用来记录在读取文件的信息的,
XAttrFeature
是用来保存额外信息的,下面三个都是和快照实现相关的特性类。
我们可以看到
Feature
是作为
INodeWithAdditionalFields
的具体属性的,这个类做为一个抽象类,在INode基础上增加了作为文件、目录或者软连接所必要的几个信息,具体为
final private long
id
;
private byte
[]
name
=
null;
private long
permission
=
0L
;
private long
modificationTime
=
0L
;
private long
accessTime
=
0L
;
protected
Feature[]
features
=
EMPTY_FEATURE
;
其中大部分属性看名字就知道作用,唯独
permission
具体说明下:
首先看下
INodeWithAdditionalFields
的源码
static enum
PermissionStatusFormat {
MODE
(
null,
16
)
,
GROUP
(
MODE
.
BITS
,
25
)
,
USER
(
GROUP
.
BITS
,
23
)
;
final
LongBitFormat
BITS
;
static
String
getUser
(
long
permission) {
final int
n = (
int
)
USER
.
BITS
.retrieve(permission)
;
return
SerialNumberManager.
INSTANCE
.getUser(n)
;
}
...
}
已及相关类
LongBitFormat
的源码:
public class
LongBitFormat
implements
Serializable {
private static final long
serialVersionUID
=
1L
;
private final
String
NAME
;
/** Bit offset */
private final int
OFFSET
;
/** Bit length */
private final int
LENGTH
;
/** Minimum value */
private final long
MIN
;
/** Maximum value */