Search in sources :

Example 1 with SingleInstanceLockFactory

use of org.apache.lucene.store.SingleInstanceLockFactory 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 2 with SingleInstanceLockFactory

use of org.apache.lucene.store.SingleInstanceLockFactory in project exhibitor by soabase.

the class IndexBuilder method open.

public void open() throws Exception {
    if (!directory.exists() && !directory.mkdirs()) {
        throw new IOException("Could not make: " + directory);
    }
    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    niofsDirectory = new NIOFSDirectory(directory, new SingleInstanceLockFactory());
    writer = new IndexWriter(niofsDirectory, conf);
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.KeywordAnalyzer) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) SingleInstanceLockFactory(org.apache.lucene.store.SingleInstanceLockFactory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 3 with SingleInstanceLockFactory

use of org.apache.lucene.store.SingleInstanceLockFactory in project derby by apache.

the class DerbyLuceneDir method getDirectory.

// ///////////////////////////////////////////////////////////////////
// 
// CONSTRUCTOR AND FACTORY METHODS
// 
// ///////////////////////////////////////////////////////////////////
/**
 * <p>
 * Lookup a directory, creating its path as necessary.
 * </p>
 */
static synchronized DerbyLuceneDir getDirectory(StorageFactory storageFactory, String schema, String table, String textcol) throws SQLException {
    DerbyLuceneDir candidate = new DerbyLuceneDir(storageFactory, schema, table, textcol);
    String key = getKey(candidate);
    DerbyLuceneDir result = _openDirectories.get(key);
    if (result == null) {
        result = candidate;
        result.setLockFactory(new SingleInstanceLockFactory());
        _openDirectories.put(key, result);
    }
    return result;
}
Also used : SingleInstanceLockFactory(org.apache.lucene.store.SingleInstanceLockFactory)

Aggregations

SingleInstanceLockFactory (org.apache.lucene.store.SingleInstanceLockFactory)3 NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)2 IOException (java.io.IOException)1 KeywordAnalyzer (org.apache.lucene.analysis.KeywordAnalyzer)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 FSDirectory (org.apache.lucene.store.FSDirectory)1 MMapDirectory (org.apache.lucene.store.MMapDirectory)1 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)1