lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r510176 [2/2] - in /lucene/java/trunk: ./ src/java/org/apache/lucene/index/ src/java/org/apache/lucene/queryParser/ src/java/org/apache/lucene/search/ src/java/org/apache/lucene/store/ src/test/org/apache/lucene/index/
Date Wed, 21 Feb 2007 20:01:37 GMT
Modified: lucene/java/trunk/src/java/org/apache/lucene/search/RemoteSearchable.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/RemoteSearchable.java?view=diff&rev=510176&r1=510175&r2=510176
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/RemoteSearchable.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/RemoteSearchable.java Wed Feb 21 12:01:36
2007
@@ -19,6 +19,7 @@
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.index.CorruptIndexException;
 
 import java.io.IOException;
 import java.rmi.Naming;
@@ -76,7 +77,7 @@
     return local.search (weight, filter, n, sort);
   }
 
-  public Document doc(int i) throws IOException {
+  public Document doc(int i) throws CorruptIndexException, IOException {
     return local.doc(i);
   }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/Searchable.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/Searchable.java?view=diff&rev=510176&r1=510175&r2=510176
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/Searchable.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/Searchable.java Wed Feb 21 12:01:36
2007
@@ -20,6 +20,7 @@
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.index.CorruptIndexException;
 
 import java.io.IOException;       // for javadoc
 
@@ -92,8 +93,10 @@
   /** Expert: Returns the stored fields of document <code>i</code>.
    * Called by {@link HitCollector} implementations.
    * @see IndexReader#document(int)
+   * @throws CorruptIndexException if the index is corrupt
+   * @throws IOException if there is a low-level IO error
    */
-  Document doc(int i) throws IOException;
+  Document doc(int i) throws CorruptIndexException, IOException;
 
   /** Expert: called to re-write queries into primitive queries.
    * @throws BooleanQuery.TooManyClauses

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/Searcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/Searcher.java?view=diff&rev=510176&r1=510175&r2=510176
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/Searcher.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/Searcher.java Wed Feb 21 12:01:36
2007
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 
+import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.document.Document;
 
@@ -187,7 +188,7 @@
   abstract public int docFreq(Term term) throws IOException;
   abstract public int maxDoc() throws IOException;
   abstract public TopDocs search(Weight weight, Filter filter, int n) throws IOException;
-  abstract public Document doc(int i) throws IOException;
+  abstract public Document doc(int i) throws CorruptIndexException, IOException;
   abstract public Query rewrite(Query query) throws IOException;
   abstract public Explanation explain(Weight weight, int doc) throws IOException;
   abstract public TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort) throws
IOException;

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java?view=diff&rev=510176&r1=510175&r2=510176
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java Wed Feb 21 12:01:36
2007
@@ -94,7 +94,7 @@
    * Attempt to clear (forcefully unlock and remove) the
    * specified lock.  Only call this at a time when you are
    * certain this lock is no longer in use.
-   * @param lockName name of the lock to be cleared.
+   * @param name name of the lock to be cleared.
    */
   public void clearLock(String name) throws IOException {
     if (lockFactory != null) {

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/Lock.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/Lock.java?view=diff&rev=510176&r1=510175&r2=510176
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/Lock.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/Lock.java Wed Feb 21 12:01:36 2007
@@ -53,9 +53,10 @@
    *  lockWaitTimeout is passed.
    * @param lockWaitTimeout length of time to wait in ms
    * @return true if lock was obtained
-   * @throws IOException if lock wait times out or obtain() throws an IOException
+   * @throws LockObtainFailedException if lock wait times out
+   * @throws IOException if obtain() throws IOException
    */
-  public boolean obtain(long lockWaitTimeout) throws IOException {
+  public boolean obtain(long lockWaitTimeout) throws LockObtainFailedException, IOException
{
     failureReason = null;
     boolean locked = obtain();
     int maxSleepCount = (int)(lockWaitTimeout / LOCK_POLL_INTERVAL);
@@ -66,7 +67,7 @@
         if (failureReason != null) {
           reason += ": " + failureReason;
         }
-        IOException e = new IOException(reason);
+        LockObtainFailedException e = new LockObtainFailedException(reason);
         if (failureReason != null) {
           e.initCause(failureReason);
         }
@@ -108,8 +109,12 @@
     /** Calls {@link #doBody} while <i>lock</i> is obtained.  Blocks if lock
      * cannot be obtained immediately.  Retries to obtain lock once per second
      * until it is obtained, or until it has tried ten times. Lock is released when
-     * {@link #doBody} exits. */
-    public Object run() throws IOException {
+     * {@link #doBody} exits.
+     * @throws LockObtainFailedException if lock could not
+     * be obtained
+     * @throws IOException if {@link Lock#obtain} throws IOException
+     */
+    public Object run() throws LockObtainFailedException, IOException {
       boolean locked = false;
       try {
          locked = lock.obtain(lockWaitTimeout);

Added: lucene/java/trunk/src/java/org/apache/lucene/store/LockObtainFailedException.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/LockObtainFailedException.java?view=auto&rev=510176
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/LockObtainFailedException.java (added)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/LockObtainFailedException.java Wed
Feb 21 12:01:36 2007
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.store;
+
+import java.io.IOException;
+
+/**
+ * This exception is thrown when the <code>write.lock</code>
+ * could not be acquired.  This
+ * happens when a writer tries to open an index
+ * that another writer already has open.
+ * @see Lock#obtain(long).
+ */
+public class LockObtainFailedException extends IOException {
+  public LockObtainFailedException(String message) {
+    super(message);
+  }
+}

Propchange: lucene/java/trunk/src/java/org/apache/lucene/store/LockObtainFailedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?view=diff&rev=510176&r1=510175&r2=510176
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Wed Feb 21 12:01:36
2007
@@ -25,6 +25,7 @@
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.LockObtainFailedException;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.document.Document;
@@ -245,6 +246,96 @@
         reader.close();
     }
 
+    // Make sure attempts to make changes after reader is
+    // closed throws IOException:
+    public void testChangesAfterClose() throws IOException
+    {
+        Directory dir = new RAMDirectory();
+
+        IndexWriter writer = null;
+        IndexReader reader = null;
+        Term searchTerm = new Term("content", "aaa");
+
+        //  add 11 documents with term : aaa
+        writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
+        for (int i = 0; i < 11; i++)
+        {
+            addDoc(writer, searchTerm.text());
+        }
+        writer.close();
+
+        reader = IndexReader.open(dir);
+
+        // Close reader:
+        reader.close();
+
+        // Then, try to make changes:
+        try {
+          reader.deleteDocument(4);
+          fail("deleteDocument after close failed to throw IOException");
+        } catch (IOException e) {
+          // expected
+        }
+
+        try {
+          reader.setNorm(5, "aaa", 2.0f);
+          fail("setNorm after close failed to throw IOException");
+        } catch (IOException e) {
+          // expected
+        }
+
+        try {
+          reader.undeleteAll();
+          fail("undeleteAll after close failed to throw IOException");
+        } catch (IOException e) {
+          // expected
+        }
+    }
+
+    // Make sure we get lock obtain failed exception with 2 writers:
+    public void testLockObtainFailed() throws IOException
+    {
+        Directory dir = new RAMDirectory();
+
+        IndexWriter writer = null;
+        IndexReader reader = null;
+        Term searchTerm = new Term("content", "aaa");
+
+        //  add 11 documents with term : aaa
+        writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
+        for (int i = 0; i < 11; i++)
+        {
+            addDoc(writer, searchTerm.text());
+        }
+
+        // Create reader:
+        reader = IndexReader.open(dir);
+
+        // Try to make changes
+        try {
+          reader.deleteDocument(4);
+          fail("deleteDocument should have hit LockObtainFailedException");
+        } catch (LockObtainFailedException e) {
+          // expected
+        }
+
+        try {
+          reader.setNorm(5, "aaa", 2.0f);
+          fail("setNorm should have hit LockObtainFailedException");
+        } catch (LockObtainFailedException e) {
+          // expected
+        }
+
+        try {
+          reader.undeleteAll();
+          fail("undeleteAll should have hit LockObtainFailedException");
+        } catch (LockObtainFailedException e) {
+          // expected
+        }
+        writer.close();
+        reader.close();
+    }
+
     // Make sure you can set norms & commit even if a reader
     // is open against the index:
     public void testWritingNorms() throws IOException
@@ -371,7 +462,7 @@
         try {
             deleted = reader.deleteDocuments(searchTerm);
             fail("Delete allowed on an index reader with stale segment information");
-        } catch (IOException e) {
+        } catch (StaleReaderException e) {
             /* success */
         }
 



Mime
View raw message