Search in sources :

Example 1 with IncorrectVersionException

use of org.apache.hadoop.hdfs.server.common.IncorrectVersionException in project hadoop by apache.

the class TestDatanodeRegistration method testRegistrationWithDifferentSoftwareVersions.

@Test
public void testRegistrationWithDifferentSoftwareVersions() throws Exception {
    Configuration conf = new HdfsConfiguration();
    conf.set(DFSConfigKeys.DFS_DATANODE_MIN_SUPPORTED_NAMENODE_VERSION_KEY, "3.0.0");
    conf.set(DFSConfigKeys.DFS_NAMENODE_MIN_SUPPORTED_DATANODE_VERSION_KEY, "3.0.0");
    MiniDFSCluster cluster = null;
    try {
        cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
        NamenodeProtocols rpcServer = cluster.getNameNodeRpc();
        long nnCTime = cluster.getNamesystem().getFSImage().getStorage().getCTime();
        StorageInfo mockStorageInfo = mock(StorageInfo.class);
        doReturn(nnCTime).when(mockStorageInfo).getCTime();
        DatanodeRegistration mockDnReg = mock(DatanodeRegistration.class);
        doReturn(HdfsServerConstants.DATANODE_LAYOUT_VERSION).when(mockDnReg).getVersion();
        doReturn("127.0.0.1").when(mockDnReg).getIpAddr();
        doReturn(123).when(mockDnReg).getXferPort();
        doReturn("fake-storage-id").when(mockDnReg).getDatanodeUuid();
        doReturn(mockStorageInfo).when(mockDnReg).getStorageInfo();
        // Should succeed when software versions are the same.
        doReturn("3.0.0").when(mockDnReg).getSoftwareVersion();
        rpcServer.registerDatanode(mockDnReg);
        // Should succeed when software version of DN is above minimum required by NN.
        doReturn("4.0.0").when(mockDnReg).getSoftwareVersion();
        rpcServer.registerDatanode(mockDnReg);
        // Should fail when software version of DN is below minimum required by NN.
        doReturn("2.0.0").when(mockDnReg).getSoftwareVersion();
        try {
            rpcServer.registerDatanode(mockDnReg);
            fail("Should not have been able to register DN with too-low version.");
        } catch (IncorrectVersionException ive) {
            GenericTestUtils.assertExceptionContains("The reported DataNode version is too low", ive);
            LOG.info("Got expected exception", ive);
        }
    } finally {
        if (cluster != null) {
            cluster.shutdown();
        }
    }
}
Also used : NamenodeProtocols(org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols) IncorrectVersionException(org.apache.hadoop.hdfs.server.common.IncorrectVersionException) DatanodeRegistration(org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration) Configuration(org.apache.hadoop.conf.Configuration) DatanodeStorageInfo(org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo) StorageInfo(org.apache.hadoop.hdfs.server.common.StorageInfo) Test(org.junit.Test)

Example 2 with IncorrectVersionException

use of org.apache.hadoop.hdfs.server.common.IncorrectVersionException in project hadoop by apache.

the class NNStorage method readProperties.

void readProperties(StorageDirectory sd, StartupOption startupOption) throws IOException {
    Properties props = readPropertiesFile(sd.getVersionFile());
    if (HdfsServerConstants.RollingUpgradeStartupOption.ROLLBACK.matches(startupOption)) {
        int lv = Integer.parseInt(getProperty(props, sd, "layoutVersion"));
        if (lv > getServiceLayoutVersion()) {
            // we should not use a newer version for rollingUpgrade rollback
            throw new IncorrectVersionException(getServiceLayoutVersion(), lv, "storage directory " + sd.getRoot().getAbsolutePath());
        }
        props.setProperty("layoutVersion", Integer.toString(HdfsServerConstants.NAMENODE_LAYOUT_VERSION));
    }
    setFieldsFromProperties(props, sd);
}
Also used : IncorrectVersionException(org.apache.hadoop.hdfs.server.common.IncorrectVersionException) Properties(java.util.Properties)

Example 3 with IncorrectVersionException

use of org.apache.hadoop.hdfs.server.common.IncorrectVersionException in project hadoop by apache.

the class NameNodeRpcServer method verifySoftwareVersion.

private void verifySoftwareVersion(DatanodeRegistration dnReg) throws IncorrectVersionException {
    String dnVersion = dnReg.getSoftwareVersion();
    if (VersionUtil.compareVersions(dnVersion, minimumDataNodeVersion) < 0) {
        IncorrectVersionException ive = new IncorrectVersionException(minimumDataNodeVersion, dnVersion, "DataNode", "NameNode");
        LOG.warn(ive.getMessage() + " DN: " + dnReg);
        throw ive;
    }
    String nnVersion = VersionInfo.getVersion();
    if (!dnVersion.equals(nnVersion)) {
        String messagePrefix = "Reported DataNode version '" + dnVersion + "' of DN " + dnReg + " does not match NameNode version '" + nnVersion + "'";
        long nnCTime = nn.getFSImage().getStorage().getCTime();
        long dnCTime = dnReg.getStorageInfo().getCTime();
        if (nnCTime != dnCTime) {
            IncorrectVersionException ive = new IncorrectVersionException(messagePrefix + " and CTime of DN ('" + dnCTime + "') does not match CTime of NN ('" + nnCTime + "')");
            LOG.warn(ive.toString(), ive);
            throw ive;
        } else {
            LOG.info(messagePrefix + ". Note: This is normal during a rolling upgrade.");
        }
    }
}
Also used : IncorrectVersionException(org.apache.hadoop.hdfs.server.common.IncorrectVersionException)

Example 4 with IncorrectVersionException

use of org.apache.hadoop.hdfs.server.common.IncorrectVersionException in project hadoop by apache.

the class BPServiceActor method checkNNVersion.

private void checkNNVersion(NamespaceInfo nsInfo) throws IncorrectVersionException {
    // build and layout versions should match
    String nnVersion = nsInfo.getSoftwareVersion();
    String minimumNameNodeVersion = dnConf.getMinimumNameNodeVersion();
    if (VersionUtil.compareVersions(nnVersion, minimumNameNodeVersion) < 0) {
        IncorrectVersionException ive = new IncorrectVersionException(minimumNameNodeVersion, nnVersion, "NameNode", "DataNode");
        LOG.warn(ive.getMessage());
        throw ive;
    }
    String dnVersion = VersionInfo.getVersion();
    if (!nnVersion.equals(dnVersion)) {
        LOG.info("Reported NameNode version '" + nnVersion + "' does not match " + "DataNode version '" + dnVersion + "' but is within acceptable " + "limits. Note: This is normal during a rolling upgrade.");
    }
}
Also used : IncorrectVersionException(org.apache.hadoop.hdfs.server.common.IncorrectVersionException)

Example 5 with IncorrectVersionException

use of org.apache.hadoop.hdfs.server.common.IncorrectVersionException in project hadoop by apache.

the class TestDatanodeRegistration method testRegistrationWithDifferentSoftwareVersionsDuringUpgrade.

@Test
public void testRegistrationWithDifferentSoftwareVersionsDuringUpgrade() throws Exception {
    Configuration conf = new HdfsConfiguration();
    conf.set(DFSConfigKeys.DFS_DATANODE_MIN_SUPPORTED_NAMENODE_VERSION_KEY, "1.0.0");
    MiniDFSCluster cluster = null;
    try {
        cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
        NamenodeProtocols rpcServer = cluster.getNameNodeRpc();
        long nnCTime = cluster.getNamesystem().getFSImage().getStorage().getCTime();
        StorageInfo mockStorageInfo = mock(StorageInfo.class);
        doReturn(nnCTime).when(mockStorageInfo).getCTime();
        DatanodeRegistration mockDnReg = mock(DatanodeRegistration.class);
        doReturn(HdfsServerConstants.DATANODE_LAYOUT_VERSION).when(mockDnReg).getVersion();
        doReturn("fake-storage-id").when(mockDnReg).getDatanodeUuid();
        doReturn(mockStorageInfo).when(mockDnReg).getStorageInfo();
        // Should succeed when software versions are the same and CTimes are the
        // same.
        doReturn(VersionInfo.getVersion()).when(mockDnReg).getSoftwareVersion();
        doReturn("127.0.0.1").when(mockDnReg).getIpAddr();
        doReturn(123).when(mockDnReg).getXferPort();
        rpcServer.registerDatanode(mockDnReg);
        // Should succeed when software versions are the same and CTimes are
        // different.
        doReturn(nnCTime + 1).when(mockStorageInfo).getCTime();
        rpcServer.registerDatanode(mockDnReg);
        // Should fail when software version of DN is different from NN and CTimes
        // are different.
        doReturn(VersionInfo.getVersion() + ".1").when(mockDnReg).getSoftwareVersion();
        try {
            rpcServer.registerDatanode(mockDnReg);
            fail("Should not have been able to register DN with different software" + " versions and CTimes");
        } catch (IncorrectVersionException ive) {
            GenericTestUtils.assertExceptionContains("does not match CTime of NN", ive);
            LOG.info("Got expected exception", ive);
        }
    } finally {
        if (cluster != null) {
            cluster.shutdown();
        }
    }
}
Also used : NamenodeProtocols(org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols) IncorrectVersionException(org.apache.hadoop.hdfs.server.common.IncorrectVersionException) DatanodeRegistration(org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration) Configuration(org.apache.hadoop.conf.Configuration) DatanodeStorageInfo(org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo) StorageInfo(org.apache.hadoop.hdfs.server.common.StorageInfo) Test(org.junit.Test)

Aggregations

IncorrectVersionException (org.apache.hadoop.hdfs.server.common.IncorrectVersionException)5 Configuration (org.apache.hadoop.conf.Configuration)2 DatanodeStorageInfo (org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo)2 StorageInfo (org.apache.hadoop.hdfs.server.common.StorageInfo)2 DatanodeRegistration (org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration)2 NamenodeProtocols (org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols)2 Test (org.junit.Test)2 Properties (java.util.Properties)1