]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Hadoop: Don't throw IOExceptions on extra calls to close
authorGreg Farnum <gregf@hq.newdream.net>
Sat, 31 Oct 2009 01:39:48 +0000 (18:39 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Tue, 3 Nov 2009 00:38:15 +0000 (16:38 -0800)
src/client/hadoop/ceph/CephInputStream.java
src/client/hadoop/ceph/CephOutputStream.java

index 15ea48abf0651fbace3706ac41c9d88b596b0e04..73c8a4ac3c8ca73d95a70b3c4bc1b7924b99d3a6 100644 (file)
@@ -221,16 +221,14 @@ public class CephInputStream extends FSInputStream {
   @Override
        public void close() throws IOException {
     ceph.debug("CephOutputStream.close:enter", ceph.TRACE);
-    if (closed) {
-      throw new IOException("Stream closed");
-    }
-
-    int result = ceph.ceph_close(fileHandle);
-    closed = true;
-    if (result != 0) {
-      throw new IOException("Close somehow failed!"
-                                                                                                               + "Don't try and use this stream again, though");
-    }
-    ceph.debug("CephOutputStream.close:exit", ceph.TRACE);
-  }
+    if (!closed) {
+                       int result = ceph.ceph_close(fileHandle);
+                       closed = true;
+                       if (result != 0) {
+                               throw new IOException("Close somehow failed!"
+                                                                                                                       + "Don't try and use this stream again, though");
+                       }
+                       ceph.debug("CephOutputStream.close:exit", ceph.TRACE);
+               }
+       }
 }
index 81359dc5ffacf8ac8d9b383d9b27bf4bed26683d..e8e5f8973bb916786aa61196238ecf52fc2505ac 100644 (file)
@@ -168,23 +168,22 @@ public class CephOutputStream extends OutputStream {
    */
   @Override
        public synchronized void flush() throws IOException {
-                       if (closed) {
-                               throw new IOException("Stream closed");
+                       if (!closed) {
+                               if (bufUsed == 0) return;
+                               int result = ceph.ceph_write(fileHandle, buffer, 0, bufUsed);
+                               if (result < 0) {
+                                       throw new IOException("CephOutputStream.write: Write of "
+                                                                                                                               + bufUsed + "bytes to fd "
+                                                                                                                               + fileHandle + " failed");
+                               }
+                               if (result != bufUsed) {
+                                       throw new IOException("CephOutputStream.write: Write of " + bufUsed
+                                                                                                                               + "bytes to fd " + fileHandle
+                                                                                                                               + "was incomplete:  only " + result + " of "
+                                                                                                                               + bufUsed + " bytes were written.");
+                               }
+                               return;
                        }
-                       if (bufUsed == 0) return;
-                       int result = ceph.ceph_write(fileHandle, buffer, 0, bufUsed);
-      if (result < 0) {
-                               throw new IOException("CephOutputStream.write: Write of "
-                                                                                                                       + bufUsed + "bytes to fd "
-                                                                                                                       + fileHandle + " failed");
-      }
-      if (result != bufUsed) {
-                               throw new IOException("CephOutputStream.write: Write of " + bufUsed
-                                                                                                                       + "bytes to fd " + fileHandle
-                                                                                                                       + "was incomplete:  only " + result + " of "
-                                                                                                                       + bufUsed + " bytes were written.");
-      }
-                       return;
        }
   
   /**
@@ -194,17 +193,15 @@ public class CephOutputStream extends OutputStream {
   @Override
        public synchronized void close() throws IOException {
       ceph.debug("CephOutputStream.close:enter", ceph.TRACE);
-      if (closed) {
-                               throw new IOException("Stream already closed");
-      }
-                       flush();
-      int result = ceph.ceph_close(fileHandle);
-      if (result != 0) {
-                               throw new IOException("Close failed!");
-      }
-       
-      closed = true;
-      ceph.debug("CephOutputStream.close:exit", ceph.TRACE);
-    }
-
+      if (!closed) {
+                               flush();
+                               int result = ceph.ceph_close(fileHandle);
+                               if (result != 0) {
+                                       throw new IOException("Close failed!");
+                               }
+                               
+                               closed = true;
+                               ceph.debug("CephOutputStream.close:exit", ceph.TRACE);
+                       }
+       }
 }