HDFS-6208. DataNode caching can leak file descriptors. Contributed by Chris Nauroth.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1586154 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8af0708580
commit
5c48f379ab
|
@ -359,6 +359,8 @@ Release 2.4.1 - UNRELEASED
|
||||||
HDFS-6209. TestValidateConfigurationSettings should use random ports.
|
HDFS-6209. TestValidateConfigurationSettings should use random ports.
|
||||||
(Arpit Agarwal via szetszwo)
|
(Arpit Agarwal via szetszwo)
|
||||||
|
|
||||||
|
HDFS-6208. DataNode caching can leak file descriptors. (cnauroth)
|
||||||
|
|
||||||
Release 2.4.0 - 2014-04-07
|
Release 2.4.0 - 2014-04-07
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -395,6 +395,8 @@ public class FsDatasetCache {
|
||||||
dataset.datanode.getMetrics().incrBlocksCached(1);
|
dataset.datanode.getMetrics().incrBlocksCached(1);
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
|
IOUtils.closeQuietly(blockIn);
|
||||||
|
IOUtils.closeQuietly(metaIn);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
if (reservedBytes) {
|
if (reservedBytes) {
|
||||||
newUsedBytes = usedBytesCount.release(length);
|
newUsedBytes = usedBytesCount.release(length);
|
||||||
|
@ -403,8 +405,6 @@ public class FsDatasetCache {
|
||||||
LOG.debug("Caching of " + key + " was aborted. We are now " +
|
LOG.debug("Caching of " + key + " was aborted. We are now " +
|
||||||
"caching only " + newUsedBytes + " + bytes in total.");
|
"caching only " + newUsedBytes + " + bytes in total.");
|
||||||
}
|
}
|
||||||
IOUtils.closeQuietly(blockIn);
|
|
||||||
IOUtils.closeQuietly(metaIn);
|
|
||||||
if (mappableBlock != null) {
|
if (mappableBlock != null) {
|
||||||
mappableBlock.close();
|
mappableBlock.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.nio.MappedByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.FileChannel.MapMode;
|
import java.nio.channels.FileChannel.MapMode;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.classification.InterfaceStability;
|
import org.apache.hadoop.classification.InterfaceStability;
|
||||||
import org.apache.hadoop.fs.ChecksumException;
|
import org.apache.hadoop.fs.ChecksumException;
|
||||||
|
@ -76,8 +77,9 @@ public class MappableBlock implements Closeable {
|
||||||
String blockFileName) throws IOException {
|
String blockFileName) throws IOException {
|
||||||
MappableBlock mappableBlock = null;
|
MappableBlock mappableBlock = null;
|
||||||
MappedByteBuffer mmap = null;
|
MappedByteBuffer mmap = null;
|
||||||
|
FileChannel blockChannel = null;
|
||||||
try {
|
try {
|
||||||
FileChannel blockChannel = blockIn.getChannel();
|
blockChannel = blockIn.getChannel();
|
||||||
if (blockChannel == null) {
|
if (blockChannel == null) {
|
||||||
throw new IOException("Block InputStream has no FileChannel.");
|
throw new IOException("Block InputStream has no FileChannel.");
|
||||||
}
|
}
|
||||||
|
@ -86,6 +88,7 @@ public class MappableBlock implements Closeable {
|
||||||
verifyChecksum(length, metaIn, blockChannel, blockFileName);
|
verifyChecksum(length, metaIn, blockChannel, blockFileName);
|
||||||
mappableBlock = new MappableBlock(mmap, length);
|
mappableBlock = new MappableBlock(mmap, length);
|
||||||
} finally {
|
} finally {
|
||||||
|
IOUtils.closeQuietly(blockChannel);
|
||||||
if (mappableBlock == null) {
|
if (mappableBlock == null) {
|
||||||
if (mmap != null) {
|
if (mmap != null) {
|
||||||
NativeIO.POSIX.munmap(mmap); // unmapping also unlocks
|
NativeIO.POSIX.munmap(mmap); // unmapping also unlocks
|
||||||
|
@ -108,7 +111,9 @@ public class MappableBlock implements Closeable {
|
||||||
BlockMetadataHeader.readHeader(new DataInputStream(
|
BlockMetadataHeader.readHeader(new DataInputStream(
|
||||||
new BufferedInputStream(metaIn, BlockMetadataHeader
|
new BufferedInputStream(metaIn, BlockMetadataHeader
|
||||||
.getHeaderSize())));
|
.getHeaderSize())));
|
||||||
FileChannel metaChannel = metaIn.getChannel();
|
FileChannel metaChannel = null;
|
||||||
|
try {
|
||||||
|
metaChannel = metaIn.getChannel();
|
||||||
if (metaChannel == null) {
|
if (metaChannel == null) {
|
||||||
throw new IOException("Block InputStream meta file has no FileChannel.");
|
throw new IOException("Block InputStream meta file has no FileChannel.");
|
||||||
}
|
}
|
||||||
|
@ -141,6 +146,9 @@ public class MappableBlock implements Closeable {
|
||||||
blockBuf.clear();
|
blockBuf.clear();
|
||||||
checksumBuf.clear();
|
checksumBuf.clear();
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(metaChannel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -147,6 +147,12 @@ public class TestCacheDirectives {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void teardown() throws Exception {
|
public void teardown() throws Exception {
|
||||||
|
// Remove cache directives left behind by tests so that we release mmaps.
|
||||||
|
RemoteIterator<CacheDirectiveEntry> iter = dfs.listCacheDirectives(null);
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
dfs.removeCacheDirective(iter.next().getInfo().getId());
|
||||||
|
}
|
||||||
|
waitForCachedBlocks(namenode, 0, 0, "teardown");
|
||||||
if (cluster != null) {
|
if (cluster != null) {
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue