Search in sources :

Example 1 with LockFactory

use of org.apache.lucene.store.LockFactory in project lucene-solr by apache.

the class LuceneTestCase method newDirectoryImpl.

static Directory newDirectoryImpl(Random random, String clazzName, LockFactory lf) {
    if (clazzName.equals("random")) {
        if (rarely(random)) {
            clazzName = RandomPicks.randomFrom(random, CORE_DIRECTORIES);
        } else {
            clazzName = "RAMDirectory";
        }
    }
    try {
        final Class<? extends Directory> clazz = CommandLineUtil.loadDirectoryClass(clazzName);
        // If it is a FSDirectory type, try its ctor(Path)
        if (FSDirectory.class.isAssignableFrom(clazz)) {
            final Path dir = createTempDir("index-" + clazzName);
            return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir, lf);
        }
        // FSDir subclass:
        try {
            Constructor<? extends Directory> pathCtor = clazz.getConstructor(Path.class, LockFactory.class);
            final Path dir = createTempDir("index");
            return pathCtor.newInstance(dir, lf);
        } catch (NoSuchMethodException nsme) {
        // Ignore
        }
        // the remaining dirs are no longer filesystem based, so we must check that the passedLockFactory is not file based:
        if (!(lf instanceof FSLockFactory)) {
            // try ctor with only LockFactory (e.g. RAMDirectory)
            try {
                return clazz.getConstructor(LockFactory.class).newInstance(lf);
            } catch (NoSuchMethodException nsme) {
            // Ignore
            }
        }
        // try empty ctor
        return clazz.newInstance();
    } catch (Exception e) {
        Rethrow.rethrow(e);
        // dummy to prevent compiler failure
        throw null;
    }
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) FSLockFactory(org.apache.lucene.store.FSLockFactory) FSDirectory(org.apache.lucene.store.FSDirectory) FSLockFactory(org.apache.lucene.store.FSLockFactory) LockFactory(org.apache.lucene.store.LockFactory) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with LockFactory

use of org.apache.lucene.store.LockFactory in project crate by crate.

the class FsDirectoryFactory method newDirectory.

@Override
public Directory newDirectory(IndexSettings indexSettings, ShardPath path) throws IOException {
    final Path location = path.resolveIndex();
    final LockFactory lockFactory = indexSettings.getValue(INDEX_LOCK_FACTOR_SETTING);
    Files.createDirectories(location);
    return newFSDirectory(location, lockFactory, indexSettings);
}
Also used : Path(java.nio.file.Path) ShardPath(org.elasticsearch.index.shard.ShardPath) NativeFSLockFactory(org.apache.lucene.store.NativeFSLockFactory) SimpleFSLockFactory(org.apache.lucene.store.SimpleFSLockFactory) LockFactory(org.apache.lucene.store.LockFactory)

Example 3 with LockFactory

use of org.apache.lucene.store.LockFactory in project elasticsearch by elastic.

the class FsDirectoryService method newDirectory.

@Override
public Directory newDirectory() throws IOException {
    final Path location = path.resolveIndex();
    final LockFactory lockFactory = indexSettings.getValue(INDEX_LOCK_FACTOR_SETTING);
    Files.createDirectories(location);
    Directory wrapped = newFSDirectory(location, lockFactory);
    Set<String> preLoadExtensions = new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING));
    wrapped = setPreload(wrapped, location, lockFactory, preLoadExtensions);
    if (indexSettings.isOnSharedFilesystem()) {
        wrapped = new SleepingLockWrapper(wrapped, 5000);
    }
    return wrapped;
}
Also used : ShardPath(org.elasticsearch.index.shard.ShardPath) Path(java.nio.file.Path) SleepingLockWrapper(org.apache.lucene.store.SleepingLockWrapper) SimpleFSLockFactory(org.apache.lucene.store.SimpleFSLockFactory) NativeFSLockFactory(org.apache.lucene.store.NativeFSLockFactory) LockFactory(org.apache.lucene.store.LockFactory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) MMapDirectory(org.apache.lucene.store.MMapDirectory) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) FileSwitchDirectory(org.apache.lucene.store.FileSwitchDirectory) HashSet(java.util.HashSet)

Example 4 with LockFactory

use of org.apache.lucene.store.LockFactory in project lucene-solr by apache.

the class RAMDirectoryFactoryTest method dotestOpenReturnsTheSameForSamePath.

private void dotestOpenReturnsTheSameForSamePath() throws IOException {
    final Directory directory = new RAMDirectory();
    RAMDirectoryFactory factory = new RAMDirectoryFactory() {

        @Override
        protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) {
            return directory;
        }
    };
    String path = "/fake/path";
    Directory dir1 = factory.get(path, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
    Directory dir2 = factory.get(path, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
    assertEquals("RAMDirectoryFactory should not create new instance of RefCntRamDirectory " + "every time open() is called for the same path", dir1, dir2);
    factory.release(dir1);
    factory.release(dir2);
    factory.close();
}
Also used : LockFactory(org.apache.lucene.store.LockFactory) DirContext(org.apache.solr.core.DirectoryFactory.DirContext) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Aggregations

LockFactory (org.apache.lucene.store.LockFactory)4 Path (java.nio.file.Path)3 Directory (org.apache.lucene.store.Directory)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 NativeFSLockFactory (org.apache.lucene.store.NativeFSLockFactory)2 SimpleFSLockFactory (org.apache.lucene.store.SimpleFSLockFactory)2 ShardPath (org.elasticsearch.index.shard.ShardPath)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 HashSet (java.util.HashSet)1 FilterPath (org.apache.lucene.mockfile.FilterPath)1 FSLockFactory (org.apache.lucene.store.FSLockFactory)1 FileSwitchDirectory (org.apache.lucene.store.FileSwitchDirectory)1 MMapDirectory (org.apache.lucene.store.MMapDirectory)1 NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)1 SleepingLockWrapper (org.apache.lucene.store.SleepingLockWrapper)1