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
This commit is contained in:
parent
e3d2e4c156
commit
9df1c533dc
|
@ -99,3 +99,8 @@ HDFS-5535 subtasks:
|
||||||
HDFS-5498. Improve datanode startup time. (kihwal)
|
HDFS-5498. Improve datanode startup time. (kihwal)
|
||||||
|
|
||||||
HDFS-6000. Avoid saving namespace when starting rolling upgrade. (jing9)
|
HDFS-6000. Avoid saving namespace when starting rolling upgrade. (jing9)
|
||||||
|
|
||||||
|
HDFS-6017. Query the status of rolling upgrade in the preparation stage in
|
||||||
|
TestRollingUpgrade and TestRollingUpgradeRollback. (Haohui Mai via
|
||||||
|
Arpit Agarwal)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hdfs;
|
package org.apache.hadoop.hdfs;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
@ -30,15 +33,11 @@ import org.apache.hadoop.hdfs.qjournal.MiniJournalCluster;
|
||||||
import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster;
|
import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster;
|
||||||
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
|
||||||
import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.NNStorage;
|
import org.apache.hadoop.hdfs.server.namenode.FSImage;
|
||||||
import org.apache.hadoop.hdfs.tools.DFSAdmin;
|
import org.apache.hadoop.hdfs.tools.DFSAdmin;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class tests rolling upgrade.
|
* This class tests rolling upgrade.
|
||||||
|
@ -384,32 +383,6 @@ public class TestRollingUpgrade {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean existRollbackFsImage(NNStorage storage)
|
|
||||||
throws IOException {
|
|
||||||
final FilenameFilter filter = new FilenameFilter() {
|
|
||||||
@Override
|
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.indexOf(NNStorage.NameNodeFile.IMAGE_ROLLBACK.getName()) != -1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
final int total = 10;
|
|
||||||
int retry = 0;
|
|
||||||
while (retry++ < total) {
|
|
||||||
for (int i = 0; i < storage.getNumStorageDirs(); i++) {
|
|
||||||
File dir = storage.getStorageDir(i).getCurrentDir();
|
|
||||||
int l = dir.list(filter).length;
|
|
||||||
if (l > 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test (timeout = 300000)
|
@Test (timeout = 300000)
|
||||||
public void testFinalize() throws Exception {
|
public void testFinalize() throws Exception {
|
||||||
final Configuration conf = new HdfsConfiguration();
|
final Configuration conf = new HdfsConfiguration();
|
||||||
|
@ -431,26 +404,42 @@ public class TestRollingUpgrade {
|
||||||
DistributedFileSystem dfs = dfsCluster.getFileSystem(0);
|
DistributedFileSystem dfs = dfsCluster.getFileSystem(0);
|
||||||
dfs.mkdirs(foo);
|
dfs.mkdirs(foo);
|
||||||
|
|
||||||
NNStorage storage = dfsCluster.getNamesystem(0).getFSImage()
|
FSImage fsimage = dfsCluster.getNamesystem(0).getFSImage();
|
||||||
.getStorage();
|
|
||||||
|
|
||||||
// start rolling upgrade
|
// start rolling upgrade
|
||||||
RollingUpgradeInfo info = dfs.rollingUpgrade(RollingUpgradeAction.PREPARE);
|
RollingUpgradeInfo info = dfs.rollingUpgrade(RollingUpgradeAction.PREPARE);
|
||||||
Assert.assertTrue(info.isStarted());
|
Assert.assertTrue(info.isStarted());
|
||||||
dfs.mkdirs(bar);
|
dfs.mkdirs(bar);
|
||||||
|
|
||||||
|
queryForPreparation(dfs);
|
||||||
|
|
||||||
// The NN should have a copy of the fsimage in case of rollbacks.
|
// The NN should have a copy of the fsimage in case of rollbacks.
|
||||||
Assert.assertTrue(existRollbackFsImage(storage));
|
Assert.assertTrue(fsimage.hasRollbackFSImage());
|
||||||
|
|
||||||
info = dfs.rollingUpgrade(RollingUpgradeAction.FINALIZE);
|
info = dfs.rollingUpgrade(RollingUpgradeAction.FINALIZE);
|
||||||
Assert.assertTrue(info.isFinalized());
|
Assert.assertTrue(info.isFinalized());
|
||||||
Assert.assertTrue(dfs.exists(foo));
|
Assert.assertTrue(dfs.exists(foo));
|
||||||
|
|
||||||
// Once finalized, there should be no more fsimage for rollbacks.
|
// Once finalized, there should be no more fsimage for rollbacks.
|
||||||
Assert.assertFalse(existRollbackFsImage(storage));
|
Assert.assertFalse(fsimage.hasRollbackFSImage());
|
||||||
} finally {
|
} finally {
|
||||||
if (cluster != null) {
|
if (cluster != null) {
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void queryForPreparation(DistributedFileSystem dfs) throws IOException,
|
||||||
|
InterruptedException {
|
||||||
|
RollingUpgradeInfo info;
|
||||||
|
int retries = 0;
|
||||||
|
while (retries < 10) {
|
||||||
|
info = dfs.rollingUpgrade(RollingUpgradeAction.QUERY);
|
||||||
|
if (info.createdRollbackImages()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Thread.sleep(1000);
|
||||||
|
++retries;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,10 +228,14 @@ public class TestRollingUpgradeRollback {
|
||||||
dfs.mkdirs(bar);
|
dfs.mkdirs(bar);
|
||||||
dfs.close();
|
dfs.close();
|
||||||
|
|
||||||
NNStorage storage0 = dfsCluster.getNameNode(0).getFSImage().getStorage();
|
TestRollingUpgrade.queryForPreparation(dfs);
|
||||||
NNStorage storage1 = dfsCluster.getNameNode(1).getFSImage().getStorage();
|
|
||||||
Assert.assertTrue(TestRollingUpgrade.existRollbackFsImage(storage0));
|
// If the query returns true, both active and the standby NN should have
|
||||||
Assert.assertTrue(TestRollingUpgrade.existRollbackFsImage(storage1));
|
// rollback fsimage ready.
|
||||||
|
Assert.assertTrue(dfsCluster.getNameNode(0).getFSImage()
|
||||||
|
.hasRollbackFSImage());
|
||||||
|
Assert.assertTrue(dfsCluster.getNameNode(1).getFSImage()
|
||||||
|
.hasRollbackFSImage());
|
||||||
|
|
||||||
// rollback NN0
|
// rollback NN0
|
||||||
dfsCluster.restartNameNode(0, true, "-rollingUpgrade",
|
dfsCluster.restartNameNode(0, true, "-rollingUpgrade",
|
||||||
|
|
Loading…
Reference in New Issue