Exemple #1
0
  void format(StorageDirectory sd, NamespaceInfo nsInfo, String datanodeUuid) throws IOException {
    sd.clearDirectory();
    this.layoutVersion = HdfsConstants.DATANODE_LAYOUT_VERSION;
    this.clusterID = nsInfo.getClusterID();
    this.namespaceID = nsInfo.getNamespaceID();
    this.cTime = 0;
    setDatanodeUuid(datanodeUuid);
    if (sd.getStorageUuid() == null) {
      // 分配新的 Storage UUID.
      sd.setStorageUuid(DatanodeStorage.generateUuid());
    }

    writeProperties(sd);
  }
Exemple #2
0
  public synchronized boolean createStorageID(StorageDirectory sd, boolean regenerateStorageIds) {
    final String oldStorageID = sd.getStorageUuid();

    if (oldStorageID == null || regenerateStorageIds) {
      sd.setStorageUuid(DatanodeStorage.generateUuid());
      LOG.info(
          "Generated new storageID "
              + sd.getStorageUuid()
              + " for directory "
              + sd.getRoot()
              + (oldStorageID == null ? "" : (" to replace " + oldStorageID)));
      return true;
    }
    return false;
  }
Exemple #3
0
 private void doTransition(
     DataNode datanode, StorageDirectory sd, NamespaceInfo nsInfo, StartupOption startOpt)
     throws IOException {
   if (startOpt == StartupOption.ROLLBACK) {
     throw new RuntimeException("未实现");
   }
   readProperties(sd);
   checkVersionUpgradable(this.layoutVersion);
   // 版本号为负数,越小越高,文件里面的layoutVersion必须比hadoop版本大或者等于
   assert this.layoutVersion >= HdfsConstants.DATANODE_LAYOUT_VERSION : "不允许将来的版本";
   boolean federationSupported =
       DataNodeLayoutVersion.supports(LayoutVersion.Feature.FEDERATION, layoutVersion);
   if (!federationSupported && getNamespaceID() != nsInfo.getNamespaceID()) {
     throw new IOException(
         "Incompatible namespaceIDs in "
             + sd.getRoot().getCanonicalPath()
             + ": namenode namespaceID = "
             + nsInfo.getNamespaceID()
             + "; datanode namespaceID = "
             + getNamespaceID());
   }
   if (federationSupported && !getClusterID().equals(nsInfo.getClusterID())) {
     throw new IOException(
         "Incompatible clusterIDs in "
             + sd.getRoot().getCanonicalPath()
             + ": namenode clusterID = "
             + nsInfo.getClusterID()
             + "; datanode clusterID = "
             + getClusterID());
   }
   boolean haveValidStorageId =
       DataNodeLayoutVersion.supports(
               LayoutVersion.Feature.ADD_DATANODE_AND_STORAGE_UUIDS, layoutVersion)
           && DatanodeStorage.isValidStorageId(sd.getStorageUuid());
   if (this.layoutVersion == HdfsConstants.DATANODE_LAYOUT_VERSION) {
     createStorageID(sd, !haveValidStorageId);
     return;
   }
   throw new IOException(
       "BUG: The stored LV = "
           + this.getLayoutVersion()
           + " is newer than the supported LV = "
           + HdfsConstants.DATANODE_LAYOUT_VERSION);
 }