Apache Lucene open-source search software
remove deprecated IndexWriter.isLocked()
Robert Muird489b8c05ddb
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex 0fb23d96b36..7abf681fe88 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -4685,24 +4685,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {testPoint("finishStartCommit");}- /**- * Returns <code>true</code> iff the index in the named directory is- * currently locked.- * @param directory the directory to check for a lock- * @throws IOException if there is a low-level IO error- * @deprecated Use of this method can only lead to race conditions. Try- * to actually obtain a lock instead.- */- @Deprecated- public static boolean isLocked(Directory directory) throws IOException {- try {- directory.obtainLock(WRITE_LOCK_NAME).close();- return false;- } catch (LockObtainFailedException failed) {- return true;- }- }-/** If {@link DirectoryReader#open(IndexWriter)} has* been called (ie, this writer is in near real-time* mode), then after a merge completes, this class can bediff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.javaindex 2704e4ac868..90bcd346877 100644--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java@@ -549,6 +549,24 @@ public final class SolrCore implements SolrInfoMBean, Closeable {// protect via synchronized(SolrCore.class)private static Set<String> dirs = new HashSet<>();+ /**+ * Returns <code>true</code> iff the index in the named directory is+ * currently locked.+ * @param directory the directory to check for a lock+ * @throws IOException if there is a low-level IO error+ * @deprecated Use of this method can only lead to race conditions. Try+ * to actually obtain a lock instead.+ */+ @Deprecated+ private static boolean isWriterLocked(Directory directory) throws IOException {+ try {+ directory.obtainLock(IndexWriter.WRITE_LOCK_NAME).close();+ return false;+ } catch (LockObtainFailedException failed) {+ return true;+ }+ }+void initIndex(boolean reload) throws IOException {String indexDir = getNewIndexDir();@@ -564,7 +582,7 @@ public final class SolrCore implements SolrInfoMBean, Closeable {final String lockType = getSolrConfig().indexConfig.lockType;Directory dir = directoryFactory.get(indexDir, DirContext.DEFAULT, lockType);try {- if (IndexWriter.isLocked(dir)) {+ if (isWriterLocked(dir)) {log.error(logid + "Solr index directory '{}' is locked (lockType={}). Throwing exception.",indexDir, lockType);throw new LockObtainFailedException