1717 */
1818package org .apache .hadoop .hdfs ;
1919
20+ import java .io .File ;
21+ import java .io .IOException ;
22+
2023import org .apache .commons .logging .Log ;
2124import org .apache .commons .logging .LogFactory ;
2225import org .apache .hadoop .conf .Configuration ;
3033import org .apache .hadoop .hdfs .qjournal .MiniQJMHACluster ;
3134import org .apache .hadoop .hdfs .server .common .HdfsServerConstants .StartupOption ;
3235import 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 ;
3437import org .apache .hadoop .hdfs .tools .DFSAdmin ;
3538import org .junit .Assert ;
3639import 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}
0 commit comments