add future support to track current merge

This commit is contained in:
Shay Banon 2011-12-16 22:55:00 +02:00
parent cb4c249a65
commit 9c1280f6eb
3 changed files with 28 additions and 0 deletions

View File

@ -86,8 +86,10 @@ public class TrackingConcurrentMergeScheduler extends ConcurrentMergeScheduler {
logger.trace("merge [{}] starting...", merge.info.name);
}
try {
TrackingMergeScheduler.setCurrentMerge(merge);
super.doMerge(merge);
} finally {
TrackingMergeScheduler.removeCurrentMerge();
long took = System.currentTimeMillis() - time;
currentMerges.dec();

View File

@ -0,0 +1,24 @@
package org.apache.lucene.index;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import java.util.concurrent.ConcurrentMap;
/**
*/
public class TrackingMergeScheduler {
private static final ConcurrentMap<Thread, MergePolicy.OneMerge> merges = ConcurrentCollections.newConcurrentMap();
public static void setCurrentMerge(MergePolicy.OneMerge merge) {
merges.put(Thread.currentThread(), merge);
}
public static void removeCurrentMerge() {
merges.remove(Thread.currentThread());
}
public static MergePolicy.OneMerge getCurrentMerge() {
return merges.get(Thread.currentThread());
}
}

View File

@ -93,8 +93,10 @@ public class TrackingSerialMergeScheduler extends MergeScheduler {
currentMergesNumDocs.inc(totalNumDocs);
currentMergesSizeInBytes.inc(totalSizeInBytes);
try {
TrackingMergeScheduler.setCurrentMerge(merge);
writer.merge(merge);
} finally {
TrackingMergeScheduler.removeCurrentMerge();
long took = System.currentTimeMillis() - time;
currentMerges.dec();