From e0da411b40d17a9ab66702baa25c9e81171067d2 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 30 Oct 2009 18:39:48 -0700 Subject: [PATCH] Hadoop: Don't throw IOExceptions on extra calls to close --- src/client/hadoop/ceph/CephInputStream.java | 22 ++++---- src/client/hadoop/ceph/CephOutputStream.java | 55 +++++++++----------- 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/src/client/hadoop/ceph/CephInputStream.java b/src/client/hadoop/ceph/CephInputStream.java index 15ea48abf0651..73c8a4ac3c8ca 100644 --- a/src/client/hadoop/ceph/CephInputStream.java +++ b/src/client/hadoop/ceph/CephInputStream.java @@ -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); + } + } } diff --git a/src/client/hadoop/ceph/CephOutputStream.java b/src/client/hadoop/ceph/CephOutputStream.java index 81359dc5ffacf..e8e5f8973bb91 100644 --- a/src/client/hadoop/ceph/CephOutputStream.java +++ b/src/client/hadoop/ceph/CephOutputStream.java @@ -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); + } + } } -- 2.39.5