File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
hadoop-hdfs-project/hadoop-hdfs/src
main/java/org/apache/hadoop/hdfs/server/namenode
test/java/org/apache/hadoop/hdfs/server/namenode/ha Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -8953,9 +8953,15 @@ private boolean isObserver() {
89538953
89548954 private void checkBlockLocationsWhenObserver (LocatedBlocks blocks , String src )
89558955 throws ObserverRetryOnActiveException {
8956- for (LocatedBlock b : blocks .getLocatedBlocks ()) {
8957- if (b .getLocations () == null || b .getLocations ().length == 0 ) {
8958- throw new ObserverRetryOnActiveException ("Zero blocklocations for " + src );
8956+ if (blocks == null ) {
8957+ return ;
8958+ }
8959+ List <LocatedBlock > locatedBlockList = blocks .getLocatedBlocks ();
8960+ if (locatedBlockList != null ) {
8961+ for (LocatedBlock b : locatedBlockList ) {
8962+ if (b .getLocations () == null || b .getLocations ().length == 0 ) {
8963+ throw new ObserverRetryOnActiveException ("Zero blocklocations for " + src );
8964+ }
89598965 }
89608966 }
89618967 }
Original file line number Diff line number Diff line change @@ -652,6 +652,29 @@ public void run() {
652652 }
653653 }
654654
655+ @ Test
656+ public void testSimpleReadEmptyDirOrFile () throws IOException {
657+ // read empty dir
658+ dfs .mkdirs (new Path ("/emptyDir" ));
659+ assertSentTo (0 );
660+
661+ dfs .getClient ().listPaths ("/" , new byte [0 ], true );
662+ assertSentTo (2 );
663+
664+ dfs .getClient ().getLocatedFileInfo ("/emptyDir" , true );
665+ assertSentTo (2 );
666+
667+ // read empty file
668+ dfs .create (new Path ("/emptyFile" ), (short )1 );
669+ assertSentTo (0 );
670+
671+ dfs .getClient ().getLocatedFileInfo ("/emptyFile" , true );
672+ assertSentTo (2 );
673+
674+ dfs .getClient ().getBlockLocations ("/emptyFile" , 0 , 1 );
675+ assertSentTo (2 );
676+ }
677+
655678 private static void assertSentTo (DistributedFileSystem fs , int nnIdx )
656679 throws IOException {
657680 assertTrue ("Request was not sent to the expected namenode " + nnIdx ,
You can’t perform that action at this time.
0 commit comments