void refreshNNList(ArrayList<InetSocketAddress> addrs, ArrayList<InetSocketAddress> lifelineAddrs) throws IOException { Set<InetSocketAddress> oldAddrs = Sets.newHashSet(); for (BPServiceActor actor : bpServices) { oldAddrs.add(actor.getNNSocketAddress()); } Set<InetSocketAddress> newAddrs = Sets.newHashSet(addrs); // Process added NNs Set<InetSocketAddress> addedNNs = Sets.difference(newAddrs, oldAddrs); for (InetSocketAddress addedNN : addedNNs) { BPServiceActor actor = new BPServiceActor(addedNN, lifelineAddrs.get(addrs.indexOf(addedNN)), this); actor.start(); bpServices.add(actor); } // Process removed NNs Set<InetSocketAddress> removedNNs = Sets.difference(oldAddrs, newAddrs); for (InetSocketAddress removedNN : removedNNs) { for (BPServiceActor actor : bpServices) { if (actor.getNNSocketAddress().equals(removedNN)) { actor.stop(); shutdownActor(actor); break; } } } }
/** * Run an immediate deletion report on this thread. Used by tests. */ @VisibleForTesting void triggerDeletionReportForTests() throws IOException { for (BPServiceActor actor : bpServices) { actor.getIbrManager().triggerDeletionReportForTests(); } }
/** * @param addr rpc address of the namenode * @return true if the datanode is connected to a NameNode at the * given address */ public boolean isConnectedToNN(InetSocketAddress addr) { for (BPOfferService bpos : getAllBpOs()) { for (BPServiceActor bpsa : bpos.getBPServiceActors()) { if (addr.equals(bpsa.getNNSocketAddress())) { return bpsa.isAlive(); } } } return false; }
void reRegister() throws IOException { if (shouldRun()) { // re-retrieve namespace info to make sure that, if the NN // was restarted, we still match its version (HDFS-2120) NamespaceInfo nsInfo = retrieveNamespaceInfo(); // and re-register register(nsInfo); scheduler.scheduleHeartbeat(); // HDFS-9917,Standby NN IBR can be very huge if standby namenode is down // for sometime. if (state == HAServiceState.STANDBY) { ibrManager.clearIBRs(); } } }
private void connectToNNAndHandshake() throws IOException { // get NN proxy bpNamenode = dn.connectToNN(nnAddr); // First phase of the handshake with NN - get the namespace // info. NamespaceInfo nsInfo = retrieveNamespaceInfo(); // Verify that this matches the other NN in this HA pair. // This also initializes our block pool in the DN if we are // the first NN connection for this BP. bpos.verifyAndSetNamespaceInfo(this, nsInfo); /* set thread name again to include NamespaceInfo when it's available. */ this.bpThread.setName(formatThreadName("heartbeating", nnAddr)); // Second phase of the handshake with the NN. register(nsInfo); }
while (shouldRun()) { try { DataNodeFaultInjector.get().startOfferService(); scheduler.isBlockReportDue(startTime); if (!dn.areHeartbeatsDisabledForTests()) { resp = sendHeartBeat(requestBlockReportLease); assert resp != null; if (resp.getFullBlockReportLeaseId() != 0) { handleRollingUpgradeStatus(resp); if (!processCommand(resp.getCommands())) continue; long endProcessCommands = monotonicNow(); cmds = blockReport(fullBlockReportLeaseId); fullBlockReportLeaseId = 0; processCommand(cmds == null ? null : cmds.toArray(new DatanodeCommand[cmds.size()])); DatanodeCommand cmd = cacheReport(); processCommand(new DatanodeCommand[]{ cmd }); sleepAfterException(); } catch (IOException e) { LOG.warn("IOException in offerService", e); sleepAfterException(); } finally {
connectToNNAndHandshake(); break; } catch (IOException ioe) { if (shouldRetryInit()) { sleepAndLogInterrupts(5000, "initializing"); } else { runningState = RunningState.FAILED; while (shouldRun()) { try { offerService(); } catch (Exception ex) { LOG.error("Exception in BPOfferService for " + this, ex); sleepAndLogInterrupts(5000, "offering service"); } finally { LOG.warn("Ending block pool service for: " + this); cleanUp();
NamespaceInfo retrieveNamespaceInfo() throws IOException { NamespaceInfo nsInfo = null; while (shouldRun()) { try { nsInfo = bpNamenode.versionRequest(); sleepAndLogInterrupts(5000, "requesting version info from NN"); checkNNVersion(nsInfo); } else { throw new IOException("DN shut down before block pool connected");
/** * @return true if the given NN address is one of the NNs for this * block pool */ boolean containsNN(InetSocketAddress addr) { for (BPServiceActor actor : bpServices) { if (actor.getNNSocketAddress().equals(addr)) { return true; } } return false; }
private void connectToNNAndHandshake() throws IOException { // get NN proxy bpNamenode = dn.connectToNN(nnAddr); // First phase of the handshake with NN - get the namespace // info. NamespaceInfo nsInfo = retrieveNamespaceInfo(); // Verify that this matches the other NN in this HA pair. // This also initializes our block pool in the DN if we are // the first NN connection for this BP. bpos.verifyAndSetNamespaceInfo(nsInfo); // Second phase of the handshake with the NN. register(nsInfo); }
/** * Called by the DN to report an error to the NNs. */ void trySendErrorReport(int errCode, String errMsg) { for (BPServiceActor actor : bpServices) { ErrorReportAction errorReportAction = new ErrorReportAction (errCode, errMsg); actor.bpThreadEnqueue(errorReportAction); } }
/** * @return true if there is at least one actor thread running which is * talking to a NameNode. */ boolean isAlive() { for (BPServiceActor actor : bpServices) { if (actor.isAlive()) { return true; } } return false; }
BPOfferService( final String nameserviceId, List<InetSocketAddress> nnAddrs, List<InetSocketAddress> lifelineNnAddrs, DataNode dn) { Preconditions.checkArgument(!nnAddrs.isEmpty(), "Must pass at least one NN."); Preconditions.checkArgument(nnAddrs.size() == lifelineNnAddrs.size(), "Must pass same number of NN addresses and lifeline addresses."); this.nameserviceId = nameserviceId; this.dn = dn; for (int i = 0; i < nnAddrs.size(); ++i) { this.bpServices.add(new BPServiceActor(nnAddrs.get(i), lifelineNnAddrs.get(i), this)); } }
if (thisBpsa.getNNSocketAddress().equals(nn.getServiceRpcAddress())) { bpsa = thisBpsa; break; "No service actor to NN at %s", nn.getServiceRpcAddress()); DatanodeProtocolClientSideTranslatorPB origNN = bpsa.getNameNodeProxy(); DatanodeProtocolClientSideTranslatorPB spy = Mockito.spy(origNN); bpsa.setNameNode(spy); return spy;
@Test public void testDifferentLayoutVersions() throws Exception { // We expect no exceptions to be thrown when the layout versions match. assertEquals(HdfsConstants.NAMENODE_LAYOUT_VERSION, actor.retrieveNamespaceInfo().getLayoutVersion()); // We expect an exception to be thrown when the NN reports a layout version // different from that of the DN. doReturn(HdfsConstants.NAMENODE_LAYOUT_VERSION * 1000).when(fakeNsInfo) .getLayoutVersion(); try { actor.retrieveNamespaceInfo(); } catch (IOException e) { fail("Should not fail to retrieve NS info from DN with different layout version"); } } }
@Before public void setUp() throws IOException { mockDnConf = mock(DNConf.class); doReturn(VersionInfo.getVersion()).when(mockDnConf).getMinimumNameNodeVersion(); DataNode mockDN = mock(DataNode.class); doReturn(true).when(mockDN).shouldRun(); doReturn(mockDnConf).when(mockDN).getDnConf(); BPOfferService mockBPOS = mock(BPOfferService.class); doReturn(mockDN).when(mockBPOS).getDataNode(); actor = new BPServiceActor(INVALID_ADDR, mockBPOS); fakeNsInfo = mock(NamespaceInfo.class); // Return a a good software version. doReturn(VersionInfo.getVersion()).when(fakeNsInfo).getSoftwareVersion(); // Return a good layout version for now. doReturn(HdfsConstants.NAMENODE_LAYOUT_VERSION).when(fakeNsInfo) .getLayoutVersion(); DatanodeProtocolClientSideTranslatorPB fakeDnProt = mock(DatanodeProtocolClientSideTranslatorPB.class); when(fakeDnProt.versionRequest()).thenReturn(fakeNsInfo); actor.setNameNode(fakeDnProt); }
while (shouldRun()) { try { final long startTime = scheduler.monotonicNow(); HeartbeatResponse resp = sendHeartBeat(); assert resp != null; dn.getMetrics().addHeartbeat(scheduler.monotonicNow() - startTime); handleRollingUpgradeStatus(resp); if (!processCommand(resp.getCommands())) continue; long endProcessCommands = monotonicNow(); List<DatanodeCommand> cmds = blockReport(); processCommand(cmds == null ? null : cmds.toArray(new DatanodeCommand[cmds.size()])); DatanodeCommand cmd = cacheReport(); processCommand(new DatanodeCommand[]{ cmd }); LOG.warn("IOException in offerService", e); processQueueMessages();
connectToNNAndHandshake(); break; } catch (IOException ioe) { if (shouldRetryInit()) { sleepAndLogInterrupts(5000, "initializing"); } else { runningState = RunningState.FAILED; while (shouldRun()) { try { offerService(); } catch (Exception ex) { LOG.error("Exception in BPOfferService for " + this, ex); sleepAndLogInterrupts(5000, "offering service"); } finally { LOG.warn("Ending block pool service for: " + this); cleanUp();
void reRegister() throws IOException { if (shouldRun()) { // re-retrieve namespace info to make sure that, if the NN // was restarted, we still match its version (HDFS-2120) NamespaceInfo nsInfo = retrieveNamespaceInfo(); // and re-register register(nsInfo); scheduler.scheduleHeartbeat(); // HDFS-9917,Standby NN IBR can be very huge if standby namenode is down // for sometime. if (state == HAServiceState.STANDBY) { ibrManager.clearIBRs(); } } }
NamespaceInfo retrieveNamespaceInfo() throws IOException { NamespaceInfo nsInfo = null; while (shouldRun()) { try { nsInfo = bpNamenode.versionRequest(); sleepAndLogInterrupts(5000, "requesting version info from NN"); checkNNVersion(nsInfo); } else { throw new IOException("DN shut down before block pool connected");