Exemplo n.º 1
0
 /**
  * Verify that the current and previous directories exist. Verify that previous hasn't been
  * modified by comparing the checksum of all it's containing files with their original checksum.
  * It is assumed that the server has recovered and upgraded. nsLevelUpgrade specify if the upgrade
  * is at top level or ns level nsLevelUpgrade=true, we search basedir/current/NS-id/previous
  * =false, we search basedir/previous
  */
 void checkResult(NodeType nodeType, String[] baseDirs, int nnIndex, boolean simulatedPrevious)
     throws IOException {
   switch (nodeType) {
     case NAME_NODE:
       for (int i = 0; i < baseDirs.length; i++) {
         assertTrue(new File(baseDirs[i], "current").isDirectory());
         assertTrue(new File(baseDirs[i], "current/VERSION").isFile());
         assertTrue(new File(baseDirs[i], "current/edits").isFile());
         assertTrue(new File(baseDirs[i], "current/fsimage").isFile());
         assertTrue(new File(baseDirs[i], "current/fstime").isFile());
       }
       break;
     case DATA_NODE:
       for (int i = 0; i < baseDirs.length; i++) {
         assertEquals(
             UpgradeUtilities.checksumContents(nodeType, new File(baseDirs[i], "current")),
             UpgradeUtilities.checksumMasterContents(nodeType));
         File nsBaseDir =
             NameSpaceSliceStorage.getNsRoot(
                 cluster.getNameNode(nnIndex).getNamespaceID(), new File(baseDirs[i], "current"));
         assertEquals(
             UpgradeUtilities.checksumContents(
                 nodeType, new File(nsBaseDir, MiniDFSCluster.FINALIZED_DIR_NAME)),
             UpgradeUtilities.checksumDatanodeNSStorageContents(nnIndex));
       }
       break;
   }
   for (int i = 0; i < baseDirs.length; i++) {
     switch (nodeType) {
       case NAME_NODE:
         assertTrue(new File(baseDirs[i], "previous").isDirectory());
         assertEquals(
             UpgradeUtilities.checksumContents(nodeType, new File(baseDirs[i], "previous")),
             UpgradeUtilities.checksumMasterContents(nodeType));
         break;
       case DATA_NODE:
         File nsBaseDir = null;
         nsBaseDir =
             NameSpaceSliceStorage.getNsRoot(
                 cluster.getNameNode(nnIndex).getNamespaceID(), new File(baseDirs[i], "current"));
         // Top level upgrade should not exist.
         assertFalse(new File(baseDirs[i], "previous").isDirectory() && !simulatedPrevious);
         assertTrue(new File(nsBaseDir, "previous").isDirectory());
         assertEquals(
             UpgradeUtilities.checksumContents(
                 nodeType, new File(nsBaseDir, "previous/finalized")),
             UpgradeUtilities.checksumDatanodeNSStorageContents(nnIndex));
     }
   }
 }
Exemplo n.º 2
0
  public void testFederationClusterUpgradeAfterFederationVersionWithTopLevelLayout()
      throws Exception {
    File[] baseDirs;
    Configuration baseConf = new Configuration();
    UpgradeUtilities.initialize(2, baseConf, true);
    for (int numDirs = 1; numDirs <= 2; numDirs++) {
      conf = new Configuration();
      conf.setInt("dfs.datanode.scan.period.hours", -1);
      conf = UpgradeUtilities.initializeStorageStateConf(numDirs, conf);
      String[] nameNodeDirs = conf.getStrings("dfs.name.dir");
      String[] dataNodeDirs = conf.getStrings("dfs.data.dir");
      log(
          "DataNode upgrade with federation layout version in current and no ns level layout version",
          numDirs);
      UpgradeUtilities.createFederatedNameNodeStorageDirs(nameNodeDirs);
      conf.set(
          FSConstants.DFS_FEDERATION_NAMESERVICES,
          baseConf.get(FSConstants.DFS_FEDERATION_NAMESERVICES));
      try {
        cluster = new MiniDFSCluster(conf, 0, StartupOption.UPGRADE, false, 2);
        baseDirs = UpgradeUtilities.createStorageDirs(DATA_NODE, dataNodeDirs, "current");
        for (int i = 0; i < 2; i++) {
          UpgradeUtilities.createVersionFile(
              DATA_NODE,
              baseDirs,
              new StorageInfo(
                  FSConstants.FEDERATION_VERSION,
                  cluster.getNameNode(i).getNamespaceID(),
                  cluster.getNameNode(i).versionRequest().getCTime()),
              cluster.getNameNode(i).getNamespaceID(),
              false);
        }
        cluster.startDataNodes(conf, 1, false, StartupOption.REGULAR, null);

        for (int i = 0; i < 2; i++) {
          checkResult(DATA_NODE, dataNodeDirs, i, false);
        }

        // Finalize upgrade.
        for (int i = 0; i < 2; i++) {
          cluster.getNameNode(i).finalizeUpgrade();
        }
        cluster.restartDataNodes();

        // Wait for datanodes to finalize.
        Thread.sleep(10000);

        for (int nnIndex = 0; nnIndex < 2; nnIndex++) {
          for (int i = 0; i < dataNodeDirs.length; i++) {
            File nsBaseDir =
                NameSpaceSliceStorage.getNsRoot(
                    cluster.getNameNode(nnIndex).getNamespaceID(),
                    new File(dataNodeDirs[i], "current"));
            assertFalse(new File(nsBaseDir, "previous").exists());
          }
        }
      } finally {
        if (cluster != null) cluster.shutdown();
        UpgradeUtilities.createEmptyDirs(nameNodeDirs);
        UpgradeUtilities.createEmptyDirs(dataNodeDirs);
      }
    }
  }