From a9234bcd9ba60d46d7799fd4e19adf4c88e5f6c7 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Fri, 21 Aug 2026 16:36:03 +0300 Subject: [PATCH] SOLR-18364: Remove deprecated SolrCore.isWriterLocked(Directory) Internal, private, single call site. Inlined its check-then-release logic directly into initIndex() and removed the wrapper method. --- .../java/org/apache/solr/core/SolrCore.java | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index de65bea0d6f..b0b22052934 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -850,24 +850,6 @@ private void initIndexReaderFactory() { // protect via synchronized(SolrCore.class) private static Set dirs = new HashSet<>(); - /** - * Returns true 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 passOnPreviousState, boolean reload) throws IOException { String indexDir = getNewIndexDir(); boolean indexExists = getDirectoryFactory().exists(indexDir); @@ -882,7 +864,14 @@ void initIndex(boolean passOnPreviousState, boolean reload) throws IOException { final String lockType = getSolrConfig().indexConfig.lockType; Directory dir = directoryFactory.get(indexDir, DirContext.DEFAULT, lockType); try { - if (isWriterLocked(dir)) { + boolean writerLocked; + try { + dir.obtainLock(IndexWriter.WRITE_LOCK_NAME).close(); + writerLocked = false; + } catch (LockObtainFailedException failed) { + writerLocked = true; + } + if (writerLocked) { log.error( "Solr index directory '{}' is locked (lockType={}). Throwing exception.", indexDir,