|
@@ -22,6 +22,7 @@ import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.fs.permission.PermissionStatus;
|
|
import org.apache.hadoop.fs.permission.PermissionStatus;
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
|
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
|
|
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
|
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.mockito.invocation.InvocationOnMock;
|
|
import org.mockito.invocation.InvocationOnMock;
|
|
import org.mockito.stubbing.Answer;
|
|
import org.mockito.stubbing.Answer;
|
|
@@ -64,19 +65,28 @@ public class TestGetBlockLocations {
|
|
FSNamesystem fsn = spy(setupFileSystem());
|
|
FSNamesystem fsn = spy(setupFileSystem());
|
|
final FSDirectory fsd = fsn.getFSDirectory();
|
|
final FSDirectory fsd = fsn.getFSDirectory();
|
|
FSEditLog editlog = fsn.getEditLog();
|
|
FSEditLog editlog = fsn.getEditLog();
|
|
|
|
+ final boolean[] deleted = new boolean[]{false};
|
|
|
|
|
|
doAnswer(new Answer<Void>() {
|
|
doAnswer(new Answer<Void>() {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
|
- INodesInPath iip = fsd.getINodesInPath(FILE_PATH, DirOp.READ);
|
|
|
|
- FSDirDeleteOp.delete(fsd, iip, new INode.BlocksMapUpdateInfo(),
|
|
|
|
- new ArrayList<INode>(), new ArrayList<Long>(),
|
|
|
|
- now());
|
|
|
|
|
|
+ if(!deleted[0]) {
|
|
|
|
+ fsn.writeLock();
|
|
|
|
+ try {
|
|
|
|
+ INodesInPath iip = fsd.getINodesInPath(FILE_PATH, DirOp.READ);
|
|
|
|
+ FSDirDeleteOp.delete(fsd, iip, new INode.BlocksMapUpdateInfo(),
|
|
|
|
+ new ArrayList<INode>(), new ArrayList<Long>(),
|
|
|
|
+ now());
|
|
|
|
+ } finally {
|
|
|
|
+ fsn.writeUnlock();
|
|
|
|
+ }
|
|
|
|
+ deleted[0] = true;
|
|
|
|
+ }
|
|
invocation.callRealMethod();
|
|
invocation.callRealMethod();
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- }).when(fsn).writeLock();
|
|
|
|
|
|
+ }).when(fsn).checkOperation(OperationCategory.WRITE);
|
|
fsn.getBlockLocations("dummy", RESERVED_PATH, 0, 1024);
|
|
fsn.getBlockLocations("dummy", RESERVED_PATH, 0, 1024);
|
|
|
|
|
|
verify(editlog, never()).logTimes(anyString(), anyLong(), anyLong());
|
|
verify(editlog, never()).logTimes(anyString(), anyLong(), anyLong());
|
|
@@ -89,22 +99,27 @@ public class TestGetBlockLocations {
|
|
final FSDirectory fsd = fsn.getFSDirectory();
|
|
final FSDirectory fsd = fsn.getFSDirectory();
|
|
FSEditLog editlog = fsn.getEditLog();
|
|
FSEditLog editlog = fsn.getEditLog();
|
|
final String DST_PATH = "/bar";
|
|
final String DST_PATH = "/bar";
|
|
- final boolean[] renamed = new boolean[1];
|
|
|
|
|
|
+ final boolean[] renamed = new boolean[] {false};
|
|
|
|
|
|
doAnswer(new Answer<Void>() {
|
|
doAnswer(new Answer<Void>() {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
|
- invocation.callRealMethod();
|
|
|
|
if (!renamed[0]) {
|
|
if (!renamed[0]) {
|
|
- FSDirRenameOp.renameTo(fsd, fsd.getPermissionChecker(), FILE_PATH,
|
|
|
|
- DST_PATH, new INode.BlocksMapUpdateInfo(),
|
|
|
|
- false);
|
|
|
|
- renamed[0] = true;
|
|
|
|
|
|
+ fsn.writeLock();
|
|
|
|
+ try {
|
|
|
|
+ FSDirRenameOp.renameTo(fsd, fsd.getPermissionChecker(), FILE_PATH,
|
|
|
|
+ DST_PATH, new INode.BlocksMapUpdateInfo(),
|
|
|
|
+ false);
|
|
|
|
+ renamed[0] = true;
|
|
|
|
+ } finally {
|
|
|
|
+ fsn.writeUnlock();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ invocation.callRealMethod();
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- }).when(fsn).writeLock();
|
|
|
|
|
|
+ }).when(fsn).checkOperation(OperationCategory.WRITE);
|
|
fsn.getBlockLocations("dummy", RESERVED_PATH, 0, 1024);
|
|
fsn.getBlockLocations("dummy", RESERVED_PATH, 0, 1024);
|
|
|
|
|
|
verify(editlog).logTimes(eq(DST_PATH), anyLong(), anyLong());
|
|
verify(editlog).logTimes(eq(DST_PATH), anyLong(), anyLong());
|
|
@@ -119,8 +134,6 @@ public class TestGetBlockLocations {
|
|
when(image.getEditLog()).thenReturn(editlog);
|
|
when(image.getEditLog()).thenReturn(editlog);
|
|
final FSNamesystem fsn = new FSNamesystem(conf, image, true);
|
|
final FSNamesystem fsn = new FSNamesystem(conf, image, true);
|
|
|
|
|
|
- final FSDirectory fsd = fsn.getFSDirectory();
|
|
|
|
- INodesInPath iip = fsd.getINodesInPath("/", DirOp.READ);
|
|
|
|
PermissionStatus perm = new PermissionStatus(
|
|
PermissionStatus perm = new PermissionStatus(
|
|
"hdfs", "supergroup",
|
|
"hdfs", "supergroup",
|
|
FsPermission.createImmutable((short) 0x1ff));
|
|
FsPermission.createImmutable((short) 0x1ff));
|
|
@@ -128,7 +141,15 @@ public class TestGetBlockLocations {
|
|
MOCK_INODE_ID, FILE_NAME.getBytes(StandardCharsets.UTF_8),
|
|
MOCK_INODE_ID, FILE_NAME.getBytes(StandardCharsets.UTF_8),
|
|
perm, 1, 1, new BlockInfo[] {}, (short) 1,
|
|
perm, 1, 1, new BlockInfo[] {}, (short) 1,
|
|
DFS_BLOCK_SIZE_DEFAULT);
|
|
DFS_BLOCK_SIZE_DEFAULT);
|
|
- fsn.getFSDirectory().addINode(iip, file, null);
|
|
|
|
|
|
+
|
|
|
|
+ fsn.writeLock();
|
|
|
|
+ try {
|
|
|
|
+ final FSDirectory fsd = fsn.getFSDirectory();
|
|
|
|
+ INodesInPath iip = fsd.getINodesInPath("/", DirOp.READ);
|
|
|
|
+ fsd.addINode(iip, file, null);
|
|
|
|
+ } finally {
|
|
|
|
+ fsn.writeUnlock();
|
|
|
|
+ }
|
|
return fsn;
|
|
return fsn;
|
|
}
|
|
}
|
|
|
|
|