jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r801245 - in /jackrabbit/branches/1.x: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/
Date Wed, 05 Aug 2009 14:53:07 GMT
Author: jukka
Date: Wed Aug  5 14:53:07 2009
New Revision: 801245

URL: http://svn.apache.org/viewvc?rev=801245&view=rev
Log:
1.x: Merged revisions 792109 (JCR-1818)

Modified:
    jackrabbit/branches/1.x/   (props changed)
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java

Propchange: jackrabbit/branches/1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug  5 14:53:07 2009
@@ -1,3 +1,3 @@
 /incubator/jackrabbit/trunk:78926
 /jackrabbit/branches/1.5:794012,794100,794102
-/jackrabbit/trunk:770143-773197,773483,773525-773555,773584,773588,773828,773835-775756,775833,775836,775840,775868,775981,775986,776036,776256,776310,776313,776321-776322,776332,776356-776357,776362,776373,776650-776693,776737,776757,776776-776777,777024,777029,777034,777478,777509,777541,777548,777936,778445,778613,778616,778621,778645,778720,778802,779032,779040,779068-779071,779074,779076,779081,779084,779086-779088,779090-779092,779094-779096,779101,779223,779225,779227-779228,779230,779233-779234,779460,779475-779476,779504,779550,779552,779555,779561,779563,779583,779590,779618,779621-779622,779624,779642,779654,779657-779659,779661,779936,780006,780010,780025,780085,780985,780989,780993,781017,781051,781054,781294-781300,781305-781311,781318,781328,781338,781344,781347,781369,781372,781377,781416-781417,781423,782621-782622,782644,782646,782652,782669,782675,782677,782683,782694,782921,782925,782930,782936,783002,783004-783005,783042-783043,783239,783278,783304,78331
 9-783321,783324,783326-783327,783330-783333,783337-783338,783340-783341,783343,783345-783346,783356,783359,783383,783386,783412,783435,783444,783447,783523,783688,783703,783708,783710,783719,783757,783759,783761,783786,783809,784011,784013,784039,784058,784060-784061,784090-784091,784106,784108-784109,784111,784117-784120,784124,784163,784261,784680,784691,784696,784760,784824,785112,785116,785157,785169,785209,785492,785517,785519,785529,785533,785535,785539-785540,785545,785580,785589-785590,785594,785597,785602,785627,785629,785631,785635,785668,785711,785725,785777,785863,785981,786003,786019,786028,786062,786075,786089-786090,786093-786094,786144,786146-786147,786149,786167,786280,786295,786319,786329-786330,786336,786409,786419,786423,786480,786485,786492,786513,786562,786565,786680,786685,787183,787219,787241,787942,787952,787964,787996,788002,788012-788013,788350-788351,788443,788446,788450,789245,789257,789269-789270,789279,789307,789312,789324,789338,789347,789485,
 789629,789809,789986,790054,790056,790065-790066,790068,790070-790071,790118,790127,790153,790235-790236,790528,790537,790541,790557-790558,790568,790590,790600,790603,790629,790814,790826,790834,790887,790892,790901,790930,790939,791180,791253,791255,791438-791439,791441,791452,791457,791475,791505,791520,791527,791737,791832,791884,791906,792102,792118,792138,792152,792155-792156,792160,792167-792168,792175,792180-792181,792211,792214,792218,792437,792453,792464,792467,792469,792485,792488,792496,792498,792509,792547-792548,792588-792589,792968,793012-793013,793015-793016,793018,793046-793047,793072,793180,793238,793240,793243,793283,793484-793485,793507,793559,793571,793830,793836,793840,794162,794190,794193,794253,794278,794293-794294,794304,794323,794329,794600,794617,794633,794641,794644,794652,794674,794702,794718,794743,794783,794994,795046,795049,795082,795096,795136,795138,795841-795842,795854,796586,796757,796845,796855,796876,796899,796955,796957,797094,797139,79
 7158,797386,797399,797410,797414,797416-797417,797424,797470,797484,797488-797489,797539,797549,797634,797662,797836,798141,798183,798196,798209,798306,798834,798844,798847-798848,798889-798890,798940,798958,799188,799284,799550,799595,799599,799610,800269,800464,800466,800478,800483,800715,800807,800829,800854,800862-800863,801104
+/jackrabbit/trunk:770143-773197,773483,773525-773555,773584,773588,773828,773835-775756,775833,775836,775840,775868,775981,775986,776036,776256,776310,776313,776321-776322,776332,776356-776357,776362,776373,776650-776693,776737,776757,776776-776777,777024,777029,777034,777478,777509,777541,777548,777936,778445,778613,778616,778621,778645,778720,778802,779032,779040,779068-779071,779074,779076,779081,779084,779086-779088,779090-779092,779094-779096,779101,779223,779225,779227-779228,779230,779233-779234,779460,779475-779476,779504,779550,779552,779555,779561,779563,779583,779590,779618,779621-779622,779624,779642,779654,779657-779659,779661,779936,780006,780010,780025,780085,780985,780989,780993,781017,781051,781054,781294-781300,781305-781311,781318,781328,781338,781344,781347,781369,781372,781377,781416-781417,781423,782621-782622,782644,782646,782652,782669,782675,782677,782683,782694,782921,782925,782930,782936,783002,783004-783005,783042-783043,783239,783243,783245,78327
 8,783304,783319-783321,783324,783326-783327,783330-783333,783337-783338,783340-783341,783343,783345-783347,783356,783359,783383,783386,783412,783435,783444,783447,783523,783688,783703,783708,783710,783719,783757,783759,783761,783786,783809,784011,784013,784039,784058,784060-784061,784090-784091,784106,784108-784109,784111,784117-784120,784124,784163,784261,784680,784691,784696,784760,784824,785112,785116,785157,785169,785209,785492,785517,785519,785529,785533,785535,785539-785540,785545,785580,785589-785590,785594,785597,785602,785627,785629,785631,785635,785668,785711,785725,785777,785863,785981,786003,786019,786028,786062,786075,786089-786090,786093-786094,786144,786146-786147,786149,786167,786280,786295,786319,786329-786330,786336,786409,786419,786423,786480,786485,786492,786513,786562,786565,786680,786685,787183,787219,787241,787942,787952,787964,787996,788002,788012-788013,788350-788351,788443,788446,788450,789245,789257,789269-789270,789279,789307,789312,789324,789338,
 789347,789485,789629,789809,789986,790054,790056,790065-790066,790068,790070-790071,790118,790127,790153,790235-790236,790528,790537,790541,790557-790558,790568,790590,790600,790603,790629,790814,790826,790834,790887,790892,790901,790930,790939,791180,791253,791255,791438-791439,791441,791452,791457,791475,791505,791520,791527,791737,791832,791884,791906,792102,792109,792118,792138,792152,792155-792156,792160,792162,792167-792168,792175,792180-792181,792211,792214,792218,792437,792453,792464,792467,792469,792485,792488,792496,792498,792508-792509,792547-792548,792588-792589,792849,792894-792895,792912,792932,792934,792968,793012-793013,793015-793016,793018,793046-793047,793072,793180,793238,793240,793243,793283,793484-793485,793507,793559,793571,793830,793836,793840,794162,794190,794193,794253,794278,794293-794294,794304,794323,794329,794600,794617,794633,794641,794644,794652,794674,794702,794718,794743,794783,794994,795046,795049,795082,795096,795136,795138,795841-795842,79
 5854,796586,796757,796845,796855,796876,796899,796955,796957,797094,797139,797158,797386,797399,797410,797414,797416-797417,797424,797470,797484,797488-797489,797539,797549,797634,797662,797836,798141,798183,798196,798209,798306,798834,798844,798847-798848,798889-798890,798940,798958,799188,799284,799550,799595,799599,799610,800269,800464,800466,800478,800483,800715,800807,800829,800854,800862-800863,801104

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java?rev=801245&r1=801244&r2=801245&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
Wed Aug  5 14:53:07 2009
@@ -18,9 +18,6 @@
 
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.IndexReader;
-import org.apache.commons.collections.Buffer;
-import org.apache.commons.collections.BufferUtils;
-import org.apache.commons.collections.buffer.UnboundedFifoBuffer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,15 +25,15 @@
 import java.util.Collections;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Semaphore;
 import java.io.IOException;
 
-import EDU.oswego.cs.dl.util.concurrent.Sync;
-import EDU.oswego.cs.dl.util.concurrent.Mutex;
-
 /**
  * Merges indexes in a separate daemon thread.
  */
-class IndexMerger extends Thread implements IndexListener {
+class IndexMerger implements IndexListener {
 
     /**
      * Logger instance for this class.
@@ -66,13 +63,7 @@
     /**
      * Queue of merge Tasks
      */
-    private final Buffer mergeTasks = BufferUtils.blockingBuffer(new UnboundedFifoBuffer());
-
-    /**
-     * List of id <code>Term</code> that identify documents that were deleted
-     * while a merge was running.
-     */
-    private final List deletedDocuments = Collections.synchronizedList(new ArrayList());
+    private final BlockingQueue mergeTasks = new LinkedBlockingQueue();
 
     /**
      * List of <code>IndexBucket</code>s in ascending document limit.
@@ -92,27 +83,41 @@
     /**
      * Mutex that is acquired when replacing indexes on MultiIndex.
      */
-    private final Sync indexReplacement = new Mutex();
+    private final Semaphore indexReplacement;
 
     /**
-     * When released, indicates that this index merger is idle.
+     * List of merger threads that are currently busy.
      */
-    private final Sync mergerIdle = new Mutex();
+    private final List busyMergers = new ArrayList();
+
+    /**
+     * List of merger threads.
+     */
+    private final List workers = new ArrayList();
 
     /**
      * Creates an <code>IndexMerger</code>.
      *
      * @param multiIndex the <code>MultiIndex</code>.
+     * @param numWorkers the number of worker threads to use.
      */
-    IndexMerger(MultiIndex multiIndex) {
+    IndexMerger(MultiIndex multiIndex, int numWorkers) {
         this.multiIndex = multiIndex;
-        setName("IndexMerger");
-        setDaemon(true);
-        try {
-            mergerIdle.acquire();
-        } catch (InterruptedException e) {
-            // will never happen, lock is free upon construction
-            throw new InternalError("Unable to acquire mutex after construction");
+        for (int i = 0; i < numWorkers; i++) {
+            Worker w = new Worker();
+            workers.add(w);
+            busyMergers.add(w);
+        }
+        this.indexReplacement = new Semaphore(workers.size());
+    }
+
+    /**
+     * Starts this index merger.
+     */
+    void start() {
+        Iterator iterator = workers.iterator();
+        while (iterator.hasNext()) {
+            ((Worker) iterator.next()).start();
         }
     }
 
@@ -150,8 +155,9 @@
 
             // put index in bucket
             IndexBucket bucket = (IndexBucket) indexBuckets.get(indexBuckets.size() - 1);
-            for (int i = 0; i < indexBuckets.size(); i++) {
-                bucket = (IndexBucket) indexBuckets.get(i);
+            Iterator iterator = indexBuckets.iterator();
+            while (iterator.hasNext()) {
+                bucket = (IndexBucket) iterator.next();
                 if (bucket.fits(numDocs)) {
                     break;
                 }
@@ -184,8 +190,15 @@
                     if (log.isDebugEnabled()) {
                         log.debug("requesting merge for " + indexesToMerge);
                     }
-                    mergeTasks.add(new Merge(idxs));
-                    log.debug("merge queue now contains " + mergeTasks.size() + " tasks.");
+                    addMergeTask(new Merge(idxs));
+                    if (log.isDebugEnabled()) {
+                        log.debug("merge queue now contains " + mergeTasks.size() + " tasks.");
+                        int numBusy;
+                        synchronized (busyMergers) {
+                            numBusy = busyMergers.size();
+                        }
+                        log.debug("# of busy merge workers: " + numBusy);
+                    }
                 }
             }
         }
@@ -196,18 +209,28 @@
      */
     public void documentDeleted(Term id) {
         log.debug("document deleted: " + id.text());
-        deletedDocuments.add(id);
+        synchronized (busyMergers) {
+            Iterator iterator = busyMergers.iterator();
+            while (iterator.hasNext()) {
+                ((Worker) iterator.next()).documentDeleted(id);
+            }
+        }
     }
 
     /**
      * When the calling thread returns this index merger will be idle, that is
-     * there will be no merge tasks pending anymore. The method returns immediately
-     * if there are currently no tasks pending at all.
+     * there will be no merge tasks pending anymore. The method returns
+     * immediately if there are currently no tasks pending at all.
+     *
+     * @throws InterruptedException if this thread is interrupted while waiting
+     *                              for the worker threads to become idle.
      */
     void waitUntilIdle() throws InterruptedException {
-        mergerIdle.acquire();
-        // and immediately release again
-        mergerIdle.release();
+        synchronized (busyMergers) {
+            while (!busyMergers.isEmpty()) {
+                busyMergers.wait();
+            }
+        }
     }
 
     /**
@@ -216,135 +239,50 @@
      */
     void dispose() {
         log.debug("dispose IndexMerger");
-        // get mutex for index replacements
+        // get all permits for index replacements
         try {
-            indexReplacement.acquire();
+            indexReplacement.acquire(workers.size());
         } catch (InterruptedException e) {
-            log.warn("Interrupted while acquiring index replacement sync: " + e);
+            log.warn("Interrupted while acquiring index replacement permits: " + e);
             // try to stop IndexMerger without the sync
         }
 
+        log.debug("merge queue size: " + mergeTasks.size());
         // clear task queue
         mergeTasks.clear();
 
         // send quit
-        mergeTasks.add(QUIT);
+        addMergeTask(QUIT);
         log.debug("quit sent");
 
         try {
-            // give the merger thread some time to quit,
-            // it is possible that the merger is busy working on a large index.
+            // give the merger threads some time to quit,
+            // it is possible that the mergers are busy working on a large index.
             // if that is the case we will just ignore it and the daemon will
             // die without being able to finish the merge.
             // at this point it is not possible anymore to replace indexes
-            // on the MultiIndex because we hold the indexReplacement Sync.
-            this.join(500);
-            if (isAlive()) {
-                log.info("Unable to stop IndexMerger. Daemon is busy.");
-            } else {
-                log.debug("IndexMerger thread stopped");
-            }
-            log.debug("merge queue size: " + mergeTasks.size());
-        } catch (InterruptedException e) {
-            log.warn("Interrupted while waiting for IndexMerger thread to terminate.");
-        }
-    }
-
-    /**
-     * Implements the index merging.
-     */
-    public void run() {
-        for (;;) {
-            boolean isIdle = false;
-            if (mergeTasks.size() == 0) {
-                mergerIdle.release();
-                isIdle = true;
-            }
-            Merge task = (Merge) mergeTasks.remove();
-            if (task == QUIT) {
-                mergerIdle.release();
-                break;
-            }
-            if (isIdle) {
-                try {
-                    mergerIdle.acquire();
-                } catch (InterruptedException e) {
-                    Thread.interrupted();
-                    log.warn("Unable to acquire mergerIdle sync");
+            // on the MultiIndex because we hold all indexReplacement permits.
+            Iterator iterator = workers.iterator();
+            while (iterator.hasNext()) {
+                Thread t = (Thread) iterator.next();
+                t.join(500);
+                if (t.isAlive()) {
+                    log.info("Unable to stop IndexMerger.Worker. Daemon is busy.");
+                } else {
+                    log.debug("IndexMerger.Worker thread stopped");
                 }
             }
-
-            log.debug("accepted merge request");
-
-            // reset deleted documents
-            deletedDocuments.clear();
-
-            // get readers
-            String[] names = new String[task.indexes.length];
-            for (int i = 0; i < task.indexes.length; i++) {
-                names[i] = task.indexes[i].name;
-            }
-            try {
-                log.debug("create new index");
-                PersistentIndex index = multiIndex.getOrCreateIndex(null);
-                boolean success = false;
-                try {
-
-                    log.debug("get index readers from MultiIndex");
-                    IndexReader[] readers = multiIndex.getIndexReaders(names, this);
-                    try {
-                        // do the merge
-                        long time = System.currentTimeMillis();
-                        index.addIndexes(readers);
-                        time = System.currentTimeMillis() - time;
-                        int docCount = 0;
-                        for (int i = 0; i < readers.length; i++) {
-                            docCount += readers[i].numDocs();
-                        }
-                        log.info("merged " + docCount + " documents in " + time + " ms into
" + index.getName() + ".");
-                    } finally {
-                        for (int i = 0; i < readers.length; i++) {
-                            try {
-                                Util.closeOrRelease(readers[i]);
-                            } catch (IOException e) {
-                                log.warn("Unable to close IndexReader: " + e);
-                            }
-                        }
-                    }
-
-                    // inform multi index
-                    // if we cannot get the sync immediately we have to quit
-                    if (!indexReplacement.attempt(0)) {
-                        log.debug("index merging canceled");
-                        break;
-                    }
-                    try {
-                        log.debug("replace indexes");
-                        multiIndex.replaceIndexes(names, index, deletedDocuments);
-                    } finally {
-                        indexReplacement.release();
-                    }
-
-                    success = true;
-
-                } finally {
-                    if (!success) {
-                        // delete index
-                        log.debug("deleting index " + index.getName());
-                        multiIndex.deleteIndex(index);
-                    }
-                }
-            } catch (Throwable e) {
-                log.error("Error while merging indexes: ", e);
-            }
+        } catch (InterruptedException e) {
+            log.warn("Interrupted while waiting for IndexMerger threads to terminate.");
         }
-        log.info("IndexMerger terminated");
     }
 
     //-----------------------< merge properties >-------------------------------
 
     /**
      * The merge factor.
+     *
+     * @param mergeFactor the merge factor.
      */
     public void setMergeFactor(int mergeFactor) {
         this.mergeFactor = mergeFactor;
@@ -353,6 +291,8 @@
 
     /**
      * The initial threshold for number of documents to merge to a new index.
+     *
+     * @param minMergeDocs the min merge docs number.
      */
     public void setMinMergeDocs(int minMergeDocs) {
         this.minMergeDocs = minMergeDocs;
@@ -360,6 +300,8 @@
 
     /**
      * The maximum number of document to merge.
+     *
+     * @param maxMergeDocs the max merge docs number.
      */
     public void setMaxMergeDocs(int maxMergeDocs) {
         this.maxMergeDocs = maxMergeDocs;
@@ -367,6 +309,18 @@
 
     //------------------------------< internal >--------------------------------
 
+    private void addMergeTask(Merge task) {
+        for (;;) {
+            try {
+                mergeTasks.put(task);
+                break;
+            } catch (InterruptedException e) {
+                // try again
+                Thread.interrupted();
+            }
+        }
+    }
+
     /**
      * Implements a simple struct that holds the name of an index and how
      * many document it contains. <code>Index</code> is comparable using the
@@ -448,6 +402,8 @@
      */
     private static final class IndexBucket extends ArrayList {
 
+        private static final long serialVersionUID = 2985514550083374904L;
+
         /**
          * The lower document limit.
          */
@@ -496,4 +452,130 @@
             return allowMerge;
         }
     }
+
+    private class Worker extends Thread implements IndexListener {
+
+        /**
+         * List of id <code>Term</code> that identify documents that were deleted
+         * while a merge was running.
+         */
+        private final List deletedDocuments = Collections.synchronizedList(new ArrayList());
+
+        public Worker() {
+            setName("IndexMerger.Worker");
+            setDaemon(true);
+        }
+
+        /**
+         * Implements the index merging.
+         */
+        public void run() {
+            for (;;) {
+                boolean isIdle = false;
+                if (mergeTasks.size() == 0) {
+                    synchronized (busyMergers) {
+                        busyMergers.remove(this);
+                        busyMergers.notifyAll();
+                    }
+                    isIdle = true;
+                }
+                Merge task;
+                for (;;) {
+                    try {
+                        task = (Merge) mergeTasks.take();
+                        break;
+                    } catch (InterruptedException e) {
+                        // try again
+                        Thread.interrupted();
+                    }
+                }
+                if (task == QUIT) {
+                    synchronized (busyMergers) {
+                        busyMergers.remove(this);
+                    }
+                    // put back QUIT to signal other workers
+                    addMergeTask(task);
+                    break;
+                }
+                if (isIdle) {
+                    synchronized (busyMergers) {
+                        busyMergers.add(this);
+                    }
+                }
+
+                log.debug("accepted merge request");
+
+                // reset deleted documents
+                deletedDocuments.clear();
+
+                // get readers
+                String[] names = new String[task.indexes.length];
+                for (int i = 0; i < task.indexes.length; i++) {
+                    names[i] = task.indexes[i].name;
+                }
+                try {
+                    log.debug("create new index");
+                    PersistentIndex index = multiIndex.getOrCreateIndex(null);
+                    boolean success = false;
+                    try {
+
+                        log.debug("get index readers from MultiIndex");
+                        IndexReader[] readers = multiIndex.getIndexReaders(names, IndexMerger.this);
+                        try {
+                            // do the merge
+                            long time = System.currentTimeMillis();
+                            index.addIndexes(readers);
+                            time = System.currentTimeMillis() - time;
+                            int docCount = 0;
+                            for (int i = 0; i < readers.length; i++) {
+                                docCount += readers[i].numDocs();
+                            }
+                            log.info("merged " + docCount + " documents in " + time + " ms
into " + index.getName() + ".");
+                        } finally {
+                            for (int i = 0; i < readers.length; i++) {
+                                try {
+                                    Util.closeOrRelease(readers[i]);
+                                } catch (IOException e) {
+                                    log.warn("Unable to close IndexReader: " + e);
+                                }
+                            }
+                        }
+
+                        // inform multi index
+                        // if we cannot get the sync immediately we have to quit
+                        if (!indexReplacement.tryAcquire()) {
+                            log.debug("index merging canceled");
+                            break;
+                        }
+                        try {
+                            log.debug("replace indexes");
+                            multiIndex.replaceIndexes(names, index, deletedDocuments);
+                        } finally {
+                            indexReplacement.release();
+                        }
+
+                        success = true;
+
+                    } finally {
+                        if (!success) {
+                            // delete index
+                            log.debug("deleting index " + index.getName());
+                            multiIndex.deleteIndex(index);
+                        }
+                    }
+                } catch (Throwable e) {
+                    log.error("Error while merging indexes: ", e);
+                }
+            }
+            log.info("IndexMerger.Worker terminated");
+        }
+
+        /**
+         * @inheritDoc
+         */
+        public void documentDeleted(Term id) {
+            log.debug("document deleted: " + id.text());
+            deletedDocuments.add(id);
+        }
+    }
 }

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=801245&r1=801244&r2=801245&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Wed Aug  5 14:53:07 2009
@@ -241,7 +241,7 @@
         removeDeletable();
 
         // initialize IndexMerger
-        merger = new IndexMerger(this);
+        merger = new IndexMerger(this, handler.getIndexMergerPoolSize());
         merger.setMaxMergeDocs(handler.getMaxMergeDocs());
         merger.setMergeFactor(handler.getMergeFactor());
         merger.setMinMergeDocs(handler.getMinMergeDocs());

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=801245&r1=801244&r2=801245&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Wed Aug  5 14:53:07 2009
@@ -167,6 +167,11 @@
     public static final int DEFAULT_TERM_INFOS_INDEX_DIVISOR = 1;
 
     /**
+     * The default value for {@link #indexMergerPoolSize}.
+     */
+    public static final int DEFAULT_INDEX_MERGER_POOL_SIZE = 2;
+
+    /**
      * The path factory.
      */
     protected static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
@@ -440,6 +445,11 @@
     private boolean initializeHierarchyCache = true;
 
     /**
+     * The number of worker threads for merging index segments.
+     */
+    private int indexMergerPoolSize = DEFAULT_INDEX_MERGER_POOL_SIZE;
+
+    /**
      * Indicates if this <code>SearchIndex</code> is closed and cannot be used
      * anymore.
      */
@@ -698,6 +708,8 @@
     /**
      * This method returns the QueryNodeFactory used to parse Queries. This method
      * may be overridden to provide a customized QueryNodeFactory
+     *
+     * @return the query node factory.
      */
     protected DefaultQueryNodeFactory getQueryNodeFactory() {
         return DEFAULT_QUERY_NODE_FACTORY;
@@ -2143,6 +2155,26 @@
         this.initializeHierarchyCache = initializeHierarchyCache;
     }
 
+    /**
+     * @return the current size of the index merger pool.
+     */
+    public int getIndexMergerPoolSize() {
+        return indexMergerPoolSize;
+    }
+
+    /**
+     * Sets a new value for the index merger pool size.
+     *
+     * @param indexMergerPoolSize the number of worker threads.
+     * @throws IllegalArgumentException if the size is less than or equal 0.
+     */
+    public void setIndexMergerPoolSize(int indexMergerPoolSize) {
+        if (indexMergerPoolSize <= 0) {
+            throw new IllegalArgumentException("must be greater than 0");
+        }
+        this.indexMergerPoolSize = indexMergerPoolSize;
+    }
+
     //----------------------------< internal >----------------------------------
 
     /**



Mime
View raw message