|
@@ -19,21 +19,15 @@ package org.apache.hadoop.hdfs.server.namenode;
|
|
|
|
|
|
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
|
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
|
|
-import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
|
|
|
|
|
|
-import static org.mockito.Mockito.doAnswer;
|
|
|
-import static org.mockito.Mockito.spy;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
|
|
|
-import org.apache.commons.lang3.reflect.FieldUtils;
|
|
|
import org.apache.hadoop.fs.UnresolvedLinkException;
|
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.fs.permission.PermissionStatus;
|
|
|
-import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
|
import org.apache.hadoop.hdfs.protocol.Block;
|
|
|
import org.apache.hadoop.hdfs.protocol.BlockType;
|
|
|
import org.apache.hadoop.hdfs.protocol.DatanodeID;
|
|
@@ -47,7 +41,6 @@ import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.MkdirOp;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease;
|
|
|
-import org.apache.hadoop.hdfs.server.namenode.ha.EditLogTailer;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeCommand;
|
|
@@ -57,11 +50,6 @@ import org.apache.hadoop.ipc.Server;
|
|
|
import org.apache.hadoop.ipc.StandbyException;
|
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
|
import org.apache.hadoop.test.Whitebox;
|
|
|
-import org.mockito.ArgumentMatcher;
|
|
|
-import org.mockito.ArgumentMatchers;
|
|
|
-import org.mockito.Mockito;
|
|
|
-import org.mockito.invocation.InvocationOnMock;
|
|
|
-import org.mockito.stubbing.Answer;
|
|
|
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer.FSIMAGE_ATTRIBUTE_KEY;
|
|
|
|
|
@@ -269,97 +257,6 @@ public class NameNodeAdapter {
|
|
|
return fsn.getStoredBlock(b);
|
|
|
}
|
|
|
|
|
|
- public static FSNamesystem spyOnNamesystem(NameNode nn) {
|
|
|
- FSNamesystem fsnSpy = Mockito.spy(nn.getNamesystem());
|
|
|
- FSNamesystem fsnOld = nn.namesystem;
|
|
|
- fsnOld.writeLock();
|
|
|
- fsnSpy.writeLock();
|
|
|
- nn.namesystem = fsnSpy;
|
|
|
- try {
|
|
|
- FieldUtils.writeDeclaredField(
|
|
|
- (NameNodeRpcServer)nn.getRpcServer(), "namesystem", fsnSpy, true);
|
|
|
- FieldUtils.writeDeclaredField(
|
|
|
- fsnSpy.getBlockManager(), "namesystem", fsnSpy, true);
|
|
|
- FieldUtils.writeDeclaredField(
|
|
|
- fsnSpy.getLeaseManager(), "fsnamesystem", fsnSpy, true);
|
|
|
- FieldUtils.writeDeclaredField(
|
|
|
- fsnSpy.getBlockManager().getDatanodeManager(),
|
|
|
- "namesystem", fsnSpy, true);
|
|
|
- FieldUtils.writeDeclaredField(
|
|
|
- BlockManagerTestUtil.getHeartbeatManager(fsnSpy.getBlockManager()),
|
|
|
- "namesystem", fsnSpy, true);
|
|
|
- } catch (IllegalAccessException e) {
|
|
|
- throw new RuntimeException("Cannot set spy FSNamesystem", e);
|
|
|
- } finally {
|
|
|
- fsnSpy.writeUnlock();
|
|
|
- fsnOld.writeUnlock();
|
|
|
- }
|
|
|
- return fsnSpy;
|
|
|
- }
|
|
|
-
|
|
|
- public static BlockManager spyOnBlockManager(NameNode nn) {
|
|
|
- BlockManager bmSpy = Mockito.spy(nn.getNamesystem().getBlockManager());
|
|
|
- nn.getNamesystem().setBlockManagerForTesting(bmSpy);
|
|
|
- return bmSpy;
|
|
|
- }
|
|
|
-
|
|
|
- public static ReentrantReadWriteLock spyOnFsLock(FSNamesystem fsn) {
|
|
|
- ReentrantReadWriteLock spy = Mockito.spy(fsn.getFsLockForTests());
|
|
|
- fsn.setFsLockForTests(spy);
|
|
|
- return spy;
|
|
|
- }
|
|
|
-
|
|
|
- public static FSImage spyOnFsImage(NameNode nn1) {
|
|
|
- FSNamesystem fsn = nn1.getNamesystem();
|
|
|
- FSImage spy = Mockito.spy(fsn.getFSImage());
|
|
|
- Whitebox.setInternalState(fsn, "fsImage", spy);
|
|
|
- return spy;
|
|
|
- }
|
|
|
-
|
|
|
- public static FSEditLog spyOnEditLog(NameNode nn) {
|
|
|
- FSEditLog spyEditLog = spy(nn.getNamesystem().getFSImage().getEditLog());
|
|
|
- DFSTestUtil.setEditLogForTesting(nn.getNamesystem(), spyEditLog);
|
|
|
- EditLogTailer tailer = nn.getNamesystem().getEditLogTailer();
|
|
|
- if (tailer != null) {
|
|
|
- tailer.setEditLog(spyEditLog);
|
|
|
- }
|
|
|
- return spyEditLog;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Spy on EditLog to delay execution of doEditTransaction() for MkdirOp.
|
|
|
- */
|
|
|
- public static FSEditLog spyDelayMkDirTransaction(
|
|
|
- final NameNode nn, final long delay) {
|
|
|
- FSEditLog realEditLog = nn.getFSImage().getEditLog();
|
|
|
- FSEditLogAsync spyEditLog = (FSEditLogAsync) spy(realEditLog);
|
|
|
- DFSTestUtil.setEditLogForTesting(nn.getNamesystem(), spyEditLog);
|
|
|
- Answer<Boolean> ans = new Answer<Boolean>() {
|
|
|
- @Override
|
|
|
- public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
|
|
- Thread.sleep(delay);
|
|
|
- return (Boolean) invocation.callRealMethod();
|
|
|
- }
|
|
|
- };
|
|
|
- ArgumentMatcher<FSEditLogOp> am = new ArgumentMatcher<FSEditLogOp>() {
|
|
|
- @Override
|
|
|
- public boolean matches(FSEditLogOp argument) {
|
|
|
- FSEditLogOp op = (FSEditLogOp) argument;
|
|
|
- return op.opCode == FSEditLogOpCodes.OP_MKDIR;
|
|
|
- }
|
|
|
- };
|
|
|
- doAnswer(ans).when(spyEditLog).doEditTransaction(
|
|
|
- ArgumentMatchers.argThat(am));
|
|
|
- return spyEditLog;
|
|
|
- }
|
|
|
-
|
|
|
- public static JournalSet spyOnJournalSet(NameNode nn) {
|
|
|
- FSEditLog editLog = nn.getFSImage().getEditLog();
|
|
|
- JournalSet js = Mockito.spy(editLog.getJournalSet());
|
|
|
- editLog.setJournalSetForTesting(js);
|
|
|
- return js;
|
|
|
- }
|
|
|
-
|
|
|
public static String getMkdirOpPath(FSEditLogOp op) {
|
|
|
if (op.opCode == FSEditLogOpCodes.OP_MKDIR) {
|
|
|
return ((MkdirOp) op).path;
|