commit 08dbc16de1073187f5a1632c59b2ec44e4bb8958 Author: nspiegelberg Date: 47 seconds ago HBASE-4776 HLog.closed should be checked inside of updateLock diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java b/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java index 85c8cb1..e4c9a1a 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java @@ -193,7 +193,7 @@ public class HLog implements Syncable { private final ConcurrentSkipListMap lastSeqWritten = new ConcurrentSkipListMap(Bytes.BYTES_COMPARATOR); - private volatile boolean closed = false; + private boolean closed = false; private final AtomicLong logSeqNum = new AtomicLong(0); @@ -570,10 +570,6 @@ public class HLog implements Syncable { this.cacheFlushLock.lock(); this.logRollRunning = true; try { - if (closed) { - LOG.debug("HLog closed. Skipping rolling of writer"); - return regionsToFlush; - } // Do all the preparation outside of the updateLock to block // as less as possible the incoming writes long currentFilenum = this.filenum; @@ -606,6 +602,11 @@ public class HLog implements Syncable { } synchronized (updateLock) { + if (closed) { + LOG.debug("HLog closed. Skipping rolling of writer"); + nextWriter.close(); // creates empty log file + return regionsToFlush; + } // Clean up current writer. Path oldFile = cleanupCurrentWriter(currentFilenum); this.writer = nextWriter; @@ -1000,11 +1001,11 @@ public class HLog implements Syncable { public long append(HRegionInfo regionInfo, HLogKey logKey, WALEdit logEdit, HTableDescriptor htd, boolean doSync) throws IOException { - if (this.closed) { - throw new IOException("Cannot append; log is closed"); - } long txid = 0; synchronized (updateLock) { + if (this.closed) { + throw new IOException("Cannot append; log is closed"); + } long seqNum = obtainSeqNum(); logKey.setLogSeqNum(seqNum); // The 'lastSeqWritten' map holds the sequence number of the oldest @@ -1079,11 +1080,11 @@ public class HLog implements Syncable { final long now, HTableDescriptor htd, boolean doSync) throws IOException { if (edits.isEmpty()) return this.unflushedEntries.get();; - if (this.closed) { - throw new IOException("Cannot append; log is closed"); - } long txid = 0; synchronized (this.updateLock) { + if (this.closed) { + throw new IOException("Cannot append; log is closed"); + } long seqNum = obtainSeqNum(); // The 'lastSeqWritten' map holds the sequence number of the oldest // write for each region (i.e. the first edit added to the particular @@ -1510,11 +1511,11 @@ public class HLog implements Syncable { final byte [] tableName, final long logSeqId, final boolean isMetaRegion) throws IOException { try { - if (this.closed) { - return; - } long txid = 0; synchronized (updateLock) { + if (this.closed) { + return; + } long now = System.currentTimeMillis(); WALEdit edit = completeCacheFlushLogEdit(); HLogKey key = makeKey(encodedRegionName, tableName, logSeqId,