|
@@ -33,13 +33,12 @@ import org.apache.hadoop.fs.Path;
|
|
|
*/
|
|
|
public class TestCheckpoint extends TestCase {
|
|
|
static final long seed = 0xDEADBEEFL;
|
|
|
- static final int blockSize = 8192;
|
|
|
- static final int fileSize = 16384;
|
|
|
- static final int numDatanodes = 4;
|
|
|
+ static final int blockSize = 4096;
|
|
|
+ static final int fileSize = 8192;
|
|
|
+ static final int numDatanodes = 1;
|
|
|
|
|
|
private void writeFile(FileSystem fileSys, Path name, int repl)
|
|
|
throws IOException {
|
|
|
- // create and write a file that contains three blocks of data
|
|
|
FSOutputStream stm = fileSys.createRaw(name, true, (short)repl,
|
|
|
(long)blockSize);
|
|
|
byte[] buffer = new byte[fileSize];
|
|
@@ -56,7 +55,7 @@ public class TestCheckpoint extends TestCase {
|
|
|
String[][] locations = fileSys.getFileCacheHints(name, 0, fileSize);
|
|
|
for (int idx = 0; idx < locations.length; idx++) {
|
|
|
assertEquals("Number of replicas for block" + idx,
|
|
|
- Math.min(numDatanodes, repl), locations[idx].length);
|
|
|
+ Math.min(numDatanodes, repl), locations[idx].length);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -111,8 +110,7 @@ public class TestCheckpoint extends TestCase {
|
|
|
//
|
|
|
removeOneNameDir(namedirs);
|
|
|
try {
|
|
|
- cluster = new MiniDFSCluster(65312, conf, numDatanodes,
|
|
|
- false, false);
|
|
|
+ cluster = new MiniDFSCluster(65312, conf, 1, 1);
|
|
|
assertTrue(false);
|
|
|
} catch (IOException e) {
|
|
|
// no nothing
|
|
@@ -126,15 +124,11 @@ public class TestCheckpoint extends TestCase {
|
|
|
private void testSecondaryNamenodeError1(Configuration conf)
|
|
|
throws IOException {
|
|
|
System.out.println("Starting testSecondaryNamenodeError 1");
|
|
|
- Path file1 = new Path("checkpoint.dat");
|
|
|
+ Path file1 = new Path("checkpointxx.dat");
|
|
|
MiniDFSCluster cluster = new MiniDFSCluster(65312, conf, numDatanodes,
|
|
|
false, false);
|
|
|
+ cluster.waitActive();
|
|
|
FileSystem fileSys = cluster.getFileSystem();
|
|
|
- try {
|
|
|
- Thread.sleep(15000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- // nothing
|
|
|
- }
|
|
|
try {
|
|
|
assertTrue(!fileSys.exists(file1));
|
|
|
//
|
|
@@ -155,8 +149,8 @@ public class TestCheckpoint extends TestCase {
|
|
|
//
|
|
|
// Create a new file
|
|
|
//
|
|
|
- writeFile(fileSys, file1, 3);
|
|
|
- checkFile(fileSys, file1, 3);
|
|
|
+ writeFile(fileSys, file1, 1);
|
|
|
+ checkFile(fileSys, file1, 1);
|
|
|
} finally {
|
|
|
fileSys.close();
|
|
|
cluster.shutdown();
|
|
@@ -170,14 +164,10 @@ public class TestCheckpoint extends TestCase {
|
|
|
System.out.println("Starting testSecondaryNamenodeError 2");
|
|
|
cluster = new MiniDFSCluster(65312, conf, numDatanodes,
|
|
|
false, false);
|
|
|
+ cluster.waitActive();
|
|
|
fileSys = cluster.getFileSystem();
|
|
|
try {
|
|
|
- Thread.sleep(15000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- // nothing
|
|
|
- }
|
|
|
- try {
|
|
|
- checkFile(fileSys, file1, 3);
|
|
|
+ checkFile(fileSys, file1, 1);
|
|
|
cleanupFile(fileSys, file1);
|
|
|
SecondaryNameNode secondary = new SecondaryNameNode(conf);
|
|
|
secondary.doCheckpoint();
|
|
@@ -194,15 +184,11 @@ public class TestCheckpoint extends TestCase {
|
|
|
private void testSecondaryNamenodeError2(Configuration conf)
|
|
|
throws IOException {
|
|
|
System.out.println("Starting testSecondaryNamenodeError 21");
|
|
|
- Path file1 = new Path("checkpoint.dat");
|
|
|
+ Path file1 = new Path("checkpointyy.dat");
|
|
|
MiniDFSCluster cluster = new MiniDFSCluster(65312, conf, numDatanodes,
|
|
|
false, false);
|
|
|
+ cluster.waitActive();
|
|
|
FileSystem fileSys = cluster.getFileSystem();
|
|
|
- try {
|
|
|
- Thread.sleep(15000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- // nothing
|
|
|
- }
|
|
|
try {
|
|
|
assertTrue(!fileSys.exists(file1));
|
|
|
//
|
|
@@ -223,8 +209,8 @@ public class TestCheckpoint extends TestCase {
|
|
|
//
|
|
|
// Create a new file
|
|
|
//
|
|
|
- writeFile(fileSys, file1, 3);
|
|
|
- checkFile(fileSys, file1, 3);
|
|
|
+ writeFile(fileSys, file1, 1);
|
|
|
+ checkFile(fileSys, file1, 1);
|
|
|
} finally {
|
|
|
fileSys.close();
|
|
|
cluster.shutdown();
|
|
@@ -238,14 +224,10 @@ public class TestCheckpoint extends TestCase {
|
|
|
System.out.println("Starting testSecondaryNamenodeError 22");
|
|
|
cluster = new MiniDFSCluster(65312, conf, numDatanodes,
|
|
|
false, false);
|
|
|
+ cluster.waitActive();
|
|
|
fileSys = cluster.getFileSystem();
|
|
|
try {
|
|
|
- Thread.sleep(15000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- // nothing
|
|
|
- }
|
|
|
- try {
|
|
|
- checkFile(fileSys, file1, 3);
|
|
|
+ checkFile(fileSys, file1, 1);
|
|
|
cleanupFile(fileSys, file1);
|
|
|
SecondaryNameNode secondary = new SecondaryNameNode(conf);
|
|
|
secondary.doCheckpoint();
|
|
@@ -256,7 +238,7 @@ public class TestCheckpoint extends TestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* Tests checkpoint in DFS.
|
|
|
*/
|
|
|
public void testCheckpoint() throws IOException {
|
|
@@ -266,15 +248,9 @@ public class TestCheckpoint extends TestCase {
|
|
|
|
|
|
Configuration conf = new Configuration();
|
|
|
MiniDFSCluster cluster = new MiniDFSCluster(65312, conf, numDatanodes, false);
|
|
|
+ cluster.waitActive();
|
|
|
FileSystem fileSys = cluster.getFileSystem();
|
|
|
|
|
|
- // Now wait for 15 seconds to give datanodes chance to register
|
|
|
- // themselves and to report heartbeat
|
|
|
- try {
|
|
|
- Thread.sleep(15000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- // nothing
|
|
|
- }
|
|
|
try {
|
|
|
//
|
|
|
// verify that 'format' really blew away all pre-existing files
|
|
@@ -286,8 +262,8 @@ public class TestCheckpoint extends TestCase {
|
|
|
//
|
|
|
// Create file1
|
|
|
//
|
|
|
- writeFile(fileSys, file1, 3);
|
|
|
- checkFile(fileSys, file1, 3);
|
|
|
+ writeFile(fileSys, file1, 1);
|
|
|
+ checkFile(fileSys, file1, 1);
|
|
|
|
|
|
//
|
|
|
// Take a checkpoint
|
|
@@ -304,20 +280,16 @@ public class TestCheckpoint extends TestCase {
|
|
|
// Restart cluster and verify that file1 still exist.
|
|
|
//
|
|
|
cluster = new MiniDFSCluster(65312, conf, numDatanodes, false, false);
|
|
|
+ cluster.waitActive();
|
|
|
fileSys = cluster.getFileSystem();
|
|
|
- try {
|
|
|
- Thread.sleep(15000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- // nothing
|
|
|
- }
|
|
|
try {
|
|
|
// check that file1 still exists
|
|
|
- checkFile(fileSys, file1, 3);
|
|
|
+ checkFile(fileSys, file1, 1);
|
|
|
cleanupFile(fileSys, file1);
|
|
|
|
|
|
// create new file file2
|
|
|
- writeFile(fileSys, file2, 3);
|
|
|
- checkFile(fileSys, file2, 3);
|
|
|
+ writeFile(fileSys, file2, 1);
|
|
|
+ checkFile(fileSys, file2, 1);
|
|
|
|
|
|
//
|
|
|
// Take a checkpoint
|
|
@@ -336,23 +308,19 @@ public class TestCheckpoint extends TestCase {
|
|
|
//
|
|
|
cluster = new MiniDFSCluster(65312, conf, numDatanodes, false, false);
|
|
|
fileSys = cluster.getFileSystem();
|
|
|
- try {
|
|
|
- Thread.sleep(15000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- // nothing
|
|
|
- }
|
|
|
|
|
|
assertTrue(!fileSys.exists(file1));
|
|
|
|
|
|
try {
|
|
|
// verify that file2 exists
|
|
|
- checkFile(fileSys, file2, 3);
|
|
|
- cleanupFile(fileSys, file2);
|
|
|
+ checkFile(fileSys, file2, 1);
|
|
|
} finally {
|
|
|
fileSys.close();
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
|
|
|
+ // file2 is left behind.
|
|
|
+
|
|
|
testSecondaryNamenodeError1(conf);
|
|
|
testSecondaryNamenodeError2(conf);
|
|
|
testNamedirError(conf, namedirs);
|