Skip to content
This repository
Browse code

Pass digestinputstream to loader instead of DIS in FSImage.loadImage()

Summary:
With this patch, I am passing a unwrapped digestinputstream istead of
datainputstream. There is a small thing that InputStream sometimes is
passed from outside (I think for snapshot code), and hence I need to
check if the digestinputstream is not null.

Test Plan: manually, with lzo codec

Reviewers: hkuang, pritam, weiyan

Reviewed By: weiyan
  • Loading branch information...
commit 20a5d4ab6df486c9c65d0373c2c6aad5b461d2c9 1 parent 583d5f3
authored Alex Feinberg committed
15  src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java
@@ -126,11 +126,11 @@ private void checkNotLoaded() {
126 126
       }
127 127
     }
128 128
 
129  
-    void load(File curFile, DataInputStream in)
130  
-      throws IOException
131  
-    {
  129
+    void load(File curFile, DataInputStream in) throws IOException {
132 130
       checkNotLoaded();
133  
-      assert curFile != null : "curFile is null";
  131
+      DigestInputStream fin = null;
  132
+      if (curFile == null )
  133
+        throw new IOException("curFile is null");
134 134
 
135 135
       long startTime = now();
136 136
 
@@ -142,9 +142,8 @@ void load(File curFile, DataInputStream in)
142 142
       if (in == null) {
143 143
         FileInputStream fis = new FileInputStream(curFile);
144 144
         digester = MD5Hash.getDigester();
145  
-        DigestInputStream fin = new DigestInputStream(
146  
-           fis, digester);
147  
-        in = new DataInputStream(fin); 
  145
+        fin = new DigestInputStream(fis, digester);
  146
+        in = new DataInputStream(fin);
148 147
       }     
149 148
       try {
150 149
         /*
@@ -195,7 +194,7 @@ void load(File curFile, DataInputStream in)
195 194
         } else {
196 195
           compression = FSImageCompression.createNoopCompression();
197 196
         }
198  
-        in = compression.unwrapInputStream(in);
  197
+        in = compression.unwrapInputStream(fin != null ? fin : in);
199 198
 
200 199
         LOG.info("Loading image file " + curFile + " using " + compression);
201 200
         

0 notes on commit 20a5d4a

Please sign in to comment.
Something went wrong with that request. Please try again.