|
@@ -47,7 +47,7 @@ public class TestFileCreation extends junit.framework.TestCase {
|
|
|
static final String DIR = "/" + TestFileCreation.class.getSimpleName() + "/";
|
|
|
|
|
|
{
|
|
|
- ((Log4JLogger)DataNode.LOG).getLogger().setLevel(Level.ALL);
|
|
|
+ //((Log4JLogger)DataNode.LOG).getLogger().setLevel(Level.ALL);
|
|
|
((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL);
|
|
|
((Log4JLogger)FSNamesystem.LOG).getLogger().setLevel(Level.ALL);
|
|
|
}
|
|
@@ -696,4 +696,99 @@ public class TestFileCreation extends junit.framework.TestCase {
|
|
|
|
|
|
System.out.println("testLeaseExpireHardLimit successful");
|
|
|
}
|
|
|
+
|
|
|
+ /** Test lease recovery Triggered by DFSClient. */
|
|
|
+ public void testClientTriggeredLeaseRecovery() throws Exception {
|
|
|
+ final int REPLICATION = 3;
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.setInt("dfs.datanode.handler.count", 1);
|
|
|
+ conf.setInt("dfs.replication", REPLICATION);
|
|
|
+ MiniDFSCluster cluster = new MiniDFSCluster(conf, REPLICATION, true, null);
|
|
|
+
|
|
|
+ try {
|
|
|
+ final FileSystem fs = cluster.getFileSystem();
|
|
|
+ final Path dir = new Path("/wrwelkj");
|
|
|
+
|
|
|
+ SlowWriter[] slowwriters = new SlowWriter[10];
|
|
|
+ for(int i = 0; i < slowwriters.length; i++) {
|
|
|
+ slowwriters[i] = new SlowWriter(fs, new Path(dir, "file" + i));
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ for(int i = 0; i < slowwriters.length; i++) {
|
|
|
+ slowwriters[i].start();
|
|
|
+ }
|
|
|
+
|
|
|
+ //stop a datanode, it should have least recover.
|
|
|
+ cluster.stopDataNode(new Random().nextInt(REPLICATION));
|
|
|
+
|
|
|
+ //let the slow writer writes a few more seconds
|
|
|
+ System.out.println("Wait a few seconds");
|
|
|
+ Thread.sleep(5000);
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ for(int i = 0; i < slowwriters.length; i++) {
|
|
|
+ if (slowwriters[i] != null) {
|
|
|
+ slowwriters[i].interrupt();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(int i = 0; i < slowwriters.length; i++) {
|
|
|
+ if (slowwriters[i] != null) {
|
|
|
+ slowwriters[i].join();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Verify the file
|
|
|
+ System.out.println("Verify the file");
|
|
|
+ for(int i = 0; i < slowwriters.length; i++) {
|
|
|
+ System.out.println(slowwriters[i].filepath + ": length="
|
|
|
+ + fs.getFileStatus(slowwriters[i].filepath).getLen());
|
|
|
+ FSDataInputStream in = null;
|
|
|
+ try {
|
|
|
+ in = fs.open(slowwriters[i].filepath);
|
|
|
+ for(int j = 0, x; (x = in.read()) != -1; j++) {
|
|
|
+ assertEquals(j, x);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ IOUtils.closeStream(in);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (cluster != null) {cluster.shutdown();}
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static class SlowWriter extends Thread {
|
|
|
+ final FileSystem fs;
|
|
|
+ final Path filepath;
|
|
|
+
|
|
|
+ SlowWriter(FileSystem fs, Path filepath) {
|
|
|
+ super(SlowWriter.class.getSimpleName() + ":" + filepath);
|
|
|
+ this.fs = fs;
|
|
|
+ this.filepath = filepath;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void run() {
|
|
|
+ FSDataOutputStream out = null;
|
|
|
+ int i = 0;
|
|
|
+ try {
|
|
|
+ out = fs.create(filepath);
|
|
|
+ for(; ; i++) {
|
|
|
+ System.out.println(getName() + " writes " + i);
|
|
|
+ out.write(i);
|
|
|
+ out.sync();
|
|
|
+ sleep(100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception e) {
|
|
|
+ System.out.println(getName() + " dies: e=" + e);
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ System.out.println(getName() + ": i=" + i);
|
|
|
+ IOUtils.closeStream(out);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|