Search in sources :

Example 1 with NIOFSDirectory

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

the class IndexStoreTests method doTestStoreDirectory.

private void doTestStoreDirectory(Index index, Path tempDir, String typeSettingValue, IndexModule.Type type) throws IOException {
    Settings.Builder settingsBuilder = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
    if (typeSettingValue != null) {
        settingsBuilder.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), typeSettingValue);
    }
    Settings settings = settingsBuilder.build();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
    FsDirectoryService service = new FsDirectoryService(indexSettings, null, new ShardPath(false, tempDir, tempDir, new ShardId(index, 0)));
    try (Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) {
        switch(type) {
            case NIOFS:
                assertTrue(type + " " + directory.toString(), directory instanceof NIOFSDirectory);
                break;
            case MMAPFS:
                assertTrue(type + " " + directory.toString(), directory instanceof MMapDirectory);
                break;
            case SIMPLEFS:
                assertTrue(type + " " + directory.toString(), directory instanceof SimpleFSDirectory);
                break;
            case FS:
                if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) {
                    assertTrue(directory.toString(), directory instanceof MMapDirectory);
                } else if (Constants.WINDOWS) {
                    assertTrue(directory.toString(), directory instanceof SimpleFSDirectory);
                } else {
                    assertTrue(directory.toString(), directory instanceof NIOFSDirectory);
                }
                break;
            default:
                fail();
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) ShardPath(org.elasticsearch.index.shard.ShardPath) IndexSettings(org.elasticsearch.index.IndexSettings) MMapDirectory(org.apache.lucene.store.MMapDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) MMapDirectory(org.apache.lucene.store.MMapDirectory) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory)

Example 2 with NIOFSDirectory

use of org.apache.lucene.store.NIOFSDirectory in project geode by apache.

the class RawIndexRepositoryFactory method computeIndexRepository.

@Override
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository) throws IOException {
    final IndexRepository repo;
    if (oldRepository != null) {
        oldRepository.cleanup();
    }
    LuceneRawIndex indexForRaw = (LuceneRawIndex) index;
    BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
    Directory dir = null;
    if (indexForRaw.withPersistence()) {
        String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(), index.getRegionPath() + "_" + bucketId);
        File location = new File(index.getName(), bucketLocation);
        if (!location.exists()) {
            location.mkdirs();
        }
        dir = new NIOFSDirectory(location.toPath());
    } else {
        dir = new RAMDirectory();
    }
    IndexWriterConfig config = new IndexWriterConfig(indexForRaw.getAnalyzer());
    IndexWriter writer = new IndexWriter(dir, config);
    return new IndexRepositoryImpl(null, writer, serializer, indexForRaw.getIndexStats(), dataBucket, null, "");
}
Also used : NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexWriter(org.apache.lucene.index.IndexWriter) File(java.io.File) RAMDirectory(org.apache.lucene.store.RAMDirectory) RegionDirectory(org.apache.geode.cache.lucene.internal.directory.RegionDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) IndexRepositoryImpl(org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)

Example 3 with NIOFSDirectory

use of org.apache.lucene.store.NIOFSDirectory in project orientdb by orientechnologies.

the class OLuceneDirectoryFactory method createDirectory.

private Directory createDirectory(ODatabaseDocumentInternal database, String indexName, ODocument metadata, String luceneType) {
    String luceneBasePath = metadata.containsField(DIRECTORY_PATH) ? metadata.<String>field(DIRECTORY_PATH) : OLUCENE_BASE_DIR;
    Path luceneIndexPath = Paths.get(database.getStorage().getConfiguration().getDirectory(), luceneBasePath, indexName);
    try {
        if (DIRECTORY_NIO.equals(luceneType)) {
            return new NIOFSDirectory(luceneIndexPath);
        }
        if (DIRECTORY_MMAP.equals(luceneType)) {
            return new MMapDirectory(luceneIndexPath);
        }
    } catch (IOException e) {
        OLogManager.instance().error(this, "unable to create Lucene Directory with type " + luceneType, e);
    }
    OLogManager.instance().warn(this, "unable to create Lucene Directory, FALL BACK to ramDir");
    return new RAMDirectory();
}
Also used : Path(java.nio.file.Path) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IOException(java.io.IOException) MMapDirectory(org.apache.lucene.store.MMapDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Example 4 with NIOFSDirectory

use of org.apache.lucene.store.NIOFSDirectory in project zm-mailbox by Zimbra.

the class LuceneDirectory method open.

/**
 * Creates a new {@link LuceneDirectory} with {@code SingleInstanceLockFactory}.
 * <p>
 * You can switch Lucene's {@link FSDirectory} implementation by {@link LC#zimbra_index_lucene_io_impl}.
 * <ul>
 *  <li>{@code null} -Lucene will try to pick the best {@link FSDirectory} implementation given the current
 *      environment. Currently this returns {@link MMapDirectory} for most Solaris and Windows 64-bit JREs,
 *      {@link NIOFSDirectory} for other non-Windows JREs, and {@link SimpleFSDirectory} for other JREs on Windows.
 *  <li>{@code simple} - straightforward implementation using java.io.RandomAccessFile. However, it has poor
 *      concurrent performance (multiple threads will bottleneck) as it synchronizes when multiple threads read from
 *      the same file.
 *  <li>{@code nio} - uses java.nio's FileChannel's positional io when reading to avoid synchronization when reading
 *      from the same file. Unfortunately, due to a Windows-only Sun JRE bug this is a poor choice for Windows, but
 *      on all other platforms this is the preferred choice.
 *  <li>{@code mmap} - uses memory-mapped IO when reading. This is a good choice if you have plenty of virtual
 *      memory relative to your index size, eg if you are running on a 64 bit JRE, or you are running on a 32 bit
 *      JRE but your index sizes are small enough to fit into the virtual memory space. Java has currently the
 *      limitation of not being able to unmap files from user code. The files are unmapped, when GC releases the
 *      byte buffers. Due to this bug in Sun's JRE, MMapDirectory's IndexInput.close() is unable to close the
 *      underlying OS file handle. Only when GC finally collects the underlying objects, which could be quite some
 *      time later, will the file handle be closed. This will consume additional transient disk usage: on Windows,
 *      attempts to delete or overwrite the files will result in an exception; on other platforms, which typically
 *      have a "delete on last close" semantics, while such operations will succeed, the bytes are still consuming
 *      space on disk. For many applications this limitation is not a problem (e.g. if you have plenty of disk
 *      space, and you don't rely on overwriting files on Windows) but it's still an important limitation to be
 *      aware of. This class supplies a (possibly dangerous) workaround mentioned in the bug report, which may fail
 *      on non-Sun JVMs.
 * </ul>
 *
 * @param path directory path
 */
public static LuceneDirectory open(File path) throws IOException {
    String impl = LC.zimbra_index_lucene_io_impl.value();
    FSDirectory dir;
    if ("nio".equals(impl)) {
        dir = new NIOFSDirectory(path, new SingleInstanceLockFactory());
    } else if ("mmap".equals(impl)) {
        dir = new MMapDirectory(path, new SingleInstanceLockFactory());
    } else if ("simple".equals(impl)) {
        dir = new SimpleFSDirectory(path, new SingleInstanceLockFactory());
    } else {
        dir = FSDirectory.open(path, new SingleInstanceLockFactory());
    }
    ZimbraLog.index.info("OpenLuceneIndex impl=%s,dir=%s", dir.getClass().getSimpleName(), path);
    return new LuceneDirectory(dir);
}
Also used : NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) SingleInstanceLockFactory(org.apache.lucene.store.SingleInstanceLockFactory) MMapDirectory(org.apache.lucene.store.MMapDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory)

Example 5 with NIOFSDirectory

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

the class FsDirectoryFactory method newFSDirectory.

protected Directory newFSDirectory(Path location, LockFactory lockFactory, IndexSettings indexSettings) throws IOException {
    final String storeType = indexSettings.getSettings().get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), IndexModule.Type.FS.getSettingsKey());
    IndexModule.Type type;
    if (IndexModule.Type.FS.match(storeType)) {
        type = IndexModule.defaultStoreType(IndexModule.NODE_STORE_ALLOW_MMAP.getWithFallback(indexSettings.getNodeSettings()));
    } else {
        type = IndexModule.Type.fromSettingsKey(storeType);
    }
    Set<String> preLoadExtensions = new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING));
    switch(type) {
        case HYBRIDFS:
            // Use Lucene defaults
            final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
            if (primaryDirectory instanceof MMapDirectory) {
                MMapDirectory mMapDirectory = (MMapDirectory) primaryDirectory;
                return new HybridDirectory(lockFactory, setPreload(mMapDirectory, lockFactory, preLoadExtensions));
            } else {
                return primaryDirectory;
            }
        case MMAPFS:
            return setPreload(new MMapDirectory(location, lockFactory), lockFactory, preLoadExtensions);
        case SIMPLEFS:
            return new SimpleFSDirectory(location, lockFactory);
        case NIOFS:
            return new NIOFSDirectory(location, lockFactory);
        default:
            throw new AssertionError("unexpected built-in store type [" + type + "]");
    }
}
Also used : NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexModule(org.elasticsearch.index.IndexModule) MMapDirectory(org.apache.lucene.store.MMapDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) HashSet(java.util.HashSet)

Aggregations

NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)11 MMapDirectory (org.apache.lucene.store.MMapDirectory)6 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)5 Directory (org.apache.lucene.store.Directory)4 IndexWriter (org.apache.lucene.index.IndexWriter)3 FSDirectory (org.apache.lucene.store.FSDirectory)3 File (java.io.File)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 RAMDirectory (org.apache.lucene.store.RAMDirectory)2 SingleInstanceLockFactory (org.apache.lucene.store.SingleInstanceLockFactory)2 Settings (org.elasticsearch.common.settings.Settings)2 IndexSettings (org.elasticsearch.index.IndexSettings)2 ShardId (org.elasticsearch.index.shard.ShardId)2 FileSystem (java.nio.file.FileSystem)1 HashSet (java.util.HashSet)1 RegionDirectory (org.apache.geode.cache.lucene.internal.directory.RegionDirectory)1 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)1 IndexRepositoryImpl (org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)1