Skip to content

Apache Lucene open-source search software

LUCENE-6525: Deprecate IndexWriterConfig's write lock timeout

Robert Muir5438754ac1cd
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 2eec4cb7d85..4eaf785e13b 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -100,6 +100,9 @@ API Changes
* LUCENE-6552: Add MergePolicy.OneMerge.getMergeInfo and rename
setInfo to setMergeInfo (Simon Willnauer, Mike McCandless)
+* LUCENE-6525: Deprecate IndexWriterConfig's writeLockTimeout.
+ (Robert Muir)
+
Bug fixes
* LUCENE-6500: ParallelCompositeReader did not always call
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index c9617a8d37e..37f6ea9566c 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -59,6 +59,7 @@ import org.apache.lucene.store.Lock;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.MergeInfo;
import org.apache.lucene.store.RateLimitedIndexOutput;
+import org.apache.lucene.store.SleepingLockWrapper;
import org.apache.lucene.store.TrackingDirectoryWrapper;
import org.apache.lucene.store.LockValidatingDirectoryWrapper;
import org.apache.lucene.util.Accountable;
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java
index 623a342d91d..f614e5762ce 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java
@@ -24,6 +24,7 @@ import org.apache.lucene.codecs.Codec;
import org.apache.lucene.index.DocumentsWriterPerThread.IndexingChain;
import org.apache.lucene.index.IndexWriter.IndexReaderWarmer;
import org.apache.lucene.search.similarities.Similarity;
+import org.apache.lucene.store.SleepingLockWrapper;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.PrintStreamInfoStream;
import org.apache.lucene.util.SetOnce;
@@ -87,11 +88,11 @@ public final class IndexWriterConfig extends LiveIndexWriterConfig {
public final static double DEFAULT_RAM_BUFFER_SIZE_MB = 16.0;
/**
- * Default value for the write lock timeout (1,000 ms).
- *
- * @see #setDefaultWriteLockTimeout(long)
+ * Default value for the write lock timeout (0 ms: no sleeping).
+ * @deprecated Use {@link SleepingLockWrapper} if you want sleeping.
*/
- public static long WRITE_LOCK_TIMEOUT = 1000;
+ @Deprecated
+ public static final long WRITE_LOCK_TIMEOUT = 0;
/** Default setting for {@link #setReaderPooling}. */
public final static boolean DEFAULT_READER_POOLING = false;
@@ -113,24 +114,6 @@ public final class IndexWriterConfig extends LiveIndexWriterConfig {
/** Default value for whether calls to {@link IndexWriter#close()} include a commit. */
public final static boolean DEFAULT_COMMIT_ON_CLOSE = true;
- /**
- * Sets the default (for any instance) maximum time to wait for a write lock
- * (in milliseconds).
- */
- public static void setDefaultWriteLockTimeout(long writeLockTimeout) {
- WRITE_LOCK_TIMEOUT = writeLockTimeout;
- }
-
- /**
- * Returns the default write lock timeout for newly instantiated
- * IndexWriterConfigs.
- *
- * @see #setDefaultWriteLockTimeout(long)
- */
- public static long getDefaultWriteLockTimeout() {
- return WRITE_LOCK_TIMEOUT;
- }
-
// indicates whether this config instance is already attached to a writer.
// not final so that it can be cloned properly.
private SetOnce<IndexWriter> writer = new SetOnce<>();
@@ -264,11 +247,12 @@ public final class IndexWriterConfig extends LiveIndexWriterConfig {
/**
* Sets the maximum time to wait for a write lock (in milliseconds) for this
- * instance. You can change the default value for all instances by calling
- * {@link #setDefaultWriteLockTimeout(long)}. Note that the value can be zero,
- * for no sleep/retry behavior.
+ * instance. Note that the value can be zero, for no sleep/retry behavior.
*
- * <p>Only takes effect when IndexWriter is first created. */
+ * <p>Only takes effect when IndexWriter is first created.
+ * @deprecated Use {@link SleepingLockWrapper} if you want sleeping.
+ */
+ @Deprecated
public IndexWriterConfig setWriteLockTimeout(long writeLockTimeout) {
this.writeLockTimeout = writeLockTimeout;
return this;
diff --git a/lucene/core/src/java/org/apache/lucene/index/LiveIndexWriterConfig.java b/lucene/core/src/java/org/apache/lucene/index/LiveIndexWriterConfig.java
index 801e01454d6..846037102ed 100644
--- a/lucene/core/src/java/org/apache/lucene/index/LiveIndexWriterConfig.java
+++ b/lucene/core/src/java/org/apache/lucene/index/LiveIndexWriterConfig.java
@@ -24,6 +24,7 @@ import org.apache.lucene.index.IndexWriter.IndexReaderWarmer;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.similarities.Similarity;
+import org.apache.lucene.store.SleepingLockWrapper;
import org.apache.lucene.util.InfoStream;
/**
@@ -60,7 +61,11 @@ public class LiveIndexWriterConfig {
/** {@link MergeScheduler} to use for running merges. */
protected volatile MergeScheduler mergeScheduler;
- /** Timeout when trying to obtain the write lock on init. */
+ /**
+ * Timeout when trying to obtain the write lock on init.
+ * @deprecated Use {@link SleepingLockWrapper} if you want sleeping.
+ */
+ @Deprecated
protected volatile long writeLockTimeout;
/** {@link IndexingChain} that determines how documents are
@@ -355,7 +360,9 @@ public class LiveIndexWriterConfig {
* Returns allowed timeout when acquiring the write lock.
*
* @see IndexWriterConfig#setWriteLockTimeout(long)
+ * @deprecated Use {@link SleepingLockWrapper} if you want sleeping.
*/
+ @Deprecated
public long getWriteLockTimeout() {
return writeLockTimeout;
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/SleepingLockWrapper.java b/lucene/core/src/java/org/apache/lucene/store/SleepingLockWrapper.java
similarity index 93%
rename from lucene/core/src/java/org/apache/lucene/index/SleepingLockWrapper.java
rename to lucene/core/src/java/org/apache/lucene/store/SleepingLockWrapper.java
index 3a01d3b94ee..7f808d1ca54 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SleepingLockWrapper.java
+++ b/lucene/core/src/java/org/apache/lucene/store/SleepingLockWrapper.java
@@ -1,4 +1,4 @@
-package org.apache.lucene.index;
+package org.apache.lucene.store;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,10 +19,6 @@ package org.apache.lucene.index;
import java.io.IOException;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FilterDirectory;
-import org.apache.lucene.store.Lock;
-import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.ThreadInterruptedException;
/**
@@ -31,7 +27,7 @@ import org.apache.lucene.util.ThreadInterruptedException;
* <p>
* This is not a good idea.
*/
-final class SleepingLockWrapper extends FilterDirectory {
+public final class SleepingLockWrapper extends FilterDirectory {
/**
* Pass this lockWaitTimeout to try forever to obtain the lock.
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterConfig.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterConfig.java
index a575425b137..0f0d380e02b 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterConfig.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterConfig.java
@@ -63,8 +63,6 @@ public class TestIndexWriterConfig extends LuceneTestCase {
assertEquals(OpenMode.CREATE_OR_APPEND, conf.getOpenMode());
// we don't need to assert this, it should be unspecified
assertTrue(IndexSearcher.getDefaultSimilarity() == conf.getSimilarity());
- assertEquals(IndexWriterConfig.getDefaultWriteLockTimeout(), conf.getWriteLockTimeout());
- assertEquals(IndexWriterConfig.WRITE_LOCK_TIMEOUT, IndexWriterConfig.getDefaultWriteLockTimeout());
assertEquals(IndexWriterConfig.DEFAULT_MAX_BUFFERED_DELETE_TERMS, conf.getMaxBufferedDeleteTerms());
assertEquals(IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB, conf.getRAMBufferSizeMB(), 0.0);
assertEquals(IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS, conf.getMaxBufferedDocs());
@@ -179,7 +177,7 @@ public class TestIndexWriterConfig extends LuceneTestCase {
@Test
public void testConstants() throws Exception {
// Tests that the values of the constants does not change
- assertEquals(1000, IndexWriterConfig.WRITE_LOCK_TIMEOUT);
+ assertEquals(0, IndexWriterConfig.WRITE_LOCK_TIMEOUT);
assertEquals(-1, IndexWriterConfig.DISABLE_AUTO_FLUSH);
assertEquals(IndexWriterConfig.DISABLE_AUTO_FLUSH, IndexWriterConfig.DEFAULT_MAX_BUFFERED_DELETE_TERMS);
assertEquals(IndexWriterConfig.DISABLE_AUTO_FLUSH, IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSleepingLockWrapper.java b/lucene/core/src/test/org/apache/lucene/store/TestSleepingLockWrapper.java
similarity index 95%
rename from lucene/core/src/test/org/apache/lucene/index/TestSleepingLockWrapper.java
rename to lucene/core/src/test/org/apache/lucene/store/TestSleepingLockWrapper.java
index daa3952ac77..c4608965f82 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestSleepingLockWrapper.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestSleepingLockWrapper.java
@@ -1,4 +1,4 @@
-package org.apache.lucene.index;
+package org.apache.lucene.store;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,10 +20,10 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.nio.file.Path;
-import org.apache.lucene.index.SleepingLockWrapper;
import org.apache.lucene.store.BaseLockFactoryTestCase;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.SingleInstanceLockFactory;
+import org.apache.lucene.store.SleepingLockWrapper;
import org.apache.lucene.util.TestUtil;
/** Simple tests for SleepingLockWrapper */