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 1447305) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java (working copy) @@ -221,7 +221,7 @@ /** * Thread that handles optional sync'ing */ - private final LogSyncer logSyncerThread; + private final LogSyncer logSyncer; /** Number of log close errors tolerated before we abort */ private final int closeErrorsTolerated; @@ -349,7 +349,7 @@ this.closeErrorsTolerated = conf.getInt( "hbase.regionserver.logroll.errors.tolerated", 0); - this.logSyncerThread = new LogSyncer(this.optionalFlushInterval); + this.logSyncer = new LogSyncer(this.optionalFlushInterval); LOG.info("HLog configuration: blocksize=" + StringUtils.byteDesc(this.blocksize) + @@ -379,8 +379,11 @@ // handle the reflection necessary to call getNumCurrentReplicas() this.getNumCurrentReplicas = getGetNumCurrentReplicas(this.hdfs_out); - Threads.setDaemonThreadRunning(logSyncerThread.getThread(), - Thread.currentThread().getName() + ".logSyncer"); + // When optionalFlushInterval is set as 0, don't start a thread for deferred log sync. + if (this.optionalFlushInterval > 0) { + Threads.setDaemonThreadRunning(logSyncer.getThread(), Thread.currentThread().getName() + + ".logSyncer"); + } coprocessorHost = new WALCoprocessorHost(this, conf); this.metrics = new MetricsWAL(); @@ -798,13 +801,16 @@ if (this.closed) { return; } - try { - logSyncerThread.close(); - // Make sure we synced everything - logSyncerThread.join(this.optionalFlushInterval*2); - } catch (InterruptedException e) { - LOG.error("Exception while waiting for syncer thread to die", e); - Thread.currentThread().interrupt(); + // When optionalFlushInterval is 0, the logSyncer is not started as a Thread. + if (this.optionalFlushInterval > 0) { + try { + logSyncer.close(); + // Make sure we synced everything + logSyncer.join(this.optionalFlushInterval * 2); + } catch (InterruptedException e) { + LOG.error("Exception while waiting for syncer thread to die", e); + Thread.currentThread().interrupt(); + } } try { // Prevent all further flushing and rolling. @@ -1089,9 +1095,9 @@ return; } doneUpto = this.unflushedEntries.get(); - pending = logSyncerThread.getPendingWrites(); + pending = logSyncer.getPendingWrites(); try { - logSyncerThread.hlogFlush(tempWriter, pending); + logSyncer.hlogFlush(tempWriter, pending); } catch(IOException io) { ioe = io; LOG.error("syncer encountered error, will retry. txid=" + txid, ioe); @@ -1102,7 +1108,7 @@ synchronized (flushLock) { // HBASE-4387, HBASE-5623, retry with updateLock held tempWriter = this.writer; - logSyncerThread.hlogFlush(tempWriter, pending); + logSyncer.hlogFlush(tempWriter, pending); } } } @@ -1257,7 +1263,7 @@ // coprocessor hook: if (!coprocessorHost.preWALWrite(info, logKey, logEdit)) { // write to our buffer for the Hlog file. - logSyncerThread.append(new FSHLog.Entry(logKey, logEdit)); + logSyncer.append(new FSHLog.Entry(logKey, logEdit)); } long took = EnvironmentEdgeManager.currentTimeMillis() - now; coprocessorHost.postWALWrite(info, logKey, logEdit);