essFile
此类的实例支持对随机访问文件的读取和写入。随机访问文件的行为类似存储在文件系统中的一个大型 byte 数组。存在指向该隐含数组的光标或索引,称为文件指针;输入操作从文件指针开始读取字节,并随着对字节的读取而前移此文件指针。如果随机访问文件以读取/写入模式创建,则输出操作也可用;输出操作从文件指针开始写入字节,并随着对字节的写入而前移此文件指针。写入隐含数组的当前末尾之后的输出操作导致该数组扩展。该文件指针可以通过 getFilePointer 方法读取,并通过 seek 方法设置。
通常,如果此类中的所有读取例程在读取所需数量的字节之前已到达文件末尾,则抛出 EOFException(是一种 IOException)。如果由于某些原因无法读取任何字节,而不是在读取所需数量的字节之前已到达文件末尾,则抛出 IOException,而不是 EOFException。需要特别指出的是,如果流已被关闭,则可能抛出 IOException。
protected void writeCorruptedData(essFile file) throws IOException {
final String messageForPreUpgradeVersion =
"\nThis file is INTENTIONALLY CORRUPTED so that versions\n"
+ "of Hadoop prior to (which are patible\n"
+ "with this directory layout) will fail to start.\n";
(0);
();
(file, "");
(messageForPreUpgradeVersion);
().sync();
}
NameNode 目录结构
data
|
dfs
| |
name1 name2
| | | ...
current image
| | | |
fsimage fstime VERSION fsimage
NameNode 的格式化()
(Storage$StorageDirectory) line: 1431
() line: 1444
(Configuration, boolean) line: 1242
(Configuration) line: 186
格式步骤
a).data/dfs/name1/current删除, 并创建data/dfs/name1/current
b).创建镜像文件 data/dfs/name1/current/fsimage
保存文件树从根开始镜像。这是一个递归的过程,首先保存当前目录的所有子目录,然后子目录里面的子目录。
/**
* Save the contents of the FS image to the file.
*/
void saveFSImage(File newFile) throws IOException {
FSNamesystem fsNamesys = getFSNamesystem();
FSDirectory fsDir = ;
long startTime = ();
//
// Write out data
//
D
源代码分析 来自淘豆网www.taodocs.com转载请标明出处.