jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r587450 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: AbstractIndex.java FSDirectory.java IndexMerger.java MultiIndex.java PersistentIndex.java
Date Tue, 23 Oct 2007 10:39:56 GMT
Author: mreutegg
Date: Tue Oct 23 03:39:39 2007
New Revision: 587450

URL: http://svn.apache.org/viewvc?rev=587450&view=rev
Log:
JCR-863: Use FileLock for locking instead of empty file

Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FSDirectory.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java?rev=587450&r1=587449&r2=587450&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
Tue Oct 23 03:39:39 2007
@@ -31,7 +31,7 @@
 import java.io.PrintStream;
 import java.io.StringReader;
 import java.util.BitSet;
-import java.util.Enumeration;
+import java.util.Iterator;
 
 /**
  * Implements common functionality for a lucene index.
@@ -117,7 +117,7 @@
         this.indexingQueue = indexingQueue;
 
         if (!IndexReader.indexExists(directory)) {
-            indexWriter = new IndexWriter(directory, analyzer, true);
+            indexWriter = new IndexWriter(directory, analyzer);
             // immediately close, now that index has been created
             indexWriter.close();
             indexWriter = null;
@@ -220,7 +220,7 @@
             indexReader = null;
         }
         if (indexWriter == null) {
-            indexWriter = new IndexWriter(getDirectory(), analyzer, false);
+            indexWriter = new IndexWriter(getDirectory(), analyzer);
             // since lucene 2.0 setMaxBuffereDocs is equivalent to previous minMergeDocs
attribute
             indexWriter.setMaxBufferedDocs(minMergeDocs);
             indexWriter.setMaxMergeDocs(maxMergeDocs);
@@ -332,8 +332,8 @@
     private Document getFinishedDocument(Document doc) throws IOException {
         if (!Util.isDocumentReady(doc)) {
             Document copy = new Document();
-            for (Enumeration fields = doc.fields(); fields.hasMoreElements(); ) {
-                Field f = (Field) fields.nextElement();
+            for (Iterator fields = doc.getFields().iterator(); fields.hasNext(); ) {
+                Field f = (Field) fields.next();
                 Field field = null;
                 Field.TermVector tv = getTermVectorParameter(f);
                 Field.Store stored = getStoreParameter(f);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java?rev=587450&r1=587449&r2=587450&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
Tue Oct 23 03:39:39 2007
@@ -286,7 +286,7 @@
             }
             try {
                 log.debug("create new index");
-                PersistentIndex index = multiIndex.getOrCreateIndex(null, true);
+                PersistentIndex index = multiIndex.getOrCreateIndex(null);
                 boolean success = false;
                 try {
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=587450&r1=587449&r2=587450&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Tue Oct 23 03:39:39 2007
@@ -276,7 +276,7 @@
                 continue;
             }
             PersistentIndex index = new PersistentIndex(
-                    indexNames.getName(i), sub, false,
+                    indexNames.getName(i), sub,
                     handler.getTextAnalyzer(), cache, indexingQueue);
             index.setMaxMergeDocs(handler.getMaxMergeDocs());
             index.setMergeFactor(handler.getMergeFactor());
@@ -557,12 +557,10 @@
      *
      * @param indexName the name of the index to open, or <code>null</code> if
      *                  an index with a new name should be created.
-     * @param create    if the index that is opened should delete existing index
-     *                  data.
      * @return a new <code>PersistentIndex</code>.
      * @throws IOException if a new index cannot be created.
      */
-    synchronized PersistentIndex getOrCreateIndex(String indexName, boolean create)
+    synchronized PersistentIndex getOrCreateIndex(String indexName)
             throws IOException {
         // check existing
         for (Iterator it = indexes.iterator(); it.hasNext();) {
@@ -580,7 +578,7 @@
         } else {
             sub = new File(indexDir, indexName);
         }
-        PersistentIndex index = new PersistentIndex(indexName, sub, create,
+        PersistentIndex index = new PersistentIndex(indexName, sub,
                 handler.getTextAnalyzer(), cache, indexingQueue);
         index.setMaxMergeDocs(handler.getMaxMergeDocs());
         index.setMergeFactor(handler.getMergeFactor());
@@ -650,7 +648,7 @@
 
             // Index merger does not log an action when it creates the target
             // index of the merge. We have to do this here.
-            executeAndLog(new CreateIndex(getTransactionId(), index.getName(), false));
+            executeAndLog(new CreateIndex(getTransactionId(), index.getName()));
 
             executeAndLog(new AddIndex(getTransactionId(), index.getName()));
 
@@ -975,7 +973,7 @@
 
             long time = System.currentTimeMillis();
             // create index
-            CreateIndex create = new CreateIndex(getTransactionId(), null, true);
+            CreateIndex create = new CreateIndex(getTransactionId(), null);
             executeAndLog(create);
 
             // commit volatile index
@@ -1415,7 +1413,7 @@
          * @inheritDoc
          */
         public void execute(MultiIndex index) throws IOException {
-            PersistentIndex idx = index.getOrCreateIndex(indexName, false);
+            PersistentIndex idx = index.getOrCreateIndex(indexName);
             if (!index.indexNames.contains(indexName)) {
                 index.indexNames.addName(indexName);
                 // now that the index is in the active list let the merger know about it
@@ -1590,25 +1588,16 @@
         private String indexName;
 
         /**
-         * Indicates if the index is forced to be created. That is, existing
-         * index data is deleted.
-         */
-        private final boolean create;
-
-        /**
          * Creates a new CreateIndex action.
          *
          * @param transactionId the id of the transaction that executes this
          *                      action.
          * @param indexName     the name of the index to add, or <code>null</code>
          *                      if an index with a new name should be created.
-         * @param create        if <code>true</code> existing index data is
-         *                      overwritten.
          */
-        CreateIndex(long transactionId, String indexName, boolean create) {
+        CreateIndex(long transactionId, String indexName) {
             super(transactionId, Action.TYPE_CREATE_INDEX);
             this.indexName = indexName;
-            this.create = create;
         }
 
         /**
@@ -1622,8 +1611,7 @@
          */
         static CreateIndex fromString(long transactionId, String arguments) {
             // when created from String, this action is executed as redo action
-            // -> don't create index, simply open it.
-            return new CreateIndex(transactionId, arguments, false);
+            return new CreateIndex(transactionId, arguments);
         }
 
         /**
@@ -1632,7 +1620,7 @@
          * @inheritDoc
          */
         public void execute(MultiIndex index) throws IOException {
-            PersistentIndex idx = index.getOrCreateIndex(indexName, create);
+            PersistentIndex idx = index.getOrCreateIndex(indexName);
             indexName = idx.getName();
         }
 
@@ -1641,7 +1629,7 @@
          */
         public void undo(MultiIndex index) throws IOException {
             if (index.hasIndex(indexName)) {
-                PersistentIndex idx = index.getOrCreateIndex(indexName, false);
+                PersistentIndex idx = index.getOrCreateIndex(indexName);
                 idx.close();
                 index.deleteIndex(idx);
             }
@@ -1911,7 +1899,7 @@
          */
         public void execute(MultiIndex index) throws IOException {
             VolatileIndex volatileIndex = index.getVolatileIndex();
-            PersistentIndex persistentIndex = index.getOrCreateIndex(targetIndex, true);
+            PersistentIndex persistentIndex = index.getOrCreateIndex(targetIndex);
             persistentIndex.copyIndex(volatileIndex);
             index.resetVolatileIndex();
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java?rev=587450&r1=587449&r2=587450&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java
Tue Oct 23 03:39:39 2007
@@ -16,15 +16,14 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.NativeFSLockFactory;
 
 import java.io.IOException;
 import java.io.File;
@@ -35,21 +34,9 @@
  */
 class PersistentIndex extends AbstractIndex {
 
-    /** The logger instance for this class */
-    private static final Logger log = LoggerFactory.getLogger(PersistentIndex.class);
-
-    /** Name of the write lock file */
-    private static final String WRITE_LOCK = IndexWriter.WRITE_LOCK_NAME;
-
-    /** Name of the commit lock file */
-    private static final String COMMIT_LOCK = "commit.lock";
-
     /** The name of this persistent index */
     private final String name;
 
-    /** Set to <code>true</code> if this index encountered locks on startup */
-    private boolean lockEncountered = false;
-
     /**
      * If non <code>null</code>, <code>listener</code> needs to be
informed
      * when a document is deleted.
@@ -61,7 +48,6 @@
      * <code>indexDir</code>.
      * @param name the name of this index.
      * @param indexDir the directory to store the index.
-     * @param create if <code>true</code> an existing index is deleted.
      * @param analyzer the analyzer for text tokenizing.
      * @param cache the document number cache
      * @param indexingQueue the indexing queue.
@@ -70,32 +56,13 @@
      * @throws IOException if an error occurs while opening / creating
      *  the index.
      */
-    PersistentIndex(String name, File indexDir, boolean create,
+    PersistentIndex(String name, File indexDir,
                     Analyzer analyzer, DocNumberCache cache,
                     IndexingQueue indexingQueue)
             throws IOException {
-        super(analyzer, FSDirectory.getDirectory(indexDir, create),
+        super(analyzer, FSDirectory.getDirectory(indexDir, new NativeFSLockFactory(indexDir)),
                 cache, indexingQueue);
         this.name = name;
-
-        // check if index is locked, probably from an unclean repository
-        // shutdown
-        File writeLock = new File(indexDir, WRITE_LOCK);
-        if (writeLock.exists()) {
-            lockEncountered = true;
-            log.warn("Removing write lock on search index.");
-            if (!writeLock.delete()) {
-                log.error("Unable to remove write lock on search index.");
-            }
-        }
-        File commitLock = new File(indexDir, COMMIT_LOCK);
-        if (commitLock.exists()) {
-            lockEncountered = true;
-            log.warn("Removing commit lock on search index.");
-            if (!commitLock.delete()) {
-                log.error("Unable to remove write lock on search index.");
-            }
-        }
     }
 
     /**
@@ -107,17 +74,6 @@
             listener.documentDeleted(idTerm);
         }
         return num;
-    }
-
-    /**
-     * Returns <code>true</code> if this index encountered a lock on the file
-     * system during startup. This indicates a unclean shutdown.
-     *
-     * @return <code>true</code> if this index encountered a lock on startup;
-     *         <code>false</code> otherwise.
-     */
-    boolean getLockEncountered() {
-        return lockEncountered;
     }
 
     /**



Mime
View raw message