HDFS-16653. Improve error messages in ShortCircuitCache. (#5568). Contributed by ECFuzz.
Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
parent
441fb23293
commit
339bc7b3a6
|
@ -37,6 +37,7 @@ import org.apache.commons.collections.map.LinkedMap;
|
|||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.hdfs.ExtendedBlockId;
|
||||
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
|
||||
import org.apache.hadoop.hdfs.client.impl.DfsClientConf.ShortCircuitConf;
|
||||
import org.apache.hadoop.hdfs.net.DomainPeer;
|
||||
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
|
||||
|
@ -379,13 +380,17 @@ public class ShortCircuitCache implements Closeable {
|
|||
public ShortCircuitCache(int maxTotalSize, long maxNonMmappedEvictableLifespanMs,
|
||||
int maxEvictableMmapedSize, long maxEvictableMmapedLifespanMs,
|
||||
long mmapRetryTimeoutMs, long staleThresholdMs, int shmInterruptCheckMs) {
|
||||
Preconditions.checkArgument(maxTotalSize >= 0);
|
||||
Preconditions.checkArgument(maxTotalSize >= 0,
|
||||
"maxTotalSize must be greater than zero.");
|
||||
this.maxTotalSize = maxTotalSize;
|
||||
Preconditions.checkArgument(maxNonMmappedEvictableLifespanMs >= 0);
|
||||
Preconditions.checkArgument(maxNonMmappedEvictableLifespanMs >= 0,
|
||||
"maxNonMmappedEvictableLifespanMs must be greater than zero.");
|
||||
this.maxNonMmappedEvictableLifespanMs = maxNonMmappedEvictableLifespanMs;
|
||||
Preconditions.checkArgument(maxEvictableMmapedSize >= 0);
|
||||
Preconditions.checkArgument(maxEvictableMmapedSize >= 0,
|
||||
HdfsClientConfigKeys.Mmap.CACHE_SIZE_KEY + " must be greater than zero.");
|
||||
this.maxEvictableMmapedSize = maxEvictableMmapedSize;
|
||||
Preconditions.checkArgument(maxEvictableMmapedLifespanMs >= 0);
|
||||
Preconditions.checkArgument(maxEvictableMmapedLifespanMs >= 0,
|
||||
"maxEvictableMmapedLifespanMs must be greater than zero.");
|
||||
this.maxEvictableMmapedLifespanMs = maxEvictableMmapedLifespanMs;
|
||||
this.mmapRetryTimeoutMs = mmapRetryTimeoutMs;
|
||||
this.staleThresholdMs = staleThresholdMs;
|
||||
|
|
|
@ -80,6 +80,7 @@ import org.apache.hadoop.net.unix.TemporarySocketDirectory;
|
|||
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
|
||||
import org.apache.hadoop.security.token.Token;
|
||||
import org.apache.hadoop.test.GenericTestUtils;
|
||||
import org.apache.hadoop.test.LambdaTestUtils;
|
||||
import org.apache.hadoop.util.DataChecksum;
|
||||
import org.apache.hadoop.util.Time;
|
||||
import org.junit.Assert;
|
||||
|
@ -171,7 +172,23 @@ public class TestShortCircuitCache {
|
|||
new ShortCircuitCache(10, 1, 10, 1, 1, 10000, 0);
|
||||
cache.close();
|
||||
}
|
||||
|
||||
|
||||
@Test(timeout=5000)
|
||||
public void testInvalidConfiguration() throws Exception {
|
||||
LambdaTestUtils.intercept(IllegalArgumentException.class,
|
||||
"maxTotalSize must be greater than zero.",
|
||||
() -> new ShortCircuitCache(-1, 1, 10, 1, 1, 10000, 0));
|
||||
LambdaTestUtils.intercept(IllegalArgumentException.class,
|
||||
"maxNonMmappedEvictableLifespanMs must be greater than zero.",
|
||||
() -> new ShortCircuitCache(10, -1, 10, 1, 1, 10000, 0));
|
||||
LambdaTestUtils.intercept(IllegalArgumentException.class,
|
||||
"dfs.client.mmap.cache.size must be greater than zero.",
|
||||
() -> new ShortCircuitCache(10, 1, -1, 1, 1, 10000, 0));
|
||||
LambdaTestUtils.intercept(IllegalArgumentException.class,
|
||||
"maxEvictableMmapedLifespanMs must be greater than zero.",
|
||||
() -> new ShortCircuitCache(10, 1, 10, -1, 1, 10000, 0));
|
||||
}
|
||||
|
||||
@Test(timeout=60000)
|
||||
public void testAddAndRetrieve() throws Exception {
|
||||
final ShortCircuitCache cache =
|
||||
|
|
Loading…
Reference in New Issue