HDFS-3359. DFSClient.close should close cached sockets. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1333624 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9aae7c22ac
commit
25882b199b
|
@ -592,6 +592,8 @@ Release 2.0.0 - UNRELEASED
|
|||
HDFS-3351. NameNode#initializeGenericKeys should always set fs.defaultFS
|
||||
regardless of whether HA or Federation is enabled. (atm)
|
||||
|
||||
HDFS-3359. DFSClient.close should close cached sockets. (todd)
|
||||
|
||||
BREAKDOWN OF HDFS-1623 SUBTASKS
|
||||
|
||||
HDFS-2179. Add fencing framework and mechanisms for NameNode HA. (todd)
|
||||
|
|
|
@ -560,6 +560,7 @@ public class DFSClient implements java.io.Closeable {
|
|||
void abort() {
|
||||
clientRunning = false;
|
||||
closeAllFilesBeingWritten(true);
|
||||
socketCache.clear();
|
||||
closeConnectionToNamenode();
|
||||
}
|
||||
|
||||
|
@ -597,6 +598,7 @@ public class DFSClient implements java.io.Closeable {
|
|||
public synchronized void close() throws IOException {
|
||||
if(clientRunning) {
|
||||
closeAllFilesBeingWritten(false);
|
||||
socketCache.clear();
|
||||
clientRunning = false;
|
||||
leaserenewer.closeClient(this);
|
||||
// close connections to the namenode
|
||||
|
|
|
@ -85,6 +85,7 @@ public class TestDistributedFileSystem {
|
|||
/**
|
||||
* Tests DFSClient.close throws no ConcurrentModificationException if
|
||||
* multiple files are open.
|
||||
* Also tests that any cached sockets are closed. (HDFS-3359)
|
||||
*/
|
||||
@Test
|
||||
public void testDFSClose() throws Exception {
|
||||
|
@ -94,11 +95,23 @@ public class TestDistributedFileSystem {
|
|||
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
|
||||
FileSystem fileSys = cluster.getFileSystem();
|
||||
|
||||
// create two files
|
||||
// create two files, leaving them open
|
||||
fileSys.create(new Path("/test/dfsclose/file-0"));
|
||||
fileSys.create(new Path("/test/dfsclose/file-1"));
|
||||
|
||||
// create another file, close it, and read it, so
|
||||
// the client gets a socket in its SocketCache
|
||||
Path p = new Path("/non-empty-file");
|
||||
DFSTestUtil.createFile(fileSys, p, 1L, (short)1, 0L);
|
||||
DFSTestUtil.readFile(fileSys, p);
|
||||
|
||||
DFSClient client = ((DistributedFileSystem)fileSys).dfs;
|
||||
SocketCache cache = client.socketCache;
|
||||
assertEquals(1, cache.size());
|
||||
|
||||
fileSys.close();
|
||||
|
||||
assertEquals(0, cache.size());
|
||||
} finally {
|
||||
if (cluster != null) {cluster.shutdown();}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue