private static boolean format(Configuration conf,
boolean isConfirmationNeeded
) throws IOException {
boolean allowFormat = conf.getBoolean("dfs.namenode.support.allowformat", // 获取format配置文件,
true);
if (!allowFormat) {
throw new IOException("The option dfs.namenode.support.allowformat is "
+ "set to false for this filesystem, so it "
+ "cannot be formatted. You will need to set "
+ "dfs.namenode.support.allowformat parameter "
+ "to true in order to format this filesystem");
} }

为了防止生产集群误操作hadoop被format,可加入一下配置,

<property>
  <name>dfs.namenode.support.allowformat</name>
  <value>flase</value>
  <description>Does HDFS namenode allow itself to be formatted?
               You should consider setting this to false for any production
               cluster, to avoid any possibility of formatting a running DFS.
  </description>
</property>

Collection<File> dirsToFormat = FSNamesystem.getNamespaceDirs(conf); //获取namenode元数据目录, FSNamesystem.java  395行
 Collection<File> editDirsToFormat =
FSNamesystem.getNamespaceEditsDirs(conf); // 获取editlog目录, FSNamesystem.java 406行

 public static Collection<File> getNamespaceDirs(Configuration conf) {
Collection<String> dirNames = conf.getStringCollection("dfs.name.dir");
if (dirNames.isEmpty())
dirNames.add("/tmp/hadoop/dfs/name"); //如果不配置目录,将使用默认目录:/tmp/hadoop/dfs/name
Collection<File> dirs = new ArrayList<File>(dirNames.size());
for(String name : dirNames) {
dirs.add(new File(name)); //新建目录的意思
}
return dirs; //最后将目录返回
}
Collection 网上看好像是接口的意思,记得以前学的时候implements是接口的意思,这个问题,有待深入,哈哈
  for(Iterator<File> it = dirsToFormat.iterator(); it.hasNext();) {   //这里是个for 循环,说明元数据目录可配置多个,直到所有目录
File curDir = it.next();
if (!curDir.exists())
continue;
if (isConfirmationNeeded) {
System.err.print("Re-format filesystem in " + curDir +" ? (Y or N) "); //如果已经被format过,将提示是否re-format
if (!(System.in.read() == 'Y')) {
System.err.println("Format aborted in "+ curDir);
return true;
}
while(System.in.read() != '\n'); // discard the enter-key 直接回车不输入的话,应该是不格式化,
 FSNamesystem nsys = new FSNamesystem(new FSImage(dirsToFormat,
editDirsToFormat), conf); //先实例化FSNamesystem,传入namenode和editlog两个目录
nsys.dir.fsImage.format(); //执行format
return false;
}

//开始看format的过程:

  FSNamesystem(FSImage fsImage, Configuration conf) throws IOException {
this.fsLock = new ReentrantReadWriteLock();
setConfigurationParameters(conf); // setConfigurationParameters FSNamesystem.java 466行
this.dir = new FSDirectory(fsImage, this, conf);
}
private void setConfigurationParameters(Configuration conf)
throws IOException {
fsNamesystemObject = this; if (conf.getBoolean("hadoop.disable.shell",false)){
conf.setStrings(UnixUserGroupInformation.UGI_PROPERTY_NAME, new String[]{"hadoop", "hadoop"});
Shell.setDisabled(true);
} try {
fsOwner = UnixUserGroupInformation.login(conf);
} catch (LoginException e) {
throw new IOException(StringUtils.stringifyException(e));
} LOG.info("fsOwner=" + fsOwner);
         // 用户和目录权限
this.hasRwLock = conf.getBoolean("dfs.rwlock", false);
this.supergroup = conf.get("dfs.permissions.supergroup", "supergroup");
this.isPermissionEnabled = conf.getBoolean("dfs.permissions", true);
this.persistBlocks = conf.getBoolean("dfs.persist.blocks", false);
LOG.info("supergroup=" + supergroup);
LOG.info("isPermissionEnabled=" + isPermissionEnabled);
short filePermission = (short)conf.getInt("dfs.upgrade.permission", 0777);
this.defaultPermission = PermissionStatus.createImmutable(
fsOwner.getUserName(), supergroup, new FsPermission(filePermission)); this.maxCorruptFilesReturned = conf.getInt("dfs.corruptfilesreturned.max",
DEFAULT_MAX_CORRUPT_FILES_RETURNED);
this.defaultReplication = conf.getInt("dfs.replication", 3);
this.maxReplication = conf.getInt("dfs.replication.max", 512);
this.minReplication = conf.getInt("dfs.replication.min", 1);
if (minReplication <= 0) // 获取备份数,最大512个,最小1个,小于1 报异常
throw new IOException(
"Unexpected configuration parameters: dfs.replication.min = "
+ minReplication
+ " must be greater than 0");
if (maxReplication >= (int)Short.MAX_VALUE)
throw new IOException(
"Unexpected configuration parameters: dfs.replication.max = "
+ maxReplication + " must be less than " + (Short.MAX_VALUE));
if (maxReplication < minReplication)
throw new IOException(
"Unexpected configuration parameters: dfs.replication.min = "
+ minReplication
+ " must be less than dfs.replication.max = "
+ maxReplication);
this.maxReplicationStreams = conf.getInt("dfs.max-repl-streams", 2);
long heartbeatInterval = conf.getLong("dfs.heartbeat.interval", 3) * 1000; // 心跳时间
this.heartbeatRecheckInterval = conf.getInt(
"heartbeat.recheck.interval", 5 * 60 * 1000); // 5 minutes // 5分钟check
this.heartbeatExpireInterval = 2 * heartbeatRecheckInterval +
10 * heartbeatInterval;                                  // 10分钟丢弃
this.replicationRecheckInterval =
conf.getInt("dfs.replication.interval", 3) * 1000L;
this.defaultBlockSize = conf.getLong("dfs.block.size", DEFAULT_BLOCK_SIZE);
this.maxFsObjects = conf.getLong("dfs.max.objects", 0);
this.blockInvalidateLimit = Math.max(this.blockInvalidateLimit,
20*(int)(heartbeatInterval/1000));
this.accessTimePrecision = conf.getLong("dfs.access.time.precision", 0);
this.supportAppends = conf.getBoolean("dfs.support.append", false); // set soft and hard lease period
long hardLeaseLimit = conf.getLong(FSConstants.DFS_HARD_LEASE_KEY,
FSConstants.LEASE_HARDLIMIT_PERIOD);
long softLeaseLimit = conf.getLong(FSConstants.DFS_SOFT_LEASE_KEY,
FSConstants.LEASE_SOFTLIMIT_PERIOD);
this.leaseManager.setLeasePeriod(
Math.min(hardLeaseLimit, softLeaseLimit), hardLeaseLimit);
}

默认快大小是64M

<property>
  <name>dfs.block.size</name>
  <value>67108864</value>
  <description>The default block size for new files.</description>
</property>

 FSDirectory(FSImage fsImage, FSNamesystem ns, Configuration conf) {
rootDir = new INodeDirectoryWithQuota(INodeDirectory.ROOT_NAME,
ns.createFsOwnerPermissions(new FsPermission((short)0755)),
Integer.MAX_VALUE, -1);
this.fsImage = fsImage;
namesystem = ns;
initialize(conf);
}

hadoop format过程的更多相关文章

  1. hadoop安装过程中出现的错误

    此次来记录一下我在安装Hadoop安装过程中出现的错误,安装过程参照慕课网林子雨教程进行安装,在尝试过程中出现的错误如下: 1.在安装Ubuntu时,新建虚拟电脑时,并没有在版本的输入框中有Ubunt ...

  2. hadoop 安装过程记录

    1)首先配置好了四个linux虚拟机 root pwd:z****l*3 关闭了防火墙 开通了 sshd服务 开通了 ftp服务 配置了 jdk 1.8 配置好了互信 (之前配置的过程忘了!--检查了 ...

  3. hadoop format 重新格式化

    前文:如果格式化完之后,使用jps命令发现进程都已经启动,但是使用web页面打不开hadoop的网页,可能原因就是防火墙没关或者是哪个配置过程配错了. 1.关闭防火墙 一般最好是关闭防火墙比较关闭. ...

  4. Hadoop安装过程

    1.安装JDK apt-get install openjdk-7-jdk 2.配置环境变量 vim /etc/profile 编辑: export JAVA_HOME=/usr/lib/jvm/ja ...

  5. hadoop: Shuffle过程详解 (转载)

    原文地址:http://langyu.iteye.com/blog/992916 另一篇博文:http://www.cnblogs.com/gwgyk/p/3997849.html Shuffle过程 ...

  6. Hadoop 安装过程中出现的问题

    1.hadoop-daemon.sh start namenode 启动失败 查看hadoop/logs 下面的日志 出现 2017-04-11 15:35:13,860 WARN org.apach ...

  7. Ubuntu Hadoop使用过程中的一些技巧1

    权限不足:打开有管理员权限的文件夹:sudo nautilus  输入密码即可进入最高权限的文件管理界面可以快速对文件进行修改删除操作 修改权限:chmod命令     chmod -R 777 文件 ...

  8. Hadoop - MapReduce 过程

    Hadoop - MapReduce 一.MapReduce设计理念 map--->映射 reduce--->归纳 mapreduce必须构建在hdfs之上的一种大数据离线计算框架 在线: ...

  9. windows + hadoop + eclipse 过程记录

    昨天在本机上搭建了伪分布式的hadoop,今天决定在eclipse中搭建hadoop的环境,毕竟磨刀不误砍柴工 安装的hadoop是2.7.5版本,要想使用eclipse写MapReduce需要一个  ...

随机推荐

  1. awk 工具简介NF-NR

    相较于 sed 常常作用于一整个行的处理, awk 则比较倾向于一行当中分成数个『字段』来处理. 因此,awk 相当的适合处理小型的数据数据处理呢!awk 通常运作的模式是这样的:[root@linu ...

  2. 6.6.2 自己主动泛型化(automatic generalization)

    6.6.2 自己主动泛型化(automatic generalization) 在这一章,我们已经实现了几个 F# 的高阶函数.也看到了在 F# 和 C# 中并排的实现.F# 实现的非常重要方面,是我 ...

  3. poj 2891 Strange Way to Express Integers(中国剩余定理)

    http://poj.org/problem?id=2891 题意:求解一个数x使得 x%8 = 7,x%11 = 9; 若x存在,输出最小整数解.否则输出-1: ps: 思路:这不是简单的中国剩余定 ...

  4. WCF技术剖析之十七:消息(Message)详解(上篇)

    原文:WCF技术剖析之十七:消息(Message)详解(上篇) [爱心链接:拯救一个25岁身患急性白血病的女孩[内有苏州电视台经济频道<天天山海经>为此录制的节目视频(苏州话)]]消息交换 ...

  5. Coin Toss

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=31329#problem/G 使用二维数组f[ i ] [ j  ] 表示前i 位中有j个 ...

  6. android 按字母搜索

    在看Oplayer的时候看见滑动字母来实现listView的内容搜索,所以就把里面的核心的函数扣除来做了一个demo,分为两部分一个是布局,另一个就是代码了,具体的如下: 布局: <?xml v ...

  7. C++断言assert

    assert宏是在标准库中提供的.它在库文件<cassert>中声明,它能够在程序中測试逻辑表达式,假设指定的逻辑表达式是false,assert()就会终止程序,并显示诊断消息.关闭断言 ...

  8. 跟着鬼哥学so改动,一,准备篇

    图/文 听鬼哥说故事 闲话少说,so的改动,重要性大家都知道,这里从头编写so文件,分析so文件,改动so文件,打算做一个系列的教程,当然,主要是看时间同意. android的sdk配置以及ndk环境 ...

  9. sql:oracle, CURSOR

    CursorsYou use a cursor to fetch rows returned by a query. You retrieve the rows into the cursor usi ...

  10. Java面试宝典2014版

    一. Java基础部分......................................................................................... ...