diff --git a/src/main/java/org/apache/lucene/index/TrackingConcurrentMergeScheduler.java b/src/main/java/org/apache/lucene/index/TrackingConcurrentMergeScheduler.java index cd0799a9798..bd6c7d497be 100644 --- a/src/main/java/org/apache/lucene/index/TrackingConcurrentMergeScheduler.java +++ b/src/main/java/org/apache/lucene/index/TrackingConcurrentMergeScheduler.java @@ -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(); diff --git a/src/main/java/org/apache/lucene/index/TrackingMergeScheduler.java b/src/main/java/org/apache/lucene/index/TrackingMergeScheduler.java new file mode 100644 index 00000000000..cd09e513df4 --- /dev/null +++ b/src/main/java/org/apache/lucene/index/TrackingMergeScheduler.java @@ -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 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()); + } +} diff --git a/src/main/java/org/apache/lucene/index/TrackingSerialMergeScheduler.java b/src/main/java/org/apache/lucene/index/TrackingSerialMergeScheduler.java index b1a34c954f3..6cef4553d62 100644 --- a/src/main/java/org/apache/lucene/index/TrackingSerialMergeScheduler.java +++ b/src/main/java/org/apache/lucene/index/TrackingSerialMergeScheduler.java @@ -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();