Java Code Examples for org.apache.lucene.store.SimpleFSLockFactory

The following examples show how to use org.apache.lucene.store.SimpleFSLockFactory. These examples are extracted from open source projects. 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 Project: lucene-solr   Source File: StandardDirectoryFactory.java    License: 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
@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 Project: lucene-solr   Source File: TestIndexWriter.java    License: 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
/**
 * 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.");
}