DivyanshIITB commented on code in PR #14335: URL: https://github.com/apache/lucene/pull/14335#discussion_r1998646829
########## lucene/core/src/java/org/apache/lucene/index/MultiTenantMergeScheduler.java: ########## @@ -0,0 +1,44 @@ +package org.apache.lucene.index; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.io.IOException; + +/** + * A multi-tenant merge scheduler that shares a global thread pool across multiple IndexWriters. + */ +public class MultiTenantMergeScheduler extends MergeScheduler { + + // Shared global thread pool + private static final ExecutorService MERGE_THREAD_POOL = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() / 2); + + @Override + public void merge(MergeScheduler.MergeSource mergeSource, MergeTrigger trigger) throws IOException { + while (true) { + MergePolicy.OneMerge merge = mergeSource.getNextMerge(); + if (merge == null) { + break; + } + // Submit merge task to the shared thread pool + Future<?> future = MERGE_THREAD_POOL.submit(() -> { + try { + mergeSource.merge(merge); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + + try { + future.get(); // Ensure the task completes + } catch (Exception e) { + throw new IOException("Merge operation failed", e); + } + } + } + + @Override + public void close() { Review Comment: Thanks for pointing this out! I’ve updated close() to properly wait for all running merges, similar to sync() in ConcurrentMergeScheduler. Now, merge() tracks active tasks, and I've added cleanup for completed futures. Also, I introduced shutdownThreadPool() to allow safe global shutdown. Let me know if this works! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org