Search in sources :

Example 6 with RollingUpgradeInfo

use of org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo 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)

Example 7 with RollingUpgradeInfo

use of org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo in project hadoop by apache.

the class TestRollingUpgrade method testFinalize.

private void testFinalize(int nnCount) 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).setNumNameNodes(nnCount).build();
        MiniDFSCluster dfsCluster = cluster.getDfsCluster();
        dfsCluster.waitActive();
        // let other NN tail editlog every 1s
        for (int i = 1; i < nnCount; i++) {
            dfsCluster.getConfiguration(i).setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
        }
        dfsCluster.restartNameNodes();
        dfsCluster.transitionToActive(0);
        DistributedFileSystem dfs = dfsCluster.getFileSystem(0);
        dfs.mkdirs(foo);
        FSImage fsimage = dfsCluster.getNamesystem(0).getFSImage();
        // start rolling upgrade
        RollingUpgradeInfo info = dfs.rollingUpgrade(RollingUpgradeAction.PREPARE);
        Assert.assertTrue(info.isStarted());
        dfs.mkdirs(bar);
        queryForPreparation(dfs);
        // The NN should have a copy of the fsimage in case of rollbacks.
        Assert.assertTrue(fsimage.hasRollbackFSImage());
        info = dfs.rollingUpgrade(RollingUpgradeAction.FINALIZE);
        Assert.assertTrue(info.isFinalized());
        Assert.assertTrue(dfs.exists(foo));
        // Once finalized, there should be no more fsimage for rollbacks.
        Assert.assertFalse(fsimage.hasRollbackFSImage());
        // Should have no problem in restart and replaying edits that include
        // the FINALIZE op.
        dfsCluster.restartNameNode(0);
    } finally {
        if (cluster != null) {
            cluster.shutdown();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FSImage(org.apache.hadoop.hdfs.server.namenode.FSImage) Configuration(org.apache.hadoop.conf.Configuration) RollingUpgradeInfo(org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo) MiniQJMHACluster(org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster)

Example 8 with RollingUpgradeInfo

use of org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo in project hadoop by apache.

the class ClientNamenodeProtocolServerSideTranslatorPB method rollingUpgrade.

@Override
public RollingUpgradeResponseProto rollingUpgrade(RpcController controller, RollingUpgradeRequestProto req) throws ServiceException {
    try {
        final RollingUpgradeInfo info = server.rollingUpgrade(PBHelperClient.convert(req.getAction()));
        final RollingUpgradeResponseProto.Builder b = RollingUpgradeResponseProto.newBuilder();
        if (info != null) {
            b.setRollingUpgradeInfo(PBHelperClient.convert(info));
        }
        return b.build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) RollingUpgradeInfo(org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo) RollingUpgradeResponseProto(org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.RollingUpgradeResponseProto) IOException(java.io.IOException)

Example 9 with RollingUpgradeInfo

use of org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo in project hadoop by apache.

the class NameNodeConnector method isUpgrading.

/**
   * @return true if an upgrade is in progress, false if not.
   * @throws IOException
   */
public boolean isUpgrading() throws IOException {
    // fsimage upgrade
    final boolean isUpgrade = !namenode.isUpgradeFinalized();
    // rolling upgrade
    RollingUpgradeInfo info = fs.rollingUpgrade(HdfsConstants.RollingUpgradeAction.QUERY);
    final boolean isRollingUpgrade = (info != null && !info.isFinalized());
    return (isUpgrade || isRollingUpgrade);
}
Also used : RollingUpgradeInfo(org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo)

Example 10 with RollingUpgradeInfo

use of org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo in project hadoop by apache.

the class FSNamesystem method getRollingUpgradeStatus.

// NameNodeMXBean
@Override
public RollingUpgradeInfo.Bean getRollingUpgradeStatus() {
    if (!isRollingUpgrade()) {
        return null;
    }
    RollingUpgradeInfo upgradeInfo = getRollingUpgradeInfo();
    if (upgradeInfo.createdRollbackImages()) {
        return new RollingUpgradeInfo.Bean(upgradeInfo);
    }
    readLock();
    try {
        // check again after acquiring the read lock.
        upgradeInfo = getRollingUpgradeInfo();
        if (upgradeInfo == null) {
            return null;
        }
        if (!upgradeInfo.createdRollbackImages()) {
            boolean hasRollbackImage = this.getFSImage().hasRollbackFSImage();
            upgradeInfo.setCreatedRollbackImages(hasRollbackImage);
        }
    } catch (IOException ioe) {
        LOG.warn("Encountered exception setting Rollback Image", ioe);
    } finally {
        readUnlock("getRollingUpgradeStatus");
    }
    return new RollingUpgradeInfo.Bean(upgradeInfo);
}
Also used : RollingUpgradeInfo(org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo) IOException(java.io.IOException) FSNamesystemMBean(org.apache.hadoop.hdfs.server.namenode.metrics.FSNamesystemMBean) StandardMBean(javax.management.StandardMBean)

Aggregations

RollingUpgradeInfo (org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo)10 Configuration (org.apache.hadoop.conf.Configuration)6 Path (org.apache.hadoop.fs.Path)5 MiniQJMHACluster (org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster)5 IOException (java.io.IOException)3 Test (org.junit.Test)3 File (java.io.File)2 ServiceException (com.google.protobuf.ServiceException)1 StandardMBean (javax.management.StandardMBean)1 RollingUpgradeResponseProto (org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.RollingUpgradeResponseProto)1 MiniJournalCluster (org.apache.hadoop.hdfs.qjournal.MiniJournalCluster)1 FSImage (org.apache.hadoop.hdfs.server.namenode.FSImage)1 NNStorage (org.apache.hadoop.hdfs.server.namenode.NNStorage)1 FSNamesystemMBean (org.apache.hadoop.hdfs.server.namenode.metrics.FSNamesystemMBean)1