本文整理匯總了Java中org.apache.lucene.store.LockObtainFailedException類的典型用法代碼示例。如果您正苦於以下問題:Java LockObtainFailedException類的具體用法?Java LockObtainFailedException怎麽用?Java LockObtainFailedException使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。
LockObtainFailedException類屬於org.apache.lucene.store包,在下文中一共展示了LockObtainFailedException類的37個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: acquireFSLockForPaths
點讚 3
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,
示例2: acquireFSLockForPaths
點讚 3
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,
示例3: processAllDescriptions
點讚 3
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) context.performQuery(countQuery)).get(0);
SelectQuery 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,
示例4: testLocksBlock
點讚 3
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,
示例5: testSimpleLockErrorOnStartup
點讚 3
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,
示例6: obtain
點讚 3
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,
示例7: obtain
點讚 3
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,
示例8: TestEmails
點讚 3
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,
示例9: newWriter
點讚 3
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
/**
* Makes a writer for catalog documents.
*
* getCatalogIndexPath() and newCatalogAnalyzer().
*
The index will be creating it if it does not already exist.
*
* 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,
示例10: testWhetherDeleteAllDeletesWriteLock
點讚 3
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,
示例11: testSimpleLockErrorOnStartup
點讚 3
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,
示例12: testNativeLockErrorOnStartup
點讚 3
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,
示例13: testFetchDocuments
點讚 3
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
@Test
public void testFetchDocuments() throws CorruptIndexException, LockObtainFailedException, IOException {
Selector selector = new Selector();
selector.setLocationId("shard/0");
Set columnFamiliesToFetch = new HashSet();
columnFamiliesToFetch.add("f1");
columnFamiliesToFetch.add("f2");
selector.setColumnFamiliesToFetch(columnFamiliesToFetch);
ResetableDocumentStoredFieldVisitor resetableDocumentStoredFieldVisitor = new ResetableDocumentStoredFieldVisitor();
// List 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 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,
示例14: testFetchDocumentsStrictFamilyOrder
點讚 3
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
@Test
public void testFetchDocumentsStrictFamilyOrder() throws CorruptIndexException, LockObtainFailedException,
IOException {
Selector selector = new Selector();
selector.setLocationId("shard/0");
Set columnFamiliesToFetch = new HashSet();
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 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,
示例15: getReader
點讚 3
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,
示例16: getReaderWithDocsHavingFamily
點讚 3
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
private IndexReader getReaderWithDocsHavingFamily() 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", "f2", Store.YES));
Document doc1 = new Document();
doc1.add(new StringField("a", "b", Store.YES));
doc1.add(new StringField("family", "f1", Store.YES));
writer.addDocument(doc);
writer.addDocument(doc1);
writer.close();
return DirectoryReader.open(directory);
}
開發者ID:apache,項目名稱:incubator-blur,代碼行數:19,
示例17: index
點讚 3
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
private static void index(String datafolder, String indexfolder) throws CorruptIndexException,
LockObtainFailedException, IOException {
Analyzer a = new StandardAnalyzer(Version.LUCENE_41);
Directory d = FSDirectory.open(new File(indexfolder));
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_41, new StandardAnalyzer(Version.LUCENE_41));
IndexWriter indexWriter = new IndexWriter(d, config);
Document doc = new Document();
// Fieldable contentfield=new Field("content", new
// FileReader(datafolder));
// doc.add(contentfield);
// Fieldable namefield=new Field("filename",datafolder, Store.YES,
// Index.NOT_ANALYZED);
// doc.add(namefield);
indexWriter.addDocument(doc);
indexWriter.commit();
}
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:20,
示例18: testWriteLock
點讚 3
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public void testWriteLock() throws IOException {
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_41,
AosAnalyser.NO_LIMIT_TOKEN_COUNT_SIMPLE_ANALYSER);
IndexWriter writer1 = new IndexWriter(directory, config);
IndexWriter writer2 = null;
try {
writer2 = new IndexWriter(directory, config);
fail("We should never reach this point");
}
catch (LockObtainFailedException e) {
// e.printStackTrace();
}
finally {
writer1.close();
assertNull(writer2);
}
}
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:21,
示例19: obtain
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
@Override
public boolean obtain(long lockWaitTimeout) throws LockObtainFailedException, IOException {
try {
return super.obtain(lockWaitTimeout);
} catch (LockObtainFailedException e) {
throw annotateException(
e,
(File) null,
Thread.getAllStackTraces(),
RecordOwnerLockFactory.this);
}
}
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,
示例20: acquireWriter
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
/**
* The writer operates under readLock(!) since we do not want to lock out readers,
* but just close, clear and commit operations.
*
* @return
* @throws IOException
*/
IndexWriter acquireWriter () throws IOException {
checkPreconditions();
hit();
boolean ok = false;
rwLock.readLock().lock();
try {
try {
final IndexWriter writer = indexWriterRef.acquire(new Callable() {
@NonNull
public IndexWriter call() throws IOException {
final IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_35, analyzer);
//Linux: The posix::fsync(int) is very slow on Linux ext3,
//minimize number of files sync is done on.
//http://netbeans.org/bugzilla/show_bug.cgi?id=208224
//All OS: The CFS is better for SSD disks.
final TieredMergePolicy mergePolicy = new TieredMergePolicy();
mergePolicy.setNoCFSRatio(1.0);
iwc.setMergePolicy(mergePolicy);
return new FlushIndexWriter (fsDir, iwc);
}
});
ok = true;
return writer;
} catch (LockObtainFailedException lf) {
//Already annotated
throw lf;
} catch (IOException ioe) {
//Issue #149757 - logging
throw RecordOwnerLockFactory.annotateException (
ioe,
folder,
null);
}
} finally {
if (!ok) {
rwLock.readLock().unlock();
}
}
}
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:47,
示例21: createWriter
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
private IndexWriter createWriter(boolean create) throws IOException {
try {
final IndexWriterConfig iwc = getIndexWriterConfig(create);
return createWriter(store.directory(), iwc);
} catch (LockObtainFailedException ex) {
logger.warn("could not lock IndexWriter", ex);
throw ex;
}
}
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,
示例22: restart
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public void restart() throws Throwable {
this.configHost.log(Level.INFO, "Restarting gateway ...");
long exp = Utils.fromNowMicrosUtc(this.configHost.getOperationTimeoutMicros());
// Skip deleting the temporary folder by calling
// stop on the base class. This is because
// when the host restarts, we want it to re-hydrate
// its configuration from the existing index.
super.stop();
do {
Thread.sleep(2000);
try {
startSynchronously(this.arguments);
break;
} catch (Throwable e) {
Logger.getAnonymousLogger().warning(String
.format("exception on gateway restart: %s", e.getMessage()));
try {
super.stop();
} catch (Throwable e1) {
}
if (e instanceof LockObtainFailedException) {
Logger.getAnonymousLogger()
.warning("Lock held exception on gateway restart, retrying ...");
continue;
}
throw e;
}
} while (Utils.getSystemNowMicrosUtc() < exp);
this.configHost.log(Level.INFO, "Gateway restarted successfully ...");
}
開發者ID:vmware,項目名稱:xenon-utils,代碼行數:34,
示例23: acquire
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
void acquire(long timeoutInMillis) throws LockObtainFailedException{
try {
if (mutex.tryAcquire(timeoutInMillis, TimeUnit.MILLISECONDS) == false) {
throw new LockObtainFailedException("Can't lock shard " + shardId + ", timed out after " + timeoutInMillis + "ms");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new LockObtainFailedException("Can't lock shard " + shardId + ", interrupted", e);
}
}
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:11,
示例24: lockIndexAndAck
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
private void lockIndexAndAck(String index, DiscoveryNodes nodes, String nodeId, ClusterState clusterState, Settings indexSettings) throws IOException {
try {
// we are waiting until we can lock the index / all shards on the node and then we ack the delete of the store to the
// master. If we can't acquire the locks here immediately there might be a shard of this index still holding on to the lock
// due to a "currently canceled recovery" or so. The shard will delete itself BEFORE the lock is released so it's guaranteed to be
// deleted by the time we get the lock
indicesService.processPendingDeletes(new Index(index), indexSettings, new TimeValue(30, TimeUnit.MINUTES));
transportService.sendRequest(clusterState.nodes().masterNode(),
INDEX_STORE_DELETED_ACTION_NAME, new NodeIndexStoreDeletedMessage(index, nodeId), EmptyTransportResponseHandler.INSTANCE_SAME);
} catch (LockObtainFailedException exc) {
logger.warn("[{}] failed to lock all shards for index - timed out after 30 seconds", index);
} catch (InterruptedException e) {
logger.warn("[{}] failed to lock all shards for index - interrupted", index);
}
}
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:16,
示例25: CreateIndex
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public CreateIndex(String indexDir, String dataDir, int numberOfSents,
String indexName, boolean gzip) throws CorruptIndexException,
LockObtainFailedException, IOException {
analyser = new NodeTreebankAnalyser(false);
writer = new IndexWriter("index" + File.separator + indexDir, analyser,
true, IndexWriter.MaxFieldLength.UNLIMITED);
this.indexDir = indexDir;
this.dataLocation = new File(dataDir);
this.numSents = numberOfSents;
this.gzip = gzip;
this.indexName = indexName.replaceAll("_", " ");
}
開發者ID:arne-cl,項目名稱:fangorn,代碼行數:13,
示例26: main
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public static void main(String[] args) throws CorruptIndexException,
LockObtainFailedException, IOException {
if (args.length != 5) {
System.out.println("Your arguments were:");
for (int i = 0; i < args.length; i++) {
System.out.println((i + 1) + ". " + args[i]);
}
System.out
.println("Usage: java CreateIndex ");
System.out
.println("Enter -1 for if all sentences should be indexed.");
System.out
.println("Underscores in will be replaced with spaces.");
System.exit(1);
}
final String dataSource = args[0];
CreateIndex ix = new CreateIndex(args[1], dataSource,
Integer.parseInt(args[3]), args[2],
Boolean.parseBoolean(args[4]));
long start = System.currentTimeMillis();
ix.create();
ix.commit();
long stop = System.currentTimeMillis();
System.out.println("Total number of sentences indexed: "
+ ix.sentencesProcessed());
System.out.println("Total time (sec): " + ((stop - start) / 1000.0));
}
開發者ID:arne-cl,項目名稱:fangorn,代碼行數:29,
示例27: CreateTextIndex
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public CreateTextIndex(String indexDir, String dataDir, boolean isGzip,
Integer numOfSents) throws CorruptIndexException,
LockObtainFailedException, IOException {
writer = new IndexWriter(indexDir, new FastStringAnalyser(), true,
IndexWriter.MaxFieldLength.UNLIMITED);
this.dataDir = new File(dataDir);
this.numSents = numOfSents;
this.isGzip = isGzip;
this.sentencesProcessed = 0;
}
開發者ID:arne-cl,項目名稱:fangorn,代碼行數:11,
示例28: index
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public void index() throws CorruptIndexException,
LockObtainFailedException, IOException {
Directory dir = FSDirectory.open(indexDirectory);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41,StandardAnalyzer.STOP_WORDS_SET);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_41, analyzer);
if (indexDirectory.exists()) {
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
} else {
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
}
IndexWriter writer = new IndexWriter(dir, iwc);
for (File f : sourceDirectory.listFiles()) {
System.out.println("Indexing Document "+f.getName());
Document doc = new Document();
FieldType fieldType = new FieldType();
fieldType.setIndexed(true);
fieldType.setIndexOptions(FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
fieldType.setStored(true);
fieldType.setStoreTermVectors(true);
fieldType.setTokenized(true);
Field contentField = new Field(fieldName, ExtractText(f), fieldType);
doc.add(contentField);
doc.add(new TextField("FileName", f.getName(), Field.Store.YES));
doc.add(new TextField("FilePath",f.getCanonicalPath(),Field.Store.YES));
writer.addDocument(doc);
}
writer.close();
}
開發者ID:unsw-cse-soc,項目名稱:Data-curation-API,代碼行數:29,
示例29: createOrLoadIndexWriter
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
protected static IndexWriter createOrLoadIndexWriter(URI index, Analyzer analyser) throws CorruptIndexException, LockObtainFailedException, IOException {
Directory directory = FSDirectory.open(Paths.get(index));
IndexWriterConfig iwc = new IndexWriterConfig(analyser);
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
iwc.setSimilarity(new SnomedSimilarity());
IndexWriter writer = new IndexWriter(directory, iwc);
return writer;
}
開發者ID:wardle,項目名稱:rsterminology,代碼行數:9,
示例30: getIndexWriter
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
/**
* Obtain index writer
*/
public static synchronized IndexWriter getIndexWriter() throws CorruptIndexException,
LockObtainFailedException, IOException {
if (indexWriter == null) {
IndexWriterConfig iwc = new IndexWriterConfig(Config.LUCENE_VERSION, getAnalyzer());
FSDirectory fsd = new SimpleFSDirectory(new File(INDEX_PATH));
indexWriter = new IndexWriter(fsd, iwc);
}
return indexWriter;
}
開發者ID:openkm,項目名稱:document-management-system,代碼行數:14,
示例31: createIndex
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public void createIndex() throws CorruptIndexException, LockObtainFailedException, IOException
{
docStore = new SeldonMySQLDocumentStore(jdbc);
File luceneFile = new File(luceneDir);
//IndexWriter writer = new IndexWriter(FSDirectory.open(luceneFile), new StandardAnalyzer(Version.LUCENE_CURRENT), recreate, IndexWriter.MaxFieldLength.LIMITED);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_CURRENT, new WhitespaceAnalyzer(Version.LUCENE_CURRENT));
IndexWriter writer = new IndexWriter(FSDirectory.open(luceneFile), config);
IndexSearcher reader = null;
DirectoryReader ireader = null;
if (!recreate)
{
ireader = DirectoryReader.open(FSDirectory.open(luceneFile));
reader = new IndexSearcher(ireader);
}
BufferedWriter fileWriter = null;
if (yahooLDAfile != null)
fileWriter = new BufferedWriter(new FileWriter(yahooLDAfile));
else if (outFile != null)
fileWriter = new BufferedWriter(new FileWriter(outFile));
updateComments(reader,writer,itemType,recreate,fileWriter);
if (fileWriter != null)
fileWriter.close();
if (ireader != null)
ireader.close();
writer.close();
}
開發者ID:SeldonIO,項目名稱:semantic-vectors-lucene-tools,代碼行數:31,
示例32: testWriterLock
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
/**
* Test what happens if we try to write to a locked taxonomy writer,
* and see that we can unlock it and continue.
*/
@Test
public void testWriterLock() throws Exception {
// native fslock impl gets angry if we use it, so use RAMDirectory explicitly.
Directory indexDir = new RAMDirectory();
TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
tw.addCategory(new FacetLabel("hi", "there"));
tw.commit();
// we deliberately not close the write now, and keep it open and
// locked.
// Verify that the writer worked:
TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
assertEquals(2, tr.getOrdinal(new FacetLabel("hi", "there")));
// Try to open a second writer, with the first one locking the directory.
// We expect to get a LockObtainFailedException.
try {
assertNull(new DirectoryTaxonomyWriter(indexDir));
fail("should have failed to write in locked directory");
} catch (LockObtainFailedException e) {
// this is what we expect to happen.
}
// Remove the lock, and now the open should succeed, and we can
// write to the new writer.
DirectoryTaxonomyWriter.unlock(indexDir);
TaxonomyWriter tw2 = new DirectoryTaxonomyWriter(indexDir);
tw2.addCategory(new FacetLabel("hey"));
tw2.close();
// See that the writer indeed wrote:
TaxonomyReader newtr = TaxonomyReader.openIfChanged(tr);
assertNotNull(newtr);
tr.close();
tr = newtr;
assertEquals(3, tr.getOrdinal(new FacetLabel("hey")));
tr.close();
tw.close();
indexDir.close();
}
開發者ID:europeana,項目名稱:search,代碼行數:41,
示例33: populate
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
private static void populate(Directory directory, IndexWriterConfig config) throws CorruptIndexException, LockObtainFailedException, IOException {
IndexWriter writer = new IndexWriter(directory, config);
for (int i = 0; i < NUMBER_OF_DOCUMENTS; i++) {
Document document = new Document();
for (int f = 0; f < NUMBER_OF_FIELDS; f++) {
document.add(newStringField("field" + f, getText(), Field.Store.NO));
}
writer.addDocument(document);
}
writer.forceMerge(1);
writer.close();
}
開發者ID:europeana,項目名稱:search,代碼行數:13,
示例34: testOpenTwoIndexWritersOnDifferentThreads
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public void testOpenTwoIndexWritersOnDifferentThreads() throws IOException, InterruptedException {
final Directory dir = newDirectory();
CountDownLatch oneIWConstructed = new CountDownLatch(1);
DelayedIndexAndCloseRunnable thread1 = new DelayedIndexAndCloseRunnable(
dir, oneIWConstructed);
DelayedIndexAndCloseRunnable thread2 = new DelayedIndexAndCloseRunnable(
dir, oneIWConstructed);
thread1.start();
thread2.start();
oneIWConstructed.await();
thread1.startIndexing();
thread2.startIndexing();
thread1.join();
thread2.join();
// ensure the directory is closed if we hit the timeout and throw assume
// TODO: can we improve this in LuceneTestCase? I dont know what the logic would be...
try {
assumeFalse("aborting test: timeout obtaining lock", thread1.failure instanceof LockObtainFailedException);
assumeFalse("aborting test: timeout obtaining lock", thread2.failure instanceof LockObtainFailedException);
assertFalse("Failed due to: " + thread1.failure, thread1.failed);
assertFalse("Failed due to: " + thread2.failure, thread2.failed);
// now verify that we have two documents in the index
IndexReader reader = DirectoryReader.open(dir);
assertEquals("IndexReader should have one document per thread running", 2,
reader.numDocs());
reader.close();
} finally {
dir.close();
}
}
開發者ID:europeana,項目名稱:search,代碼行數:37,
示例35: testNativeLockErrorOnStartup
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
@Test
public void testNativeLockErrorOnStartup() throws Exception {
File indexDir = new File(initCoreDataDir, "index");
log.info("Acquiring lock on {}", indexDir.getAbsolutePath());
Directory directory = newFSDirectory(indexDir, new NativeFSLockFactory());
//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","native");
//opening a new core on the same index
initCore("solrconfig-basic.xml", "schema.xml");
CoreContainer cc = h.getCoreContainer();
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,代碼行數:27,
示例36: obtainLock
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public Lock obtainLock(Directory dir, String lockName) throws IOException {
if (locks.add(lockName))
return new LockImpl(lockName);
else
throw new LockObtainFailedException("lock instance already obtained: (dir=" + dir + ", lockName=" + lockName + ")");
}
開發者ID:apache,項目名稱:ignite,代碼行數:8,
示例37: getDocumentWriter
點讚 2
import org.apache.lucene.store.LockObtainFailedException; //導入依賴的package包/類
public synchronized DocumentWriter getDocumentWriter() throws CorruptIndexException, LockObtainFailedException, IOException {
if ( documentwriter != null )
return documentwriter;
documentwriter= new DocumentWriter( this );
return documentwriter;
}
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:8,
注:本文中的org.apache.lucene.store.LockObtainFailedException類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。