Skip to content

Commit dfe7912

Browse files
committed
Add TestRollingUpgradeDowngrade.java for HDFS-6024
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-5535@1572434 13f79535-47bb-0310-9956-ffa450edef68
1 parent a90a202 commit dfe7912

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hdfs;
19+
20+
import static org.mockito.Mockito.doReturn;
21+
import static org.mockito.Mockito.spy;
22+
23+
import java.io.IOException;
24+
25+
import org.apache.hadoop.conf.Configuration;
26+
import org.apache.hadoop.fs.Path;
27+
import org.apache.hadoop.hdfs.protocol.HdfsConstants.RollingUpgradeAction;
28+
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
29+
import org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo;
30+
import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster;
31+
import org.apache.hadoop.hdfs.server.common.IncorrectVersionException;
32+
import org.apache.hadoop.hdfs.server.namenode.NNStorage;
33+
import org.apache.hadoop.hdfs.server.namenode.NameNodeLayoutVersion;
34+
import org.junit.Assert;
35+
import org.junit.Test;
36+
37+
public class TestRollingUpgradeDowngrade {
38+
39+
@Test(timeout = 300000)
40+
public void testDowngrade() throws IOException {
41+
final Configuration conf = new HdfsConfiguration();
42+
MiniQJMHACluster cluster = null;
43+
final Path foo = new Path("/foo");
44+
final Path bar = new Path("/bar");
45+
46+
try {
47+
cluster = new MiniQJMHACluster.Builder(conf).build();
48+
MiniDFSCluster dfsCluster = cluster.getDfsCluster();
49+
dfsCluster.waitActive();
50+
51+
dfsCluster.transitionToActive(0);
52+
DistributedFileSystem dfs = dfsCluster.getFileSystem(0);
53+
dfs.mkdirs(foo);
54+
55+
// start rolling upgrade
56+
RollingUpgradeInfo info = dfs
57+
.rollingUpgrade(RollingUpgradeAction.PREPARE);
58+
Assert.assertTrue(info.isStarted());
59+
dfs.mkdirs(bar);
60+
dfs.close();
61+
62+
dfsCluster.restartNameNode(0, true, "-rollingUpgrade", "downgrade");
63+
// shutdown NN1
64+
dfsCluster.shutdownNameNode(1);
65+
dfsCluster.transitionToActive(0);
66+
67+
dfs = dfsCluster.getFileSystem(0);
68+
Assert.assertTrue(dfs.exists(foo));
69+
Assert.assertTrue(dfs.exists(bar));
70+
} finally {
71+
if (cluster != null) {
72+
cluster.shutdown();
73+
}
74+
}
75+
}
76+
77+
/**
78+
* Ensure that during downgrade the NN fails to load a fsimage with newer
79+
* format.
80+
*/
81+
@Test(expected = IncorrectVersionException.class)
82+
public void testRejectNewFsImage() throws IOException {
83+
final Configuration conf = new Configuration();
84+
MiniDFSCluster cluster = null;
85+
try {
86+
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
87+
cluster.waitActive();
88+
DistributedFileSystem fs = cluster.getFileSystem();
89+
fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
90+
fs.saveNamespace();
91+
fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
92+
NNStorage storage = spy(cluster.getNameNode().getFSImage().getStorage());
93+
int futureVersion = NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION - 1;
94+
doReturn(futureVersion).when(storage).getServiceLayoutVersion();
95+
storage.writeAll();
96+
cluster.restartNameNode(0, true, "-rollingUpgrade", "downgrade");
97+
} finally {
98+
if (cluster != null) {
99+
cluster.shutdown();
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)