jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r544247 - in /jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: IndexMerger.java MultiIndex.java Recovery.java
Date Mon, 04 Jun 2007 20:24:21 GMT
Author: jukka
Date: Mon Jun  4 13:24:19 2007
New Revision: 544247

URL: http://svn.apache.org/viewvc?view=rev&rev=544247
Log:
1.3: Merged revision 533080 (JCR-778)

Modified:
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java?view=diff&rev=544247&r1=544246&r2=544247
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
Mon Jun  4 13:24:19 2007
@@ -95,6 +95,11 @@
     private final Sync indexReplacement = new Mutex();
 
     /**
+     * When released, indicates that this index merger is idle.
+     */
+    private final Sync mergerIdle = new Mutex();
+
+    /**
      * Creates an <code>IndexMerger</code>.
      *
      * @param multiIndex the <code>MultiIndex</code>.
@@ -103,6 +108,12 @@
         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");
+        }
     }
 
     /**
@@ -189,6 +200,17 @@
     }
 
     /**
+     * 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.
+     */
+    void waitUntilIdle() throws InterruptedException {
+        mergerIdle.acquire();
+        // and immediately release again
+        mergerIdle.release();
+    }
+
+    /**
      * Signals this <code>IndexMerger</code> to stop and waits until it
      * has terminated.
      */
@@ -233,9 +255,23 @@
      */
     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");
+                }
             }
 
             log.debug("accepted merge request");

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?view=diff&rev=544247&r1=544246&r2=544247
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Mon Jun  4 13:24:19 2007
@@ -299,6 +299,16 @@
             // now that we are ready, start index merger
             merger.start();
 
+            if (redoLogApplied) {
+                // wait for the index merge to finish pending jobs
+                try {
+                    merger.waitUntilIdle();
+                } catch (InterruptedException e) {
+                    // move on
+                }
+                flush();
+            }
+
             // do an initial index if there are no indexes at all
             if (indexNames.size() == 0) {
                 reindexing = true;
@@ -572,7 +582,7 @@
         try {
             // if we are reindexing there is already an active transaction
             if (!reindexing) {
-                executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
+                executeAndLog(new Start(Action.INTERNAL_TRANS_REPL_INDEXES));
             }
             // delete obsolete indexes
             Set names = new HashSet(Arrays.asList(obsoleteIndexes));
@@ -1169,12 +1179,17 @@
         public static final int TYPE_DELETE_INDEX = 7;
 
         /**
-         * Transaction identifier for internal actions like index replace or
-         * volatile index commit triggered by timer thread.
+         * Transaction identifier for internal actions like volatile index
+         * commit triggered by timer thread.
          */
         static final long INTERNAL_TRANSACTION = -1;
 
         /**
+         * Transaction identifier for internal action that replaces indexs.
+         */
+        static final long INTERNAL_TRANS_REPL_INDEXES = -2;
+
+        /**
          * The id of the transaction that executed this action.
          */
         private final long transactionId;
@@ -1563,6 +1578,7 @@
         public void undo(MultiIndex index) throws IOException {
             if (index.hasIndex(indexName)) {
                 PersistentIndex idx = index.getOrCreateIndex(indexName, false);
+                idx.close();
                 index.deleteIndex(idx);
             }
         }

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java?view=diff&rev=544247&r1=544246&r2=544247
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java
Mon Jun  4 13:24:19 2007
@@ -142,6 +142,14 @@
                 case MultiIndex.Action.TYPE_CREATE_INDEX:
                 case MultiIndex.Action.TYPE_DELETE_INDEX:
                 case MultiIndex.Action.TYPE_DELETE_NODE:
+                    // ignore actions by the index merger.
+                    // the previously created index of a merge has been
+                    // deleted because it was considered dirty.
+                    // we are conservative here and let the index merger do
+                    // its work again.
+                    if (a.getTransactionId() == MultiIndex.Action.INTERNAL_TRANS_REPL_INDEXES)
{
+                        continue;
+                    }
                     a.execute(index);
             }
         }
@@ -152,6 +160,10 @@
             if (losers.contains(new Long(a.getTransactionId()))) {
                 break;
             } else {
+                // ignore actions by the index merger.
+                if (a.getTransactionId() == MultiIndex.Action.INTERNAL_TRANS_REPL_INDEXES)
{
+                    continue;
+                }
                 a.execute(index);
             }
         }



Mime
View raw message