Search in sources :

Example 21 with NamespaceInfo

use of org.apache.hadoop.hdfs.server.protocol.NamespaceInfo in project hadoop by apache.

the class BackupNode method handshake.

private NamespaceInfo handshake(Configuration conf) throws IOException {
    // connect to name node
    InetSocketAddress nnAddress = NameNode.getServiceAddress(conf, true);
    this.namenode = NameNodeProxies.createNonHAProxy(conf, nnAddress, NamenodeProtocol.class, UserGroupInformation.getCurrentUser(), true).getProxy();
    this.nnRpcAddress = NetUtils.getHostPortString(nnAddress);
    this.nnHttpAddress = DFSUtil.getInfoServer(nnAddress, conf, DFSUtil.getHttpClientScheme(conf)).toURL();
    // get version and id info from the name-node
    NamespaceInfo nsInfo = null;
    while (!isStopRequested()) {
        try {
            nsInfo = handshake(namenode);
            break;
        } catch (SocketTimeoutException e) {
            // name-node is busy
            LOG.info("Problem connecting to server: " + nnAddress);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                LOG.warn("Encountered exception ", e);
            }
        }
    }
    return nsInfo;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) NamespaceInfo(org.apache.hadoop.hdfs.server.protocol.NamespaceInfo)

Example 22 with NamespaceInfo

use of org.apache.hadoop.hdfs.server.protocol.NamespaceInfo in project hadoop by apache.

the class BackupNode method handshake.

// TODO: move to a common with DataNode util class
private static NamespaceInfo handshake(NamenodeProtocol namenode) throws IOException, SocketTimeoutException {
    NamespaceInfo nsInfo;
    // throws SocketTimeoutException 
    nsInfo = namenode.versionRequest();
    String errorMsg = null;
    // verify build version
    if (!nsInfo.getBuildVersion().equals(Storage.getBuildVersion())) {
        errorMsg = "Incompatible build versions: active name-node BV = " + nsInfo.getBuildVersion() + "; backup node BV = " + Storage.getBuildVersion();
        LOG.error(errorMsg);
        throw new IOException(errorMsg);
    }
    assert HdfsServerConstants.NAMENODE_LAYOUT_VERSION == nsInfo.getLayoutVersion() : "Active and backup node layout versions must be the same. Expected: " + HdfsServerConstants.NAMENODE_LAYOUT_VERSION + " actual " + nsInfo.getLayoutVersion();
    return nsInfo;
}
Also used : IOException(java.io.IOException) NamespaceInfo(org.apache.hadoop.hdfs.server.protocol.NamespaceInfo)

Example 23 with NamespaceInfo

use of org.apache.hadoop.hdfs.server.protocol.NamespaceInfo in project hadoop by apache.

the class BootstrapStandby method doRun.

private int doRun() throws IOException {
    // find the active NN
    NamenodeProtocol proxy = null;
    NamespaceInfo nsInfo = null;
    boolean isUpgradeFinalized = false;
    RemoteNameNodeInfo proxyInfo = null;
    for (int i = 0; i < remoteNNs.size(); i++) {
        proxyInfo = remoteNNs.get(i);
        InetSocketAddress otherIpcAddress = proxyInfo.getIpcAddress();
        proxy = createNNProtocolProxy(otherIpcAddress);
        try {
            // Get the namespace from any active NN. If you just formatted the primary NN and are
            // bootstrapping the other NNs from that layout, it will only contact the single NN.
            // However, if there cluster is already running and you are adding a NN later (e.g.
            // replacing a failed NN), then this will bootstrap from any node in the cluster.
            nsInfo = proxy.versionRequest();
            isUpgradeFinalized = proxy.isUpgradeFinalized();
            break;
        } catch (IOException ioe) {
            LOG.warn("Unable to fetch namespace information from remote NN at " + otherIpcAddress + ": " + ioe.getMessage());
            if (LOG.isDebugEnabled()) {
                LOG.debug("Full exception trace", ioe);
            }
        }
    }
    if (nsInfo == null) {
        LOG.fatal("Unable to fetch namespace information from any remote NN. Possible NameNodes: " + remoteNNs);
        return ERR_CODE_FAILED_CONNECT;
    }
    if (!checkLayoutVersion(nsInfo)) {
        LOG.fatal("Layout version on remote node (" + nsInfo.getLayoutVersion() + ") does not match " + "this node's layout version (" + HdfsServerConstants.NAMENODE_LAYOUT_VERSION + ")");
        return ERR_CODE_INVALID_VERSION;
    }
    System.out.println("=====================================================\n" + "About to bootstrap Standby ID " + nnId + " from:\n" + "           Nameservice ID: " + nsId + "\n" + "        Other Namenode ID: " + proxyInfo.getNameNodeID() + "\n" + "  Other NN's HTTP address: " + proxyInfo.getHttpAddress() + "\n" + "  Other NN's IPC  address: " + proxyInfo.getIpcAddress() + "\n" + "             Namespace ID: " + nsInfo.getNamespaceID() + "\n" + "            Block pool ID: " + nsInfo.getBlockPoolID() + "\n" + "               Cluster ID: " + nsInfo.getClusterID() + "\n" + "           Layout version: " + nsInfo.getLayoutVersion() + "\n" + "       isUpgradeFinalized: " + isUpgradeFinalized + "\n" + "=====================================================");
    NNStorage storage = new NNStorage(conf, dirsToFormat, editUrisToFormat);
    if (!isUpgradeFinalized) {
        // the remote NameNode is in upgrade state, this NameNode should also
        // create the previous directory. First prepare the upgrade and rename
        // the current dir to previous.tmp.
        LOG.info("The active NameNode is in Upgrade. " + "Prepare the upgrade for the standby NameNode as well.");
        if (!doPreUpgrade(storage, nsInfo)) {
            return ERR_CODE_ALREADY_FORMATTED;
        }
    } else if (!format(storage, nsInfo)) {
        // prompt the user to format storage
        return ERR_CODE_ALREADY_FORMATTED;
    }
    // download the fsimage from active namenode
    int download = downloadImage(storage, proxy, proxyInfo);
    if (download != 0) {
        return download;
    }
    // finish the upgrade: rename previous.tmp to previous
    if (!isUpgradeFinalized) {
        doUpgrade(storage);
    }
    return 0;
}
Also used : NNStorage(org.apache.hadoop.hdfs.server.namenode.NNStorage) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) NamespaceInfo(org.apache.hadoop.hdfs.server.protocol.NamespaceInfo) NamenodeProtocol(org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol)

Example 24 with NamespaceInfo

use of org.apache.hadoop.hdfs.server.protocol.NamespaceInfo in project hadoop by apache.

the class TestBlockListAsLongs method testCapabilitiesInited.

@Test
public void testCapabilitiesInited() {
    NamespaceInfo nsInfo = new NamespaceInfo();
    assertTrue(nsInfo.isCapabilitySupported(Capability.STORAGE_BLOCK_REPORT_BUFFERS));
}
Also used : NamespaceInfo(org.apache.hadoop.hdfs.server.protocol.NamespaceInfo) Test(org.junit.Test)

Example 25 with NamespaceInfo

use of org.apache.hadoop.hdfs.server.protocol.NamespaceInfo in project hadoop by apache.

the class InternalDataNodeTestUtils method startDNWithMockNN.

/**
   * Starts an instance of DataNode with NN mocked. Called should ensure to
   * shutdown the DN
   *
   * @throws IOException
   */
public static DataNode startDNWithMockNN(Configuration conf, final InetSocketAddress nnSocketAddr, final String dnDataDir) throws IOException {
    FileSystem.setDefaultUri(conf, "hdfs://" + nnSocketAddr.getHostName() + ":" + nnSocketAddr.getPort());
    ArrayList<StorageLocation> locations = new ArrayList<StorageLocation>();
    File dataDir = new File(dnDataDir);
    FileUtil.fullyDelete(dataDir);
    dataDir.mkdirs();
    StorageLocation location = StorageLocation.parse(dataDir.getPath());
    locations.add(location);
    final DatanodeProtocolClientSideTranslatorPB namenode = mock(DatanodeProtocolClientSideTranslatorPB.class);
    Mockito.doAnswer(new Answer<DatanodeRegistration>() {

        @Override
        public DatanodeRegistration answer(InvocationOnMock invocation) throws Throwable {
            return (DatanodeRegistration) invocation.getArguments()[0];
        }
    }).when(namenode).registerDatanode(Mockito.any(DatanodeRegistration.class));
    when(namenode.versionRequest()).thenReturn(new NamespaceInfo(1, TEST_CLUSTER_ID, TEST_POOL_ID, 1L));
    when(namenode.sendHeartbeat(Mockito.any(DatanodeRegistration.class), Mockito.any(StorageReport[].class), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(VolumeFailureSummary.class), Mockito.anyBoolean(), Mockito.any(SlowPeerReports.class))).thenReturn(new HeartbeatResponse(new DatanodeCommand[0], new NNHAStatusHeartbeat(HAServiceState.ACTIVE, 1), null, ThreadLocalRandom.current().nextLong() | 1L));
    DataNode dn = new DataNode(conf, locations, null, null) {

        @Override
        DatanodeProtocolClientSideTranslatorPB connectToNN(InetSocketAddress nnAddr) throws IOException {
            Assert.assertEquals(nnSocketAddr, nnAddr);
            return namenode;
        }
    };
    // Trigger a heartbeat so that it acknowledges the NN as active.
    dn.getAllBpOs().get(0).triggerHeartbeatForTests();
    return dn;
}
Also used : HeartbeatResponse(org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) VolumeFailureSummary(org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary) DatanodeProtocolClientSideTranslatorPB(org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB) DatanodeRegistration(org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration) DatanodeCommand(org.apache.hadoop.hdfs.server.protocol.DatanodeCommand) NNHAStatusHeartbeat(org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SlowPeerReports(org.apache.hadoop.hdfs.server.protocol.SlowPeerReports) NamespaceInfo(org.apache.hadoop.hdfs.server.protocol.NamespaceInfo) File(java.io.File)

Aggregations

NamespaceInfo (org.apache.hadoop.hdfs.server.protocol.NamespaceInfo)35 IOException (java.io.IOException)13 Test (org.junit.Test)13 File (java.io.File)8 InetSocketAddress (java.net.InetSocketAddress)7 Storage (org.apache.hadoop.hdfs.server.common.Storage)6 StorageDirectory (org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory)6 ArrayList (java.util.ArrayList)5 DatanodeProtocolClientSideTranslatorPB (org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB)5 DataStorage (org.apache.hadoop.hdfs.server.datanode.DataStorage)5 Configuration (org.apache.hadoop.conf.Configuration)4 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)4 StorageLocation (org.apache.hadoop.hdfs.server.datanode.StorageLocation)4 DatanodeRegistration (org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration)4 NNHAStatusHeartbeat (org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat)4 SlowPeerReports (org.apache.hadoop.hdfs.server.protocol.SlowPeerReports)4 VolumeFailureSummary (org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary)4 HeartbeatResponse (org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse)3 MultipleIOException (org.apache.hadoop.io.MultipleIOException)3 Matchers.anyString (org.mockito.Matchers.anyString)3