HBASE-7728 deadlock occurs between hlog roller and hlog syncer (Ted Yu)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1441631 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2013-02-01 21:13:14 +00:00
parent 997c8f8d6b
commit 003a05896e
1 changed files with 14 additions and 5 deletions

View File

@ -827,6 +827,7 @@ class FSHLog implements HLog, Syncable {
} }
if (this.writer != null) { if (this.writer != null) {
this.writer.close(); this.writer.close();
this.writer = null;
} }
} }
} }
@ -1081,16 +1082,24 @@ class FSHLog implements HLog, Syncable {
// issue the sync to HDFS. If sync is successful, then update // issue the sync to HDFS. If sync is successful, then update
// syncedTillHere to indicate that transactions till this // syncedTillHere to indicate that transactions till this
// number has been successfully synced. // number has been successfully synced.
IOException ioe = null;
List<Entry> pending = null;
synchronized (flushLock) { synchronized (flushLock) {
if (txid <= this.syncedTillHere) { if (txid <= this.syncedTillHere) {
return; return;
} }
doneUpto = this.unflushedEntries.get(); doneUpto = this.unflushedEntries.get();
List<Entry> pending = logSyncerThread.getPendingWrites(); pending = logSyncerThread.getPendingWrites();
try { try {
logSyncerThread.hlogFlush(tempWriter, pending); logSyncerThread.hlogFlush(tempWriter, pending);
} catch(IOException io) { } catch(IOException io) {
synchronized (this.updateLock) { ioe = io;
LOG.error("syncer encountered error, will retry. txid=" + txid, ioe);
}
}
if (ioe != null && pending != null) {
synchronized (this.updateLock) {
synchronized (flushLock) {
// HBASE-4387, HBASE-5623, retry with updateLock held // HBASE-4387, HBASE-5623, retry with updateLock held
tempWriter = this.writer; tempWriter = this.writer;
logSyncerThread.hlogFlush(tempWriter, pending); logSyncerThread.hlogFlush(tempWriter, pending);
@ -1102,14 +1111,14 @@ class FSHLog implements HLog, Syncable {
return; return;
} }
try { try {
tempWriter.sync(); if (tempWriter != null) tempWriter.sync();
} catch(IOException ex) { } catch(IOException ex) {
synchronized (this.updateLock) { synchronized (this.updateLock) {
// HBASE-4387, HBASE-5623, retry with updateLock held // HBASE-4387, HBASE-5623, retry with updateLock held
// TODO: we don't actually need to do it for concurrent close - what is the point // TODO: we don't actually need to do it for concurrent close - what is the point
// of syncing new unrelated writer? Keep behavior for now. // of syncing new unrelated writer? Keep behavior for now.
tempWriter = this.writer; tempWriter = this.writer;
tempWriter.sync(); if (tempWriter != null) tempWriter.sync();
} }
} }
this.syncedTillHere = Math.max(this.syncedTillHere, doneUpto); this.syncedTillHere = Math.max(this.syncedTillHere, doneUpto);