SOLR-6518: CachingDirectoryFactory subclasses must init directory with NoLockFactory, because the real lock factory gets set later via injectLockFactory

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1624928 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2014-09-15 00:49:27 +00:00
parent 3bb1cfb449
commit 0dcd2f3e65
8 changed files with 40 additions and 18 deletions

View File

@ -38,6 +38,7 @@ import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.store.RateLimitedDirectoryWrapper;
import org.apache.lucene.store.SimpleFSLockFactory;
import org.apache.lucene.store.SingleInstanceLockFactory;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.util.NamedList;
@ -347,18 +348,25 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
directory = cacheValue.directory;
}
if (directory == null) {
if (directory == null) {
directory = create(fullPath, dirContext);
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);
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);
success = true;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(directory);
}
}
} else {
cacheValue.refCnt++;
log.debug("Reusing cached directory: {}", cacheValue);

View File

@ -20,6 +20,7 @@ package org.apache.solr.core;
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;
@ -59,7 +60,8 @@ public class MMapDirectoryFactory extends StandardDirectoryFactory {
@Override
protected Directory create(String path, DirContext dirContext) throws IOException {
MMapDirectory mapDirectory = new MMapDirectory(new File(path).toPath(), null, maxChunk);
// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
MMapDirectory mapDirectory = new MMapDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory(), maxChunk);
try {
mapDirectory.setUseUnmap(unmapHack);
} catch (Exception e) {

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.store.NoLockFactory;
/**
@ -31,7 +32,8 @@ public class NIOFSDirectoryFactory extends StandardDirectoryFactory {
@Override
protected Directory create(String path, DirContext dirContext) throws IOException {
return new NIOFSDirectory(new File(path).toPath());
// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
return new NIOFSDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory());
}
@Override

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
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,7 +52,8 @@ public class NRTCachingDirectoryFactory extends StandardDirectoryFactory {
@Override
protected Directory create(String path, DirContext dirContext) throws IOException {
return new NRTCachingDirectory(FSDirectory.open(new File(path).toPath()), maxMergeSizeMB, maxCachedMB);
// 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);
}
@Override

View File

@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.store.SimpleFSDirectory;
@ -31,7 +32,8 @@ public class SimpleFSDirectoryFactory extends StandardDirectoryFactory {
@Override
protected Directory create(String path, DirContext dirContext) throws IOException {
return new SimpleFSDirectory(new File(path).toPath());
// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
return new SimpleFSDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory());
}
@Override

View File

@ -24,6 +24,7 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.NRTCachingDirectory;
import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.store.RateLimitedDirectoryWrapper;
import org.apache.solr.core.CachingDirectoryFactory.CacheValue;
@ -39,7 +40,8 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
@Override
protected Directory create(String path, DirContext dirContext) throws IOException {
return FSDirectory.open(new File(path).toPath());
// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
return FSDirectory.open(new File(path).toPath(), NoLockFactory.getNoLockFactory());
}
@Override

View File

@ -22,6 +22,7 @@ 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.solr.SolrTestCaseJ4;
import org.junit.BeforeClass;
import org.junit.Test;
@ -58,7 +59,8 @@ public class AlternateDirectoryTest extends SolrTestCaseJ4 {
public Directory create(String path, DirContext dirContext) throws IOException {
openCalled = true;
return dir = newFSDirectory(new File(path).toPath());
// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
return dir = newFSDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory());
}
}

View File

@ -24,6 +24,7 @@ import java.nio.file.Path;
import org.apache.lucene.store.Directory;
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,7 +36,8 @@ public class MockFSDirectoryFactory extends StandardDirectoryFactory {
@Override
public Directory create(String path, DirContext dirContext) throws IOException {
Directory dir = LuceneTestCase.newFSDirectory(new File(path).toPath());
// we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
Directory dir = LuceneTestCase.newFSDirectory(new File(path).toPath(), NoLockFactory.getNoLockFactory());
// 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