/** * Extracted out for test purposes. */ protected BPOfferService createBPOS( final String nameserviceId, List<InetSocketAddress> nnAddrs, List<InetSocketAddress> lifelineNnAddrs) { return new BPOfferService(nameserviceId, nnAddrs, lifelineNnAddrs, dn); } }
/** * Get the NameNode corresponding to the given block pool. * * @param bpid Block pool Id * @return Namenode corresponding to the bpid * @throws IOException if unable to get the corresponding NameNode */ DatanodeProtocolClientSideTranslatorPB getActiveNamenodeForBP( String bpid) throws IOException { BPOfferService bpos = datanode.getBPOfferService(bpid); if (bpos == null) { throw new IOException("No block pool offer service for bpid=" + bpid); } DatanodeProtocolClientSideTranslatorPB activeNN = bpos.getActiveNN(); if (activeNN == null) { throw new IOException( "Block pool " + bpid + " has not recognized an active NN"); } return activeNN; }
/** * Returned information is a JSON representation of a map with * name node host name as the key and block pool Id as the value. * Note that, if there are multiple NNs in an NA nameservice, * a given block pool may be represented twice. */ @Override // DataNodeMXBean public String getNamenodeAddresses() { final Map<String, String> info = new HashMap<String, String>(); for (BPOfferService bpos : blockPoolManager.getAllNamenodeThreads()) { if (bpos != null) { for (BPServiceActor actor : bpos.getBPServiceActors()) { info.put(actor.getNNSocketAddress().getHostName(), bpos.getBlockPoolId()); } } } return JSON.toString(info); }
boolean shouldRetryInit() { if (hasBlockPoolId()) { // One of the namenode registered successfully. lets continue retry for // other. return true; } return isAlive(); }
private String formatThreadName( final String action, final InetSocketAddress addr) { String bpId = bpos.getBlockPoolId(true); final String prefix = bpId != null ? bpId : bpos.getNameserviceId(); return prefix + " " + action + " to " + addr; }
public void testPickActiveNameNode() throws Exception { BPOfferService bpos = setupBPOSForNNs(mockNN1, mockNN2); bpos.start(); try { waitForInitialization(bpos); assertNull(bpos.getActiveNN()); bpos.triggerHeartbeatForTests(); assertSame(mockNN1, bpos.getActiveNN()); bpos.triggerHeartbeatForTests(); assertSame(mockNN2, bpos.getActiveNN()); bpos.triggerHeartbeatForTests(); assertSame(mockNN2, bpos.getActiveNN()); bpos.triggerHeartbeatForTests(); assertNull(bpos.getActiveNN()); bpos.triggerHeartbeatForTests(); assertSame(mockNN1, bpos.getActiveNN()); bpos.stop();
@Test public void testIBRClearanceForStandbyOnReRegister() throws Exception { final BPOfferService bpos = setupBPOSForNNs(mockNN1, mockNN2); bpos.start(); try { waitForInitialization(bpos); assertNull(bpos.getActiveNN()); bpos.triggerHeartbeatForTests(); assertSame(mockNN1, bpos.getActiveNN()); Mockito.doReturn(storage).when(mockFSDataset).getStorage("storage0"); bpos.notifyNamenodeReceivedBlock(FAKE_BLOCK, null, "storage0", false); bpos.triggerHeartbeatForTests(); "IBR size before reRegister should be non-0", 1, getStandbyIBRSize( bpos)); bpos.triggerHeartbeatForTests(); GenericTestUtils.waitFor(new Supplier<Boolean>() { @Override bpos.stop(); bpos.join();
/** * After one of the BPServiceActors registers successfully with the * NN, it calls this function to verify that the NN it connected to * is consistent with other NNs serving the block-pool. */ void registrationSucceeded(BPServiceActor bpServiceActor, DatanodeRegistration reg) throws IOException { writeLock(); try { if (bpRegistration != null) { checkNSEquality(bpRegistration.getStorageInfo().getNamespaceID(), reg.getStorageInfo().getNamespaceID(), "namespace ID"); checkNSEquality(bpRegistration.getStorageInfo().getClusterID(), reg.getStorageInfo().getClusterID(), "cluster ID"); } bpRegistration = reg; dn.bpRegistrationSucceeded(bpRegistration, getBlockPoolId()); // Add the initial block token secret keys to the DN's secret manager. if (dn.isBlockTokenEnabled) { dn.blockPoolTokenSecretManager.addKeys(getBlockPoolId(), reg.getExportedKeys()); } } finally { writeUnlock(); } }
String getBlockPoolId() { return getBlockPoolId(false); }
@Override public String toString() { readLock(); try { if (bpNSInfo == null) { // If we haven't yet connected to our NN, we don't yet know our // own block pool ID. // If _none_ of the block pools have connected yet, we don't even // know the DatanodeID ID of this DN. String datanodeUuid = dn.getDatanodeUuid(); if (datanodeUuid == null || datanodeUuid.isEmpty()) { datanodeUuid = "unassigned"; } return "Block pool <registering> (Datanode Uuid " + datanodeUuid + ")"; } else { return "Block pool " + getBlockPoolId() + " (Datanode Uuid " + dn.getDatanodeUuid() + ")"; } } finally { readUnlock(); } }
synchronized void remove(BPOfferService t) { offerServices.remove(t); if (t.hasBlockPoolId()) { // It's possible that the block pool never successfully registered // with any NN, so it was never added it to this map bpByBlockPoolId.remove(t.getBlockPoolId()); } boolean removed = false; for (Iterator<BPOfferService> it = bpByNameserviceId.values().iterator(); it.hasNext() && !removed;) { BPOfferService bpos = it.next(); if (bpos == t) { it.remove(); LOG.info("Removed " + bpos); removed = true; } } if (!removed) { LOG.warn("Couldn't remove BPOS " + t + " from bpByNameserviceId map"); } }
bpos.stop(); bpos.join(); ArrayList<InetSocketAddress> addrs = Lists.newArrayList(addrMap.get(nsToRefresh).values()); bpos.refreshNNList(addrs);
/** * A datanode is considered to be fully started if all the BP threads are * alive and all the block pools are initialized. * * @return true - if the data node is fully started */ public boolean isDatanodeFullyStarted() { for (BPOfferService bp : blockPoolManager.getAllNamenodeThreads()) { if (!bp.isInitialized() || !bp.isAlive()) { return false; } } return true; }
/** * Returned information is a JSON representation of an array, * each element of the array is a map contains the information * about a block pool service actor. */ @Override // DataNodeMXBean public String getBPServiceActorInfo() { final ArrayList<Map<String, String>> infoArray = new ArrayList<Map<String, String>>(); for (BPOfferService bpos : blockPoolManager.getAllNamenodeThreads()) { if (bpos != null) { for (BPServiceActor actor : bpos.getBPServiceActors()) { infoArray.add(actor.getActorInfoMap()); } } } return JSON.toString(infoArray); }
private void handleRollingUpgradeStatus(HeartbeatResponse resp) throws IOException { RollingUpgradeStatus rollingUpgradeStatus = resp.getRollingUpdateStatus(); if (rollingUpgradeStatus != null && rollingUpgradeStatus.getBlockPoolId().compareTo(bpos.getBlockPoolId()) != 0) { // Can this ever occur? LOG.error("Invalid BlockPoolId " + rollingUpgradeStatus.getBlockPoolId() + " in HeartbeatResponse. Expected " + bpos.getBlockPoolId()); } else { bpos.signalRollingUpgrade(rollingUpgradeStatus); } }
List<BPServiceActor> actors = bpos.getBPServiceActors(); assertEquals(2, actors.size()); bpos.start(); try { waitForInitialization(bpos); bpos.stop();
public void testBasicFunctionality() throws Exception { BPOfferService bpos = setupBPOSForNNs(mockNN1, mockNN2); bpos.start(); try { waitForInitialization(bpos); bpos.notifyNamenodeReceivedBlock(FAKE_BLOCK, null, "", false); bpos.stop();
/** * A data node is considered to be up if one of the bp services is up */ public boolean isDatanodeUp() { for (BPOfferService bp : blockPoolManager.getAllNamenodeThreads()) { if (bp.isAlive()) { return true; } } return false; }
return null; }).when(bpos).refreshNNList( Mockito.<ArrayList<InetSocketAddress>>any()); } catch (IOException e) { return null; }).when(bpos).stop(); return bpos;