HDFS-8441. Erasure Coding: make condition check earlier for setReplication. (waltersu4549)
This commit is contained in:
parent
7af05a3db4
commit
3d734df24c
@ -250,3 +250,6 @@
|
|||||||
|
|
||||||
HDFS-8294. Erasure Coding: Fix Findbug warnings present in erasure coding.
|
HDFS-8294. Erasure Coding: Fix Findbug warnings present in erasure coding.
|
||||||
(Rakesh R via zhz)
|
(Rakesh R via zhz)
|
||||||
|
|
||||||
|
HDFS-8441. Erasure Coding: make condition check earlier for setReplication.
|
||||||
|
(waltersu4549)
|
||||||
|
@ -380,7 +380,7 @@ static INodeDirectory unprotectedSetQuota(
|
|||||||
static BlockInfoContiguous[] unprotectedSetReplication(
|
static BlockInfoContiguous[] unprotectedSetReplication(
|
||||||
FSDirectory fsd, String src, short replication, short[] blockRepls)
|
FSDirectory fsd, String src, short replication, short[] blockRepls)
|
||||||
throws QuotaExceededException, UnresolvedLinkException,
|
throws QuotaExceededException, UnresolvedLinkException,
|
||||||
SnapshotAccessControlException {
|
SnapshotAccessControlException, UnsupportedActionException {
|
||||||
assert fsd.hasWriteLock();
|
assert fsd.hasWriteLock();
|
||||||
|
|
||||||
final INodesInPath iip = fsd.getINodesInPath4Write(src, true);
|
final INodesInPath iip = fsd.getINodesInPath4Write(src, true);
|
||||||
@ -389,6 +389,11 @@ static BlockInfoContiguous[] unprotectedSetReplication(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
INodeFile file = inode.asFile();
|
INodeFile file = inode.asFile();
|
||||||
|
if (file.isStriped()) {
|
||||||
|
throw new UnsupportedActionException(
|
||||||
|
"Cannot set replication to a file with striped blocks");
|
||||||
|
}
|
||||||
|
|
||||||
final short oldBR = file.getPreferredBlockReplication();
|
final short oldBR = file.getPreferredBlockReplication();
|
||||||
|
|
||||||
// before setFileReplication, check for increasing block replication.
|
// before setFileReplication, check for increasing block replication.
|
||||||
|
@ -2404,7 +2404,18 @@ private HdfsFileStatus startFileInt(final String src,
|
|||||||
if (!DFSUtil.isValidName(src)) {
|
if (!DFSUtil.isValidName(src)) {
|
||||||
throw new InvalidPathException(src);
|
throw new InvalidPathException(src);
|
||||||
}
|
}
|
||||||
blockManager.verifyReplication(src, replication, clientMachine);
|
|
||||||
|
checkOperation(OperationCategory.READ);
|
||||||
|
readLock();
|
||||||
|
try {
|
||||||
|
checkOperation(OperationCategory.READ);
|
||||||
|
if (!isInECZone(src)) {
|
||||||
|
blockManager.verifyReplication(src, replication, clientMachine);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
readUnlock();
|
||||||
|
}
|
||||||
|
|
||||||
checkOperation(OperationCategory.WRITE);
|
checkOperation(OperationCategory.WRITE);
|
||||||
if (blockSize < minBlockSize) {
|
if (blockSize < minBlockSize) {
|
||||||
throw new IOException("Specified block size is less than configured" +
|
throw new IOException("Specified block size is less than configured" +
|
||||||
@ -7605,6 +7616,13 @@ void createErasureCodingZone(final String srcArg, final ECSchema schema,
|
|||||||
logAuditEvent(success, "createErasureCodingZone", srcArg, null, resultingStat);
|
logAuditEvent(success, "createErasureCodingZone", srcArg, null, resultingStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isInECZone(String src) throws IOException {
|
||||||
|
byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
|
||||||
|
src = FSDirectory.resolvePath(src, pathComponents, dir);
|
||||||
|
final INodesInPath iip = dir.getINodesInPath(src, true);
|
||||||
|
return dir.isInECZone(iip);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the erasure coding information for specified src
|
* Get the erasure coding information for specified src
|
||||||
*/
|
*/
|
||||||
|
@ -429,8 +429,6 @@ private void setFileReplication(short replication) {
|
|||||||
/** Set the replication factor of this file. */
|
/** Set the replication factor of this file. */
|
||||||
public final INodeFile setFileReplication(short replication,
|
public final INodeFile setFileReplication(short replication,
|
||||||
int latestSnapshotId) throws QuotaExceededException {
|
int latestSnapshotId) throws QuotaExceededException {
|
||||||
Preconditions.checkState(!isStriped(),
|
|
||||||
"Cannot set replication to a file with striped blocks");
|
|
||||||
recordModification(latestSnapshotId);
|
recordModification(latestSnapshotId);
|
||||||
setFileReplication(replication);
|
setFileReplication(replication);
|
||||||
return this;
|
return this;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.apache.hadoop.hdfs;
|
package org.apache.hadoop.hdfs;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.fs.permission.FsPermission;
|
import org.apache.hadoop.fs.permission.FsPermission;
|
||||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingInfo;
|
import org.apache.hadoop.hdfs.protocol.ErasureCodingInfo;
|
||||||
@ -35,6 +36,7 @@
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class TestErasureCodingZones {
|
public class TestErasureCodingZones {
|
||||||
|
private Configuration conf;
|
||||||
private MiniDFSCluster cluster;
|
private MiniDFSCluster cluster;
|
||||||
private DistributedFileSystem fs;
|
private DistributedFileSystem fs;
|
||||||
private static final int BLOCK_SIZE = 1024;
|
private static final int BLOCK_SIZE = 1024;
|
||||||
@ -42,7 +44,7 @@ public class TestErasureCodingZones {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setupCluster() throws IOException {
|
public void setupCluster() throws IOException {
|
||||||
Configuration conf = new HdfsConfiguration();
|
conf = new HdfsConfiguration();
|
||||||
conf.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE);
|
conf.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE);
|
||||||
cluster = new MiniDFSCluster.Builder(conf).
|
cluster = new MiniDFSCluster.Builder(conf).
|
||||||
numDataNodes(1).build();
|
numDataNodes(1).build();
|
||||||
@ -149,6 +151,26 @@ public void testMoveValidity() throws IOException, InterruptedException {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReplication() throws IOException {
|
||||||
|
final Path testDir = new Path("/ec");
|
||||||
|
fs.mkdir(testDir, FsPermission.getDirDefault());
|
||||||
|
fs.createErasureCodingZone(testDir, null, 0);
|
||||||
|
final Path fooFile = new Path(testDir, "foo");
|
||||||
|
// create ec file with replication=0
|
||||||
|
fs.create(fooFile, FsPermission.getFileDefault(), true,
|
||||||
|
conf.getInt(CommonConfigurationKeys.IO_FILE_BUFFER_SIZE_KEY, 4096),
|
||||||
|
(short)0, fs.getDefaultBlockSize(fooFile), null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.setReplication(fooFile, (short) 3);
|
||||||
|
fail("Shouldn't allow to set replication to a file with striped blocks");
|
||||||
|
} catch (IOException e) {
|
||||||
|
assertExceptionContains(
|
||||||
|
"Cannot set replication to a file with striped blocks", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetErasureCodingInfoWithSystemDefaultSchema() throws Exception {
|
public void testGetErasureCodingInfoWithSystemDefaultSchema() throws Exception {
|
||||||
String src = "/ec";
|
String src = "/ec";
|
||||||
|
Loading…
Reference in New Issue
Block a user