Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6E582118B4 for ; Wed, 17 Sep 2014 16:31:18 +0000 (UTC) Received: (qmail 95894 invoked by uid 500); 17 Sep 2014 16:31:18 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 95885 invoked by uid 99); 17 Sep 2014 16:31:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Sep 2014 16:31:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Sep 2014 16:30:51 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 658162388993; Wed, 17 Sep 2014 16:30:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1625644 - in /lucene/dev/trunk/solr: ./ contrib/map-reduce/src/java/org/apache/solr/hadoop/ core/src/java/org/apache/solr/core/ core/src/java/org/apache/solr/store/hdfs/ core/src/test/org/apache/solr/core/ core/src/test/org/apache/solr/han... Date: Wed, 17 Sep 2014 16:30:47 -0000 To: commits@lucene.apache.org From: uschindler@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140917163048.658162388993@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: uschindler Date: Wed Sep 17 16:30:46 2014 New Revision: 1625644 URL: http://svn.apache.org/r1625644 Log: SOLR-6519: Make DirectoryFactory#create() take LockFactory Modified: lucene/dev/trunk/solr/CHANGES.txt lucene/dev/trunk/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java lucene/dev/trunk/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.java lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java lucene/dev/trunk/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java Modified: lucene/dev/trunk/solr/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/CHANGES.txt (original) +++ lucene/dev/trunk/solr/CHANGES.txt Wed Sep 17 16:30:46 2014 @@ -105,6 +105,9 @@ Other Changes * SOLR-6073: Remove helper methods from CollectionsRequest (SolrJ) for CollectionsAPI calls 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 release Modified: lucene/dev/trunk/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.java (original) +++ lucene/dev/trunk/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/TreeMergeOutputFormat.java Wed Sep 17 16:30:46 2014 @@ -38,6 +38,7 @@ import org.apache.lucene.index.MergePoli 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 exten 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 exten 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"); Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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 CachingDirectoryFa return otherCacheValue.path.startsWith(cacheValue.path + "/") && two > one; } - - @Override - protected abstract Directory create(String path, DirContext dirContext) throws IOException; @Override public boolean exists(String path) throws IOException { @@ -349,15 +347,11 @@ public abstract class CachingDirectoryFa } 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 CachingDirectoryFa } } - 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 } Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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 i * * @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. Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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. 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 extend } @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 extend 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 extend 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); Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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; // javadocs import 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 extend } @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; Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NIOFSDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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.NoLockFac 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); } @Override Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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 } @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); } @Override Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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; } } Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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.SimpleFSD 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); } @Override Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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.CachingDirec */ 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); + } } @Override Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java (original) +++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java Wed Sep 17 16:30:46 2014 @@ -34,7 +34,7 @@ import org.apache.lucene.store.BaseDirec 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 BaseD 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); Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.java (original) +++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/AlternateDirectoryTest.java Wed Sep 17 16:30:46 2014 @@ -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 exte 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); } } Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java (original) +++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java Wed Sep 17 16:30:46 2014 @@ -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 ext 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; } }; Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java (original) +++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java Wed Sep 17 16:30:46 2014 @@ -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 CoreMergeIndexesAdminHandle 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); } } } Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java (original) +++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java Wed Sep 17 16:30:46 2014 @@ -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 S 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(); } Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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 extend 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 factory Directory cdir = reduce(dir); cdir = reduce(cdir); Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java?rev=1625644&r1=1625643&r2=1625644&view=diff ============================================================================== --- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java (original) +++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java Wed Sep 17 16:30:46 2014 @@ -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.LuceneTest 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