LUCENE-2820: revert until I find the cause of the deadlock

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1050899 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-12-19 17:07:24 +00:00
parent 5f9bb3f0a8
commit 65b27c2adb
1 changed files with 27 additions and 54 deletions

View File

@ -65,6 +65,7 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
protected Directory dir;
private boolean closed;
protected IndexWriter writer;
protected int mergeThreadCount;
@ -146,37 +147,18 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
* pause & unpause threads. */
protected synchronized void updateMergeThreads() {
// Only look at threads that are alive & not in the
// process of stopping (ie have an active merge):
final List<MergeThread> activeMerges = new ArrayList<MergeThread>();
int threadIdx = 0;
while (threadIdx < mergeThreads.size()) {
final MergeThread mergeThread = mergeThreads.get(threadIdx);
if (!mergeThread.isAlive()) {
// Prune any dead threads
mergeThreads.remove(threadIdx);
continue;
}
if (mergeThread.getCurrentMerge() != null) {
activeMerges.add(mergeThread);
}
threadIdx++;
}
CollectionUtil.mergeSort(activeMerges, compareByMergeDocCount);
CollectionUtil.mergeSort(mergeThreads, compareByMergeDocCount);
final int count = mergeThreads.size();
int pri = mergeThreadPriority;
final int activeMergeCount = activeMerges.size();
for (threadIdx=0;threadIdx<activeMergeCount;threadIdx++) {
final MergeThread mergeThread = activeMerges.get(threadIdx);
for(int i=0;i<count;i++) {
final MergeThread mergeThread = mergeThreads.get(i);
final MergePolicy.OneMerge merge = mergeThread.getCurrentMerge();
if (merge == null) {
if (merge == null) {
continue;
}
final boolean doPause;
if (threadIdx < activeMergeCount-maxThreadCount) {
if (i < count-maxThreadCount) {
doPause = true;
} else {
doPause = false;
@ -226,29 +208,23 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
@Override
public void close() {
sync();
closed = true;
}
/** Wait for any running merge threads to finish */
public void sync() {
while(true) {
MergeThread toSync = null;
synchronized(this) {
for(MergeThread t : mergeThreads) {
if (t.isAlive()) {
toSync = t;
break;
}
}
public synchronized void sync() {
while(mergeThreadCount() > 0) {
if (verbose())
message("now wait for threads; currently " + mergeThreads.size() + " still running");
final int count = mergeThreads.size();
if (verbose()) {
for(int i=0;i<count;i++)
message(" " + i + ": " + mergeThreads.get(i));
}
if (toSync != null) {
try {
toSync.join();
} catch (InterruptedException ie) {
throw new ThreadInterruptedException(ie);
}
} else {
break;
try {
wait();
} catch (InterruptedException ie) {
throw new ThreadInterruptedException(ie);
}
}
}
@ -335,17 +311,11 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
// merge:
merger = getMergeThread(writer, merge);
mergeThreads.add(merger);
if (verbose()) {
updateMergeThreads();
if (verbose())
message(" launch new thread [" + merger.getName() + "]");
}
merger.start();
// Must call this after starting the thread else
// the new thread is removed from mergeThreads
// (since it's not alive yet):
updateMergeThreads();
success = true;
}
} finally {
@ -439,6 +409,7 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
message(" merge thread: do another merge " + merge.segString(dir));
} else {
done = true;
updateMergeThreads();
break;
}
}
@ -458,8 +429,10 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
}
} finally {
synchronized(ConcurrentMergeScheduler.this) {
updateMergeThreads();
ConcurrentMergeScheduler.this.notifyAll();
boolean removed = mergeThreads.remove(this);
assert removed;
updateMergeThreads();
}
}
}