示例#1
0
 @Override
 public void flush(Flush flush) throws EngineException {
   if (indexWriter == null) {
     throw new EngineClosedException(shardId);
   }
   // check outside the lock as well so we can check without blocking on the write lock
   if (disableFlushCounter > 0) {
     throw new FlushNotAllowedEngineException(
         shardId, "Recovery is in progress, flush is not allowed");
   }
   rwl.writeLock().lock();
   try {
     if (indexWriter == null) {
       throw new EngineClosedException(shardId);
     }
     if (disableFlushCounter > 0) {
       throw new FlushNotAllowedEngineException(
           shardId, "Recovery is in progress, flush is not allowed");
     }
     if (flush.full()) {
       // disable refreshing, not dirty
       dirty = false;
       refreshMutex.set(true);
       try {
         // that's ok if the index writer failed and is in inconsistent state
         // we will get an exception on a dirty operation, and will cause the shard
         // to be allocated to a different node
         indexWriter.close();
         indexWriter = createWriter();
         AcquirableResource<ReaderSearcherHolder> current = nrtResource;
         nrtResource = buildNrtResource(indexWriter);
         current.markForClose();
         translog.newTranslog(newTransactionLogId());
       } catch (IOException e) {
         throw new FlushFailedEngineException(shardId, e);
       } finally {
         refreshMutex.set(false);
       }
     } else {
       try {
         indexWriter.commit();
         translog.newTranslog(newTransactionLogId());
       } catch (IOException e) {
         throw new FlushFailedEngineException(shardId, e);
       }
     }
   } finally {
     rwl.writeLock().unlock();
   }
   if (flush.refresh()) {
     refresh(new Refresh(false));
   }
 }
示例#2
0
  @Override
  public void start() throws EngineException {
    rwl.writeLock().lock();
    try {
      if (indexWriter != null) {
        throw new EngineAlreadyStartedException(shardId);
      }
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Starting engine with ram_buffer_size["
                + indexingBufferSize
                + "], refresh_interval["
                + refreshInterval
                + "]");
      }
      try {
        this.indexWriter = createWriter();
      } catch (IOException e) {
        throw new EngineCreationFailureException(shardId, "Failed to create engine", e);
      }

      try {
        translog.newTranslog(newTransactionLogId());
        this.nrtResource = buildNrtResource(indexWriter);
      } catch (IOException e) {
        try {
          indexWriter.rollback();
        } catch (IOException e1) {
          // ignore
        } finally {
          try {
            indexWriter.close();
          } catch (IOException e1) {
            // ignore
          }
        }
        throw new EngineCreationFailureException(shardId, "Failed to open reader on writer", e);
      }
    } finally {
      rwl.writeLock().unlock();
    }
  }