HDFS-15246. ArrayIndexOfboundsException in BlockManager CreateLocatedBlock. Contributed by Hemanth Boyina.
(cherry picked from commit 8b7695bb26
)
This commit is contained in:
parent
1148d3895f
commit
57d2fff84b
@ -655,8 +655,13 @@ private static class RenameOperation {
|
||||
// snapshot is taken on the dst tree, changes will be recorded in the
|
||||
// latest snapshot of the src tree.
|
||||
if (isSrcInSnapshot) {
|
||||
if (srcChild.isFile()) {
|
||||
INodeFile file = srcChild.asFile();
|
||||
file.recordModification(srcLatestSnapshotId, true);
|
||||
} else {
|
||||
srcChild.recordModification(srcLatestSnapshotId);
|
||||
}
|
||||
}
|
||||
|
||||
// check srcChild for reference
|
||||
srcRefDstSnapshot = srcChildIsReference ?
|
||||
|
@ -40,6 +40,7 @@
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.BlockLocation;
|
||||
import org.apache.hadoop.fs.ContentSummary;
|
||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
@ -70,6 +71,7 @@
|
||||
import org.apache.hadoop.util.ToolRunner;
|
||||
import org.slf4j.event.Level;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -1460,4 +1462,37 @@ public void testQuotaSpaceConsumedWithSnapshots() throws IOException {
|
||||
fs.getQuotaUsage(root).getSpaceConsumed());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test truncate on a snapshotted file.
|
||||
*/
|
||||
@Test
|
||||
public void testTruncatewithRenameandSnapshot() throws Exception {
|
||||
final Path dir = new Path("/dir");
|
||||
fs.mkdirs(dir, new FsPermission((short) 0777));
|
||||
final Path file = new Path(dir, "file");
|
||||
final Path movedFile = new Path("/file");
|
||||
|
||||
// 1. create a file and snapshot for dir which is having a file
|
||||
DFSTestUtil.createFile(fs, file, 10, (short) 3, 0);
|
||||
fs.allowSnapshot(dir);
|
||||
Path snapshotPath = fs.createSnapshot(dir, "s0");
|
||||
assertTrue(fs.exists(snapshotPath));
|
||||
|
||||
// 2. move the file
|
||||
fs.rename(file, new Path("/"));
|
||||
|
||||
// 3.truncate the moved file
|
||||
final boolean isReady = fs.truncate(movedFile, 5);
|
||||
if (!isReady) {
|
||||
checkBlockRecovery(movedFile);
|
||||
}
|
||||
FileStatus fileStatus = fs.getFileStatus(movedFile);
|
||||
assertEquals(5, fileStatus.getLen());
|
||||
|
||||
// 4. get block locations of file which is in snapshot
|
||||
LocatedBlocks locations = fs.getClient().getNamenode()
|
||||
.getBlockLocations("/dir/.snapshot/s0/file", 0, 10);
|
||||
assertEquals(10, locations.get(0).getBlockSize());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user