Пример #1
0
 private IndexWriter createWriter() throws IOException {
   IndexWriter indexWriter = null;
   try {
     // release locks when started
     if (IndexWriter.isLocked(store.directory())) {
       logger.warn("shard is locked, releasing lock");
       IndexWriter.unlock(store.directory());
     }
     boolean create = !IndexReader.indexExists(store.directory());
     indexWriter =
         new IndexWriter(
             store.directory(),
             analysisService.defaultIndexAnalyzer(),
             create,
             deletionPolicy,
             IndexWriter.MaxFieldLength.UNLIMITED);
     indexWriter.setMergeScheduler(mergeScheduler.newMergeScheduler());
     indexWriter.setMergePolicy(mergePolicyProvider.newMergePolicy(indexWriter));
     indexWriter.setSimilarity(similarityService.defaultIndexSimilarity());
     indexWriter.setRAMBufferSizeMB(indexingBufferSize.mbFrac());
     indexWriter.setTermIndexInterval(termIndexInterval);
   } catch (IOException e) {
     safeClose(indexWriter);
     throw e;
   }
   return indexWriter;
 }
Пример #2
0
 private AcquirableResource<ReaderSearcherHolder> buildNrtResource(IndexWriter indexWriter)
     throws IOException {
   IndexReader indexReader = indexWriter.getReader();
   IndexSearcher indexSearcher = new IndexSearcher(indexReader);
   indexSearcher.setSimilarity(similarityService.defaultSearchSimilarity());
   return newAcquirableResource(new ReaderSearcherHolder(indexSearcher));
 }
Пример #3
0
 @Override
 public void refresh(Refresh refresh) throws EngineException {
   // we obtain a read lock here, since we don't want a flush to happen while we are refreshing
   // since it flushes the index as well (though, in terms of concurrency, we are allowed to do it)
   rwl.readLock().lock();
   if (indexWriter == null) {
     throw new EngineClosedException(shardId);
   }
   try {
     // this engine always acts as if waitForOperations=true
     if (refreshMutex.compareAndSet(false, true)) {
       IndexWriter currentWriter = indexWriter;
       if (currentWriter == null) {
         throw new EngineClosedException(shardId);
       }
       try {
         if (dirty) {
           dirty = false;
           AcquirableResource<ReaderSearcherHolder> current = nrtResource;
           IndexReader newReader = current.resource().reader().reopen(true);
           if (newReader != current.resource().reader()) {
             IndexSearcher indexSearcher = new IndexSearcher(newReader);
             indexSearcher.setSimilarity(similarityService.defaultSearchSimilarity());
             nrtResource = newAcquirableResource(new ReaderSearcherHolder(indexSearcher));
             current.markForClose();
           }
         }
       } catch (AlreadyClosedException e) {
         // an index writer got replaced on us, ignore
       } catch (Exception e) {
         if (indexWriter == null) {
           throw new EngineClosedException(shardId);
         } else if (currentWriter != indexWriter) {
           // an index writer got replaced on us, ignore
         } else {
           throw new RefreshFailedEngineException(shardId, e);
         }
       } finally {
         refreshMutex.set(false);
       }
     }
   } finally {
     rwl.readLock().unlock();
   }
 }