Skip to content

Commit 60b858b

Browse files
committed
HDFS-8656. Preserve compatibility of ClientProtocol#rollingUpgrade after finalization.
1 parent de480d6 commit 60b858b

File tree

6 files changed

+68
-19
lines changed

6 files changed

+68
-19
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,8 @@ public boolean restoreFailedStorage(String arg)
853853
/**
854854
* Rolling upgrade operations.
855855
* @param action either query, prepare or finalize.
856-
* @return rolling upgrade information.
856+
* @return rolling upgrade information. On query, if no upgrade is in
857+
* progress, returns null.
857858
*/
858859
@Idempotent
859860
public RollingUpgradeInfo rollingUpgrade(RollingUpgradeAction action)

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,9 @@ Release 2.7.1 - UNRELEASED
11101110
HDFS-8626. Reserved RBW space is not released if creation of RBW File
11111111
fails. (kanaka kumar avvaru via Arpit Agarwal)
11121112

1113+
HDFS08656. Preserve compatibility of ClientProtocol#rollingUpgrade after
1114+
finalization. (wang)
1115+
11131116
Release 2.7.0 - 2015-04-20
11141117

11151118
INCOMPATIBLE CHANGES

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6757,10 +6757,12 @@ RollingUpgradeInfo queryRollingUpgrade() throws IOException {
67576757
checkOperation(OperationCategory.READ);
67586758
readLock();
67596759
try {
6760-
if (rollingUpgradeInfo != null) {
6761-
boolean hasRollbackImage = this.getFSImage().hasRollbackFSImage();
6762-
rollingUpgradeInfo.setCreatedRollbackImages(hasRollbackImage);
6760+
if (!isRollingUpgrade()) {
6761+
return null;
67636762
}
6763+
Preconditions.checkNotNull(rollingUpgradeInfo);
6764+
boolean hasRollbackImage = this.getFSImage().hasRollbackFSImage();
6765+
rollingUpgradeInfo.setCreatedRollbackImages(hasRollbackImage);
67646766
return rollingUpgradeInfo;
67656767
} finally {
67666768
readUnlock();

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeMXBean.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ public interface NameNodeMXBean {
8181
public boolean isUpgradeFinalized();
8282

8383
/**
84-
* Gets the RollingUpgrade information
84+
* Gets the RollingUpgrade information.
8585
*
86-
* @return Rolling upgrade information
86+
* @return Rolling upgrade information if an upgrade is in progress. Else
87+
* (e.g. if there is no upgrade or the upgrade is finalized), returns null.
8788
*/
8889
public RollingUpgradeInfo.Bean getRollingUpgradeStatus();
8990

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

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@
1919

2020
import java.io.File;
2121
import java.io.IOException;
22+
import java.lang.management.ManagementFactory;
2223
import java.util.concurrent.ThreadLocalRandom;
2324

25+
import javax.management.AttributeNotFoundException;
26+
import javax.management.InstanceNotFoundException;
27+
import javax.management.MBeanException;
28+
import javax.management.MBeanServer;
29+
import javax.management.MalformedObjectNameException;
30+
import javax.management.ObjectName;
31+
import javax.management.ReflectionException;
32+
import javax.management.openmbean.CompositeDataSupport;
33+
2434
import org.apache.commons.logging.Log;
2535
import org.apache.commons.logging.LogFactory;
2636
import org.apache.hadoop.conf.Configuration;
@@ -45,7 +55,9 @@
4555
import org.junit.Assert;
4656
import org.junit.Test;
4757

48-
import static org.junit.Assert.assertTrue;
58+
import static org.junit.Assert.assertEquals;
59+
import static org.junit.Assert.assertNotEquals;
60+
import static org.junit.Assert.assertNull;
4961

5062
/**
5163
* This class tests rolling upgrade.
@@ -56,7 +68,7 @@ public class TestRollingUpgrade {
5668
public static void runCmd(DFSAdmin dfsadmin, boolean success,
5769
String... args) throws Exception {
5870
if (success) {
59-
Assert.assertEquals(0, dfsadmin.run(args));
71+
assertEquals(0, dfsadmin.run(args));
6072
} else {
6173
Assert.assertTrue(dfsadmin.run(args) != 0);
6274
}
@@ -86,6 +98,7 @@ public void testDFSAdminRollingUpgradeCommands() throws Exception {
8698
//illegal argument "abc" to rollingUpgrade option
8799
runCmd(dfsadmin, false, "-rollingUpgrade", "abc");
88100

101+
checkMxBeanIsNull();
89102
//query rolling upgrade
90103
runCmd(dfsadmin, true, "-rollingUpgrade");
91104

@@ -96,11 +109,16 @@ public void testDFSAdminRollingUpgradeCommands() throws Exception {
96109

97110
//query rolling upgrade
98111
runCmd(dfsadmin, true, "-rollingUpgrade", "query");
112+
checkMxBean();
99113

100114
dfs.mkdirs(bar);
101115

102116
//finalize rolling upgrade
103117
runCmd(dfsadmin, true, "-rollingUpgrade", "finalize");
118+
// RollingUpgradeInfo should be null after finalization, both via
119+
// Java API and in JMX
120+
assertNull(dfs.rollingUpgrade(RollingUpgradeAction.QUERY));
121+
checkMxBeanIsNull();
104122

105123
dfs.mkdirs(baz);
106124

@@ -197,7 +215,7 @@ public void testRollingUpgradeWithQJM() throws Exception {
197215
LOG.info("START\n" + info1);
198216

199217
//query rolling upgrade
200-
Assert.assertEquals(info1, dfs.rollingUpgrade(RollingUpgradeAction.QUERY));
218+
assertEquals(info1, dfs.rollingUpgrade(RollingUpgradeAction.QUERY));
201219

202220
dfs.mkdirs(bar);
203221
cluster.shutdown();
@@ -218,13 +236,13 @@ public void testRollingUpgradeWithQJM() throws Exception {
218236
Assert.assertFalse(dfs2.exists(baz));
219237

220238
//query rolling upgrade in cluster2
221-
Assert.assertEquals(info1, dfs2.rollingUpgrade(RollingUpgradeAction.QUERY));
239+
assertEquals(info1, dfs2.rollingUpgrade(RollingUpgradeAction.QUERY));
222240

223241
dfs2.mkdirs(baz);
224242

225243
LOG.info("RESTART cluster 2");
226244
cluster2.restartNameNode();
227-
Assert.assertEquals(info1, dfs2.rollingUpgrade(RollingUpgradeAction.QUERY));
245+
assertEquals(info1, dfs2.rollingUpgrade(RollingUpgradeAction.QUERY));
228246
Assert.assertTrue(dfs2.exists(foo));
229247
Assert.assertTrue(dfs2.exists(bar));
230248
Assert.assertTrue(dfs2.exists(baz));
@@ -238,7 +256,7 @@ public void testRollingUpgradeWithQJM() throws Exception {
238256

239257
LOG.info("RESTART cluster 2 again");
240258
cluster2.restartNameNode();
241-
Assert.assertEquals(info1, dfs2.rollingUpgrade(RollingUpgradeAction.QUERY));
259+
assertEquals(info1, dfs2.rollingUpgrade(RollingUpgradeAction.QUERY));
242260
Assert.assertTrue(dfs2.exists(foo));
243261
Assert.assertTrue(dfs2.exists(bar));
244262
Assert.assertTrue(dfs2.exists(baz));
@@ -259,8 +277,30 @@ public void testRollingUpgradeWithQJM() throws Exception {
259277
}
260278
}
261279

280+
private static CompositeDataSupport getBean()
281+
throws MalformedObjectNameException, MBeanException,
282+
AttributeNotFoundException, InstanceNotFoundException,
283+
ReflectionException {
284+
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
285+
ObjectName mxbeanName =
286+
new ObjectName("Hadoop:service=NameNode,name=NameNodeInfo");
287+
return (CompositeDataSupport)mbs.getAttribute(mxbeanName,
288+
"RollingUpgradeStatus");
289+
}
290+
291+
private static void checkMxBeanIsNull() throws Exception {
292+
CompositeDataSupport ruBean = getBean();
293+
assertNull(ruBean);
294+
}
295+
296+
private static void checkMxBean() throws Exception {
297+
CompositeDataSupport ruBean = getBean();
298+
assertNotEquals(0l, ruBean.get("startTime"));
299+
assertEquals(0l, ruBean.get("finalizeTime"));
300+
}
301+
262302
@Test
263-
public void testRollback() throws IOException {
303+
public void testRollback() throws Exception {
264304
// start a cluster
265305
final Configuration conf = new HdfsConfiguration();
266306
MiniDFSCluster cluster = null;
@@ -279,10 +319,13 @@ public void testRollback() throws IOException {
279319
out.write(data, 0, data.length);
280320
out.close();
281321

322+
checkMxBeanIsNull();
282323
startRollingUpgrade(foo, bar, file, data, cluster);
324+
checkMxBean();
283325
cluster.getFileSystem().rollEdits();
284326
cluster.getFileSystem().rollEdits();
285327
rollbackRollingUpgrade(foo, bar, file, data, cluster);
328+
checkMxBeanIsNull();
286329

287330
startRollingUpgrade(foo, bar, file, data, cluster);
288331
cluster.getFileSystem().rollEdits();
@@ -356,18 +399,18 @@ public void testDFSAdminDatanodeUpgradeControlCommands() throws Exception {
356399
// check the datanode
357400
final String dnAddr = dn.getDatanodeId().getIpcAddr(false);
358401
final String[] args1 = {"-getDatanodeInfo", dnAddr};
359-
Assert.assertEquals(0, dfsadmin.run(args1));
402+
runCmd(dfsadmin, true, args1);
360403

361404
// issue shutdown to the datanode.
362405
final String[] args2 = {"-shutdownDatanode", dnAddr, "upgrade" };
363-
Assert.assertEquals(0, dfsadmin.run(args2));
406+
runCmd(dfsadmin, true, args2);
364407

365408
// the datanode should be down.
366409
Thread.sleep(2000);
367410
Assert.assertFalse("DataNode should exit", dn.isDatanodeUp());
368411

369412
// ping should fail.
370-
Assert.assertEquals(-1, dfsadmin.run(args1));
413+
assertEquals(-1, dfsadmin.run(args1));
371414
} finally {
372415
if (cluster != null) cluster.shutdown();
373416
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.apache.hadoop.hdfs.MiniDFSCluster;
2929
import org.apache.hadoop.hdfs.server.datanode.DataNode;
3030
import org.apache.hadoop.hdfs.server.namenode.top.TopConf;
31-
import org.apache.hadoop.hdfs.server.namenode.top.window.RollingWindowManager;
3231
import org.apache.hadoop.io.nativeio.NativeIO;
3332
import org.apache.hadoop.io.nativeio.NativeIO.POSIX.NoMlockCacheManipulator;
3433
import org.apache.hadoop.util.VersionInfo;
@@ -46,8 +45,6 @@
4645
import java.util.Map;
4746
import java.util.concurrent.TimeUnit;
4847

49-
import static org.apache.hadoop.hdfs.server.namenode.top.window.RollingWindowManager.Op;
50-
import static org.apache.hadoop.hdfs.server.namenode.top.window.RollingWindowManager.TopWindow;
5148
import static org.junit.Assert.assertEquals;
5249
import static org.junit.Assert.assertNotNull;
5350
import static org.junit.Assert.assertNull;
@@ -197,6 +194,8 @@ public void testNameNodeMXBeanInfo() throws Exception {
197194
assertEquals(NativeIO.POSIX.getCacheManipulator().getMemlockLimit() *
198195
cluster.getDataNodes().size(),
199196
mbs.getAttribute(mxbeanName, "CacheCapacity"));
197+
assertNull("RollingUpgradeInfo should be null when there is no rolling"
198+
+ " upgrade", mbs.getAttribute(mxbeanName, "RollingUpgradeStatus"));
200199
} finally {
201200
if (cluster != null) {
202201
for (URI dir : cluster.getNameDirs(0)) {

0 commit comments

Comments
 (0)