Update of /var/cvs/contributions/lucene/src/org/mmbase/module/lucene
In directory james.mmbase.org:/tmp/cvs-serv30667

Modified Files:
        Indexer.java Searcher.java 
Log Message:
moved repare method to Indexer, add some check to make it impposible to run 2 
full indices at the same time


See also: 
http://cvs.mmbase.org/viewcvs/contributions/lucene/src/org/mmbase/module/lucene


Index: Indexer.java
===================================================================
RCS file: 
/var/cvs/contributions/lucene/src/org/mmbase/module/lucene/Indexer.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -b -r1.60 -r1.61
--- Indexer.java        20 Aug 2008 10:53:20 -0000      1.60
+++ Indexer.java        20 Aug 2008 11:17:02 -0000      1.61
@@ -34,7 +34,7 @@
  *
  * @author Pierre van Rooden
  * @author Michiel Meeuwissen
- * @version $Id: Indexer.java,v 1.60 2008/08/20 10:53:20 michiel Exp $
+ * @version $Id: Indexer.java,v 1.61 2008/08/20 11:17:02 michiel Exp $
  **/
 public class Indexer {
 
@@ -84,6 +84,7 @@
     private final List<IndexDefinition> queries;
 
 
+    private boolean fullIndexing = false;
 
     // of course life would be easier if we could used BoundedFifoBuffer of 
jakarta or so, but
     // actually it's ont very hard to simulate it:
@@ -412,12 +413,15 @@
      * and indexing the results.
      */
     public void fullIndex() {
+        if (! fullIndexing) {
+            synchronized(this) {
         log.service("Doing full index for " + toString());
         long errorCountBefore = errorCount;
         EventManager.getInstance().propagateEvent(new 
FullIndexEvents.Event(getName(), FullIndexEvents.Status.START, 0));
         IndexWriter writer = null;
         Directory fullIndex = null;
         try {
+                    fullIndexing = true;
             clear(true);
             fullIndex = getDirectoryForFullIndex();
             writer = new IndexWriter(fullIndex, analyzer, true);
@@ -456,10 +460,15 @@
             log.error("Cannot run FullIndex: " + e.getMessage(), e);
         } finally {
             if (writer != null) { try { writer.close(); } catch (IOException 
ioe) { log.error("Can't close index writer: " + ioe.getMessage()); } }
+                    fullIndexing = false;
 
         }
         EventManager.getInstance().propagateEvent(new 
NewSearcher.Event(getName()));
     }
+        } else {
+            log.info("Refusing to full-index, because already busy");
+        }
+    }
 
     /**
      * Runs the queries for the given cursor, and indexes all nodes that are 
returned.
@@ -568,6 +577,22 @@
             throw new RuntimeException(ioe);
         }
     }
+    protected void repare(final CorruptIndexException ci, final boolean copy) {
+        if (! fullIndexing) {
+            synchronized(this) {
+                org.mmbase.util.ThreadPools.jobsExecutor.execute(new 
Runnable() {
+                        public void run() {
+                            log.info("Reparing index " + Indexer.this + " 
because " + ci.getMessage());
+                            Indexer.this.clear(true);
+                            if (! copy) {
+                                Indexer.this.clear(false);
+                                Indexer.this.fullIndex();
+                            }
+                        }
+                    });
+            }
+        }
+    }
 
     public String toString() {
         return getName() + queries;


Index: Searcher.java
===================================================================
RCS file: 
/var/cvs/contributions/lucene/src/org/mmbase/module/lucene/Searcher.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- Searcher.java       20 Aug 2008 10:54:39 -0000      1.52
+++ Searcher.java       20 Aug 2008 11:17:02 -0000      1.53
@@ -34,7 +34,7 @@
  * A wrapper around Lucene's [EMAIL PROTECTED] 
org.apache.lucene.search.IndexSearcher}. Every [EMAIL PROTECTED] Indexer} has 
its own Searcher.
  *
  * @author Pierre van Rooden
- * @version $Id: Searcher.java,v 1.52 2008/08/20 10:54:39 michiel Exp $
+ * @version $Id: Searcher.java,v 1.53 2008/08/20 11:17:02 michiel Exp $
  * @todo  Should the StopAnalyzers be replaced by index.analyzer? Something 
else?
  **/
 public class Searcher implements NewSearcher.Listener, 
FullIndexEvents.Listener {
@@ -86,18 +86,6 @@
         return status != FullIndexEvents.Status.IDLE ? intermediateSize : -1;
     }
 
-    protected void repare(final CorruptIndexException ci, final boolean copy) {
-        org.mmbase.util.ThreadPools.jobsExecutor.execute(new Runnable() {
-                public void run() {
-                    log.info("Reparing index " + index + " because " + 
ci.getMessage());
-                    index.clear(true);
-                    if (! copy) {
-                        index.clear(false);
-                        index.fullIndex();
-                    }
-                }
-            });
-    }
 
     protected synchronized IndexSearcher getSearcher(boolean copy) throws 
IOException {
         if (copy) return  new IndexSearcher(index.getDirectoryForFullIndex());
@@ -125,7 +113,8 @@
                 needsNewSearcher = false;
                 return searcher;
             } catch (CorruptIndexException ci) {
-                repare(ci, copy);
+                index.addError(ci.getMessage());
+                index.repare(ci, copy);
                 throw ci;
             }
         } else {
@@ -302,7 +291,8 @@
                 log.debug(nfe + " returning -1");
                 return -1;
             } catch (CorruptIndexException ci) {
-                repare(ci, copy);
+                index.addError(ci.getMessage());
+                index.repare(ci, copy);
                 log.warn(ci + " returning -1");
                 return -1;
             } catch (IOException ioe) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to