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:
parent
7cc48c8e87
commit
df3f681ef0
|
@ -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
|
segment is created that does not have those deletes. This flag allow to
|
||||||
only merge segments that have deletes. Defaults to `false`.
|
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
|
|flush |Should a flush be performed after the optimize. Defaults to
|
||||||
`true`.
|
`true`.
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.action.admin.indices.optimize;
|
package org.elasticsearch.action.admin.indices.optimize;
|
||||||
|
|
||||||
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
|
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
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 int MAX_NUM_SEGMENTS = -1;
|
||||||
public static final boolean ONLY_EXPUNGE_DELETES = false;
|
public static final boolean ONLY_EXPUNGE_DELETES = false;
|
||||||
public static final boolean FLUSH = true;
|
public static final boolean FLUSH = true;
|
||||||
public static final boolean REFRESH = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean waitForMerge = Defaults.WAIT_FOR_MERGE;
|
private boolean waitForMerge = Defaults.WAIT_FOR_MERGE;
|
||||||
|
|
||||||
private int maxNumSegments = Defaults.MAX_NUM_SEGMENTS;
|
private int maxNumSegments = Defaults.MAX_NUM_SEGMENTS;
|
||||||
|
|
||||||
private boolean onlyExpungeDeletes = Defaults.ONLY_EXPUNGE_DELETES;
|
private boolean onlyExpungeDeletes = Defaults.ONLY_EXPUNGE_DELETES;
|
||||||
|
|
||||||
private boolean flush = Defaults.FLUSH;
|
private boolean flush = Defaults.FLUSH;
|
||||||
|
|
||||||
private boolean refresh = Defaults.FLUSH;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an optimization request over one or more indices.
|
* Constructs an optimization request over one or more indices.
|
||||||
*
|
*
|
||||||
|
@ -136,28 +131,15 @@ public class OptimizeRequest extends BroadcastOperationRequest<OptimizeRequest>
|
||||||
return this;
|
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 {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
waitForMerge = in.readBoolean();
|
waitForMerge = in.readBoolean();
|
||||||
maxNumSegments = in.readInt();
|
maxNumSegments = in.readInt();
|
||||||
onlyExpungeDeletes = in.readBoolean();
|
onlyExpungeDeletes = in.readBoolean();
|
||||||
flush = 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 {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
@ -166,6 +148,8 @@ public class OptimizeRequest extends BroadcastOperationRequest<OptimizeRequest>
|
||||||
out.writeInt(maxNumSegments);
|
out.writeInt(maxNumSegments);
|
||||||
out.writeBoolean(onlyExpungeDeletes);
|
out.writeBoolean(onlyExpungeDeletes);
|
||||||
out.writeBoolean(flush);
|
out.writeBoolean(flush);
|
||||||
out.writeBoolean(refresh);
|
if (out.getVersion().onOrBefore(Version.V_0_90_3)) {
|
||||||
|
out.writeBoolean(false); // old refresh flag
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,14 +74,6 @@ public class OptimizeRequestBuilder extends BroadcastOperationRequestBuilder<Opt
|
||||||
return this;
|
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
|
@Override
|
||||||
protected void doExecute(ActionListener<OptimizeResponse> listener) {
|
protected void doExecute(ActionListener<OptimizeResponse> listener) {
|
||||||
((IndicesAdminClient) client).optimize(request, listener);
|
((IndicesAdminClient) client).optimize(request, listener);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.action.admin.indices.optimize;
|
package org.elasticsearch.action.admin.indices.optimize;
|
||||||
|
|
||||||
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
|
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
@ -34,7 +35,6 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
|
||||||
private int maxNumSegments = OptimizeRequest.Defaults.MAX_NUM_SEGMENTS;
|
private int maxNumSegments = OptimizeRequest.Defaults.MAX_NUM_SEGMENTS;
|
||||||
private boolean onlyExpungeDeletes = OptimizeRequest.Defaults.ONLY_EXPUNGE_DELETES;
|
private boolean onlyExpungeDeletes = OptimizeRequest.Defaults.ONLY_EXPUNGE_DELETES;
|
||||||
private boolean flush = OptimizeRequest.Defaults.FLUSH;
|
private boolean flush = OptimizeRequest.Defaults.FLUSH;
|
||||||
private boolean refresh = OptimizeRequest.Defaults.REFRESH;
|
|
||||||
|
|
||||||
ShardOptimizeRequest() {
|
ShardOptimizeRequest() {
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
|
||||||
maxNumSegments = request.maxNumSegments();
|
maxNumSegments = request.maxNumSegments();
|
||||||
onlyExpungeDeletes = request.onlyExpungeDeletes();
|
onlyExpungeDeletes = request.onlyExpungeDeletes();
|
||||||
flush = request.flush();
|
flush = request.flush();
|
||||||
refresh = request.refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean waitForMerge() {
|
boolean waitForMerge() {
|
||||||
|
@ -64,10 +63,6 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
|
||||||
return flush;
|
return flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refresh() {
|
|
||||||
return refresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
|
@ -75,7 +70,9 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
|
||||||
maxNumSegments = in.readInt();
|
maxNumSegments = in.readInt();
|
||||||
onlyExpungeDeletes = in.readBoolean();
|
onlyExpungeDeletes = in.readBoolean();
|
||||||
flush = in.readBoolean();
|
flush = in.readBoolean();
|
||||||
refresh = in.readBoolean();
|
if (in.getVersion().onOrBefore(Version.V_0_90_3)) {
|
||||||
|
in.readBoolean(); // old refresh flag
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,6 +82,8 @@ class ShardOptimizeRequest extends BroadcastShardOperationRequest {
|
||||||
out.writeInt(maxNumSegments);
|
out.writeInt(maxNumSegments);
|
||||||
out.writeBoolean(onlyExpungeDeletes);
|
out.writeBoolean(onlyExpungeDeletes);
|
||||||
out.writeBoolean(flush);
|
out.writeBoolean(flush);
|
||||||
out.writeBoolean(refresh);
|
if (out.getVersion().onOrBefore(Version.V_0_90_3)) {
|
||||||
|
out.writeBoolean(false); // old refresh flag
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,6 @@ public class TransportOptimizeAction extends TransportBroadcastOperationAction<O
|
||||||
.maxNumSegments(request.maxNumSegments())
|
.maxNumSegments(request.maxNumSegments())
|
||||||
.onlyExpungeDeletes(request.onlyExpungeDeletes())
|
.onlyExpungeDeletes(request.onlyExpungeDeletes())
|
||||||
.flush(request.flush())
|
.flush(request.flush())
|
||||||
.refresh(request.refresh())
|
|
||||||
);
|
);
|
||||||
return new ShardOptimizeResponse(request.index(), request.shardId());
|
return new ShardOptimizeResponse(request.index(), request.shardId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,6 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
|
||||||
private int maxNumSegments = -1;
|
private int maxNumSegments = -1;
|
||||||
private boolean onlyExpungeDeletes = false;
|
private boolean onlyExpungeDeletes = false;
|
||||||
private boolean flush = false;
|
private boolean flush = false;
|
||||||
private boolean refresh = false;
|
|
||||||
|
|
||||||
public Optimize() {
|
public Optimize() {
|
||||||
}
|
}
|
||||||
|
@ -312,18 +311,9 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refresh() {
|
|
||||||
return refresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optimize refresh(boolean refresh) {
|
|
||||||
this.refresh = refresh;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "waitForMerge[" + waitForMerge + "], maxNumSegments[" + maxNumSegments + "], onlyExpungeDeletes[" + onlyExpungeDeletes + "], flush[" + flush + "], refresh[" + refresh + "]";
|
return "waitForMerge[" + waitForMerge + "], maxNumSegments[" + maxNumSegments + "], onlyExpungeDeletes[" + onlyExpungeDeletes + "], flush[" + flush + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -995,9 +995,6 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
|
||||||
if (optimize.flush()) {
|
if (optimize.flush()) {
|
||||||
flush(new Flush().force(true));
|
flush(new Flush().force(true));
|
||||||
}
|
}
|
||||||
if (optimize.refresh()) {
|
|
||||||
refresh(new Refresh().force(true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -67,7 +67,6 @@ public class RestOptimizeAction extends BaseRestHandler {
|
||||||
optimizeRequest.maxNumSegments(request.paramAsInt("max_num_segments", optimizeRequest.maxNumSegments()));
|
optimizeRequest.maxNumSegments(request.paramAsInt("max_num_segments", optimizeRequest.maxNumSegments()));
|
||||||
optimizeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", optimizeRequest.onlyExpungeDeletes()));
|
optimizeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", optimizeRequest.onlyExpungeDeletes()));
|
||||||
optimizeRequest.flush(request.paramAsBoolean("flush", optimizeRequest.flush()));
|
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);
|
BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.THREAD_PER_SHARD);
|
||||||
if (operationThreading == BroadcastOperationThreading.NO_THREADS) {
|
if (operationThreading == BroadcastOperationThreading.NO_THREADS) {
|
||||||
|
|
|
@ -700,16 +700,18 @@ public class CompletionSuggestSearchTests extends AbstractSharedClusterTest {
|
||||||
.field("somefield", "somevalue")
|
.field("somefield", "somevalue")
|
||||||
.endObject()
|
.endObject()
|
||||||
).get(); // we have 2 docs in a segment...
|
).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);
|
assertNoFailures(actionGet);
|
||||||
|
refresh();
|
||||||
// update the first one and then merge.. the target segment will have no value in FIELD
|
// update the first one and then merge.. the target segment will have no value in FIELD
|
||||||
client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
|
client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.field("somefield", "somevalue")
|
.field("somefield", "somevalue")
|
||||||
.endObject()
|
.endObject()
|
||||||
).get();
|
).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);
|
assertNoFailures(actionGet);
|
||||||
|
refresh();
|
||||||
|
|
||||||
assertSuggestions("b");
|
assertSuggestions("b");
|
||||||
assertThat(2l, equalTo(client().prepareCount(INDEX).get().getCount()));
|
assertThat(2l, equalTo(client().prepareCount(INDEX).get().getCount()));
|
||||||
|
|
Loading…
Reference in New Issue