@Override // DatanodeProtocol public void commitBlockSynchronization(ExtendedBlock block, long newgenerationstamp, long newlength, boolean closeFile, boolean deleteblock, DatanodeID[] newtargets, String[] newtargetstorages) throws IOException { checkNNStartup(); namesystem.commitBlockSynchronization(block, newgenerationstamp, newlength, closeFile, deleteblock, newtargets, newtargetstorages); }
/** {@inheritDoc} */ public void commitBlockSynchronization(Block block, long newgenerationstamp, long newlength, boolean closeFile, boolean deleteblock, DatanodeID[] newtargets ) throws IOException { namesystem.commitBlockSynchronization(block, newgenerationstamp, newlength, closeFile, deleteblock, newtargets); }
/** {@inheritDoc} */ public void commitBlockSynchronization(Block block, long newgenerationstamp, long newlength, boolean closeFile, boolean deleteblock, DatanodeID[] newtargets ) throws IOException { namesystem.commitBlockSynchronization(block, newgenerationstamp, newlength, closeFile, deleteblock, newtargets); }
@Override // DatanodeProtocol public void commitBlockSynchronization(ExtendedBlock block, long newgenerationstamp, long newlength, boolean closeFile, boolean deleteblock, DatanodeID[] newtargets, String[] newtargetstorages) throws IOException { checkNNStartup(); namesystem.commitBlockSynchronization(block, newgenerationstamp, newlength, closeFile, deleteblock, newtargets, newtargetstorages); }
@Override // DatanodeProtocol public void commitBlockSynchronization(ExtendedBlock block, long newgenerationstamp, long newlength, boolean closeFile, boolean deleteblock, DatanodeID[] newtargets, String[] newtargetstorages) throws IOException { checkNNStartup(); namesystem.commitBlockSynchronization(block, newgenerationstamp, newlength, closeFile, deleteblock, newtargets, newtargetstorages); }
@Test public void testCommitBlockSynchronization_BlockNotFound () throws IOException { if(LOG.isDebugEnabled()) { LOG.debug("Running " + GenericTestUtils.getMethodName()); } long recoveryId = 2002; long newSize = 273487234; Path file = spy(new Path("/" + GenericTestUtils.getMethodName() + "_test.dat")); DatanodeDescriptor dnd = mock(DatanodeDescriptor.class); PermissionStatus ps = new PermissionStatus("test", "test", new FsPermission((short)0777)); mockFileBlocks(2, HdfsConstants.BlockUCState.COMMITTED, HdfsConstants.BlockUCState.UNDER_CONSTRUCTION, file, dnd, ps, false); BlockInfo lastBlock = fsn.dir.getFileINode(anyString()).getLastBlock(); try { fsn.commitBlockSynchronization(lastBlock, recoveryId, newSize, true, false, new DatanodeID[1]); } catch (IOException ioe) { assertTrue(ioe.getMessage().startsWith("Block (=")); } }
@Test public void testCommitBlockSynchronization_WrongLesserRecoveryID() throws IOException { if(LOG.isDebugEnabled()) { LOG.debug("Running " + GenericTestUtils.getMethodName()); } long recoveryId = 2002; long newSize = 273487234; Path file = spy(new Path("/" + GenericTestUtils.getMethodName() + "_test.dat")); DatanodeDescriptor dnd = mock(DatanodeDescriptor.class); PermissionStatus ps = new PermissionStatus("test", "test", new FsPermission((short)0777)); mockFileBlocks(2, HdfsConstants.BlockUCState.COMMITTED, HdfsConstants.BlockUCState.UNDER_CONSTRUCTION, file, dnd, ps, true); BlockInfo lastBlock = fsn.dir.getFileINode(anyString()).getLastBlock(); when(((BlockInfoUnderConstruction)lastBlock).getBlockRecoveryId()).thenReturn(recoveryId+100); try { fsn.commitBlockSynchronization(lastBlock, recoveryId, newSize, true, false, new DatanodeID[1]); } catch (IOException ioe) { assertTrue(ioe.getMessage().startsWith("The recovery id " + recoveryId + " does not match current recovery id " + (recoveryId+100))); } }
@Test public void testCommitBlockSynchronization_notUR () throws IOException { if(LOG.isDebugEnabled()) { LOG.debug("Running " + GenericTestUtils.getMethodName()); } long recoveryId = 2002; long newSize = 273487234; Path file = spy(new Path("/" + GenericTestUtils.getMethodName() + "_test.dat")); DatanodeDescriptor dnd = mock(DatanodeDescriptor.class); PermissionStatus ps = new PermissionStatus("test", "test", new FsPermission((short)0777)); mockFileBlocks(2, HdfsConstants.BlockUCState.COMMITTED, HdfsConstants.BlockUCState.COMPLETE, file, dnd, ps, true); BlockInfo lastBlock = fsn.dir.getFileINode(anyString()).getLastBlock(); when(lastBlock.isComplete()).thenReturn(true); try { fsn.commitBlockSynchronization(lastBlock, recoveryId, newSize, true, false, new DatanodeID[1]); } catch (IOException ioe) { assertTrue(ioe.getMessage().startsWith("Unexpected block (=")); } }
@Test public void testCommitBlockSynchronization_WrongGreaterRecoveryID() throws IOException { if(LOG.isDebugEnabled()) { LOG.debug("Running " + GenericTestUtils.getMethodName()); } long recoveryId = 2002; long newSize = 273487234; Path file = spy(new Path("/" + GenericTestUtils.getMethodName() + "_test.dat")); DatanodeDescriptor dnd = mock(DatanodeDescriptor.class); PermissionStatus ps = new PermissionStatus("test", "test", new FsPermission((short)0777)); mockFileBlocks(2, HdfsConstants.BlockUCState.COMMITTED, HdfsConstants.BlockUCState.UNDER_CONSTRUCTION, file, dnd, ps, true); BlockInfo lastBlock = fsn.dir.getFileINode(anyString()).getLastBlock(); when(((BlockInfoUnderConstruction)lastBlock).getBlockRecoveryId()).thenReturn(recoveryId-100); try { fsn.commitBlockSynchronization(lastBlock, recoveryId, newSize, true, false, new DatanodeID[1]); } catch (IOException ioe) { assertTrue(ioe.getMessage().startsWith("The recovery id " + recoveryId + " does not match current recovery id " + (recoveryId-100))); } }
@Test public void testCommitBlockSynchronization_EqualRecoveryID() throws IOException { if(LOG.isDebugEnabled()) { LOG.debug("Running " + GenericTestUtils.getMethodName()); } long recoveryId = 2002; long newSize = 273487234; Path file = spy(new Path("/" + GenericTestUtils.getMethodName() + "_test.dat")); DatanodeDescriptor dnd = mock(DatanodeDescriptor.class); PermissionStatus ps = new PermissionStatus("test", "test", new FsPermission((short)0777)); mockFileBlocks(2, HdfsConstants.BlockUCState.COMMITTED, HdfsConstants.BlockUCState.UNDER_CONSTRUCTION, file, dnd, ps, true); BlockInfo lastBlock = fsn.dir.getFileINode(anyString()).getLastBlock(); when(((BlockInfoUnderConstruction)lastBlock).getBlockRecoveryId()).thenReturn(recoveryId); boolean recoveryChecked = false; try { fsn.commitBlockSynchronization(lastBlock, recoveryId, newSize, true, false, new DatanodeID[1]); } catch (NullPointerException ioe) { // It is fine to get NPE here because the datanodes array is empty recoveryChecked = true; } assertTrue("commitBlockSynchronization had to throw NPE here", recoveryChecked); }
@Test public void testCommitBlockSynchronizationWithDelete() throws IOException { INodeFile file = mockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = makeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[0]; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, false, true, newTargets, null); // Simulate removing the last block from the file. doReturn(false).when(file).removeLastBlock(any(Block.class)); // Repeat the call to make sure it does not throw namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, false, true, newTargets, null); }
@Test public void testCommitBlockSynchronizationWithClose() throws IOException { INodeFile file = mockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = makeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[0]; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, true, false, newTargets, null); // Repeat the call to make sure it returns true namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, true, false, newTargets, null); BlockInfoContiguous completedBlockInfo = new BlockInfoContiguous(block, (short) 1); completedBlockInfo.setBlockCollection(file); completedBlockInfo.setGenerationStamp(genStamp); doReturn(completedBlockInfo).when(namesystemSpy) .getStoredBlock(any(Block.class)); doReturn(completedBlockInfo).when(file).getLastBlock(); namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, true, false, newTargets, null); }
@Test public void testCommitBlockSynchronization() throws IOException { INodeFile file = mockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = makeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[0]; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, false, false, newTargets, null); // Repeat the call to make sure it does not throw namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, false, false, newTargets, null); // Simulate 'completing' the block. BlockInfoContiguous completedBlockInfo = new BlockInfoContiguous(block, (short) 1); completedBlockInfo.setBlockCollection(file); completedBlockInfo.setGenerationStamp(genStamp); doReturn(completedBlockInfo).when(namesystemSpy) .getStoredBlock(any(Block.class)); doReturn(completedBlockInfo).when(file).getLastBlock(); // Repeat the call to make sure it does not throw namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, false, false, newTargets, null); }
@Test public void testCommitBlockSynchronizationWithCloseAndNonExistantTarget() throws IOException { INodeFile file = mockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = makeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[]{ new DatanodeID("0.0.0.0", "nonexistantHost", "1", 0, 0, 0, 0)}; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, true, false, newTargets, null); // Repeat the call to make sure it returns true namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, true, false, newTargets, null); } }
@Test public void testCommitBlockSynchronization2() throws IOException { INodeFile file = mockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = makeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[0]; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.commitBlockSynchronization( lastBlock, genStamp, length, false, false, newTargets, null); // Make sure the call fails if the generation stamp does not match // the block recovery ID. try { namesystemSpy.commitBlockSynchronization( lastBlock, genStamp - 1, length, false, false, newTargets, null); fail("Failed to get expected IOException on generation stamp/" + "recovery ID mismatch"); } catch (IOException ioe) { // Expected exception. } }