Optimize API: Remove refresh flag

Refresh flag in optimize is problematic, since the shards refresh is allowed to execute on is different compared to the optimize shards. In order to do optimize and then refresh, they should be executed as separate APIs when needed.
closes #3690
This commit is contained in:
Shay Banon 2013-09-13 21:44:38 +02:00
parent 7cc48c8e87
commit df3f681ef0
9 changed files with 20 additions and 61 deletions

View File

@ -30,9 +30,6 @@ just marked as deleted. During a merge process of segments, a new
segment is created that does not have those deletes. This flag allow to
only merge segments that have deletes. Defaults to `false`.
|refresh |Should a refresh be performed after the optimize. Defaults to
`true`.
|flush |Should a flush be performed after the optimize. Defaults to
`true`.

View File

@ -19,6 +19,7 @@
package org.elasticsearch.action.admin.indices.optimize;
import org.elasticsearch.Version;
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -46,19 +47,13 @@ public class OptimizeRequest extends BroadcastOperationRequest<OptimizeRequest>
public static final int MAX_NUM_SEGMENTS = -1;
public static final boolean ONLY_EXPUNGE_DELETES = false;
public static final boolean FLUSH = true;
public static final boolean REFRESH = true;
}
private boolean waitForMerge = Defaults.WAIT_FOR_MERGE;
private int maxNumSegments = Defaults.MAX_NUM_SEGMENTS;
private boolean onlyExpungeDeletes = Defaults.ONLY_EXPUNGE_DELETES;
private boolean flush = Defaults.FLUSH;
private boolean refresh = Defaults.FLUSH;
/**
* Constructs an optimization request over one or more indices.
*
@ -136,28 +131,15 @@ public class OptimizeRequest extends BroadcastOperationRequest<OptimizeRequest>
return this;
}
/**
* Should refresh be performed after the optimization. Defaults to <tt>true</tt>.
*/
public boolean refresh() {
return refresh;
}
/**
* Should refresh be performed after the optimization. Defaults to <tt>true</tt>.
*/
public OptimizeRequest refresh(boolean refresh) {
this.refresh = refresh;
return this;
}
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
waitForMerge = in.readBoolean();
maxNumSegments = in.readInt();
onlyExpungeDeletes = in.readBoolean();
flush = in.readBoolean();
refresh = in.readBoolean();
if (in.getVersion().onOrBefore(Version.V_0_90_3)) {
in.readBoolean(); // old refresh flag
}
}
public void writeTo(StreamOutput out) throws IOException {
@ -166,6 +148,8 @@ public class OptimizeRequest extends BroadcastOperationRequest<OptimizeRequest>
out.writeInt(maxNumSegments);
out.writeBoolean(onlyExpungeDeletes);
out.writeBoolean(flush);
out.writeBoolean(refresh);
if (out.getVersion().onOrBefore(Version.V_0_90_3)) {
out.writeBoolean(false); // old refresh flag
}
}
}

View File

@ -74,14 +74,6 @@ public class OptimizeRequestBuilder extends BroadcastOperationRequestBuilder<Opt
return this;
}
/**
* Should refresh be performed after the optimization. Defaults to <tt>true</tt>.
*/
public OptimizeRequestBuilder setRefresh(boolean refresh) {
request.refresh(refresh);
return this;
}
@Override
protected void doExecute(ActionListener<OptimizeResponse> listener) {
((IndicesAdminClient) client).optimize(request, listener);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.action.admin.indices.optimize;
import org.elasticsearch.Version;
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -34,7 +35,6 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
private int maxNumSegments = OptimizeRequest.Defaults.MAX_NUM_SEGMENTS;
private boolean onlyExpungeDeletes = OptimizeRequest.Defaults.ONLY_EXPUNGE_DELETES;
private boolean flush = OptimizeRequest.Defaults.FLUSH;
private boolean refresh = OptimizeRequest.Defaults.REFRESH;
ShardOptimizeRequest() {
}
@ -45,7 +45,6 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
maxNumSegments = request.maxNumSegments();
onlyExpungeDeletes = request.onlyExpungeDeletes();
flush = request.flush();
refresh = request.refresh();
}
boolean waitForMerge() {
@ -64,10 +63,6 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
return flush;
}
public boolean refresh() {
return refresh;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
@ -75,7 +70,9 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
maxNumSegments = in.readInt();
onlyExpungeDeletes = in.readBoolean();
flush = in.readBoolean();
refresh = in.readBoolean();
if (in.getVersion().onOrBefore(Version.V_0_90_3)) {
in.readBoolean(); // old refresh flag
}
}
@Override
@ -85,6 +82,8 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
out.writeInt(maxNumSegments);
out.writeBoolean(onlyExpungeDeletes);
out.writeBoolean(flush);
out.writeBoolean(refresh);
if (out.getVersion().onOrBefore(Version.V_0_90_3)) {
out.writeBoolean(false); // old refresh flag
}
}
}

View File

@ -117,7 +117,6 @@ public class TransportOptimizeAction extends TransportBroadcastOperationAction<O
.maxNumSegments(request.maxNumSegments())
.onlyExpungeDeletes(request.onlyExpungeDeletes())
.flush(request.flush())
.refresh(request.refresh())
);
return new ShardOptimizeResponse(request.index(), request.shardId());
}

View File

@ -271,7 +271,6 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
private int maxNumSegments = -1;
private boolean onlyExpungeDeletes = false;
private boolean flush = false;
private boolean refresh = false;
public Optimize() {
}
@ -312,18 +311,9 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
return this;
}
public boolean refresh() {
return refresh;
}
public Optimize refresh(boolean refresh) {
this.refresh = refresh;
return this;
}
@Override
public String toString() {
return "waitForMerge[" + waitForMerge + "], maxNumSegments[" + maxNumSegments + "], onlyExpungeDeletes[" + onlyExpungeDeletes + "], flush[" + flush + "], refresh[" + refresh + "]";
return "waitForMerge[" + waitForMerge + "], maxNumSegments[" + maxNumSegments + "], onlyExpungeDeletes[" + onlyExpungeDeletes + "], flush[" + flush + "]";
}
}

View File

@ -995,9 +995,6 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
if (optimize.flush()) {
flush(new Flush().force(true));
}
if (optimize.refresh()) {
refresh(new Refresh().force(true));
}
}
@Override
@ -1522,7 +1519,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
return searcher;
}
}
private static final class RecoveryCounter {
private volatile int ongoingRecoveries = 0;

View File

@ -67,7 +67,6 @@ public class RestOptimizeAction extends BaseRestHandler {
optimizeRequest.maxNumSegments(request.paramAsInt("max_num_segments", optimizeRequest.maxNumSegments()));
optimizeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", optimizeRequest.onlyExpungeDeletes()));
optimizeRequest.flush(request.paramAsBoolean("flush", optimizeRequest.flush()));
optimizeRequest.refresh(request.paramAsBoolean("refresh", optimizeRequest.refresh()));
BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.THREAD_PER_SHARD);
if (operationThreading == BroadcastOperationThreading.NO_THREADS) {

View File

@ -700,16 +700,18 @@ public class CompletionSuggestSearchTests extends AbstractSharedClusterTest {
.field("somefield", "somevalue")
.endObject()
).get(); // we have 2 docs in a segment...
OptimizeResponse actionGet = client().admin().indices().prepareOptimize().setFlush(true).setMaxNumSegments(1).setRefresh(true).execute().actionGet();
OptimizeResponse actionGet = client().admin().indices().prepareOptimize().setFlush(true).setMaxNumSegments(1).execute().actionGet();
assertNoFailures(actionGet);
refresh();
// update the first one and then merge.. the target segment will have no value in FIELD
client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
.startObject()
.field("somefield", "somevalue")
.endObject()
).get();
actionGet = client().admin().indices().prepareOptimize().setFlush(true).setMaxNumSegments(1).setRefresh(true).execute().actionGet();
actionGet = client().admin().indices().prepareOptimize().setFlush(true).setMaxNumSegments(1).execute().actionGet();
assertNoFailures(actionGet);
refresh();
assertSuggestions("b");
assertThat(2l, equalTo(client().prepareCount(INDEX).get().getCount()));