String getBlockPoolId() { return getBlockPoolId(false); }
boolean hasBlockPoolId() { return getBlockPoolId(true) != null; }
synchronized void addBlockPool(BPOfferService bpos) { Preconditions.checkArgument(offerServices.contains(bpos), "Unknown BPOS: %s", bpos); if (bpos.getBlockPoolId() == null) { throw new IllegalArgumentException("Null blockpool id"); } bpByBlockPoolId.put(bpos.getBlockPoolId(), bpos); }
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; }
private void checkBlock(ExtendedBlock block) { Preconditions.checkArgument(block != null, "block is null"); final String bpId = getBlockPoolId(); Preconditions.checkArgument(block.getBlockPoolId().equals(bpId), "block belongs to BP %s instead of BP %s", block.getBlockPoolId(), bpId); }
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"); } }
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); } }
Map<String, String> getActorInfoMap() { final Map<String, String> info = new HashMap<String, String>(); info.put("NamenodeAddress", getNameNodeAddress()); info.put("BlockPoolID", bpos.getBlockPoolId()); info.put("ActorState", getRunningState()); info.put("LastHeartbeat", String.valueOf(getScheduler().getLastHearbeatTime())); info.put("LastBlockReport", String.valueOf(getScheduler().getLastBlockReportTime())); info.put("maxBlockReportSize", String.valueOf(getMaxBlockReportSize())); info.put("maxDataLength", String.valueOf(maxDataLength)); return info; }
/** * 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); }
if (dn.isBlockTokenEnabled) { dn.blockPoolTokenSecretManager.addKeys( getBlockPoolId(), ((KeyUpdateCommand) cmd).getExportedKeys());
@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(); } }
DatanodeCommand cacheReport() throws IOException { // If caching is disabled, do not send a cache report if (dn.getFSDataset().getCacheCapacity() == 0) { return null; } // send cache report if timer has expired. DatanodeCommand cmd = null; final long startTime = monotonicNow(); if (startTime - lastCacheReport > dnConf.cacheReportInterval) { if (LOG.isDebugEnabled()) { LOG.debug("Sending cacheReport from service actor: " + this); } lastCacheReport = startTime; String bpid = bpos.getBlockPoolId(); List<Long> blockIds = dn.getFSDataset().getCacheReport(bpid); long createTime = monotonicNow(); cmd = bpNamenode.cacheReport(bpRegistration, bpid, blockIds); long sendTime = monotonicNow(); long createCost = createTime - startTime; long sendCost = sendTime - createTime; dn.getMetrics().addCacheReport(sendCost); if (LOG.isDebugEnabled()) { LOG.debug("CacheReport of " + blockIds.size() + " block(s) took " + createCost + " msec to generate and " + sendCost + " msecs for RPC and NN processing"); } } return cmd; }
bpos.getBlockPoolId()); dn.getFSDataset().getBlockReports(bpos.getBlockPoolId()); bpRegistration, bpos.getBlockPoolId(), reports, new BlockReportContext(1, 0, reportId, fullBrLeaseId, true)); blockReportSizes.add( StorageBlockReport singleReport[] = { reports[r] }; DatanodeCommand cmd = bpNamenode.blockReport( bpRegistration, bpos.getBlockPoolId(), singleReport, new BlockReportContext(reports.length, r, reportId, fullBrLeaseId, true));
/** * Remove the given block pool from the block scanner, dataset, and storage. */ void shutdownBlockPool(BPOfferService bpos) { blockPoolManager.remove(bpos); if (bpos.hasBlockPoolId()) { // Possible that this is shutting down before successfully // registering anywhere. If that's the case, we wouldn't have // a block pool id String bpId = bpos.getBlockPoolId(); blockScanner.disableBlockPoolId(bpId); if (data != null) { data.shutdownBlockPool(bpId); } if (storage != null) { storage.removeBlockPoolStorage(bpId); } } }
private void sendLifeline() throws IOException { StorageReport[] reports = dn.getFSDataset().getStorageReports(bpos.getBlockPoolId()); if (LOG.isDebugEnabled()) { LOG.debug("Sending lifeline with " + reports.length + " storage " + " reports from service actor: " + BPServiceActor.this); } VolumeFailureSummary volumeFailureSummary = dn.getFSDataset() .getVolumeFailureSummary(); int numFailedVolumes = volumeFailureSummary != null ? volumeFailureSummary.getFailedStorageLocations().length : 0; lifelineNamenode.sendLifeline(bpRegistration, reports, dn.getFSDataset().getCacheCapacity(), dn.getFSDataset().getCacheUsed(), dn.getXmitsInProgress(), dn.getXceiverCount(), numFailedVolumes, volumeFailureSummary); } }
/** * 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(); } }
/** * Signal the current rolling upgrade status as indicated by the NN. * @param rollingUpgradeStatus rolling upgrade status */ void signalRollingUpgrade(RollingUpgradeStatus rollingUpgradeStatus) throws IOException { if (rollingUpgradeStatus == null) { return; } String bpid = getBlockPoolId(); if (!rollingUpgradeStatus.isFinalized()) { dn.getFSDataset().enableTrash(bpid); dn.getFSDataset().setRollingUpgradeMarker(bpid); } else { dn.getFSDataset().clearTrash(bpid); dn.getFSDataset().clearRollingUpgradeMarker(bpid); } }
String bp = ((FinalizeCommand) cmd).getBlockPoolId(); LOG.info("Got finalize command for block pool " + bp); assert getBlockPoolId().equals(bp) : "BP " + getBlockPoolId() + " received DNA_FINALIZE " + "for other block pool " + bp; if (dn.isBlockTokenEnabled) { dn.blockPoolTokenSecretManager.addKeys( getBlockPoolId(), ((KeyUpdateCommand) cmd).getExportedKeys());
blockScanner.enableBlockPoolId(bpos.getBlockPoolId()); initDirectoryScanner(getConf()); initDiskBalancer(data, getConf());
scheduler.scheduleNextHeartbeat(); StorageReport[] reports = dn.getFSDataset().getStorageReports(bpos.getBlockPoolId()); if (LOG.isDebugEnabled()) { LOG.debug("Sending heartbeat with " + reports.length +