Skip to content

Commit

Permalink
Flush API: Add refresh flag (refresh after flush). Closes #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Feb 15, 2010
1 parent 687d795 commit 9633108
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
* @author kimchy (Shay Banon)
*/
public class FlushRequest extends BroadcastOperationRequest {

private boolean refresh = false;

FlushRequest() {

}
Expand All @@ -37,6 +43,15 @@ public FlushRequest(String... indices) {
operationThreading(BroadcastOperationThreading.THREAD_PER_SHARD);
}

public boolean refresh() {
return this.refresh;
}

public FlushRequest refresh(boolean refresh) {
this.refresh = refresh;
return this;
}

@Override public FlushRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
Expand All @@ -46,4 +61,14 @@ public FlushRequest(String... indices) {
super.operationThreading(operationThreading);
return this;
}

@Override public void writeTo(DataOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(refresh);
}

@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
super.readFrom(in);
refresh = in.readBoolean();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,27 @@
*/
public class ShardFlushRequest extends BroadcastShardOperationRequest {

private boolean refresh;

ShardFlushRequest() {
}

public ShardFlushRequest(String index, int shardId) {
public ShardFlushRequest(String index, int shardId, FlushRequest request) {
super(index, shardId);
this.refresh = request.refresh();
}

public boolean refresh() {
return this.refresh;
}

@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
super.readFrom(in);
refresh = in.readBoolean();
}

@Override public void writeTo(DataOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(refresh);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class TransportFlushAction extends TransportBroadcastOperationAction<Flus
}

@Override protected ShardFlushRequest newShardRequest(ShardRouting shard, FlushRequest request) {
return new ShardFlushRequest(shard.index(), shard.id());
return new ShardFlushRequest(shard.index(), shard.id(), request);
}

@Override protected ShardFlushResponse newShardResponse() {
Expand All @@ -85,7 +85,7 @@ public class TransportFlushAction extends TransportBroadcastOperationAction<Flus

@Override protected ShardFlushResponse shardOperation(ShardFlushRequest request) throws ElasticSearchException {
IndexShard indexShard = indicesService.indexServiceSafe(request.index()).shardSafe(request.shardId());
indexShard.flush(new Engine.Flush());
indexShard.flush(new Engine.Flush().refresh(request.refresh()));
return new ShardFlushResponse(request.index(), request.shardId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class HttpFlushAction extends BaseHttpServerHandler {
operationThreading = BroadcastOperationThreading.THREAD_PER_SHARD;
}
flushRequest.operationThreading(operationThreading);
flushRequest.refresh(HttpActions.paramAsBoolean("refresh", false));
client.admin().indices().execFlush(flushRequest, new ActionListener<FlushResponse>() {
@Override public void onResponse(FlushResponse response) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,25 @@ public boolean waitForOperations() {

static class Flush {

private boolean refresh = false;

/**
* Should a refresh be performed after flushing. Defaults to <tt>false</tt>.
*/
public boolean refresh() {
return this.refresh;
}

/**
* Should a refresh be performed after flushing. Defaults to <tt>false</tt>.
*/
public Flush refresh(boolean refresh) {
this.refresh = refresh;
return this;
}

@Override public String toString() {
return "";
return "refresh[" + refresh + "]";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine,
} finally {
rwl.writeLock().unlock();
}
if (flush.refresh()) {
refresh(new Refresh(false));
}
}

@Override public void optimize(Optimize optimize) throws EngineException {
Expand Down

0 comments on commit 9633108

Please sign in to comment.