Skip to content

Commit 7d9b7da

Browse files
committed
HDFS-6017. Query the status of rolling upgrade in the preparation stage in TestRollingUpgrade and TestRollingUpgradeRollback. (Contributed by Haohui Mai)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-5535@1571875 13f79535-47bb-0310-9956-ffa450edef68
1 parent 35b4af3 commit 7d9b7da

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,8 @@ HDFS-5535 subtasks:
9999
HDFS-5498. Improve datanode startup time. (kihwal)
100100

101101
HDFS-6000. Avoid saving namespace when starting rolling upgrade. (jing9)
102+
103+
HDFS-6017. Query the status of rolling upgrade in the preparation stage in
104+
TestRollingUpgrade and TestRollingUpgradeRollback. (Haohui Mai via
105+
Arpit Agarwal)
106+

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*/
1818
package org.apache.hadoop.hdfs;
1919

20+
import java.io.File;
21+
import java.io.IOException;
22+
2023
import org.apache.commons.logging.Log;
2124
import org.apache.commons.logging.LogFactory;
2225
import org.apache.hadoop.conf.Configuration;
@@ -30,15 +33,11 @@
3033
import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster;
3134
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
3235
import org.apache.hadoop.hdfs.server.datanode.DataNode;
33-
import org.apache.hadoop.hdfs.server.namenode.NNStorage;
36+
import org.apache.hadoop.hdfs.server.namenode.FSImage;
3437
import org.apache.hadoop.hdfs.tools.DFSAdmin;
3538
import org.junit.Assert;
3639
import org.junit.Test;
3740

38-
import java.io.File;
39-
import java.io.FilenameFilter;
40-
import java.io.IOException;
41-
4241

4342
/**
4443
* This class tests rolling upgrade.
@@ -384,32 +383,6 @@ public void testDowngrade() throws Exception {
384383
}
385384
}
386385

387-
public static boolean existRollbackFsImage(NNStorage storage)
388-
throws IOException {
389-
final FilenameFilter filter = new FilenameFilter() {
390-
@Override
391-
public boolean accept(File dir, String name) {
392-
return name.indexOf(NNStorage.NameNodeFile.IMAGE_ROLLBACK.getName()) != -1;
393-
}
394-
};
395-
final int total = 10;
396-
int retry = 0;
397-
while (retry++ < total) {
398-
for (int i = 0; i < storage.getNumStorageDirs(); i++) {
399-
File dir = storage.getStorageDir(i).getCurrentDir();
400-
int l = dir.list(filter).length;
401-
if (l > 0) {
402-
return true;
403-
}
404-
}
405-
try {
406-
Thread.sleep(1000);
407-
} catch (InterruptedException e) {
408-
}
409-
}
410-
return false;
411-
}
412-
413386
@Test (timeout = 300000)
414387
public void testFinalize() throws Exception {
415388
final Configuration conf = new HdfsConfiguration();
@@ -431,26 +404,42 @@ public void testFinalize() throws Exception {
431404
DistributedFileSystem dfs = dfsCluster.getFileSystem(0);
432405
dfs.mkdirs(foo);
433406

434-
NNStorage storage = dfsCluster.getNamesystem(0).getFSImage()
435-
.getStorage();
407+
FSImage fsimage = dfsCluster.getNamesystem(0).getFSImage();
436408

437409
// start rolling upgrade
438410
RollingUpgradeInfo info = dfs.rollingUpgrade(RollingUpgradeAction.PREPARE);
439411
Assert.assertTrue(info.isStarted());
440412
dfs.mkdirs(bar);
413+
414+
queryForPreparation(dfs);
415+
441416
// The NN should have a copy of the fsimage in case of rollbacks.
442-
Assert.assertTrue(existRollbackFsImage(storage));
417+
Assert.assertTrue(fsimage.hasRollbackFSImage());
443418

444419
info = dfs.rollingUpgrade(RollingUpgradeAction.FINALIZE);
445420
Assert.assertTrue(info.isFinalized());
446421
Assert.assertTrue(dfs.exists(foo));
447422

448423
// Once finalized, there should be no more fsimage for rollbacks.
449-
Assert.assertFalse(existRollbackFsImage(storage));
424+
Assert.assertFalse(fsimage.hasRollbackFSImage());
450425
} finally {
451426
if (cluster != null) {
452427
cluster.shutdown();
453428
}
454429
}
455430
}
431+
432+
static void queryForPreparation(DistributedFileSystem dfs) throws IOException,
433+
InterruptedException {
434+
RollingUpgradeInfo info;
435+
int retries = 0;
436+
while (retries < 10) {
437+
info = dfs.rollingUpgrade(RollingUpgradeAction.QUERY);
438+
if (info.createdRollbackImages()) {
439+
break;
440+
}
441+
Thread.sleep(1000);
442+
++retries;
443+
}
444+
}
456445
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeRollback.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,14 @@ public void testRollbackWithHAQJM() throws Exception {
228228
dfs.mkdirs(bar);
229229
dfs.close();
230230

231-
NNStorage storage0 = dfsCluster.getNameNode(0).getFSImage().getStorage();
232-
NNStorage storage1 = dfsCluster.getNameNode(1).getFSImage().getStorage();
233-
Assert.assertTrue(TestRollingUpgrade.existRollbackFsImage(storage0));
234-
Assert.assertTrue(TestRollingUpgrade.existRollbackFsImage(storage1));
231+
TestRollingUpgrade.queryForPreparation(dfs);
232+
233+
// If the query returns true, both active and the standby NN should have
234+
// rollback fsimage ready.
235+
Assert.assertTrue(dfsCluster.getNameNode(0).getFSImage()
236+
.hasRollbackFSImage());
237+
Assert.assertTrue(dfsCluster.getNameNode(1).getFSImage()
238+
.hasRollbackFSImage());
235239

236240
// rollback NN0
237241
dfsCluster.restartNameNode(0, true, "-rollingUpgrade",

0 commit comments

Comments
 (0)