Index: src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java (revision 1234274) +++ src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java (working copy) @@ -735,8 +735,10 @@ private final Set blacklistedRegions = Collections.synchronizedSet( new TreeSet(Bytes.BYTES_COMPARATOR)); - private boolean hasClosed = false; + private boolean closeCompleted = false; + + private boolean logWritersClosed = false; /** * Start the threads that will pump data from the entryBuffers * to the output files. @@ -760,20 +762,24 @@ List finishWritingAndClose() throws IOException { LOG.info("Waiting for split writer threads to finish"); - for (WriterThread t : writerThreads) { - t.finish(); - } - for (WriterThread t: writerThreads) { - try { - t.join(); - } catch (InterruptedException ie) { - throw new IOException(ie); + try { + for (WriterThread t : writerThreads) { + t.finish(); } - checkForErrors(); + for (WriterThread t : writerThreads) { + try { + t.join(); + } catch (InterruptedException ie) { + throw new IOException(ie); + } + checkForErrors(); + } + LOG.info("Split writers finished"); + + return closeStreams(); + } finally { + closeLogWriters(); } - LOG.info("Split writers finished"); - - return closeStreams(); } /** @@ -781,7 +787,7 @@ * @return the list of paths written. */ private List closeStreams() throws IOException { - Preconditions.checkState(!hasClosed); + Preconditions.checkState(!closeCompleted); List paths = new ArrayList(); List thrown = Lists.newArrayList(); @@ -822,13 +828,35 @@ } paths.add(dst); } + logWritersClosed = true; + if (!thrown.isEmpty()) { throw MultipleIOException.createIOException(thrown); } - hasClosed = true; + closeCompleted = true; return paths; } + + private void closeLogWriters() throws IOException { + // close the log writer streams only if they are not closed + // in closeStreams(). + if (!closeCompleted && !logWritersClosed) { + List thrown = Lists.newArrayList(); + for (WriterAndPath wap : logWriters.values()) { + try { + wap.w.close(); + } catch (IOException ioe) { + LOG.error("Couldn't close log at " + wap.p, ioe); + thrown.add(ioe); + continue; + } + } + if (!thrown.isEmpty()) { + throw MultipleIOException.createIOException(thrown); + } + } + } /** * Get a writer and path for a log starting at the given entry.