Example usage for org.apache.lucene.store SimpleFSLockFactory INSTANCE

List of usage examples for org.apache.lucene.store SimpleFSLockFactory INSTANCE

Introduction

In this page you can find the example usage for org.apache.lucene.store SimpleFSLockFactory INSTANCE.

Prototype

SimpleFSLockFactory INSTANCE

To view the source code for org.apache.lucene.store SimpleFSLockFactory INSTANCE.

Click Source Link

Document

Singleton instance

Usage

From source file:org.eclipse.dltk.internal.core.index.lucene.IndexContainer.java

License:Open Source License

private IndexWriter createWriter(Path path) throws IOException {
    Directory indexDir = new IndexDirectory(path, SimpleFSLockFactory.INSTANCE);
    purgeLocks(path);//from   ww  w. j a v  a2  s.c  o  m
    IndexWriterConfig config = new IndexWriterConfig(new SimpleAnalyzer());
    ConcurrentMergeScheduler mergeScheduler = new ConcurrentMergeScheduler();
    mergeScheduler.setDefaultMaxMergesAndThreads(true);
    config.setMergeScheduler(mergeScheduler);
    config.setOpenMode(OpenMode.CREATE_OR_APPEND);
    config.setWriteLockTimeout(WRITE_LOCK_TIMEOUT);
    config.setCommitOnClose(false);
    return new IndexWriter(indexDir, config);
}

From source file:org.elasticsearch.index.store.FsDirectoryService.java

License:Apache License

public static LockFactory buildLockFactory(Settings indexSettings) {
    String fsLock = indexSettings.get("index.store.fs.lock",
            indexSettings.get("index.store.fs.fs_lock", "native"));
    LockFactory lockFactory;//ww w  . j  a  v  a  2s  .  c o m
    if (fsLock.equals("native")) {
        lockFactory = NativeFSLockFactory.INSTANCE;
    } else if (fsLock.equals("simple")) {
        lockFactory = SimpleFSLockFactory.INSTANCE;
    } else {
        throw new IllegalArgumentException("unrecognized fs_lock \"" + fsLock + "\": must be native or simple");
    }
    return lockFactory;
}

From source file:org.hibernate.search.store.impl.DefaultLockFactoryCreator.java

License:LGPL

@Override
public LockFactory createLockFactory(File indexDir, Properties dirConfiguration) {
    //For FS-based indexes default to "native", default to "single" otherwise.
    String defaultStrategy = indexDir == null ? "single" : "native";
    String lockFactoryName = dirConfiguration.getProperty(Environment.LOCKING_STRATEGY, defaultStrategy);
    if ("simple".equals(lockFactoryName)) {
        if (indexDir == null) {
            throw LOG.indexBasePathRequiredForLockingStrategy("simple");
        }//from  ww w. jav a  2  s .  c  o m
        return SimpleFSLockFactory.INSTANCE;
    } else if ("native".equals(lockFactoryName)) {
        if (indexDir == null) {
            throw LOG.indexBasePathRequiredForLockingStrategy("native");
        }
        return NativeFSLockFactory.INSTANCE;
    } else if ("single".equals(lockFactoryName)) {
        return new SingleInstanceLockFactory();
    } else if ("none".equals(lockFactoryName)) {
        return NoLockFactory.INSTANCE;
    } else {
        LockFactoryProvider lockFactoryFactory = ClassLoaderHelper.instanceFromName(LockFactoryProvider.class,
                lockFactoryName, Environment.LOCKING_STRATEGY, serviceManager);
        return lockFactoryFactory.createLockFactory(indexDir, dirConfiguration);
    }
}

From source file:org.modeshape.jcr.index.lucene.LuceneConfig.java

License:Apache License

private LockFactory lockFactory(String lockFactoryClass) {
    if (StringUtil.isBlank(lockFactoryClass)) {
        return null;
    }// ww  w .  ja  v  a 2  s.com
    switch (lockFactoryClass) {
    case "org.apache.lucene.store.NativeFSLockFactory": {
        return NativeFSLockFactory.INSTANCE;
    }
    case "org.apache.lucene.store.NoLockFactory": {
        return NoLockFactory.INSTANCE;
    }
    case "org.apache.lucene.store.SimpleFSLockFactory": {
        return SimpleFSLockFactory.INSTANCE;
    }
    default:
        throw new IllegalArgumentException("Unknown lock factory implementation: " + lockFactoryClass);
    }
}

From source file:org.opengrok.indexer.index.IndexDatabase.java

License:Open Source License

LockFactory pickLockFactory(RuntimeEnvironment env) {
    switch (env.getLuceneLocking()) {
    case ON:/*from  ww  w.  ja  v  a 2s . c o  m*/
    case SIMPLE:
        return SimpleFSLockFactory.INSTANCE;
    case NATIVE:
        return NativeFSLockFactory.INSTANCE;
    case OFF:
    default:
        return NoLockFactory.INSTANCE;
    }
}

From source file:stroom.index.server.AbstractIndexShard.java

License:Apache License

protected void open() throws IOException {
    if (directory == null) {
        final Path dir = getIndexPath();

        try {//from  w  w w. j  a v  a 2s.co m
            if (readOnly) {
                directory = new NIOFSDirectory(dir, NoLockFactory.INSTANCE);

            } else {
                if (!Files.isDirectory(dir)) {
                    try {
                        Files.createDirectories(dir);
                    } catch (final IOException e) {
                        throw new IOException("getDirectory() - Failed to create directory " + dir);
                    }
                }

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Opening and locking index dir = " + dir.toAbsolutePath().toString()
                            + " exists " + Files.isDirectory(dir));
                }

                directory = new NIOFSDirectory(dir, SimpleFSLockFactory.INSTANCE);

                // We have opened the index so update the DB object.
                if (directory != null) {
                    indexShard.setStatus(IndexShardStatus.OPEN);
                    indexShard = service.save(indexShard);
                }
            }
        } finally {
            if (directory == null) {
                LOGGER.error("Failed to open: " + dir.toAbsolutePath().toString());
            }
        }
    }
}

From source file:stroom.index.server.IndexShardWriterImpl.java

License:Apache License

private synchronized boolean doOpen(final boolean create) {
    boolean success = false;

    try {// w ww.j  a  v a  2s .c om
        // Never open deleted index shards.
        if (IndexShardStatus.DELETED.equals(indexShard.getStatus())) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Shard is deleted " + indexShard);
            }
            return false;
        }

        // Don't open old index shards for writing.
        final Version currentVersion = LuceneVersionUtil
                .getLuceneVersion(LuceneVersionUtil.getCurrentVersion());
        final Version shardVersion = LuceneVersionUtil.getLuceneVersion(indexShard.getIndexVersion());
        if (!shardVersion.equals(currentVersion)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Shard version is different to current version " + indexShard);
            }
            return false;
        }

        final long startMs = System.currentTimeMillis();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Opening " + indexShard);
        }

        if (create) {
            // Make sure the index directory does not exist. If one does
            // then throw an exception
            // as we don't want to overwrite an index.
            if (Files.isDirectory(dir)) {
                // This is a workaround for lingering .nfs files.
                Files.list(dir).forEach(file -> {
                    if (Files.isDirectory(file) || !file.getFileName().startsWith(".")) {
                        throw new IndexException("Attempting to create a new index in \""
                                + dir.toAbsolutePath().toString() + "\" but one already exists.");
                    }
                });
            } else {
                // Try and make all required directories.
                try {
                    Files.createDirectories(dir);
                } catch (final IOException e) {
                    throw new IndexException("Unable to create directories for new index in \""
                            + dir.toAbsolutePath().toString() + "\"");
                }
            }
        }

        // Create lucene directory object.
        directory = new NIOFSDirectory(dir, SimpleFSLockFactory.INSTANCE);

        analyzerWrapper.setVersion(shardVersion);
        final IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzerWrapper);

        // In debug mode we do extra trace in LUCENE and we also count
        // certain logging info like merge and flush
        // counts, so you can get this later using the trace method.
        if (LOGGER.isDebugEnabled()) {
            loggerPrintStream = new LoggerPrintStream(LOGGER);
            for (final String term : LOG_WATCH_TERMS.values()) {
                loggerPrintStream.addWatchTerm(term);
            }
            indexWriterConfig.setInfoStream(loggerPrintStream);
        }

        // IndexWriter to use for adding data to the index.
        indexWriter = new IndexWriter(directory, indexWriterConfig);

        final LiveIndexWriterConfig liveIndexWriterConfig = indexWriter.getConfig();
        liveIndexWriterConfig.setRAMBufferSizeMB(ramBufferSizeMB);

        // TODO : We might still want to write separate segments I'm not
        // sure on pros/cons?
        liveIndexWriterConfig.setUseCompoundFile(false);
        liveIndexWriterConfig.setMaxBufferedDocs(Integer.MAX_VALUE);

        // Check the number of committed docs in this shard.
        documentCount.set(indexWriter.numDocs());
        lastDocumentCount = documentCount.get();
        if (create) {
            if (lastDocumentCount != 0) {
                LOGGER.error("Index should be new but already contains docs: " + lastDocumentCount);
            }
        } else if (indexShard.getDocumentCount() != lastDocumentCount) {
            LOGGER.error("Mismatch document count.  Index says " + lastDocumentCount + " DB says "
                    + indexShard.getDocumentCount());
        }

        // We have opened the index so update the DB object.
        setStatus(IndexShardStatus.OPEN);

        // Output some debug.
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("getIndexWriter() - Opened " + indexShard + " in "
                    + (System.currentTimeMillis() - startMs) + "ms");
        }

        success = true;
    } catch (final LockObtainFailedException t) {
        LOGGER.warn(t.getMessage());
    } catch (final Throwable t) {
        LOGGER.error(t.getMessage(), t);
    }

    return success;
}