Selaa lähdekoodia

[ENGINE] Remove dirty flag and force boolean for refresh

Today we have a dirty flag indicating that a refresh must
be executed. We also allow users to bypass this by setting
a force=true boolean on the refresh request / command. All
these flags are unneeded since the SearcherManager has all
the information to do the right thing if it's dirty or not.
Simon Willnauer 10 vuotta sitten
vanhempi
commit
03f1fcc85e
17 muutettua tiedostoa jossa 66 lisäystä ja 149 poistoa
  1. 0 23
      src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequest.java
  2. 0 9
      src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java
  3. 0 18
      src/main/java/org/elasticsearch/action/admin/indices/refresh/ShardRefreshRequest.java
  4. 2 2
      src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java
  5. 2 2
      src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java
  6. 2 2
      src/main/java/org/elasticsearch/action/delete/TransportDeleteAction.java
  7. 2 2
      src/main/java/org/elasticsearch/action/delete/TransportShardDeleteAction.java
  8. 1 3
      src/main/java/org/elasticsearch/action/get/TransportGetAction.java
  9. 1 1
      src/main/java/org/elasticsearch/action/get/TransportShardMultiGetAction.java
  10. 2 2
      src/main/java/org/elasticsearch/action/index/TransportIndexAction.java
  11. 2 3
      src/main/java/org/elasticsearch/index/engine/Engine.java
  12. 6 31
      src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java
  13. 1 1
      src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java
  14. 1 1
      src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java
  15. 28 32
      src/main/java/org/elasticsearch/index/shard/IndexShard.java
  16. 0 1
      src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java
  17. 16 16
      src/test/java/org/elasticsearch/index/engine/internal/InternalEngineTests.java

+ 0 - 23
src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequest.java

@@ -37,7 +37,6 @@ import java.io.IOException;
  */
 public class RefreshRequest extends BroadcastOperationRequest<RefreshRequest> {
 
-    private boolean force = true;
 
     RefreshRequest() {
     }
@@ -54,26 +53,4 @@ public class RefreshRequest extends BroadcastOperationRequest<RefreshRequest> {
         super(indices);
     }
 
-    public boolean force() {
-        return force;
-    }
-
-    /**
-     * Forces calling refresh, overriding the check that dirty operations even happened. Defaults
-     * to true (note, still lightweight if no refresh is needed).
-     */
-    public RefreshRequest force(boolean force) {
-        this.force = force;
-        return this;
-    }
-
-    public void readFrom(StreamInput in) throws IOException {
-        super.readFrom(in);
-        force = in.readBoolean();
-    }
-
-    public void writeTo(StreamOutput out) throws IOException {
-        super.writeTo(out);
-        out.writeBoolean(force);
-    }
 }

+ 0 - 9
src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java

@@ -34,15 +34,6 @@ public class RefreshRequestBuilder extends BroadcastOperationRequestBuilder<Refr
         super(indicesClient, new RefreshRequest());
     }
 
-    /**
-     * Forces calling refresh, overriding the check that dirty operations even happened. Defaults
-     * to true (note, still lightweight if no refresh is needed).
-     */
-    public RefreshRequestBuilder setForce(boolean force) {
-        request.force(force);
-        return this;
-    }
-
     @Override
     protected void doExecute(ActionListener<RefreshResponse> listener) {
         client.refresh(request, listener);

+ 0 - 18
src/main/java/org/elasticsearch/action/admin/indices/refresh/ShardRefreshRequest.java

@@ -31,29 +31,11 @@ import java.io.IOException;
  */
 class ShardRefreshRequest extends BroadcastShardOperationRequest {
 
-    private boolean force = true;
-
     ShardRefreshRequest() {
     }
 
     ShardRefreshRequest(ShardId shardId, RefreshRequest request) {
         super(shardId, request);
-        force = request.force();
-    }
-
-    public boolean force() {
-        return force;
     }
 
-    @Override
-    public void readFrom(StreamInput in) throws IOException {
-        super.readFrom(in);
-        force = in.readBoolean();
-    }
-
-    @Override
-    public void writeTo(StreamOutput out) throws IOException {
-        super.writeTo(out);
-        out.writeBoolean(force);
-    }
 }

+ 2 - 2
src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java

@@ -107,8 +107,8 @@ public class TransportRefreshAction extends TransportBroadcastOperationAction<Re
     @Override
     protected ShardRefreshResponse shardOperation(ShardRefreshRequest request) throws ElasticsearchException {
         IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id());
-        indexShard.refresh("api", request.force());
-        logger.trace("{} refresh request executed, force: [{}]", indexShard.shardId(), request.force());
+        indexShard.refresh("api");
+        logger.trace("{} refresh request executed, force: [{}]", indexShard.shardId());
         return new ShardRefreshResponse(request.shardId());
     }
 

+ 2 - 2
src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java

@@ -355,7 +355,7 @@ public class TransportShardBulkAction extends TransportShardReplicationOperation
 
         if (request.refresh()) {
             try {
-                indexShard.refresh("refresh_flag_bulk", false);
+                indexShard.refresh("refresh_flag_bulk");
             } catch (Throwable e) {
                 // ignore
             }
@@ -620,7 +620,7 @@ public class TransportShardBulkAction extends TransportShardReplicationOperation
 
         if (request.refresh()) {
             try {
-                indexShard.refresh("refresh_flag_bulk", false);
+                indexShard.refresh("refresh_flag_bulk");
             } catch (Throwable e) {
                 // ignore
             }

+ 2 - 2
src/main/java/org/elasticsearch/action/delete/TransportDeleteAction.java

@@ -182,7 +182,7 @@ public class TransportDeleteAction extends TransportShardReplicationOperationAct
 
         if (request.refresh()) {
             try {
-                indexShard.refresh("refresh_flag_delete", false);
+                indexShard.refresh("refresh_flag_delete");
             } catch (Exception e) {
                 // ignore
             }
@@ -202,7 +202,7 @@ public class TransportDeleteAction extends TransportShardReplicationOperationAct
 
         if (request.refresh()) {
             try {
-                indexShard.refresh("refresh_flag_delete", false);
+                indexShard.refresh("refresh_flag_delete");
             } catch (Exception e) {
                 // ignore
             }

+ 2 - 2
src/main/java/org/elasticsearch/action/delete/TransportShardDeleteAction.java

@@ -92,7 +92,7 @@ public class TransportShardDeleteAction extends TransportShardReplicationOperati
 
         if (request.refresh()) {
             try {
-                indexShard.refresh("refresh_flag_delete", false);
+                indexShard.refresh("refresh_flag_delete");
             } catch (Exception e) {
                 // ignore
             }
@@ -117,7 +117,7 @@ public class TransportShardDeleteAction extends TransportShardReplicationOperati
 
         if (request.refresh()) {
             try {
-                indexShard.refresh("refresh_flag_delete", false);
+                indexShard.refresh("refresh_flag_delete");
             } catch (Exception e) {
                 // ignore
             }

+ 1 - 3
src/main/java/org/elasticsearch/action/get/TransportGetAction.java

@@ -41,8 +41,6 @@ import org.elasticsearch.transport.TransportService;
  */
 public class TransportGetAction extends TransportShardSingleOperationAction<GetRequest, GetResponse> {
 
-    public static final boolean REFRESH_FORCE = false;
-
     private final IndicesService indicesService;
     private final boolean realtime;
 
@@ -90,7 +88,7 @@ public class TransportGetAction extends TransportShardSingleOperationAction<GetR
         IndexShard indexShard = indexService.shardSafe(shardId.id());
 
         if (request.refresh() && !request.realtime()) {
-            indexShard.refresh("refresh_flag_get", REFRESH_FORCE);
+            indexShard.refresh("refresh_flag_get");
         }
 
         GetResult result = indexShard.getService().get(request.type(), request.id(), request.fields(),

+ 1 - 1
src/main/java/org/elasticsearch/action/get/TransportShardMultiGetAction.java

@@ -98,7 +98,7 @@ public class TransportShardMultiGetAction extends TransportShardSingleOperationA
         IndexShard indexShard = indexService.shardSafe(shardId.id());
 
         if (request.refresh() && !request.realtime()) {
-            indexShard.refresh("refresh_flag_mget", TransportGetAction.REFRESH_FORCE);
+            indexShard.refresh("refresh_flag_mget");
         }
 
         MultiGetShardResponse response = new MultiGetShardResponse();

+ 2 - 2
src/main/java/org/elasticsearch/action/index/TransportIndexAction.java

@@ -205,7 +205,7 @@ public class TransportIndexAction extends TransportShardReplicationOperationActi
         }
         if (request.refresh()) {
             try {
-                indexShard.refresh("refresh_flag_index", false);
+                indexShard.refresh("refresh_flag_index");
             } catch (Throwable e) {
                 // ignore
             }
@@ -236,7 +236,7 @@ public class TransportIndexAction extends TransportShardReplicationOperationActi
         }
         if (request.refresh()) {
             try {
-                indexShard.refresh("refresh_flag_index", false);
+                indexShard.refresh("refresh_flag_index");
             } catch (Exception e) {
                 // ignore
             }

+ 2 - 3
src/main/java/org/elasticsearch/index/engine/Engine.java

@@ -88,10 +88,9 @@ public interface Engine extends Closeable {
 
     /**
      * Refreshes the engine for new search operations to reflect the latest
-     * changes. Pass <tt>true</tt> if the refresh operation should include
-     * all the operations performed up to this call.
+     * changes.
      */
-    void refresh(String source, boolean force) throws EngineException;
+    void refresh(String source) throws EngineException;
 
     /**
      * Flushes the state of the engine, clearing memory.

+ 6 - 31
src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java

@@ -111,9 +111,6 @@ public class InternalEngine implements Engine {
 
     private final AtomicBoolean isClosed = new AtomicBoolean(false);
     private volatile boolean closedOrFailed = false;
-    // flag indicating if a dirty operation has occurred since the last refresh
-    private volatile boolean dirty = false;
-
     private final AtomicBoolean optimizeMutex = new AtomicBoolean();
     // we use flushNeeded here, since if there are no changes, then the commit won't write
     // will not really happen, and then the commitUserData and the new translog will not be reflected
@@ -127,9 +124,6 @@ public class InternalEngine implements Engine {
     private final LiveVersionMap versionMap;
 
     private final Object[] dirtyLocks;
-
-    private final Object refreshMutex = new Object();
-
     private volatile Throwable failedEngine = null;
     private final Lock failEngineLock = new ReentrantLock();
     private final FailedEngineListener failedEngineListener;
@@ -350,7 +344,6 @@ public class InternalEngine implements Engine {
                     innerCreate(create, writer);
                 }
             }
-            dirty = true;
             flushNeeded = true;
         } catch (OutOfMemoryError | IllegalStateException | IOException t) {
             maybeFailEngine(t, "create");
@@ -458,7 +451,6 @@ public class InternalEngine implements Engine {
                     innerIndex(index, writer);
                 }
             }
-            dirty = true;
             flushNeeded = true;
         } catch (OutOfMemoryError | IllegalStateException | IOException t) {
             maybeFailEngine(t, "index");
@@ -482,7 +474,7 @@ public class InternalEngine implements Engine {
                 engineConfig.getThreadPool().executor(ThreadPool.Names.REFRESH).execute(new Runnable() {
                     public void run() {
                         try {
-                            refresh("version_table_full", false);
+                            refresh("version_table_full");
                         } catch (EngineClosedException ex) {
                             // ignore
                         }
@@ -551,7 +543,6 @@ public class InternalEngine implements Engine {
         try (InternalLock _ = readLock.acquire()) {
             final IndexWriter indexWriter = currentIndexWriter();
             innerDelete(delete, indexWriter);
-            dirty = true;
             flushNeeded = true;
         } catch (OutOfMemoryError | IllegalStateException | IOException t) {
             maybeFailEngine(t, "delete");
@@ -631,7 +622,6 @@ public class InternalEngine implements Engine {
 
             indexWriter.deleteDocuments(query);
             translog.add(new Translog.DeleteByQuery(delete));
-            dirty = true;
             flushNeeded = true;
         } catch (Throwable t) {
             maybeFailEngine(t, "delete_by_query");
@@ -640,7 +630,7 @@ public class InternalEngine implements Engine {
 
         // TODO: This is heavy, since we refresh, but we must do this because we don't know which documents were in fact deleted (i.e., our
         // versionMap isn't updated), so we must force a cutover to a new reader to "see" the deletions:
-        refresh("delete_by_query", true);
+        refresh("delete_by_query");
     }
 
     @Override
@@ -692,9 +682,7 @@ public class InternalEngine implements Engine {
               the store is closed so we need to make sure we increment it here
              */
             try {
-                // we are either dirty due to a document added or due to a
-                // finished merge - either way we should refresh
-                return dirty || !searcherManager.isSearcherCurrent();
+                return !searcherManager.isSearcherCurrent();
             } catch (IOException e) {
                 logger.error("failed to access searcher manager", e);
                 failEngine("failed to access searcher manager", e);
@@ -707,23 +695,12 @@ public class InternalEngine implements Engine {
     }
 
     @Override
-    public void refresh(String source, boolean force) throws EngineException {
+    public void refresh(String source) 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)
         try (InternalLock _ = readLock.acquire()) {
             ensureOpen();
-            // maybeRefresh will only allow one refresh to execute, and the rest will "pass through",
-            // but, we want to make sure not to loose ant refresh calls, if one is taking time
-            synchronized (refreshMutex) {
-                if (refreshNeeded() || force) {
-                    // we set dirty to false, even though the refresh hasn't happened yet
-                    // as the refresh only holds for data indexed before it. Any data indexed during
-                    // the refresh will not be part of it and will set the dirty flag back to true
-                    dirty = false;
-                    boolean refreshed = searcherManager.maybeRefresh();
-                    assert refreshed : "failed to refresh even though refreshMutex was acquired";
-                }
-            }
+            searcherManager.maybeRefreshBlocking();
         } catch (AlreadyClosedException e) {
             ensureOpen();
         } catch (EngineClosedException e) {
@@ -762,8 +739,6 @@ public class InternalEngine implements Engine {
                     if (onGoingRecoveries.get() > 0) {
                         throw new FlushNotAllowedEngineException(shardId, "Recovery is in progress, flush is not allowed");
                     }
-                    // disable refreshing, not dirty
-                    dirty = false;
                     try {
                         { // commit and close the current writer - we write the current tanslog ID just in case
                             final long translogId = translog.currentId();
@@ -813,7 +788,7 @@ public class InternalEngine implements Engine {
                             indexWriter.setCommitData(Collections.singletonMap(Translog.TRANSLOG_ID_KEY, Long.toString(translogId)));
                             indexWriter.commit();
                             // we need to refresh in order to clear older version values
-                            refresh("version_table_flush", true);
+                            refresh("version_table_flush");
                             // we need to move transient to current only after we refresh
                             // so items added to current will still be around for realtime get
                             // when tans overrides it

+ 1 - 1
src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java

@@ -143,7 +143,7 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem
                         indexShard.postRecovery("post recovery from gateway");
                     }
                     // refresh the shard
-                    indexShard.refresh("post_gateway", true);
+                    indexShard.refresh("post_gateway");
 
                     recoveryState.getTimer().time(System.currentTimeMillis() - recoveryState.getTimer().startTime());
                     recoveryState.setStage(RecoveryState.Stage.DONE);

+ 1 - 1
src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java

@@ -275,7 +275,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent imple
         }
 
         private int loadQueries(IndexShard shard) {
-            shard.refresh("percolator_load_queries", true);
+            shard.refresh("percolator_load_queries");
             // Maybe add a mode load? This isn't really a write. We need write b/c state=post_recovery
             try (Engine.Searcher searcher = shard.acquireSearcher("percolator_load_queries", true)) {
                 Query query = new ConstantScoreQuery(

+ 28 - 32
src/main/java/org/elasticsearch/index/shard/IndexShard.java

@@ -226,10 +226,6 @@ public class IndexShard extends AbstractIndexShardComponent {
         return this.store;
     }
 
-    public Engine engine() {
-        return engineSafe();
-    }
-
     public Translog translog() {
         return translog;
     }
@@ -315,7 +311,7 @@ public class IndexShard extends AbstractIndexShardComponent {
             if (newRouting.state() == ShardRoutingState.STARTED || newRouting.state() == ShardRoutingState.RELOCATING) {
                 // we want to refresh *before* we move to internal STARTED state
                 try {
-                    engineSafe().refresh("cluster_state_started", true);
+                    engine().refresh("cluster_state_started");
                 } catch (Throwable t) {
                     logger.debug("failed to refresh due to move to cluster wide started", t);
                 }
@@ -410,7 +406,7 @@ public class IndexShard extends AbstractIndexShardComponent {
             if (logger.isTraceEnabled()) {
                 logger.trace("index [{}][{}]{}", create.type(), create.id(), create.docs());
             }
-            engineSafe().create(create);
+            engine().create(create);
             create.endTime(System.nanoTime());
         } catch (Throwable ex) {
             indexingService.postCreate(create, ex);
@@ -434,7 +430,7 @@ public class IndexShard extends AbstractIndexShardComponent {
             if (logger.isTraceEnabled()) {
                 logger.trace("index [{}][{}]{}", index.type(), index.id(), index.docs());
             }
-            engineSafe().index(index);
+            engine().index(index);
             index.endTime(System.nanoTime());
         } catch (Throwable ex) {
             indexingService.postIndex(index, ex);
@@ -457,7 +453,7 @@ public class IndexShard extends AbstractIndexShardComponent {
             if (logger.isTraceEnabled()) {
                 logger.trace("delete [{}]", delete.uid().text());
             }
-            engineSafe().delete(delete);
+            engine().delete(delete);
             delete.endTime(System.nanoTime());
         } catch (Throwable ex) {
             indexingService.postDelete(delete, ex);
@@ -485,23 +481,23 @@ public class IndexShard extends AbstractIndexShardComponent {
             logger.trace("delete_by_query [{}]", deleteByQuery.query());
         }
         deleteByQuery = indexingService.preDeleteByQuery(deleteByQuery);
-        engineSafe().delete(deleteByQuery);
+        engine().delete(deleteByQuery);
         deleteByQuery.endTime(System.nanoTime());
         indexingService.postDeleteByQuery(deleteByQuery);
     }
 
     public Engine.GetResult get(Engine.Get get) throws ElasticsearchException {
         readAllowed();
-        return engineSafe().get(get);
+        return engine().get(get);
     }
 
-    public void refresh(String source, boolean force) throws ElasticsearchException {
+    public void refresh(String source) throws ElasticsearchException {
         verifyNotClosed();
         if (logger.isTraceEnabled()) {
-            logger.trace("refresh with soruce: {} force: {}", source, force);
+            logger.trace("refresh with soruce: {}", source);
         }
         long time = System.nanoTime();
-        engineSafe().refresh(source, force);
+        engine().refresh(source);
         refreshMetric.inc(System.nanoTime() - time);
     }
 
@@ -549,7 +545,7 @@ public class IndexShard extends AbstractIndexShardComponent {
     }
 
     public SegmentsStats segmentStats() {
-        SegmentsStats segmentsStats = engineSafe().segmentsStats();
+        SegmentsStats segmentsStats = engine().segmentsStats();
         segmentsStats.addBitsetMemoryInBytes(shardBitsetFilterCache.getMemorySizeInBytes());
         return segmentsStats;
     }
@@ -611,7 +607,7 @@ public class IndexShard extends AbstractIndexShardComponent {
             logger.trace("flush with {}", request);
         }
         long time = System.nanoTime();
-        engineSafe().flush(request.full() ? Engine.FlushType.NEW_WRITER : Engine.FlushType.COMMIT_TRANSLOG, request.force(), request.waitIfOngoing());
+        engine().flush(request.full() ? Engine.FlushType.NEW_WRITER : Engine.FlushType.COMMIT_TRANSLOG, request.force(), request.waitIfOngoing());
         flushMetric.inc(System.nanoTime() - time);
     }
 
@@ -620,7 +616,7 @@ public class IndexShard extends AbstractIndexShardComponent {
         if (logger.isTraceEnabled()) {
             logger.trace("optimize with {}", optimize);
         }
-        engineSafe().forceMerge(optimize.flush(), optimize.waitForMerge(), optimize
+        engine().forceMerge(optimize.flush(), optimize.waitForMerge(), optimize
                 .maxNumSegments(), optimize.onlyExpungeDeletes(), optimize.upgrade());
     }
 
@@ -628,7 +624,7 @@ public class IndexShard extends AbstractIndexShardComponent {
         IndexShardState state = this.state; // one time volatile read
         // we allow snapshot on closed index shard, since we want to do one after we close the shard and before we close the engine
         if (state == IndexShardState.STARTED || state == IndexShardState.RELOCATED || state == IndexShardState.CLOSED) {
-            return engineSafe().snapshotIndex();
+            return engine().snapshotIndex();
         } else {
             throw new IllegalIndexShardStateException(shardId, state, "snapshot is not allowed");
         }
@@ -636,12 +632,12 @@ public class IndexShard extends AbstractIndexShardComponent {
 
     public void recover(Engine.RecoveryHandler recoveryHandler) throws EngineException {
         verifyStarted();
-        engineSafe().recover(recoveryHandler);
+        engine().recover(recoveryHandler);
     }
 
     public void failShard(String reason, Throwable e) {
         // fail the engine. This will cause this shard to also be removed from the node's index service.
-        engineSafe().failEngine(reason, e);
+        engine().failEngine(reason, e);
     }
 
     public Engine.Searcher acquireSearcher(String source) {
@@ -650,7 +646,7 @@ public class IndexShard extends AbstractIndexShardComponent {
 
     public Engine.Searcher acquireSearcher(String source, boolean searcherForWriteOperation) {
         readAllowed(searcherForWriteOperation);
-        return engineSafe().acquireSearcher(source);
+        return engine().acquireSearcher(source);
     }
 
     public void close(String reason) throws IOException {
@@ -740,11 +736,11 @@ public class IndexShard extends AbstractIndexShardComponent {
 
     public void performRecoveryFinalization(boolean withFlush) throws ElasticsearchException {
         if (withFlush) {
-            engineSafe().flush(Engine.FlushType.COMMIT_TRANSLOG, false, false);
+            engine().flush(Engine.FlushType.COMMIT_TRANSLOG, false, false);
         }
         // clear unreferenced files
         translog.clearUnreferenced();
-        engineSafe().refresh("recovery_finalization", true);
+        engine().refresh("recovery_finalization");
         synchronized (mutex) {
             changeState(IndexShardState.POST_RECOVERY, "post recovery");
         }
@@ -770,7 +766,7 @@ public class IndexShard extends AbstractIndexShardComponent {
                             source(create.source()).type(create.type()).id(create.id())
                                     .routing(create.routing()).parent(create.parent()).timestamp(create.timestamp()).ttl(create.ttl()),
                             create.version(), create.versionType().versionTypeForReplicationAndRecovery(), Engine.Operation.Origin.RECOVERY, true, false);
-                    engineSafe().create(engineCreate);
+                    engine().create(engineCreate);
                     indexOperation = engineCreate;
                     break;
                 case SAVE:
@@ -778,18 +774,18 @@ public class IndexShard extends AbstractIndexShardComponent {
                     Engine.Index engineIndex = prepareIndex(source(index.source()).type(index.type()).id(index.id())
                                     .routing(index.routing()).parent(index.parent()).timestamp(index.timestamp()).ttl(index.ttl()),
                             index.version(), index.versionType().versionTypeForReplicationAndRecovery(), Engine.Operation.Origin.RECOVERY, true);
-                    engineSafe().index(engineIndex);
+                    engine().index(engineIndex);
                     indexOperation = engineIndex;
                     break;
                 case DELETE:
                     Translog.Delete delete = (Translog.Delete) operation;
                     Uid uid = Uid.createUid(delete.uid().text());
-                    engineSafe().delete(new Engine.Delete(uid.type(), uid.id(), delete.uid(), delete.version(),
+                    engine().delete(new Engine.Delete(uid.type(), uid.id(), delete.uid(), delete.version(),
                             delete.versionType().versionTypeForReplicationAndRecovery(), Engine.Operation.Origin.RECOVERY, System.nanoTime(), false));
                     break;
                 case DELETE_BY_QUERY:
                     Translog.DeleteByQuery deleteByQuery = (Translog.DeleteByQuery) operation;
-                    engineSafe().delete(prepareDeleteByQuery(deleteByQuery.source(), deleteByQuery.filteringAliases(), Engine.Operation.Origin.RECOVERY, deleteByQuery.types()));
+                    engine().delete(prepareDeleteByQuery(deleteByQuery.source(), deleteByQuery.filteringAliases(), Engine.Operation.Origin.RECOVERY, deleteByQuery.types()));
                     break;
                 default:
                     throw new ElasticsearchIllegalStateException("No operation defined for [" + operation + "]");
@@ -905,13 +901,13 @@ public class IndexShard extends AbstractIndexShardComponent {
     }
 
     public void updateBufferSize(ByteSizeValue shardIndexingBufferSize, ByteSizeValue shardTranslogBufferSize) {
-        Engine engine = engineSafe();
+        Engine engine = engine();
         engine.updateIndexingBufferSize(shardIndexingBufferSize);
         translog().updateBuffer(shardTranslogBufferSize);
     }
 
     public void markAsInactive() {
-        Engine engine = engineSafe();
+        Engine engine = engine();
         engine.updateIndexingBufferSize(EngineConfig.INACTIVE_SHARD_INDEXING_BUFFER);
         translog().updateBuffer(Translog.INACTIVE_SHARD_TRANSLOG_BUFFER);
     }
@@ -954,8 +950,8 @@ public class IndexShard extends AbstractIndexShardComponent {
                 @Override
                 public void run() {
                     try {
-                        if (engineSafe().refreshNeeded()) {
-                            refresh("schedule", false);
+                        if (engine().refreshNeeded()) {
+                            refresh("schedule");
                         }
                     } catch (EngineClosedException e) {
                         // we are being closed, ignore
@@ -1036,7 +1032,7 @@ public class IndexShard extends AbstractIndexShardComponent {
         }
     }
 
-    private Engine engineSafe() {
+    public Engine engine() {
         Engine engine = this.currentEngineReference.get();
         if (engine == null) {
             throw new EngineClosedException(shardId);
@@ -1059,7 +1055,7 @@ public class IndexShard extends AbstractIndexShardComponent {
                     }
                 }
             } finally {
-                // close the engine all bets are off... don't use engineSafe() here it can throw an exception
+                // close the engine all bets are off... don't use engine() here it can throw an exception
                 IOUtils.closeWhileHandlingException(currentEngineReference.get());
             }
         }

+ 0 - 1
src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java

@@ -54,7 +54,6 @@ public class RestRefreshAction extends BaseRestHandler {
     public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
         RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index")));
         refreshRequest.listenerThreaded(false);
-        refreshRequest.force(request.paramAsBoolean("force", refreshRequest.force()));
         refreshRequest.indicesOptions(IndicesOptions.fromRequest(request, refreshRequest.indicesOptions()));
         client.admin().indices().refresh(refreshRequest, new RestBuilderListener<RefreshResponse>(channel) {
             @Override

+ 16 - 16
src/test/java/org/elasticsearch/index/engine/internal/InternalEngineTests.java

@@ -265,7 +265,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
 
         ParsedDocument doc2 = testParsedDocument("2", "2", "test", null, -1, -1, testDocumentWithTextField(), B_2, false);
         engine.create(new Engine.Create(null, analyzer, newUid("2"), doc2));
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         segments = engine.segments(false);
         assertThat(segments.size(), equalTo(1));
@@ -298,7 +298,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
 
         ParsedDocument doc3 = testParsedDocument("3", "3", "test", null, -1, -1, testDocumentWithTextField(), B_3, false);
         engine.create(new Engine.Create(null, analyzer, newUid("3"), doc3));
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         segments = engine.segments(false);
         assertThat(segments.size(), equalTo(2));
@@ -324,7 +324,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
 
 
         engine.delete(new Engine.Delete("test", "1", newUid("1")));
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         segments = engine.segments(false);
         assertThat(segments.size(), equalTo(2));
@@ -345,7 +345,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         engineSettingsService.refreshSettings(ImmutableSettings.builder().put(EngineConfig.INDEX_COMPOUND_ON_FLUSH, true).build());
         ParsedDocument doc4 = testParsedDocument("4", "4", "test", null, -1, -1, testDocumentWithTextField(), B_3, false);
         engine.create(new Engine.Create(null, analyzer, newUid("4"), doc4));
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         segments = engine.segments(false);
         assertThat(segments.size(), equalTo(3));
@@ -376,7 +376,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         
         ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), B_1, false);
         engine.create(new Engine.Create(null, analyzer, newUid("1"), doc));
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         segments = engine.segments(true);
         assertThat(segments.size(), equalTo(1));
@@ -384,10 +384,10 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         
         ParsedDocument doc2 = testParsedDocument("2", "2", "test", null, -1, -1, testDocumentWithTextField(), B_2, false);
         engine.create(new Engine.Create(null, analyzer, newUid("2"), doc2));
-        engine.refresh("test", false);
+        engine.refresh("test");
         ParsedDocument doc3 = testParsedDocument("3", "3", "test", null, -1, -1, testDocumentWithTextField(), B_3, false);
         engine.create(new Engine.Create(null, analyzer, newUid("3"), doc3));
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         segments = engine.segments(true);
         assertThat(segments.size(), equalTo(3));
@@ -528,7 +528,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         assertThat(getResult.exists(), equalTo(false));
         getResult.release();
         // refresh and it should be there
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         // now its there...
         searchResult = engine.acquireSearcher("test");
@@ -564,7 +564,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         getResult.release();
 
         // refresh and it should be updated
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         searchResult = engine.acquireSearcher("test");
         MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1));
@@ -588,7 +588,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         getResult.release();
 
         // refresh and it should be deleted
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         searchResult = engine.acquireSearcher("test");
         MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0));
@@ -610,7 +610,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         searchResult.close();
 
         // refresh and it should be there
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         // now its there...
         searchResult = engine.acquireSearcher("test");
@@ -644,7 +644,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         searchResult.close();
 
         // refresh and it should be updated
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         searchResult = engine.acquireSearcher("test");
         MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1));
@@ -672,7 +672,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         searchResult.close();
 
         // refresh and it should be there
-        engine.refresh("test", false);
+        engine.refresh("test");
 
         // now its there...
         searchResult = engine.acquireSearcher("test");
@@ -682,7 +682,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
 
         // delete, refresh and do a new search, it should not be there
         engine.delete(new Engine.Delete("test", "1", newUid("1")));
-        engine.refresh("test", false);
+        engine.refresh("test");
         Engine.Searcher updateSearchResult = engine.acquireSearcher("test");
         MatcherAssert.assertThat(updateSearchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0));
         updateSearchResult.close();
@@ -735,7 +735,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
 
             ParsedDocument doc2 = testParsedDocument("2", "2", "test", null, -1, -1, testDocumentWithTextField(), B_2, false);
             engine.create(new Engine.Create(null, analyzer, newUid("2"), doc2));
-            engine.refresh("foo", false);
+            engine.refresh("foo");
 
             searchResult = engine.acquireSearcher("test");
             MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 2));
@@ -1407,7 +1407,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
         Thread.sleep(1000);
 
         if (randomBoolean()) {
-            engine.refresh("test", false);
+            engine.refresh("test");
         }
 
         // Delete non-existent document