Search in sources :

Example 6 with NNStorage

use of org.apache.hadoop.hdfs.server.namenode.NNStorage in project hadoop by apache.

the class TestRollingUpgradeRollback method testRollbackWithHAQJM.

/**
   * Test rollback scenarios where StandbyNameNode does checkpoints during
   * rolling upgrade.
   */
@Test
public void testRollbackWithHAQJM() throws Exception {
    final Configuration conf = new HdfsConfiguration();
    MiniQJMHACluster cluster = null;
    final Path foo = new Path("/foo");
    final Path bar = new Path("/bar");
    try {
        cluster = new MiniQJMHACluster.Builder(conf).build();
        MiniDFSCluster dfsCluster = cluster.getDfsCluster();
        dfsCluster.waitActive();
        // let NN1 tail editlog every 1s
        dfsCluster.getConfiguration(1).setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
        dfsCluster.restartNameNode(1);
        dfsCluster.transitionToActive(0);
        DistributedFileSystem dfs = dfsCluster.getFileSystem(0);
        dfs.mkdirs(foo);
        // start rolling upgrade
        RollingUpgradeInfo info = dfs.rollingUpgrade(RollingUpgradeAction.PREPARE);
        Assert.assertTrue(info.isStarted());
        // create new directory
        dfs.mkdirs(bar);
        dfs.close();
        dfs = dfsCluster.getFileSystem(0);
        TestRollingUpgrade.queryForPreparation(dfs);
        // If the query returns true, both active and the standby NN should have
        // rollback fsimage ready.
        Assert.assertTrue(dfsCluster.getNameNode(0).getFSImage().hasRollbackFSImage());
        Assert.assertTrue(dfsCluster.getNameNode(1).getFSImage().hasRollbackFSImage());
        // rollback NN0
        dfsCluster.restartNameNode(0, true, "-rollingUpgrade", "rollback");
        // shutdown NN1
        dfsCluster.shutdownNameNode(1);
        dfsCluster.transitionToActive(0);
        // make sure /foo is still there, but /bar is not
        dfs = dfsCluster.getFileSystem(0);
        Assert.assertTrue(dfs.exists(foo));
        Assert.assertFalse(dfs.exists(bar));
        // check the details of NNStorage
        NNStorage storage = dfsCluster.getNamesystem(0).getFSImage().getStorage();
        // segments:(startSegment, mkdir, start upgrade endSegment), 
        // (startSegment, mkdir, endSegment)
        checkNNStorage(storage, 4, 7);
        // check storage in JNs
        for (int i = 0; i < NUM_JOURNAL_NODES; i++) {
            File dir = cluster.getJournalCluster().getCurrentDir(0, MiniQJMHACluster.NAMESERVICE);
            checkJNStorage(dir, 5, 7);
        }
        // restart NN0 again to make sure we can start using the new fsimage and
        // the corresponding md5 checksum
        dfsCluster.restartNameNode(0);
        // start the rolling upgrade again to make sure we do not load upgrade
        // status after the rollback
        dfsCluster.transitionToActive(0);
        dfs.rollingUpgrade(RollingUpgradeAction.PREPARE);
    } finally {
        if (cluster != null) {
            cluster.shutdown();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) NNStorage(org.apache.hadoop.hdfs.server.namenode.NNStorage) RollingUpgradeInfo(org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo) MiniQJMHACluster(org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster) File(java.io.File) Test(org.junit.Test)

Aggregations

NNStorage (org.apache.hadoop.hdfs.server.namenode.NNStorage)6 Configuration (org.apache.hadoop.conf.Configuration)3 Test (org.junit.Test)3 File (java.io.File)2 Path (org.apache.hadoop.fs.Path)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 RollingUpgradeInfo (org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo)1 MiniQJMHACluster (org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster)1 Storage (org.apache.hadoop.hdfs.server.common.Storage)1 StorageDirectory (org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory)1 BlockPoolSliceStorage (org.apache.hadoop.hdfs.server.datanode.BlockPoolSliceStorage)1 DataStorage (org.apache.hadoop.hdfs.server.datanode.DataStorage)1 INode (org.apache.hadoop.hdfs.server.namenode.INode)1 NameNode (org.apache.hadoop.hdfs.server.namenode.NameNode)1 DatanodeStorage (org.apache.hadoop.hdfs.server.protocol.DatanodeStorage)1 NamenodeProtocol (org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol)1 NamespaceInfo (org.apache.hadoop.hdfs.server.protocol.NamespaceInfo)1 DFSAdmin (org.apache.hadoop.hdfs.tools.DFSAdmin)1