|
@@ -64,7 +64,7 @@ public class TestLeaseRecovery2 extends junit.framework.TestCase {
|
|
|
//create a file
|
|
|
DistributedFileSystem dfs = (DistributedFileSystem)cluster.getFileSystem();
|
|
|
int size = AppendTestUtil.nextInt(FILE_SIZE);
|
|
|
- Path filepath = createFile(dfs, size, true);
|
|
|
+ Path filepath = createFile(dfs, size);
|
|
|
|
|
|
// set the soft limit to be 1 second so that the
|
|
|
// namenode triggers lease recovery on next attempt to write-for-open.
|
|
@@ -74,60 +74,59 @@ public class TestLeaseRecovery2 extends junit.framework.TestCase {
|
|
|
verifyFile(dfs, filepath, actual, size);
|
|
|
|
|
|
//test recoverLease
|
|
|
- // set the soft limit to be 1 hour but recoverLease should
|
|
|
- // close the file immediately
|
|
|
- cluster.setLeasePeriod(hardLease, hardLease);
|
|
|
size = AppendTestUtil.nextInt(FILE_SIZE);
|
|
|
- filepath = createFile(dfs, size, false);
|
|
|
+ filepath = createFile(dfs, size);
|
|
|
|
|
|
- // test recoverLese from a different client
|
|
|
- recoverLease(filepath, null);
|
|
|
- verifyFile(dfs, filepath, actual, size);
|
|
|
+ // set the soft limit to be 1 second so that the
|
|
|
+ // namenode triggers lease recovery on next attempt to write-for-open.
|
|
|
+ cluster.setLeasePeriod(softLease, hardLease);
|
|
|
|
|
|
- // test recoverlease from the same client
|
|
|
- size = AppendTestUtil.nextInt(FILE_SIZE);
|
|
|
- filepath = createFile(dfs, size, false);
|
|
|
-
|
|
|
- // create another file using the same client
|
|
|
- Path filepath1 = new Path("/foo" + AppendTestUtil.nextInt());
|
|
|
- FSDataOutputStream stm = dfs.create(filepath1, true,
|
|
|
- bufferSize, REPLICATION_NUM, BLOCK_SIZE);
|
|
|
-
|
|
|
- // recover the first file
|
|
|
- recoverLease(filepath, dfs);
|
|
|
+ recoverLease(filepath);
|
|
|
verifyFile(dfs, filepath, actual, size);
|
|
|
-
|
|
|
- // continue to write to the second file
|
|
|
- stm.write(buffer, 0, size);
|
|
|
- stm.close();
|
|
|
- verifyFile(dfs, filepath1, actual, size);
|
|
|
+
|
|
|
}
|
|
|
finally {
|
|
|
try {
|
|
|
- if (cluster != null) {cluster.getFileSystem().close(); cluster.shutdown();}
|
|
|
+ if (cluster != null) {cluster.shutdown();}
|
|
|
} catch (Exception e) {
|
|
|
// ignore
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void recoverLease(Path filepath, DistributedFileSystem dfs2) throws Exception {
|
|
|
- if (dfs2==null) {
|
|
|
- Configuration conf2 = new Configuration(conf);
|
|
|
- String username = UserGroupInformation.getCurrentUGI().getUserName()+"_1";
|
|
|
- UnixUserGroupInformation.saveToConf(conf2,
|
|
|
- UnixUserGroupInformation.UGI_PROPERTY_NAME,
|
|
|
- new UnixUserGroupInformation(username, new String[]{"supergroup"}));
|
|
|
- dfs2 = (DistributedFileSystem)FileSystem.get(conf2);
|
|
|
+ private void recoverLease(Path filepath) throws IOException {
|
|
|
+ Configuration conf2 = new Configuration(conf);
|
|
|
+ String username = UserGroupInformation.getCurrentUGI().getUserName()+"_1";
|
|
|
+ UnixUserGroupInformation.saveToConf(conf2,
|
|
|
+ UnixUserGroupInformation.UGI_PROPERTY_NAME,
|
|
|
+ new UnixUserGroupInformation(username, new String[]{"supergroup"}));
|
|
|
+ DistributedFileSystem dfs2 = (DistributedFileSystem)FileSystem.get(conf2);
|
|
|
+
|
|
|
+ boolean done = false;
|
|
|
+ while (!done) {
|
|
|
+ try {
|
|
|
+ dfs2.recoverLease(filepath);
|
|
|
+ done = true;
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ final String message = ioe.getMessage();
|
|
|
+ if (message.contains(AlreadyBeingCreatedException.class.getSimpleName())) {
|
|
|
+ AppendTestUtil.LOG.info("GOOD! got " + message);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ AppendTestUtil.LOG.warn("UNEXPECTED IOException", ioe);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!done) {
|
|
|
+ AppendTestUtil.LOG.info("sleep " + 1000 + "ms");
|
|
|
+ try {Thread.sleep(5000);} catch (InterruptedException e) {}
|
|
|
+ }
|
|
|
}
|
|
|
- dfs2.recoverLease(filepath);
|
|
|
- checkFileClose(dfs2, filepath);
|
|
|
}
|
|
|
|
|
|
// try to re-open the file before closing the previous handle. This
|
|
|
// should fail but will trigger lease recovery.
|
|
|
- private Path createFile(DistributedFileSystem dfs, int size,
|
|
|
- boolean triggerSoftLease) throws IOException, InterruptedException {
|
|
|
+ private Path createFile(DistributedFileSystem dfs, int size) throws IOException, InterruptedException {
|
|
|
// create a random file name
|
|
|
String filestr = "/foo" + AppendTestUtil.nextInt();
|
|
|
System.out.println("filestr=" + filestr);
|
|
@@ -143,15 +142,19 @@ public class TestLeaseRecovery2 extends junit.framework.TestCase {
|
|
|
// sync file
|
|
|
AppendTestUtil.LOG.info("sync");
|
|
|
stm.sync();
|
|
|
- if (triggerSoftLease) {
|
|
|
- AppendTestUtil.LOG.info("leasechecker.interruptAndJoin()");
|
|
|
- dfs.dfs.leasechecker.interruptAndJoin();
|
|
|
- }
|
|
|
+ AppendTestUtil.LOG.info("leasechecker.interruptAndJoin()");
|
|
|
+ dfs.dfs.leasechecker.interruptAndJoin();
|
|
|
return filepath;
|
|
|
}
|
|
|
|
|
|
- private void checkFileClose(FileSystem dfs2, Path filepath)
|
|
|
- throws IOException {
|
|
|
+ private void recoverLeaseUsingCreate(Path filepath) throws IOException {
|
|
|
+ Configuration conf2 = new Configuration(conf);
|
|
|
+ String username = UserGroupInformation.getCurrentUGI().getUserName()+"_1";
|
|
|
+ UnixUserGroupInformation.saveToConf(conf2,
|
|
|
+ UnixUserGroupInformation.UGI_PROPERTY_NAME,
|
|
|
+ new UnixUserGroupInformation(username, new String[]{"supergroup"}));
|
|
|
+ FileSystem dfs2 = FileSystem.get(conf2);
|
|
|
+
|
|
|
boolean done = false;
|
|
|
for(int i = 0; i < 10 && !done; i++) {
|
|
|
AppendTestUtil.LOG.info("i=" + i);
|
|
@@ -178,17 +181,7 @@ public class TestLeaseRecovery2 extends junit.framework.TestCase {
|
|
|
}
|
|
|
}
|
|
|
assertTrue(done);
|
|
|
- }
|
|
|
|
|
|
- private void recoverLeaseUsingCreate(Path filepath) throws IOException {
|
|
|
- Configuration conf2 = new Configuration(conf);
|
|
|
- String username = UserGroupInformation.getCurrentUGI().getUserName()+"_1";
|
|
|
- UnixUserGroupInformation.saveToConf(conf2,
|
|
|
- UnixUserGroupInformation.UGI_PROPERTY_NAME,
|
|
|
- new UnixUserGroupInformation(username, new String[]{"supergroup"}));
|
|
|
- FileSystem dfs2 = FileSystem.get(conf2);
|
|
|
-
|
|
|
- checkFileClose(dfs2, filepath);
|
|
|
}
|
|
|
|
|
|
private void verifyFile(FileSystem dfs, Path filepath, byte[] actual,
|