Apache Solr open-source search software
SOLR-6519: Make DirectoryFactory#create() take LockFactory
Uwe Schindler1866163a7251
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 408572a017a..caf88e6a88f 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -105,6 +105,9 @@ Other Changes* SOLR-6073: Remove helper methods from CollectionsRequest (SolrJ) for CollectionsAPIcalls and move to a builder design for the same. (Varun Thacker, Anshum Gupta)+* SOLR-6519: Make DirectoryFactory#create() take LockFactory.+ (Uwe Schindler)+================== 4.11.0 =================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this releasediff --git a/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.java b/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.javaindex f1da3a0d795..781996e8f69 100644--- a/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.java+++ b/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.java@@ -38,6 +38,7 @@ import org.apache.lucene.index.MergePolicy;import org.apache.lucene.index.TieredMergePolicy;import org.apache.lucene.misc.IndexMergeTool;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.NoLockFactory;import org.apache.solr.store.hdfs.HdfsDirectory;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -93,7 +94,7 @@ public class TreeMergeOutputFormat extends FileOutputFormat<Text, NullWritable>writeShardNumberFile(context);heartBeater.needHeartBeat();try {- Directory mergedIndex = new HdfsDirectory(workDir, context.getConfiguration());+ Directory mergedIndex = new HdfsDirectory(workDir, NoLockFactory.getNoLockFactory(), context.getConfiguration());// TODO: shouldn't we pull the Version from the solrconfig.xml?IndexWriterConfig writerConfig = new IndexWriterConfig(null)@@ -127,7 +128,7 @@ public class TreeMergeOutputFormat extends FileOutputFormat<Text, NullWritable>Directory[] indexes = new Directory[shards.size()];for (int i = 0; i < shards.size(); i++) {- indexes[i] = new HdfsDirectory(shards.get(i), context.getConfiguration());+ indexes[i] = new HdfsDirectory(shards.get(i), NoLockFactory.getNoLockFactory(), context.getConfiguration());}context.setStatus("Logically merging " + shards.size() + " shards into one shard");diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.javaindex 4dfa4e05eb2..7ac2342f23e 100644--- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java@@ -32,6 +32,7 @@ import java.util.Set;import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext.Context;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.NRTCachingDirectory;import org.apache.lucene.store.NativeFSLockFactory;import org.apache.lucene.store.NoLockFactory;@@ -51,7 +52,7 @@ import org.slf4j.LoggerFactory;/*** A {@link DirectoryFactory} impl base class for caching Directory instances* per path. Most DirectoryFactory implementations will want to extend this- * class and simply implement {@link DirectoryFactory#create(String, DirContext)}.+ * class and simply implement {@link DirectoryFactory#create(String, LockFactory, DirContext)}.** This is an expert class and these API's are subject to change.*@@ -316,9 +317,6 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {return otherCacheValue.path.startsWith(cacheValue.path + "/") && two > one;}-- @Override- protected abstract Directory create(String path, DirContext dirContext) throws IOException;@Overridepublic boolean exists(String path) throws IOException {@@ -349,15 +347,11 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {}if (directory == null) {- directory = create(fullPath, dirContext);+ directory = create(fullPath, createLockFactory(fullPath, rawLockType), dirContext);boolean success = false;try {directory = rateLimit(directory);-CacheValue newCacheValue = new CacheValue(fullPath, directory);-- injectLockFactory(directory, fullPath, rawLockType);-byDirectoryCache.put(directory, newCacheValue);byPathCache.put(fullPath, newCacheValue);log.info("return new directory for " + fullPath);@@ -494,52 +488,6 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {}}- private static Directory injectLockFactory(Directory dir, String lockPath,- String rawLockType) throws IOException {- if (null == rawLockType) {- // we default to "simple" for backwards compatibility- log.warn("No lockType configured for " + dir + " assuming 'simple'");- rawLockType = "simple";- }- final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();-- if ("simple".equals(lockType)) {- // multiple SimpleFSLockFactory instances should be OK- dir.setLockFactory(new SimpleFSLockFactory(new File(lockPath).toPath()));- } else if ("native".equals(lockType)) {- dir.setLockFactory(new NativeFSLockFactory(new File(lockPath).toPath()));- } else if ("single".equals(lockType)) {- if (!(dir.getLockFactory() instanceof SingleInstanceLockFactory)) dir- .setLockFactory(new SingleInstanceLockFactory());- } else if ("hdfs".equals(lockType)) {- Directory del = dir;-- if (dir instanceof NRTCachingDirectory) {- del = ((NRTCachingDirectory) del).getDelegate();- }-- if (del instanceof BlockDirectory) {- del = ((BlockDirectory) del).getDirectory();- }-- if (!(del instanceof HdfsDirectory)) {- throw new SolrException(ErrorCode.FORBIDDEN, "Directory: "- + del.getClass().getName()- + ", but hdfs lock factory can only be used with HdfsDirectory");- }-- dir.setLockFactory(new HdfsLockFactory(((HdfsDirectory)del).getHdfsDirPath(), ((HdfsDirectory)del).getConfiguration()));- } else if ("none".equals(lockType)) {- // Recipe for disaster- log.error("CONFIGURATION WARNING: locks are disabled on " + dir);- dir.setLockFactory(NoLockFactory.getNoLockFactory());- } else {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,- "Unrecognized lockType: " + rawLockType);- }- return dir;- }-protected synchronized void removeDirectory(CacheValue cacheValue) throws IOException {// this page intentionally left blank}diff --git a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.javaindex f4a2a3baadf..02f42e68ba4 100644--- a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java@@ -26,6 +26,7 @@ import java.nio.file.NoSuchFileException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FlushInfo;import org.apache.lucene.store.IOContext;+import org.apache.lucene.store.LockFactory;import org.apache.solr.common.SolrException;import org.apache.solr.core.CachingDirectoryFactory.CloseListener;import org.apache.solr.util.plugin.NamedListInitializedPlugin;@@ -76,7 +77,15 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin,** @throws IOException If there is a low-level I/O error.*/- protected abstract Directory create(String path, DirContext dirContext) throws IOException;+ protected abstract Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException;++ /**+ * Creates a new LockFactory for a given path.+ * @param lockPath the path of the index directory+ * @param rawLockType A string value as passed in config. Every factory should at least support 'none' to disable locking.+ * @throws IOException If there is a low-level I/O error.+ */+ protected abstract LockFactory createLockFactory(String lockPath, String rawLockType) throws IOException;/*** Returns true if a Directory exists for a given path.diff --git a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.javaindex e77dad119cc..819ca907306 100644--- a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java@@ -17,17 +17,26 @@ package org.apache.solr.core;* limitations under the License.*/+import java.io.File;import java.io.IOException;import java.net.URI;import java.net.URLEncoder;+import java.util.Locale;import org.apache.hadoop.conf.Configuration;+import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION;+import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.security.UserGroupInformation;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.NRTCachingDirectory;+import org.apache.lucene.store.NativeFSLockFactory;+import org.apache.lucene.store.NoLockFactory;+import org.apache.lucene.store.SimpleFSLockFactory;+import org.apache.lucene.store.SingleInstanceLockFactory;import org.apache.solr.cloud.ZkController;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;@@ -40,6 +49,7 @@ import org.apache.solr.store.blockcache.BufferStore;import org.apache.solr.store.blockcache.Cache;import org.apache.solr.store.blockcache.Metrics;import org.apache.solr.store.hdfs.HdfsDirectory;+import org.apache.solr.store.hdfs.HdfsLockFactory;import org.apache.solr.util.HdfsUtil;import org.apache.solr.util.IOUtils;import org.slf4j.Logger;@@ -98,8 +108,25 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory {}@Override- protected Directory create(String path, DirContext dirContext)- throws IOException {+ protected LockFactory createLockFactory(String lockPath, String rawLockType) throws IOException {+ if (null == rawLockType) {+ LOG.warn("No lockType configured, assuming 'hdfs'.");+ rawLockType = "hdfs";+ }+ final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();+ switch (lockType) {+ case "hdfs":+ return new HdfsLockFactory(new Path(lockPath), getConf());+ case "none":+ return NoLockFactory.getNoLockFactory();+ default:+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,+ "Unrecognized lockType: " + rawLockType);+ }+ }++ @Override+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {LOG.info("creating directory factory for path {}", path);Configuration conf = getConf();@@ -115,8 +142,8 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory {if (blockCacheWriteEnabled) {LOG.warn("Using " + BLOCKCACHE_WRITE_ENABLED + " is currently buggy and can result in readers seeing a corrupted view of the index.");}- Directory dir = null;+ final Directory dir;if (blockCacheEnabled && dirContext != DirContext.META_DATA) {int numberOfBlocksPerBank = params.getInt(NUMBEROFBLOCKSPERBANK, 16384);@@ -144,11 +171,11 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory {bufferSize, bufferCount, blockCacheGlobal);Cache cache = new BlockDirectoryCache(blockCache, path, metrics, blockCacheGlobal);- HdfsDirectory hdfsDirectory = new HdfsDirectory(new Path(path), conf);+ HdfsDirectory hdfsDirectory = new HdfsDirectory(new Path(path), lockFactory, conf);dir = new BlockDirectory(path, hdfsDirectory, cache, null,blockCacheReadEnabled, blockCacheWriteEnabled);} else {- dir = new HdfsDirectory(new Path(path), conf);+ dir = new HdfsDirectory(new Path(path), lockFactory, conf);}boolean nrtCachingDirectory = params.getBool(NRTCACHINGDIRECTORY_ENABLE, true);diff --git a/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.javaindex 81127b9a6cd..84e46a7199b 100644--- a/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java@@ -17,20 +17,18 @@ package org.apache.solr.core;*/+import java.io.File;+import java.io.IOException;+import java.nio.file.Path;+import org.apache.lucene.store.Directory;import org.apache.lucene.store.LockFactory; // javadocsimport org.apache.lucene.store.MMapDirectory;-import org.apache.lucene.store.NoLockFactory;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;-import org.apache.solr.core.DirectoryFactory.DirContext;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import java.io.File;-import java.io.IOException;-import java.nio.file.Path;-/*** Directly provide MMapDirectory instead of relying on {@link org.apache.lucene.store.FSDirectory#open}.@@ -59,12 +57,12 @@ public class MMapDirectoryFactory extends StandardDirectoryFactory {}@Override- protected Directory create(String path, DirContext dirContext) throws IOException {+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:- MMapDirectory mapDirectory = new MMapDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory(), maxChunk);+ MMapDirectory mapDirectory = new MMapDirectory(new File(path).toPath(), lockFactory, maxChunk);try {mapDirectory.setUseUnmap(unmapHack);- } catch (Exception e) {+ } catch (IllegalArgumentException e) {log.warn("Unmap not supported on this JVM, continuing on without setting unmap", e);}return mapDirectory;diff --git a/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.javaindex 53bb33e0eef..96027fdc38d 100644--- a/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.java@@ -20,8 +20,8 @@ import java.io.File;import java.io.IOException;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.NIOFSDirectory;-import org.apache.lucene.store.NoLockFactory;/**@@ -31,9 +31,9 @@ import org.apache.lucene.store.NoLockFactory;public class NIOFSDirectoryFactory extends StandardDirectoryFactory {@Override- protected Directory create(String path, DirContext dirContext) throws IOException {+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:- return new NIOFSDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory());+ return new NIOFSDirectory(new File(path).toPath(), lockFactory);}@Overridediff --git a/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.javaindex 9119af1b7bd..59ac10585c4 100644--- a/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java@@ -22,8 +22,8 @@ import java.io.IOException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.NRTCachingDirectory;-import org.apache.lucene.store.NoLockFactory;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;@@ -51,9 +51,9 @@ public class NRTCachingDirectoryFactory extends StandardDirectoryFactory {}@Override- protected Directory create(String path, DirContext dirContext) throws IOException {+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:- return new NRTCachingDirectory(FSDirectory.open(new File(path).toPath(), NoLockFactory.getNoLockFactory()), maxMergeSizeMB, maxCachedMB);+ return new NRTCachingDirectory(FSDirectory.open(new File(path).toPath(), lockFactory), maxMergeSizeMB, maxCachedMB);}@Overridediff --git a/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.javaindex d70fef2ac6b..a5ddd13aacb 100644--- a/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java@@ -20,16 +20,35 @@ package org.apache.solr.core;import java.io.IOException;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.RAMDirectory;+import org.apache.lucene.store.SingleInstanceLockFactory;+import org.apache.solr.common.SolrException;+import org.apache.solr.common.SolrException.ErrorCode;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;/*** Factory to instantiate {@link org.apache.lucene.store.RAMDirectory}*/public class RAMDirectoryFactory extends EphemeralDirectoryFactory {+ public static Logger LOG = LoggerFactory.getLogger(RAMDirectoryFactory.class);+@Override- protected Directory create(String path, DirContext dirContext) throws IOException {- return new RAMDirectory();+ protected LockFactory createLockFactory(String lockPath, String rawLockType) throws IOException {+ if (!(rawLockType == null || "single".equalsIgnoreCase(rawLockType.trim()))) {+ throw new SolrException(ErrorCode.FORBIDDEN,+ "RAMDirectory can only be used with the 'single' lock factory type.");+ }+ return new SingleInstanceLockFactory();+ }++ @Override+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {+ final Directory dir = new RAMDirectory();+ dir.setLockFactory(lockFactory); // more or less a no-op, just for completeness+ return dir;}}diff --git a/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.javaindex 6c4f06c806b..304fca22fd1 100644--- a/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java@@ -20,6 +20,7 @@ import java.io.File;import java.io.IOException;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.NoLockFactory;import org.apache.lucene.store.SimpleFSDirectory;@@ -31,9 +32,9 @@ import org.apache.lucene.store.SimpleFSDirectory;public class SimpleFSDirectoryFactory extends StandardDirectoryFactory {@Override- protected Directory create(String path, DirContext dirContext) throws IOException {+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:- return new SimpleFSDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory());+ return new SimpleFSDirectory(new File(path).toPath(), lockFactory);}@Overridediff --git a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.javaindex c247add5645..aedb8d4b0bb 100644--- a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java@@ -18,15 +18,23 @@ package org.apache.solr.core;import java.io.File;import java.io.IOException;+import java.util.Locale;import org.apache.commons.io.FileUtils;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;import org.apache.lucene.store.IOContext;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.NRTCachingDirectory;+import org.apache.lucene.store.NativeFSLockFactory;import org.apache.lucene.store.NoLockFactory;import org.apache.lucene.store.RateLimitedDirectoryWrapper;-import org.apache.solr.core.CachingDirectoryFactory.CacheValue;+import org.apache.lucene.store.SimpleFSLockFactory;+import org.apache.lucene.store.SingleInstanceLockFactory;+import org.apache.solr.common.SolrException;+import org.apache.solr.common.SolrException.ErrorCode;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;/*** Directory provider which mimics original Solr@@ -38,10 +46,33 @@ import org.apache.solr.core.CachingDirectoryFactory.CacheValue;*/public class StandardDirectoryFactory extends CachingDirectoryFactory {+ private static final Logger log = LoggerFactory.getLogger(StandardDirectoryFactory.class);+@Override- protected Directory create(String path, DirContext dirContext) throws IOException {+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:- return FSDirectory.open(new File(path).toPath(), NoLockFactory.getNoLockFactory());+ return FSDirectory.open(new File(path).toPath(), lockFactory);+ }++ @Override+ protected LockFactory createLockFactory(String lockPath, String rawLockType) throws IOException {+ if (null == rawLockType) {+ // we default to "native"+ log.warn("No lockType configured, assuming 'native'.");+ rawLockType = "native";+ }+ final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();+ switch (lockType) {+ case "simple":+ return new SimpleFSLockFactory(new File(lockPath).toPath());+ case "native":+ return new NativeFSLockFactory(new File(lockPath).toPath());+ case "none":+ return NoLockFactory.getNoLockFactory();+ default:+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,+ "Unrecognized lockType: " + rawLockType);+ }}@Overridediff --git a/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java b/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.javaindex dddd406f3bb..c6e64d27256 100644--- a/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java+++ b/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java@@ -34,7 +34,7 @@ import org.apache.lucene.store.BaseDirectory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;import org.apache.lucene.store.IndexOutput;-import org.apache.lucene.store.NoLockFactory;+import org.apache.lucene.store.LockFactory;import org.apache.solr.store.blockcache.CustomBufferedIndexInput;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -51,9 +51,9 @@ public class HdfsDirectory extends BaseDirectory {private final FileSystem fileSystem;private final FileContext fileContext;- public HdfsDirectory(Path hdfsDirPath, Configuration configuration)+ public HdfsDirectory(Path hdfsDirPath, LockFactory lockFactory, Configuration configuration)throws IOException {- setLockFactory(NoLockFactory.getNoLockFactory());+ setLockFactory(lockFactory);this.hdfsDirPath = hdfsDirPath;this.configuration = configuration;fileSystem = FileSystem.newInstance(hdfsDirPath.toUri(), configuration);diff --git a/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.java b/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.javaindex 7803df8eb60..d7158067e2b 100644--- a/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.java+++ b/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.java@@ -22,10 +22,9 @@ import java.io.IOException;import org.apache.lucene.index.DirectoryReader;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.NoLockFactory;+import org.apache.lucene.store.LockFactory;import org.apache.solr.SolrTestCaseJ4;import org.junit.BeforeClass;-import org.junit.Test;/*** test that configs can override the DirectoryFactory and@@ -56,11 +55,11 @@ public class AlternateDirectoryTest extends SolrTestCaseJ4 {public static volatile Directory dir;@Override- public Directory create(String path, DirContext dirContext) throws IOException {+ public Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {openCalled = true;// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:- return dir = newFSDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory());+ return dir = newFSDirectory(new File(path).toPath(), lockFactory);}}diff --git a/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.javaindex 6984374186d..944b707e5c7 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 @@ package org.apache.solr.core;import java.io.IOException;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.RAMDirectory;import org.apache.lucene.util.LuceneTestCase;import org.apache.solr.core.DirectoryFactory.DirContext;@@ -38,7 +39,7 @@ public class RAMDirectoryFactoryTest extends LuceneTestCase {final Directory directory = new RAMDirectory();RAMDirectoryFactory factory = new RAMDirectoryFactory() {@Override- protected Directory create(String path, DirContext dirContext) {+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) {return directory;}};diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.javaindex 32b7e02800e..5270344ddd2 100644--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java@@ -22,6 +22,7 @@ import java.io.IOException;import org.apache.commons.io.FileUtils;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.TestUtil;import org.apache.solr.SolrTestCaseJ4;@@ -60,11 +61,11 @@ public class CoreMergeIndexesAdminHandlerTest extends SolrTestCaseJ4 {public boolean fail = false;@Override- public Directory create(String path, DirContext dirContext) throws IOException {+ public Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {if (fail) {throw new FailingDirectoryFactoryException();} else {- return super.create(path, dirContext);+ return super.create(path, lockFactory, dirContext);}}}diff --git a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.javaindex 3d0bc0d8e14..5d1ae34447d 100644--- a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java+++ b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java@@ -29,6 +29,7 @@ import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;import org.apache.lucene.store.IndexOutput;+import org.apache.lucene.store.NoLockFactory;import org.apache.lucene.store.RAMDirectory;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.cloud.hdfs.HdfsTestUtil;@@ -73,7 +74,7 @@ public class HdfsDirectoryTest extends SolrTestCaseJ4 {Configuration conf = new Configuration();conf.set("dfs.permissions.enabled", "false");- directory = new HdfsDirectory(new Path(dfsCluster.getURI().toString() + createTempDir().toFile().getAbsolutePath() + "/hdfs"), conf);+ directory = new HdfsDirectory(new Path(dfsCluster.getURI().toString() + createTempDir().toFile().getAbsolutePath() + "/hdfs"), NoLockFactory.getNoLockFactory(), conf);random = random();}diff --git a/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java b/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.javaindex b78b98c0393..4f42b081606 100644--- a/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java+++ b/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java@@ -21,8 +21,10 @@ import java.io.File;import java.io.IOException;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.MockDirectoryWrapper;import org.apache.lucene.store.NRTCachingDirectory;+import org.apache.lucene.store.NoLockFactory;import org.apache.lucene.store.RateLimitedDirectoryWrapper;import org.apache.lucene.store.TrackingDirectoryWrapper;import org.apache.lucene.util.LuceneTestCase;@@ -36,8 +38,13 @@ public class MockDirectoryFactory extends EphemeralDirectoryFactory {private boolean allowReadingFilesStillOpenForWrite = Boolean.getBoolean(SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE);@Override- protected Directory create(String path, DirContext dirContext) throws IOException {- Directory dir = LuceneTestCase.newDirectory();+ protected LockFactory createLockFactory(String lockPath, String rawLockType) throws IOException {+ return NoLockFactory.getNoLockFactory(); // dummy, actually unused+ }++ @Override+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {+ Directory dir = LuceneTestCase.newDirectory(); // we ignore the given lock factoryDirectory cdir = reduce(dir);cdir = reduce(cdir);diff --git a/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java b/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.javaindex 4db7dd5cd86..9e5efa394e0 100644--- a/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java+++ b/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java@@ -22,9 +22,9 @@ import java.io.IOException;import java.nio.file.Path;import org.apache.lucene.store.Directory;+import org.apache.lucene.store.LockFactory;import org.apache.lucene.store.MockDirectoryWrapper;import org.apache.lucene.store.NRTCachingDirectory;-import org.apache.lucene.store.NoLockFactory;import org.apache.lucene.store.RateLimitedDirectoryWrapper;import org.apache.lucene.store.TrackingDirectoryWrapper;import org.apache.lucene.util.LuceneTestCase;@@ -35,9 +35,9 @@ import org.apache.lucene.util.LuceneTestCase;public class MockFSDirectoryFactory extends StandardDirectoryFactory {@Override- public Directory create(String path, DirContext dirContext) throws IOException {+ public Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:- Directory dir = LuceneTestCase.newFSDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory());+ Directory dir = LuceneTestCase.newFSDirectory(new File(path).toPath(), lockFactory);// we can't currently do this check because of how// Solr has to reboot a new Directory sometimes when replicating// or rolling back - the old directory is closed and the following