Index: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java (revision 1441291) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java (working copy) @@ -534,10 +534,10 @@ Path oldFile = null; int oldNumEntries = 0; + // Clean up current writer. + oldNumEntries = this.numEntries.get(); + oldFile = cleanupCurrentWriter(currentFilenum); synchronized (updateLock) { - // Clean up current writer. - oldNumEntries = this.numEntries.get(); - oldFile = cleanupCurrentWriter(currentFilenum); this.writer = nextWriter; this.hdfs_out = nextHdfsOut; this.numEntries.set(0); @@ -665,13 +665,16 @@ /* * Cleans up current writer closing and adding to outputfiles. - * Presumes we're operating inside an updateLock scope. * @return Path to current writer or null if none. * @throws IOException */ Path cleanupCurrentWriter(final long currentfilenum) throws IOException { Path oldFile = null; - if (this.writer != null) { + synchronized(updateLock) { + if (this.writer == null) { + return null; + } + } // Close the current writer, get a new one. try { // Wait till all current transactions are written to the hlog. @@ -683,9 +686,11 @@ " synced till here " + syncedTillHere); sync(); } - this.writer.close(); - this.writer = null; - closeErrorCount.set(0); + synchronized(updateLock) { + this.writer.close(); + this.writer = null; + closeErrorCount.set(0); + } } catch (IOException e) { LOG.error("Failed close of HLog writer", e); int errors = closeErrorCount.incrementAndGet(); @@ -708,7 +713,6 @@ oldFile = computeFilename(currentfilenum); this.outputfiles.put(Long.valueOf(this.logSeqNum.get()), oldFile); } - } return oldFile; }