lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r386749 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java
Date Fri, 17 Mar 2006 22:51:34 GMT
Author: dnaber
Date: Fri Mar 17 14:51:32 2006
New Revision: 386749

URL: http://svn.apache.org/viewcvs?rev=386749&view=rev
Log:
re-add a way to set write and commit lock timeout

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=386749&r1=386748&r2=386749&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Mar 17 14:51:32 2006
@@ -12,6 +12,11 @@
  2. LUCENE-515: Make ConstantScoreRangeQuery and ConstantScoreQuery work
     with RemoteSearchable.  (Philippe Laflamme via Yonik Seeley)
 
+ 3. Added methods to get/set writeLockTimeout and commitLockTimeout in
+    IndexWriter. These could be set in Lucene 1.4 using a system property.
+    This feature had been removed without adding the corresponding 
+    getter/setter methods.  (Daniel Naber)
+ 
 1.9.1
 
 Bug fixes

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?rev=386749&r1=386748&r2=386749&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Fri Mar 17 14:51:32
2006
@@ -59,15 +59,19 @@
 public class IndexWriter {
 
   /**
-   * Default value is 1,000.
+   * Default value for the write lock timeout (1,000).
    */
   public final static long WRITE_LOCK_TIMEOUT = 1000;
 
+  private long writeLockTimeout = WRITE_LOCK_TIMEOUT;
+
   /**
-   * Default value is 10,000.
+   * Default value for the commit lock timeout (10,000).
    */
   public final static long COMMIT_LOCK_TIMEOUT = 10000;
 
+  private long commitLockTimeout = COMMIT_LOCK_TIMEOUT;
+
   public static final String WRITE_LOCK_NAME = "write.lock";
   public static final String COMMIT_LOCK_NAME = "commit.lock";
 
@@ -252,12 +256,12 @@
       analyzer = a;
 
       Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);
-      if (!writeLock.obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock
+      if (!writeLock.obtain(writeLockTimeout)) // obtain write lock
         throw new IOException("Index locked for write: " + writeLock);
       this.writeLock = writeLock;                   // save it
 
       synchronized (directory) {        // in- & inter-process sync
-        new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT)
{
+        new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), commitLockTimeout)
{
             public Object doBody() throws IOException {
               if (create)
                 segmentInfos.write(directory);
@@ -370,6 +374,34 @@
     return infoStream;
   }
 
+  /**
+   * Sets the maximum time to wait for a commit lock (in milliseconds).
+   */
+  public void setCommitLockTimeout(long commitLockTimeout) {
+    this.commitLockTimeout = commitLockTimeout;
+  }
+
+  /**
+   * @see #setCommitLockTimeout
+   */
+  public long getCommitLockTimeout() {
+    return commitLockTimeout;
+  }
+
+  /**
+   * Sets the maximum time to wait for a write lock (in milliseconds).
+   */
+  public void setWriteLockTimeout(long writeLockTimeout) {
+    this.writeLockTimeout = writeLockTimeout;
+  }
+
+  /**
+   * @see #setWriteLockTimeout
+   */
+  public long getWriteLockTimeout() {
+    return writeLockTimeout;
+  }
+
   /** Flushes all changes to an index and closes all associated files. */
   public synchronized void close() throws IOException {
     flushRamSegments();
@@ -585,7 +617,7 @@
         sReader.close();
 
     synchronized (directory) {			  // in- & inter-process sync
-      new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) {
+      new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) {
 	  public Object doBody() throws IOException {
 	    segmentInfos.write(directory);	  // commit changes
 	    deleteSegments(segmentsToDelete);  // delete now-unused segments
@@ -597,7 +629,7 @@
     if (useCompoundFile) {
       final Vector filesToDelete = merger.createCompoundFile(mergedName + ".tmp");
       synchronized (directory) { // in- & inter-process sync
-        new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) {
+        new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) {
           public Object doBody() throws IOException {
             // make compound file visible for SegmentReaders
             directory.renameFile(mergedName + ".tmp", mergedName + ".cfs");
@@ -693,7 +725,7 @@
     merger.closeReaders();
 
     synchronized (directory) {                 // in- & inter-process sync
-      new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) {
+      new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) {
           public Object doBody() throws IOException {
             segmentInfos.write(directory);     // commit before deleting
             deleteSegments(segmentsToDelete);  // delete now-unused segments
@@ -705,7 +737,7 @@
     if (useCompoundFile) {
       final Vector filesToDelete = merger.createCompoundFile(mergedName + ".tmp");
       synchronized (directory) { // in- & inter-process sync
-        new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) {
+        new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) {
           public Object doBody() throws IOException {
             // make compound file visible for SegmentReaders
             directory.renameFile(mergedName + ".tmp", mergedName + ".cfs");



Mime
View raw message