This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_10x in repository https://gitbox.apache.org/repos/asf/solr.git
commit 783f3bc393055c476d4ceb3995412a3868fcfca6 Author: Surya Shukla <[email protected]> AuthorDate: Sat Aug 1 22:21:30 2026 +0530 SOLR-18183: Permit LockType.NONE for ephemeral directories (#4660) (cherry picked from commit 8fa14f1048f00decc7ade6fede1350a862e97d7e) --- .../java/org/apache/solr/core/ByteBuffersDirectoryFactory.java | 9 ++++++++- solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java | 9 ++++++++- .../src/test-files/solr/configsets/zipfs/conf/solrconfig.xml | 2 +- .../org/apache/solr/core/ByteBuffersDirectoryFactoryTest.java | 6 ++++++ .../src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java | 6 ++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/ByteBuffersDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/ByteBuffersDirectoryFactory.java index aeed5d589f4..aab134a266e 100644 --- a/solr/core/src/java/org/apache/solr/core/ByteBuffersDirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/ByteBuffersDirectoryFactory.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.lucene.store.ByteBuffersDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockFactory; +import org.apache.lucene.store.NoLockFactory; import org.apache.lucene.store.SingleInstanceLockFactory; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; @@ -29,13 +30,19 @@ public class ByteBuffersDirectoryFactory extends EphemeralDirectoryFactory { @Override protected LockFactory createLockFactory(String rawLockType) throws IOException { + if (rawLockType != null + && DirectoryFactory.LOCK_TYPE_NONE.equalsIgnoreCase(rawLockType.trim())) { + return NoLockFactory.INSTANCE; + } if (!(rawLockType == null || DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) { throw new SolrException( ErrorCode.FORBIDDEN, "ByteBuffersDirectory can only be used with the '" + DirectoryFactory.LOCK_TYPE_SINGLE - + "' lock factory type."); + + "' or '" + + DirectoryFactory.LOCK_TYPE_NONE + + "' lock factory types."); } return new SingleInstanceLockFactory(); } diff --git a/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java index 052dc0106f1..9b171806280 100644 --- a/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.lucene.store.ByteBuffersDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockFactory; +import org.apache.lucene.store.NoLockFactory; import org.apache.lucene.store.SingleInstanceLockFactory; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; @@ -29,13 +30,19 @@ public class RAMDirectoryFactory extends EphemeralDirectoryFactory { @Override protected LockFactory createLockFactory(String rawLockType) throws IOException { + if (rawLockType != null + && DirectoryFactory.LOCK_TYPE_NONE.equalsIgnoreCase(rawLockType.trim())) { + return NoLockFactory.INSTANCE; + } if (!(rawLockType == null || DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) { throw new SolrException( ErrorCode.FORBIDDEN, "RAMDirectory can only be used with the '" + DirectoryFactory.LOCK_TYPE_SINGLE - + "' lock factory type."); + + "' or '" + + DirectoryFactory.LOCK_TYPE_NONE + + "' lock factory types."); } return new SingleInstanceLockFactory(); } diff --git a/solr/core/src/test-files/solr/configsets/zipfs/conf/solrconfig.xml b/solr/core/src/test-files/solr/configsets/zipfs/conf/solrconfig.xml index 1beded14516..b16b37fd10c 100644 --- a/solr/core/src/test-files/solr/configsets/zipfs/conf/solrconfig.xml +++ b/solr/core/src/test-files/solr/configsets/zipfs/conf/solrconfig.xml @@ -23,7 +23,7 @@ <directoryFactory class="solr.RAMDirectoryFactory"/> <indexConfig> - <lockType>single</lockType> + <lockType>none</lockType> </indexConfig> <schemaFactory class="ClassicIndexSchemaFactory"/> diff --git a/solr/core/src/test/org/apache/solr/core/ByteBuffersDirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/ByteBuffersDirectoryFactoryTest.java index ba3c04ab6df..1c72b2fa48c 100644 --- a/solr/core/src/test/org/apache/solr/core/ByteBuffersDirectoryFactoryTest.java +++ b/solr/core/src/test/org/apache/solr/core/ByteBuffersDirectoryFactoryTest.java @@ -20,12 +20,18 @@ import java.io.IOException; import org.apache.lucene.store.ByteBuffersDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockFactory; +import org.apache.lucene.store.NoLockFactory; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.core.DirectoryFactory.DirContext; /** Test-case for ByteBuffersDirectoryFactory */ public class ByteBuffersDirectoryFactoryTest extends SolrTestCaseJ4 { + public void testLockTypeNone() throws IOException { + ByteBuffersDirectoryFactory factory = new ByteBuffersDirectoryFactory(); + assertSame(NoLockFactory.INSTANCE, factory.createLockFactory(DirectoryFactory.LOCK_TYPE_NONE)); + } + public void testOpenReturnsTheSameForSamePath() throws IOException { final Directory directory = new ByteBuffersDirectory(); ByteBuffersDirectoryFactory factory = diff --git a/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java index c0c418f8f82..70543e824e7 100644 --- a/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java +++ b/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.lucene.store.ByteBuffersDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockFactory; +import org.apache.lucene.store.NoLockFactory; import org.apache.solr.SolrTestCase; import org.apache.solr.core.DirectoryFactory.DirContext; @@ -31,6 +32,11 @@ public class RAMDirectoryFactoryTest extends SolrTestCase { dotestOpenSucceedForEmptyDir(); } + public void testLockTypeNone() throws IOException { + RAMDirectoryFactory factory = new RAMDirectoryFactory(); + assertSame(NoLockFactory.INSTANCE, factory.createLockFactory(DirectoryFactory.LOCK_TYPE_NONE)); + } + private void dotestOpenReturnsTheSameForSamePath() throws IOException { final Directory directory = new ByteBuffersDirectory(); RAMDirectoryFactory factory =
