LocatedBlocks blocks = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), fileName.toString(), 0, (long)fileLen); assertEquals("Should only find 1 block", blocks.locatedBlockCount(), 1);
@Override public Boolean get() { try { LocatedBlocks locs = NameNodeAdapter.getBlockLocations(nn, path, 0, 1000); DatanodeInfo[] dnis = locs.getLastLocatedBlock().getLocations(); for (DatanodeInfo dni : dnis) { Assert.assertNotNull(dni); } int numReplicas = dnis.length; LOG.info("Got " + numReplicas + " locs: " + locs); if (numReplicas > expectedReplicas) { cluster.triggerDeletionReports(); } cluster.triggerHeartbeats(); return numReplicas == expectedReplicas; } catch (IOException e) { LOG.warn("No block locations yet: " + e.getMessage()); return false; } } }, 500, 20000);
/** Test to ensure metrics reflects missing blocks */ public void testMissingBlock() throws Exception { // Create a file with single block with two replicas Path file = getTestPath("testMissingBlocks"); createFile(file, 100, (short)1); // Corrupt the only replica of the block to result in a missing block LocatedBlock block = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), file.toString(), 0, 1).get(0); namesystem.markBlockAsCorrupt(block.getBlock(), block.getLocations()[0]); updateMetrics(); assertEquals(1, metrics.underReplicatedBlocks.get()); assertEquals(1, metrics.missingBlocks.get()); fs.delete(file, true); updateMetrics(); assertEquals(0, metrics.underReplicatedBlocks.get()); }
LocatedBlocks blocks = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), fileName.toString(), 0, (long)fileLen); assertEquals("Should only find 1 block", blocks.locatedBlockCount(), 1);
LocatedBlocks lbs = NameNodeAdapter.getBlockLocations(cluster.getNameNode(0), openFile, 0, fileSize);
fdos.hsync(); LocatedBlocks lbs = NameNodeAdapter.getBlockLocations( cluster.getNameNode(0), openFile, 0, fileSize);
/** Corrupt a block and ensure metrics reflects it */ public void testCorruptBlock() throws Exception { // Create a file with single block with two replicas final Path file = getTestPath("testCorruptBlock"); createFile(file, 100, (short)2); // Corrupt first replica of the block LocatedBlock block = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), file.toString(), 0, 1).get(0); namesystem.markBlockAsCorrupt(block.getBlock(), block.getLocations()[0]); updateMetrics(); assertEquals(1, metrics.corruptBlocks.get()); assertEquals(1, metrics.pendingReplicationBlocks.get()); assertEquals(1, metrics.scheduledReplicationBlocks.get()); fs.delete(file, true); updateMetrics(); assertEquals(0, metrics.corruptBlocks.get()); assertEquals(0, metrics.pendingReplicationBlocks.get()); assertEquals(0, metrics.scheduledReplicationBlocks.get()); }
final LocatedBlocks locatedblocks = NameNodeAdapter.getBlockLocations( namenode, f, 0, 1); final List<LocatedBlock> lb = locatedblocks.getLocatedBlocks();
DatanodeInfo[] lastBlockLocations = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), "/testRecoveryDecommission", 0, fileSize) .getLastLocatedBlock().getLocations();
LocatedBlocks oldBlocks = NameNodeAdapter.getBlockLocations( nn, file, 0, fileSize); assertBlocks(bm, oldBlocks, true); LocatedBlocks newBlocks = NameNodeAdapter.getBlockLocations( nn, file, 0, fileSize); assertBlocks(bm, newBlocks, true);
final LocatedBlocks locatedblocks = NameNodeAdapter.getBlockLocations( namenode, f, 0, 1); final List<LocatedBlock> lb = locatedblocks.getLocatedBlocks();
DFSTestUtil.createFile(dfs, dstPath, fileLen, replFactor, 1); LocatedBlocks lbs = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), dst, 0, fileLen); BlockManager bm = NameNodeAdapter.getNamesystem(cluster.getNameNode()).
/** Test to ensure metrics reflects missing blocks */ @Test public void testMissingBlock() throws Exception { // Create a file with single block with two replicas Path file = getTestPath("testMissingBlocks"); createFile(file, 100, (short)1); // Corrupt the only replica of the block to result in a missing block LocatedBlock block = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), file.toString(), 0, 1).get(0); cluster.getNamesystem().writeLock(); try { bm.findAndMarkBlockAsCorrupt(block.getBlock(), block.getLocations()[0], "STORAGE_ID", "TEST"); } finally { cluster.getNamesystem().writeUnlock(); } updateMetrics(); MetricsRecordBuilder rb = getMetrics(NS_METRICS); assertGauge("UnderReplicatedBlocks", 1L, rb); assertGauge("MissingBlocks", 1L, rb); assertGauge("MissingReplOneBlocks", 1L, rb); fs.delete(file, true); waitForDnMetricValue(NS_METRICS, "UnderReplicatedBlocks", 0L); }
LocatedBlock block = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), filePath.toString(), 0, 1).get(0); cluster.getNamesystem().writeLock();
/** Corrupt a block and ensure metrics reflects it */ @Test public void testCorruptBlock() throws Exception { // Create a file with single block with two replicas final Path file = getTestPath("testCorruptBlock"); createFile(file, 100, (short)2); // Corrupt first replica of the block LocatedBlock block = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), file.toString(), 0, 1).get(0); cluster.getNamesystem().writeLock(); try { bm.findAndMarkBlockAsCorrupt(block.getBlock(), block.getLocations()[0], "STORAGE_ID", "TEST"); } finally { cluster.getNamesystem().writeUnlock(); } updateMetrics(); MetricsRecordBuilder rb = getMetrics(NS_METRICS); assertGauge("CorruptBlocks", 1L, rb); assertGauge("PendingReplicationBlocks", 1L, rb); assertGauge("ScheduledReplicationBlocks", 1L, rb); fs.delete(file, true); rb = waitForDnMetricValue(NS_METRICS, "CorruptBlocks", 0L); assertGauge("PendingReplicationBlocks", 0L, rb); assertGauge("ScheduledReplicationBlocks", 0L, rb); }