org.apache.lucene.store.SimpleFSLockFactory Java Examples

The following examples show how to use org.apache.lucene.store.SimpleFSLockFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardDirectoryFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  if (null == rawLockType) {
    rawLockType = DirectoryFactory.LOCK_TYPE_NATIVE;
    log.warn("No lockType configured, assuming '{}'.", rawLockType);
  }
  final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();
  switch (lockType) {
    case DirectoryFactory.LOCK_TYPE_SIMPLE:
      return SimpleFSLockFactory.INSTANCE;
    case DirectoryFactory.LOCK_TYPE_NATIVE:
      return NativeFSLockFactory.INSTANCE;
    case DirectoryFactory.LOCK_TYPE_SINGLE:
      return new SingleInstanceLockFactory();
    case DirectoryFactory.LOCK_TYPE_NONE:
      return NoLockFactory.INSTANCE;
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
          "Unrecognized lockType: " + rawLockType);
  }
}
 
Example #2
Source File: SolrCoreCheckLockOnStartupTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleLockErrorOnStartup() throws Exception {

  Directory directory = newFSDirectory(new File(initAndGetDataDir(), "index").toPath(), SimpleFSLockFactory.INSTANCE);
  //creates a new IndexWriter without releasing the lock yet
  IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(null));

  ignoreException("locked");
  try {
    System.setProperty("solr.tests.lockType",DirectoryFactory.LOCK_TYPE_SIMPLE);
    //opening a new core on the same index
    initCore("solrconfig-basic.xml", "schema.xml");
    if (checkForCoreInitException(LockObtainFailedException.class))
      return;
    fail("Expected " + LockObtainFailedException.class.getSimpleName());
  } finally {
    System.clearProperty("solr.tests.lockType");
    unIgnoreException("locked");
    indexWriter.close();
    directory.close();
    deleteCore();
  }
}
 
Example #3
Source File: TestIndexWriter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testWhetherDeleteAllDeletesWriteLock() throws Exception {
  // Must use SimpleFSLockFactory... NativeFSLockFactory
  // somehow "knows" a lock is held against write.lock
  // even if you remove that file:
  Directory d = newFSDirectory(createTempDir("TestIndexWriter.testWhetherDeleteAllDeletesWriteLock"), SimpleFSLockFactory.INSTANCE);
  RandomIndexWriter w1 = new RandomIndexWriter(random(), d);
  w1.deleteAll();
  expectThrows(LockObtainFailedException.class, () -> {
    new RandomIndexWriter(random(), d, newIndexWriterConfig(null));
  });

  w1.close();
  d.close();
}
 
Example #4
Source File: IndexerDAO.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Inizializzazione dell'indicizzatore.
 *
 * @param dir La cartella locale contenitore dei dati persistenti.
 * @throws ApsSystemException In caso di errore
 */
@Override
public void init(File dir) throws ApsSystemException {
    try {
        this.dir = FSDirectory.open(dir.toPath(), SimpleFSLockFactory.INSTANCE);
    } catch (Throwable t) {
        logger.error("Error creating directory", t);
        throw new ApsSystemException("Error creating directory", t);
    }
    logger.debug("Indexer: search engine index ok.");
}