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();
}
}
}
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, "");
}
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();
}
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);
}
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 + "]");
}
}
Aggregations