mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-30 11:58:36 +00:00
Optimize API: Add onlyExpungeDeletes, flush and refresh parameters. Closes #15.
This commit is contained in:
parent
9633108ad6
commit
66b86a7a03
@ -44,6 +44,12 @@ public class OptimizeRequest extends BroadcastOperationRequest {
|
|||||||
|
|
||||||
private int maxNumSegments = -1;
|
private int maxNumSegments = -1;
|
||||||
|
|
||||||
|
private boolean onlyExpungeDeletes = false;
|
||||||
|
|
||||||
|
private boolean flush = false;
|
||||||
|
|
||||||
|
private boolean refresh = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an optimization request over one or more indices.
|
* Constructs an optimization request over one or more indices.
|
||||||
*
|
*
|
||||||
@ -101,15 +107,68 @@ public class OptimizeRequest extends BroadcastOperationRequest {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the optimization only expunge deletes from the index, without full optimization.
|
||||||
|
* Defaults to full optimization (<tt>false</tt>).
|
||||||
|
*/
|
||||||
|
public boolean onlyExpungeDeletes() {
|
||||||
|
return onlyExpungeDeletes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the optimization only expunge deletes from the index, without full optimization.
|
||||||
|
* Defaults to full optimization (<tt>false</tt>).
|
||||||
|
*/
|
||||||
|
public OptimizeRequest onlyExpungeDeletes(boolean onlyExpungeDeletes) {
|
||||||
|
this.onlyExpungeDeletes = onlyExpungeDeletes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should flush be performed after the optimization. Defaults to <tt>false</tt>.
|
||||||
|
*/
|
||||||
|
public boolean flush() {
|
||||||
|
return flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should flush be performed after the optimization. Defaults to <tt>false</tt>.
|
||||||
|
*/
|
||||||
|
public OptimizeRequest flush(boolean flush) {
|
||||||
|
this.flush = flush;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should refresh be performed after the optimization. Defaults to <tt>false</tt>.
|
||||||
|
*/
|
||||||
|
public boolean refresh() {
|
||||||
|
return refresh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should refresh be performed after the optimization. Defaults to <tt>false</tt>.
|
||||||
|
*/
|
||||||
|
public OptimizeRequest refresh(boolean refresh) {
|
||||||
|
this.refresh = refresh;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
|
public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
waitForMerge = in.readBoolean();
|
waitForMerge = in.readBoolean();
|
||||||
maxNumSegments = in.readInt();
|
maxNumSegments = in.readInt();
|
||||||
|
onlyExpungeDeletes = in.readBoolean();
|
||||||
|
flush = in.readBoolean();
|
||||||
|
refresh = in.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(DataOutput out) throws IOException {
|
public void writeTo(DataOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
out.writeBoolean(waitForMerge);
|
out.writeBoolean(waitForMerge);
|
||||||
out.writeInt(maxNumSegments);
|
out.writeInt(maxNumSegments);
|
||||||
|
out.writeBoolean(onlyExpungeDeletes);
|
||||||
|
out.writeBoolean(flush);
|
||||||
|
out.writeBoolean(refresh);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,6 +34,12 @@ public class ShardOptimizeRequest extends BroadcastShardOperationRequest {
|
|||||||
|
|
||||||
private int maxNumSegments = -1;
|
private int maxNumSegments = -1;
|
||||||
|
|
||||||
|
private boolean onlyExpungeDeletes = false;
|
||||||
|
|
||||||
|
private boolean flush = false;
|
||||||
|
|
||||||
|
private boolean refresh = false;
|
||||||
|
|
||||||
ShardOptimizeRequest() {
|
ShardOptimizeRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +47,9 @@ public class ShardOptimizeRequest extends BroadcastShardOperationRequest {
|
|||||||
super(index, shardId);
|
super(index, shardId);
|
||||||
waitForMerge = request.waitForMerge();
|
waitForMerge = request.waitForMerge();
|
||||||
maxNumSegments = request.maxNumSegments();
|
maxNumSegments = request.maxNumSegments();
|
||||||
|
onlyExpungeDeletes = request.onlyExpungeDeletes();
|
||||||
|
flush = request.flush();
|
||||||
|
refresh = request.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean waitForMerge() {
|
boolean waitForMerge() {
|
||||||
@ -51,15 +60,33 @@ public class ShardOptimizeRequest extends BroadcastShardOperationRequest {
|
|||||||
return maxNumSegments;
|
return maxNumSegments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean onlyExpungeDeletes() {
|
||||||
|
return onlyExpungeDeletes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean flush() {
|
||||||
|
return flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean refresh() {
|
||||||
|
return refresh;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
|
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
waitForMerge = in.readBoolean();
|
waitForMerge = in.readBoolean();
|
||||||
maxNumSegments = in.readInt();
|
maxNumSegments = in.readInt();
|
||||||
|
onlyExpungeDeletes = in.readBoolean();
|
||||||
|
flush = in.readBoolean();
|
||||||
|
refresh = in.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void writeTo(DataOutput out) throws IOException {
|
@Override public void writeTo(DataOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
out.writeBoolean(waitForMerge);
|
out.writeBoolean(waitForMerge);
|
||||||
out.writeInt(maxNumSegments);
|
out.writeInt(maxNumSegments);
|
||||||
|
out.writeBoolean(onlyExpungeDeletes);
|
||||||
|
out.writeBoolean(flush);
|
||||||
|
out.writeBoolean(refresh);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -86,7 +86,13 @@ public class TransportOptimizeAction extends TransportBroadcastOperationAction<O
|
|||||||
|
|
||||||
@Override protected ShardOptimizeResponse shardOperation(ShardOptimizeRequest request) throws ElasticSearchException {
|
@Override protected ShardOptimizeResponse shardOperation(ShardOptimizeRequest request) throws ElasticSearchException {
|
||||||
IndexShard indexShard = indicesService.indexServiceSafe(request.index()).shardSafe(request.shardId());
|
IndexShard indexShard = indicesService.indexServiceSafe(request.index()).shardSafe(request.shardId());
|
||||||
indexShard.optimize(new Engine.Optimize(request.waitForMerge(), request.maxNumSegments()));
|
indexShard.optimize(new Engine.Optimize()
|
||||||
|
.waitForMerge(request.waitForMerge())
|
||||||
|
.maxNumSegments(request.maxNumSegments())
|
||||||
|
.onlyExpungeDeletes(request.onlyExpungeDeletes())
|
||||||
|
.flush(request.flush())
|
||||||
|
.refresh(request.refresh())
|
||||||
|
);
|
||||||
return new ShardOptimizeResponse(request.index(), request.shardId());
|
return new ShardOptimizeResponse(request.index(), request.shardId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,9 @@ public class HttpOptimizeAction extends BaseHttpServerHandler {
|
|||||||
try {
|
try {
|
||||||
optimizeRequest.waitForMerge(HttpActions.paramAsBoolean(request.param("waitForMerge"), true));
|
optimizeRequest.waitForMerge(HttpActions.paramAsBoolean(request.param("waitForMerge"), true));
|
||||||
optimizeRequest.maxNumSegments(HttpActions.paramAsInt(request.param("maxNumSegments"), -1));
|
optimizeRequest.maxNumSegments(HttpActions.paramAsInt(request.param("maxNumSegments"), -1));
|
||||||
|
optimizeRequest.onlyExpungeDeletes(HttpActions.paramAsBoolean(request.param("onlyExpungeDeletes"), false));
|
||||||
|
optimizeRequest.flush(HttpActions.paramAsBoolean(request.param("flush"), false));
|
||||||
|
optimizeRequest.refresh(HttpActions.paramAsBoolean(request.param("refresh"), false));
|
||||||
|
|
||||||
// we just send back a response, no need to fork a listener
|
// we just send back a response, no need to fork a listener
|
||||||
optimizeRequest.listenerThreaded(false);
|
optimizeRequest.listenerThreaded(false);
|
||||||
|
@ -162,24 +162,62 @@ public interface Engine extends IndexShardComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class Optimize {
|
static class Optimize {
|
||||||
private final boolean waitForMerge;
|
private boolean waitForMerge = true;
|
||||||
private final int maxNumSegments;
|
private int maxNumSegments = -1;
|
||||||
|
private boolean onlyExpungeDeletes = false;
|
||||||
|
private boolean flush = false;
|
||||||
|
private boolean refresh = false;
|
||||||
|
|
||||||
public Optimize(boolean waitForMerge, int maxNumSegments) {
|
public Optimize() {
|
||||||
this.waitForMerge = waitForMerge;
|
|
||||||
this.maxNumSegments = maxNumSegments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean waitForMerge() {
|
public boolean waitForMerge() {
|
||||||
return waitForMerge;
|
return waitForMerge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optimize waitForMerge(boolean waitForMerge) {
|
||||||
|
this.waitForMerge = waitForMerge;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public int maxNumSegments() {
|
public int maxNumSegments() {
|
||||||
return maxNumSegments;
|
return maxNumSegments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optimize maxNumSegments(int maxNumSegments) {
|
||||||
|
this.maxNumSegments = maxNumSegments;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onlyExpungeDeletes() {
|
||||||
|
return onlyExpungeDeletes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optimize onlyExpungeDeletes(boolean onlyExpungeDeletes) {
|
||||||
|
this.onlyExpungeDeletes = onlyExpungeDeletes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean flush() {
|
||||||
|
return flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optimize flush(boolean flush) {
|
||||||
|
this.flush = flush;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean refresh() {
|
||||||
|
return refresh;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optimize refresh(boolean refresh) {
|
||||||
|
this.refresh = refresh;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override public String toString() {
|
||||||
return "waitForMerge[" + waitForMerge + "], maxNumSegments[" + maxNumSegments + "]";
|
return "waitForMerge[" + waitForMerge + "], maxNumSegments[" + maxNumSegments + "], onlyExpungeDeletes[" + onlyExpungeDeletes + "], flush[" + flush + "], refresh[" + refresh + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +309,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indexWriter.optimize(maxNumberOfSegments, optimize.waitForMerge());
|
if (optimize.onlyExpungeDeletes()) {
|
||||||
|
indexWriter.expungeDeletes(optimize.waitForMerge());
|
||||||
|
} else {
|
||||||
|
indexWriter.optimize(maxNumberOfSegments, optimize.waitForMerge());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OptimizeFailedEngineException(shardId, e);
|
throw new OptimizeFailedEngineException(shardId, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -317,6 +321,12 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine,
|
|||||||
optimizeMutex.set(false);
|
optimizeMutex.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (optimize.flush()) {
|
||||||
|
flush(new Flush());
|
||||||
|
}
|
||||||
|
if (optimize.refresh()) {
|
||||||
|
refresh(new Refresh(false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void snapshot(SnapshotHandler snapshotHandler) throws EngineException {
|
@Override public void snapshot(SnapshotHandler snapshotHandler) throws EngineException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user