向现有集群添加新的namenode数据目录

q3aa0525  于 2021-06-03  发布在  Hadoop
关注(0)|答案(2)|浏览(308)

要将新的namenode数据目录(dfs.name.dir、dfs.namenode.name.dir)正确添加到现有的生产群集,我需要遵循什么过程?我已将新路径添加到hdfs-site.xml文件中的逗号分隔列表中,但当我尝试启动namenode时,出现以下错误:
目录/data/nfs/dfs/nn处于不一致的状态:存储目录不存在或不可访问。
在我的情况下,我有两个目录已经到位和工作(/data/1/dfs/nn,/data/2/dfs/nn)添加新目录时,无法启动namenode。当新路径被删除时,它就开始了。新目录的fstab如下所示:
备份服务器:/hadoop\u nn/data/nfs/dfs nfs tcp,soft,intr,timeo=10,retrans=10 1 2
在上面的挂载点中,我创建了一个名为nn的文件夹。该文件夹与其他两个现有文件夹具有相同的所有权和权限。
drwx-----2 hdfs hadoop 64 1月22日16:30 nn
我是否需要手动复制现有namenode目录中的所有文件,或者namenode服务在启动时是否应该自动执行此操作?

qzlgjiam

qzlgjiam1#

我想我可能刚刚回答了我自己的问题。最后,我将一个现有namenode目录的全部内容复制到新的nfs namenode目录中,并且我能够启动namenode(注意,为了避免问题,我在复制之前停止了namenode)

cp -rp /data/1/dfs/nn /data/nfs/dfs/nn

我认为namenode会自动将现有元数据复制到新目录的假设是不正确的。

kmb7vmvb

kmb7vmvb2#

在cloudera cdh 4.5.0中,只有在以下函数(从 Storage.java ,在第418行附近)返回 NON_EXISTENT . 在每种情况下都会显示一条警告,并记录更多详细信息,请从中查找日志行 org.apache.hadoop.hdfs.server.common.Storage .
简言之,name节点似乎认为它不存在,不是目录,不可写,或者抛出了一个 SecurityException .

/**
 * Check consistency of the storage directory
 * 
 * @param startOpt a startup option.
 *  
 * @return state {@link StorageState} of the storage directory 
 * @throws InconsistentFSStateException if directory state is not 
 * consistent and cannot be recovered.
 * @throws IOException
 */
public StorageState analyzeStorage(StartupOption startOpt, Storage storage)
    throws IOException {
  assert root != null : "root is null";
  String rootPath = root.getCanonicalPath();
  try { // check that storage exists
    if (!root.exists()) {
      // storage directory does not exist
      if (startOpt != StartupOption.FORMAT) {
        LOG.warn("Storage directory " + rootPath + " does not exist");
        return StorageState.NON_EXISTENT;
      }
      LOG.info(rootPath + " does not exist. Creating ...");
      if (!root.mkdirs())
        throw new IOException("Cannot create directory " + rootPath);
    }
    // or is inaccessible
    if (!root.isDirectory()) {
      LOG.warn(rootPath + "is not a directory");
      return StorageState.NON_EXISTENT;
    }
    if (!root.canWrite()) {
      LOG.warn("Cannot access storage directory " + rootPath);
      return StorageState.NON_EXISTENT;
    }
  } catch(SecurityException ex) {
    LOG.warn("Cannot access storage directory " + rootPath, ex);
    return StorageState.NON_EXISTENT;
  }

  this.lock(); // lock storage if it exists

  if (startOpt == HdfsServerConstants.StartupOption.FORMAT)
    return StorageState.NOT_FORMATTED;

  if (startOpt != HdfsServerConstants.StartupOption.IMPORT) {
    storage.checkOldLayoutStorage(this);
  }

  // check whether current directory is valid
  File versionFile = getVersionFile();
  boolean hasCurrent = versionFile.exists();

  // check which directories exist
  boolean hasPrevious = getPreviousDir().exists();
  boolean hasPreviousTmp = getPreviousTmp().exists();
  boolean hasRemovedTmp = getRemovedTmp().exists();
  boolean hasFinalizedTmp = getFinalizedTmp().exists();
  boolean hasCheckpointTmp = getLastCheckpointTmp().exists();

  if (!(hasPreviousTmp || hasRemovedTmp
      || hasFinalizedTmp || hasCheckpointTmp)) {
    // no temp dirs - no recovery
    if (hasCurrent)
      return StorageState.NORMAL;
    if (hasPrevious)
      throw new InconsistentFSStateException(root,
                          "version file in current directory is missing.");
    return StorageState.NOT_FORMATTED;
  }

  if ((hasPreviousTmp?1:0) + (hasRemovedTmp?1:0)
      + (hasFinalizedTmp?1:0) + (hasCheckpointTmp?1:0) > 1)
    // more than one temp dirs
    throw new InconsistentFSStateException(root,
                                           "too many temporary directories.");

  // # of temp dirs == 1 should either recover or complete a transition
  if (hasCheckpointTmp) {
    return hasCurrent ? StorageState.COMPLETE_CHECKPOINT
                      : StorageState.RECOVER_CHECKPOINT;
  }

  if (hasFinalizedTmp) {
    if (hasPrevious)
      throw new InconsistentFSStateException(root,
                                             STORAGE_DIR_PREVIOUS + " and " + STORAGE_TMP_FINALIZED
                                             + "cannot exist together.");
    return StorageState.COMPLETE_FINALIZE;
  }

  if (hasPreviousTmp) {
    if (hasPrevious)
      throw new InconsistentFSStateException(root,
                                             STORAGE_DIR_PREVIOUS + " and " + STORAGE_TMP_PREVIOUS
                                             + " cannot exist together.");
    if (hasCurrent)
      return StorageState.COMPLETE_UPGRADE;
    return StorageState.RECOVER_UPGRADE;
  }

  assert hasRemovedTmp : "hasRemovedTmp must be true";
  if (!(hasCurrent ^ hasPrevious))
    throw new InconsistentFSStateException(root,
                                           "one and only one directory " + STORAGE_DIR_CURRENT 
                                           + " or " + STORAGE_DIR_PREVIOUS 
                                           + " must be present when " + STORAGE_TMP_REMOVED
                                           + " exists.");
  if (hasCurrent)
    return StorageState.COMPLETE_ROLLBACK;
  return StorageState.RECOVER_ROLLBACK;
}

相关问题