当前位置: 首页>>代码示例>>Java>>正文


Java LockObtainFailedException类代码示例

本文整理汇总了Java中org.apache.lucene.store.LockObtainFailedException的典型用法代码示例。如果您正苦于以下问题:Java LockObtainFailedException类的具体用法?Java LockObtainFailedException怎么用?Java LockObtainFailedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LockObtainFailedException类属于org.apache.lucene.store包,在下文中一共展示了LockObtainFailedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: acquireFSLockForPaths

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
/**
 * Acquires, then releases, all {@code write.lock} files in the given
 * shard paths. The "write.lock" file is assumed to be under the shard
 * path's "index" directory as used by Elasticsearch.
 *
 * @throws LockObtainFailedException if any of the locks could not be acquired
 */
public static void acquireFSLockForPaths(IndexSettings indexSettings, Path... shardPaths) throws IOException {
    Lock[] locks = new Lock[shardPaths.length];
    Directory[] dirs = new Directory[shardPaths.length];
    try {
        for (int i = 0; i < shardPaths.length; i++) {
            // resolve the directory the shard actually lives in
            Path p = shardPaths[i].resolve("index");
            // open a directory (will be immediately closed) on the shard's location
            dirs[i] = new SimpleFSDirectory(p, indexSettings.getValue(FsDirectoryService.INDEX_LOCK_FACTOR_SETTING));
            // create a lock for the "write.lock" file
            try {
                locks[i] = dirs[i].obtainLock(IndexWriter.WRITE_LOCK_NAME);
            } catch (IOException ex) {
                throw new LockObtainFailedException("unable to acquire " +
                                IndexWriter.WRITE_LOCK_NAME + " for " + p, ex);
            }
        }
    } finally {
        IOUtils.closeWhileHandlingException(locks);
        IOUtils.closeWhileHandlingException(dirs);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:NodeEnvironment.java

示例2: acquireFSLockForPaths

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
/**
 * Acquires, then releases, all {@code write.lock} files in the given
 * shard paths. The "write.lock" file is assumed to be under the shard
 * path's "index" directory as used by Elasticsearch.
 *
 * @throws LockObtainFailedException if any of the locks could not be acquired
 */
public static void acquireFSLockForPaths(Settings indexSettings, Path... shardPaths) throws IOException {
    Lock[] locks = new Lock[shardPaths.length];
    Directory[] dirs = new Directory[shardPaths.length];
    try {
        for (int i = 0; i < shardPaths.length; i++) {
            // resolve the directory the shard actually lives in
            Path p = shardPaths[i].resolve("index");
            // open a directory (will be immediately closed) on the shard's location
            dirs[i] = new SimpleFSDirectory(p, FsDirectoryService.buildLockFactory(indexSettings));
            // create a lock for the "write.lock" file
            try {
                locks[i] = dirs[i].obtainLock(IndexWriter.WRITE_LOCK_NAME);
            } catch (IOException ex) {
                throw new LockObtainFailedException("unable to acquire " +
                        IndexWriter.WRITE_LOCK_NAME + " for " + p);
            }
        }
    } finally {
        IOUtils.closeWhileHandlingException(locks);
        IOUtils.closeWhileHandlingException(dirs);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:NodeEnvironment.java

示例3: processAllDescriptions

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
/**
 * Create a new index based on all known SNOMED CT descriptions.
 * This may take a *long* time....
 * @throws IOException
 * @throws LockObtainFailedException
 * @throws CorruptIndexException
 *
 */
public void processAllDescriptions(ObjectContext context) throws CorruptIndexException, LockObtainFailedException, IOException {
	IndexWriter writer = createOrLoadIndexWriter(indexFile(), analyser());
	EJBQLQuery countQuery = new EJBQLQuery("select COUNT(d) FROM Description d");
	@SuppressWarnings("unchecked") long count = ((List<Long>) context.performQuery(countQuery)).get(0);
	SelectQuery<Description> query = SelectQuery.query(Description.class);
	System.out.println("Updating search index:");
	CayenneUtility.timedBatchIterator(context, query, BATCH_ITERATOR_COUNT, count, (batch) -> {
		try {
			for (Description d : batch) {
				processDescription(writer, d);
			}
			writer.commit();			
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	});
	System.out.println("Merging segments...");
	writer.forceMerge(1);
	writer.close();
	System.out.println("Finished updating search index");
	_searcher = createSearcher();		// create a new searcher now the index has changed.
}
 
开发者ID:wardle,项目名称:rsterminology,代码行数:31,代码来源:Search.java

示例4: testLocksBlock

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
/** Make sure an open IndexWriter on an incoming Directory
 *  causes a LockObtainFailedException */
public void testLocksBlock() throws Exception {
  Directory src = newDirectory();
  RandomIndexWriter w1 = new RandomIndexWriter(random(), src);
  w1.addDocument(new Document());
  w1.commit();

  Directory dest = newDirectory();

  IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
  iwc.setWriteLockTimeout(1);
  RandomIndexWriter w2 = new RandomIndexWriter(random(), dest, iwc);

  try {
    w2.addIndexes(src);
    fail("did not hit expected exception");
  } catch (LockObtainFailedException lofe) {
    // expected
  }

  IOUtils.close(w1, w2, src, dest);
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestAddIndexes.java

示例5: testSimpleLockErrorOnStartup

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
@Test
public void testSimpleLockErrorOnStartup() throws Exception {

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

  ignoreException("locked");
  try {
    System.setProperty("solr.tests.lockType","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();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:SolrCoreCheckLockOnStartupTest.java

示例6: obtain

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
@Override
public void obtain() throws IOException {
    if (jdbcDirectory.getDialect().useExistsBeforeInsertLock()) {
        // there are databases where the fact that an exception was
        // thrown invalidates the connection. So first we check if it
        // exists, and then insert it.
        if (jdbcDirectory.fileExists(name)) {
            throw new LockObtainFailedException("Lock instance already obtained: " + this);
        }
    }
    jdbcDirectory.getJdbcTemplate().executeUpdate(jdbcDirectory.getTable().sqlInsert(),
            new JdbcTemplate.PrepateStatementAwareCallback() {
                @Override
                public void fillPrepareStatement(final PreparedStatement ps) throws Exception {
                    ps.setFetchSize(1);
                    ps.setString(1, name);
                    ps.setNull(2, Types.BLOB);
                    ps.setLong(3, 0);
                    ps.setBoolean(4, false);
                }
            });
}
 
开发者ID:unkascrack,项目名称:lucene-jdbcdirectory,代码行数:23,代码来源:PhantomReadLock.java

示例7: obtain

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
@Override
public void obtain() throws IOException {
    jdbcDirectory.getJdbcTemplate().executeSelect(jdbcDirectory.getTable().sqlSelectNameForUpdateNoWait(),
            new JdbcTemplate.ExecuteSelectCallback() {

                @Override
                public void fillPrepareStatement(final PreparedStatement ps) throws Exception {
                    ps.setFetchSize(1);
                    ps.setString(1, name);
                }

                @Override
                public Object execute(final ResultSet rs) throws Exception {
                    if (!rs.next()) {
                        throw new LockObtainFailedException("Lock instance already obtained: " + this);
                    }
                    return null;
                }
            });
}
 
开发者ID:unkascrack,项目名称:lucene-jdbcdirectory,代码行数:21,代码来源:SelectForUpdateLock.java

示例8: TestEmails

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
@Test
     public void TestEmails() throws CorruptIndexException, LockObtainFailedException, IOException
      
    {
//         Directory dir = null;
//         IndexWriter writer_ = null;
//         
//         try {
//            dir = FSDirectory.open(new File("C:\\Indexer"));
//        } catch (IOException ex) {
//            Logger.getLogger(EmailIndexer.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        
//            writer_ = new IndexWriter(dir,
//                new StandardAnalyzer(
//                Version.LUCENE_21),
//                true,
//                IndexWriter.MaxFieldLength.UNLIMITED);
//      
//            EmailIndexer ei = new EmailIndexer(writer_, new File("C:\\Secure_DB"), null, true, null, null);
//        
//        ei.doIndexing();
       
        

    }
 
开发者ID:CoEIA,项目名称:DEM,代码行数:27,代码来源:EmailIndexerTest.java

示例9: newWriter

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
/**
 * Makes a writer for catalog documents.
 * <p/>The writer is created from the values returned by 
 * getCatalogIndexPath() and newCatalogAnalyzer(). 
 * <br/>The index will be creating it if it does not already exist.
 * <br/>
 * The writer must be closed after use.
 * @param forCompleteRebuild true if index will be completely rebuilt
 * @return the writer
 * @throws CorruptIndexException if the index is corrupt 
 * @throws LockObtainFailedException if another writer has this index 
 *         open (write.lock could not be obtained) 
 * @throws IOException if the directory cannot be read/written to, 
 *         or if it does not exist and create is false or if there is any 
 *         other low-level IO error
 */
private IndexWriter newWriter(boolean forCompleteRebuild) 
  throws CorruptIndexException, LockObtainFailedException, IOException {
  
  if (!this.useLocalWriter) {
    throw new IOException("This instance is not using a local writer.");
  }
  if (this.useSingleWriter) return this.getSingleWriter(forCompleteRebuild);
  
  File f = new File(this.luceneConfig.getIndexLocation());
  getLogger().log(Level.FINER, "Creating Lucene IndexWriter for: {0}", f.getAbsolutePath());
  IndexWriter.MaxFieldLength mfl = IndexWriter.MaxFieldLength.UNLIMITED;
  if (!forCompleteRebuild) {
    return new IndexWriter(this.newDirectory(),this.newAnalyzer(),mfl);
  } else {
    return new IndexWriter(this.newDirectory(),this.newAnalyzer(),true,mfl);
  }
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:34,代码来源:LuceneIndexAdapter.java

示例10: testWhetherDeleteAllDeletesWriteLock

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
public void testWhetherDeleteAllDeletesWriteLock() throws Exception {
  Directory d = newFSDirectory(_TestUtil.getTempDir("TestIndexWriter.testWhetherDeleteAllDeletesWriteLock"));
  // Must use SimpleFSLockFactory... NativeFSLockFactory
  // somehow "knows" a lock is held against write.lock
  // even if you remove that file:
  d.setLockFactory(new SimpleFSLockFactory());
  RandomIndexWriter w1 = new RandomIndexWriter(random(), d);
  w1.deleteAll();
  try {
    new RandomIndexWriter(random(), d, newIndexWriterConfig(TEST_VERSION_CURRENT, null).setWriteLockTimeout(100));
    fail("should not be able to create another writer");
  } catch (LockObtainFailedException lofe) {
    // expected
  }
  w1.close();
  d.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:18,代码来源:TestIndexWriter.java

示例11: testSimpleLockErrorOnStartup

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
@Test
public void testSimpleLockErrorOnStartup() throws Exception {

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

  try {
    //opening a new core on the same index
    initCore("solrconfig-simplelock.xml", "schema.xml");
    fail("Expected " + LockObtainFailedException.class.getSimpleName());
  } catch (Throwable t) {
    assertTrue(t instanceof RuntimeException);
    assertNotNull(t.getCause());
    assertTrue(t.getCause() instanceof RuntimeException);
    assertNotNull(t.getCause().getCause());
    assertTrue(t.getCause().getCause().toString(), t.getCause().getCause() instanceof LockObtainFailedException);
  } finally {
    indexWriter.close();
    directory.close();
    deleteCore();
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:24,代码来源:SolrCoreCheckLockOnStartupTest.java

示例12: testNativeLockErrorOnStartup

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
@Test
public void testNativeLockErrorOnStartup() throws Exception {

  Directory directory = newFSDirectory(new File(dataDir, "index"), new NativeFSLockFactory());
  //creates a new IndexWriter without releasing the lock yet
  IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_40, null));

  try {
    //opening a new core on the same index
    initCore("solrconfig-nativelock.xml", "schema.xml");
    fail("Expected " + LockObtainFailedException.class.getSimpleName());
  } catch(Throwable t) {
    assertTrue(t instanceof RuntimeException);
    assertNotNull(t.getCause());
    assertTrue(t.getCause() instanceof RuntimeException);
    assertNotNull(t.getCause().getCause());
    assertTrue(t.getCause().getCause() instanceof  LockObtainFailedException);
  } finally {
    indexWriter.close();
    directory.close();
    deleteCore();
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:24,代码来源:SolrCoreCheckLockOnStartupTest.java

示例13: testFetchDocuments

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
@Test
public void testFetchDocuments() throws CorruptIndexException, LockObtainFailedException, IOException {
  Selector selector = new Selector();
  selector.setLocationId("shard/0");
  Set<String> columnFamiliesToFetch = new HashSet<String>();
  columnFamiliesToFetch.add("f1");
  columnFamiliesToFetch.add("f2");
  selector.setColumnFamiliesToFetch(columnFamiliesToFetch);

  ResetableDocumentStoredFieldVisitor resetableDocumentStoredFieldVisitor = new ResetableDocumentStoredFieldVisitor();
  // List<Document> docs = BlurUtil.fetchDocuments(getReader(), new
  // Term("a","b"), resetableDocumentStoredFieldVisitor, selector, 10000000,
  // "test-context", new
  // Term(BlurConstants.PRIME_DOC,BlurConstants.PRIME_DOC_VALUE));
  AtomicBoolean moreDocsToFetch = new AtomicBoolean(false);
  AtomicInteger totalRecords = new AtomicInteger();
  List<Document> docs = BlurUtil.fetchDocuments(getReader(), resetableDocumentStoredFieldVisitor, selector, 10000000,
      "test-context", new Term(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE), null, moreDocsToFetch,
      totalRecords, null);
  assertEquals(docs.size(), 1);
  assertFalse(moreDocsToFetch.get());
  assertEquals(1, totalRecords.get());
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:24,代码来源:BlurUtilsTest.java

示例14: testFetchDocumentsStrictFamilyOrder

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
@Test
public void testFetchDocumentsStrictFamilyOrder() throws CorruptIndexException, LockObtainFailedException,
    IOException {
  Selector selector = new Selector();
  selector.setLocationId("shard/0");
  Set<String> columnFamiliesToFetch = new HashSet<String>();
  columnFamiliesToFetch.add("f1");
  columnFamiliesToFetch.add("f2");
  selector.setColumnFamiliesToFetch(columnFamiliesToFetch);
  selector.addToOrderOfFamiliesToFetch("f1");
  selector.addToOrderOfFamiliesToFetch("f2");

  ResetableDocumentStoredFieldVisitor resetableDocumentStoredFieldVisitor = new ResetableDocumentStoredFieldVisitor();
  AtomicBoolean moreDocsToFetch = new AtomicBoolean(false);
  AtomicInteger totalRecords = new AtomicInteger();
  List<Document> docs = BlurUtil.fetchDocuments(getReaderWithDocsHavingFamily(), resetableDocumentStoredFieldVisitor,
      selector, 10000000, "test-context", new Term(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE), null,
      moreDocsToFetch, totalRecords, null);
  assertEquals(docs.size(), 2);
  assertEquals(docs.get(0).getField("family").stringValue(), "f1");
  assertEquals(docs.get(1).getField("family").stringValue(), "f2");
  assertFalse(moreDocsToFetch.get());
  assertEquals(2, totalRecords.get());
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:25,代码来源:BlurUtilsTest.java

示例15: getReader

import org.apache.lucene.store.LockObtainFailedException; //导入依赖的package包/类
private IndexReader getReader() throws CorruptIndexException, LockObtainFailedException, IOException {
  RAMDirectory directory = new RAMDirectory();
  IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, new KeywordAnalyzer());
  IndexWriter writer = new IndexWriter(directory, conf);
  Document doc = new Document();
  doc.add(new StringField(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE, Store.NO));
  doc.add(new StringField("a", "b", Store.YES));
  doc.add(new StringField("family", "f1", Store.YES));

  Document doc1 = new Document();
  doc.add(new StringField("a", "b", Store.YES));
  writer.addDocument(doc);
  writer.addDocument(doc1);
  writer.close();
  return DirectoryReader.open(directory);
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:17,代码来源:BlurUtilsTest.java


注:本文中的org.apache.lucene.store.LockObtainFailedException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。