@@ -649,4 +649,182 @@ public void testFSImageWithDoubleRename() throws Exception {
649
649
fsn = cluster .getNamesystem ();
650
650
hdfs = cluster .getFileSystem ();
651
651
}
652
+
653
+
654
+ @ Test (timeout =60000 )
655
+ public void testFSImageWithRename1 () throws Exception {
656
+ final Path dir1 = new Path ("/dir1" );
657
+ final Path dir2 = new Path ("/dir2" );
658
+ hdfs .mkdirs (dir1 );
659
+ hdfs .mkdirs (dir2 );
660
+ Path dira = new Path (dir1 , "dira" );
661
+ Path dirx = new Path (dir1 , "dirx" );
662
+ Path dirb = new Path (dirx , "dirb" );
663
+ hdfs .mkdirs (dira );
664
+ hdfs .mkdirs (dirx );
665
+ hdfs .allowSnapshot (dir1 );
666
+ hdfs .createSnapshot (dir1 , "s0" );
667
+ hdfs .mkdirs (dirb );
668
+ hdfs .createSnapshot (dir1 , "s1" );
669
+ Path rennamePath = new Path (dira , "dirb" );
670
+ // mv /dir1/dirx/dirb to /dir1/dira/dirb
671
+ hdfs .rename (dirb , rennamePath );
672
+ hdfs .createSnapshot (dir1 , "s2" );
673
+ Path diry = new Path ("/dir1/dira/dirb/diry" );
674
+ hdfs .mkdirs (diry );
675
+ hdfs .createSnapshot (dir1 , "s3" );
676
+ Path file1 = new Path ("/dir1/dira/dirb/diry/file1" );
677
+ DFSTestUtil .createFile (hdfs , file1 , BLOCKSIZE , (short ) 1 , seed );
678
+ hdfs .createSnapshot (dir1 , "s4" );
679
+ hdfs .delete (new Path ("/dir1/dira/dirb" ), true );
680
+ hdfs .deleteSnapshot (dir1 , "s1" );
681
+ hdfs .deleteSnapshot (dir1 , "s3" );
682
+ // file1 should exist in the last snapshot
683
+ assertTrue (hdfs .exists (
684
+ new Path ("/dir1/.snapshot/s4/dira/dirb/diry/file1" )));
685
+
686
+ // save namespace and restart cluster
687
+ hdfs .setSafeMode (SafeModeAction .SAFEMODE_ENTER );
688
+ hdfs .saveNamespace ();
689
+ hdfs .setSafeMode (SafeModeAction .SAFEMODE_LEAVE );
690
+
691
+ cluster .shutdown ();
692
+ cluster = new MiniDFSCluster .Builder (conf ).format (false )
693
+ .numDataNodes (NUM_DATANODES ).build ();
694
+ cluster .waitActive ();
695
+ fsn = cluster .getNamesystem ();
696
+ hdfs = cluster .getFileSystem ();
697
+ }
698
+
699
+ @ Test (timeout =60000 )
700
+ public void testFSImageWithRename2 () throws Exception {
701
+ final Path dir1 = new Path ("/dir1" );
702
+ final Path dir2 = new Path ("/dir2" );
703
+ hdfs .mkdirs (dir1 );
704
+ hdfs .mkdirs (dir2 );
705
+ Path dira = new Path (dir1 , "dira" );
706
+ Path dirx = new Path (dir1 , "dirx" );
707
+ Path dirb = new Path (dirx , "dirb" );
708
+ hdfs .mkdirs (dira );
709
+ hdfs .mkdirs (dirx );
710
+ hdfs .allowSnapshot (dir1 );
711
+ hdfs .createSnapshot (dir1 , "s0" );
712
+ hdfs .mkdirs (dirb );
713
+ hdfs .createSnapshot (dir1 , "s1" );
714
+ Path rennamePath = new Path (dira , "dirb" );
715
+ // mv /dir1/dirx/dirb to /dir1/dira/dirb
716
+ hdfs .rename (dirb , rennamePath );
717
+ hdfs .createSnapshot (dir1 , "s2" );
718
+ Path file1 = new Path ("/dir1/dira/dirb/file1" );
719
+ DFSTestUtil .createFile (hdfs ,
720
+ new Path (
721
+ "/dir1/dira/dirb/file1" ), BLOCKSIZE , (short ) 1 , seed );
722
+ hdfs .createSnapshot (dir1 , "s3" );
723
+ hdfs .deleteSnapshot (dir1 , "s1" );
724
+ hdfs .deleteSnapshot (dir1 , "s3" );
725
+ assertTrue (hdfs .exists (file1 ));
726
+
727
+ // save namespace and restart cluster
728
+ hdfs .setSafeMode (SafeModeAction .SAFEMODE_ENTER );
729
+ hdfs .saveNamespace ();
730
+ hdfs .setSafeMode (SafeModeAction .SAFEMODE_LEAVE );
731
+
732
+ cluster .shutdown ();
733
+ cluster = new MiniDFSCluster .Builder (conf ).format (false )
734
+ .numDataNodes (NUM_DATANODES ).build ();
735
+ cluster .waitActive ();
736
+ fsn = cluster .getNamesystem ();
737
+ hdfs = cluster .getFileSystem ();
738
+ }
739
+
740
+ @ Test (timeout = 60000 )
741
+ public void testFSImageWithRename3 () throws Exception {
742
+ final Path dir1 = new Path ("/dir1" );
743
+ final Path dir2 = new Path ("/dir2" );
744
+ hdfs .mkdirs (dir1 );
745
+ hdfs .mkdirs (dir2 );
746
+ Path dira = new Path (dir1 , "dira" );
747
+ Path dirx = new Path (dir1 , "dirx" );
748
+ Path dirb = new Path (dirx , "dirb" );
749
+ hdfs .mkdirs (dira );
750
+ hdfs .mkdirs (dirx );
751
+ hdfs .allowSnapshot (dir1 );
752
+ hdfs .createSnapshot (dir1 , "s0" );
753
+ hdfs .mkdirs (dirb );
754
+ hdfs .createSnapshot (dir1 , "s1" );
755
+ Path rennamePath = new Path (dira , "dirb" );
756
+ // mv /dir1/dirx/dirb to /dir1/dira/dirb
757
+ hdfs .rename (dirb , rennamePath );
758
+ hdfs .createSnapshot (dir1 , "s2" );
759
+ Path diry = new Path ("/dir1/dira/dirb/diry" );
760
+ hdfs .mkdirs (diry );
761
+ hdfs .createSnapshot (dir1 , "s3" );
762
+ Path file1 = new Path ("/dir1/dira/dirb/diry/file1" );
763
+ DFSTestUtil .createFile (hdfs , file1 , BLOCKSIZE , (short ) 1 , seed );
764
+ hdfs .createSnapshot (dir1 , "s4" );
765
+ hdfs .delete (new Path ("/dir1/dira/dirb" ), true );
766
+ hdfs .deleteSnapshot (dir1 , "s1" );
767
+ hdfs .deleteSnapshot (dir1 , "s3" );
768
+ // file1 should exist in the last snapshot
769
+ assertTrue (hdfs .exists (new Path (
770
+ "/dir1/.snapshot/s4/dira/dirb/diry/file1" )));
771
+
772
+ // save namespace and restart cluster
773
+ hdfs .setSafeMode (SafeModeAction .SAFEMODE_ENTER );
774
+ hdfs .saveNamespace ();
775
+ hdfs .setSafeMode (SafeModeAction .SAFEMODE_LEAVE );
776
+
777
+ cluster .shutdown ();
778
+ cluster = new MiniDFSCluster .Builder (conf ).format (false )
779
+ .numDataNodes (NUM_DATANODES ).build ();
780
+ cluster .waitActive ();
781
+ fsn = cluster .getNamesystem ();
782
+ hdfs = cluster .getFileSystem ();
783
+ }
784
+
785
+ @ Test (timeout =60000 )
786
+ public void testFSImageWithRename4 () throws Exception {
787
+ final Path dir1 = new Path ("/dir1" );
788
+ final Path dir2 = new Path ("/dir2" );
789
+ hdfs .mkdirs (dir1 );
790
+ hdfs .mkdirs (dir2 );
791
+ Path dira = new Path (dir1 , "dira" );
792
+ Path dirx = new Path (dir1 , "dirx" );
793
+ Path dirb = new Path (dirx , "dirb" );
794
+ hdfs .mkdirs (dira );
795
+ hdfs .mkdirs (dirx );
796
+ hdfs .allowSnapshot (dir1 );
797
+ hdfs .createSnapshot (dir1 , "s0" );
798
+ hdfs .mkdirs (dirb );
799
+ hdfs .createSnapshot (dir1 , "s1" );
800
+ Path renamePath = new Path (dira , "dirb" );
801
+ // mv /dir1/dirx/dirb to /dir1/dira/dirb
802
+ hdfs .rename (dirb , renamePath );
803
+ hdfs .createSnapshot (dir1 , "s2" );
804
+ Path diry = new Path ("/dir1/dira/dirb/diry" );
805
+ hdfs .mkdirs (diry );
806
+ hdfs .createSnapshot (dir1 , "s3" );
807
+ Path file1 = new Path ("/dir1/dira/dirb/diry/file1" );
808
+ DFSTestUtil .createFile (hdfs , file1 , BLOCKSIZE , (short ) 1 , seed );
809
+ hdfs .createSnapshot (dir1 , "s4" );
810
+ hdfs .delete (new Path ("/dir1/dira/dirb/diry/file1" ), false );
811
+ hdfs .deleteSnapshot (dir1 , "s1" );
812
+ hdfs .deleteSnapshot (dir1 , "s3" );
813
+ // file1 should exist in the last snapshot
814
+ assertTrue (hdfs .exists (
815
+ new Path ("/dir1/.snapshot/s4/dira/dirb/diry/file1" )));
816
+
817
+ // save namespace and restart cluster
818
+ hdfs .setSafeMode (SafeModeAction .SAFEMODE_ENTER );
819
+ hdfs .saveNamespace ();
820
+ hdfs .setSafeMode (SafeModeAction .SAFEMODE_LEAVE );
821
+
822
+ cluster .shutdown ();
823
+ cluster = new MiniDFSCluster .Builder (conf ).format (false )
824
+ .numDataNodes (NUM_DATANODES ).build ();
825
+ cluster .waitActive ();
826
+ fsn = cluster .getNamesystem ();
827
+ hdfs = cluster .getFileSystem ();
828
+ }
829
+
652
830
}
0 commit comments