|
@@ -274,7 +274,7 @@ public class TestObserverNode {
|
|
|
*/
|
|
|
@Test
|
|
|
public void testObserverNodeSafeModeWithBlockLocations() throws Exception {
|
|
|
-
|
|
|
+
|
|
|
// Create a new file - the request should go to active.
|
|
|
dfs.create(testPath, (short)1).close();
|
|
|
assertSentTo(0);
|
|
@@ -309,12 +309,51 @@ public class TestObserverNode {
|
|
|
dfs.open(testPath).close();
|
|
|
assertSentTo(0);
|
|
|
|
|
|
+ Mockito.reset(bmSpy);
|
|
|
+
|
|
|
// Remove safe mode on observer, request should still go to it.
|
|
|
dfsCluster.getFileSystem(2).setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
|
|
|
dfs.open(testPath).close();
|
|
|
assertSentTo(2);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testObserverNodeBlockMissingRetry() throws Exception {
|
|
|
+ setObserverRead(true);
|
|
|
+
|
|
|
+ dfs.create(testPath, (short)1).close();
|
|
|
+ assertSentTo(0);
|
|
|
+
|
|
|
+ dfsCluster.rollEditLogAndTail(0);
|
|
|
+
|
|
|
+ // Mock block manager for observer to generate some fake blocks which
|
|
|
+ // will trigger the block missing exception.
|
|
|
+
|
|
|
+ BlockManager bmSpy = NameNodeAdapter
|
|
|
+ .spyOnBlockManager(dfsCluster.getNameNode(2));
|
|
|
+ final DatanodeInfo[] empty = {};
|
|
|
+ Answer ans = new Answer() {
|
|
|
+ @Override
|
|
|
+ public LocatedBlocks answer(InvocationOnMock invocationOnMock) throws Throwable {
|
|
|
+ List<LocatedBlock> fakeBlocks = new ArrayList<>();
|
|
|
+ // Remove the datanode info for the only block so it will throw
|
|
|
+ // BlockMissingException and retry.
|
|
|
+ ExtendedBlock b = new ExtendedBlock("fake-pool", new Block(12345L));
|
|
|
+ LocatedBlock fakeBlock = new LocatedBlock(b, empty);
|
|
|
+ fakeBlocks.add(fakeBlock);
|
|
|
+ return new LocatedBlocks(0, false, fakeBlocks, null, true, null);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Mockito.doAnswer(ans).when(bmSpy).createLocatedBlocks((BlockInfoContiguous[])any(),
|
|
|
+ anyLong(), anyBoolean(), anyLong(), anyLong(), anyBoolean(),
|
|
|
+ anyBoolean(), (FileEncryptionInfo)any());
|
|
|
+
|
|
|
+ dfs.open(testPath);
|
|
|
+ assertSentTo(0);
|
|
|
+
|
|
|
+ Mockito.reset(bmSpy);
|
|
|
+ }
|
|
|
+
|
|
|
private void assertSentTo(int nnIdx) throws IOException {
|
|
|
assertTrue("Request was not sent to the expected namenode " + nnIdx,
|
|
|
HATestUtil.isSentToAnyOfNameNodes(dfs, dfsCluster, nnIdx));
|