|
|
@@ -21,6 +21,7 @@ package org.elasticsearch.indices.flush;
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
|
|
|
+import org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse;
|
|
|
import org.elasticsearch.action.support.IndicesOptions;
|
|
|
import org.elasticsearch.cluster.ClusterService;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
@@ -81,9 +82,8 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
this.clusterService = clusterService;
|
|
|
this.transportService = transportService;
|
|
|
this.indexNameExpressionResolver = indexNameExpressionResolver;
|
|
|
-
|
|
|
- transportService.registerRequestHandler(PRE_SYNCED_FLUSH_ACTION_NAME, PreSyncedFlushRequest::new, ThreadPool.Names.FLUSH, new PreSyncedFlushTransportHandler());
|
|
|
- transportService.registerRequestHandler(SYNCED_FLUSH_ACTION_NAME, SyncedFlushRequest::new, ThreadPool.Names.FLUSH, new SyncedFlushTransportHandler());
|
|
|
+ transportService.registerRequestHandler(PRE_SYNCED_FLUSH_ACTION_NAME, PreShardSyncedFlushRequest::new, ThreadPool.Names.FLUSH, new PreSyncedFlushTransportHandler());
|
|
|
+ transportService.registerRequestHandler(SYNCED_FLUSH_ACTION_NAME, ShardSyncedFlushRequest::new, ThreadPool.Names.FLUSH, new SyncedFlushTransportHandler());
|
|
|
transportService.registerRequestHandler(IN_FLIGHT_OPS_ACTION_NAME, InFlightOpsRequest::new, ThreadPool.Names.SAME, new InFlightOpCountTransportHandler());
|
|
|
}
|
|
|
|
|
|
@@ -109,7 +109,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
* a utility method to perform a synced flush for all shards of multiple indices. see {@link #attemptSyncedFlush(ShardId, ActionListener)}
|
|
|
* for more details.
|
|
|
*/
|
|
|
- public void attemptSyncedFlush(final String[] aliasesOrIndices, IndicesOptions indicesOptions, final ActionListener<IndicesSyncedFlushResult> listener) {
|
|
|
+ public void attemptSyncedFlush(final String[] aliasesOrIndices, IndicesOptions indicesOptions, final ActionListener<SyncedFlushResponse> listener) {
|
|
|
final ClusterState state = clusterService.state();
|
|
|
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, indicesOptions, aliasesOrIndices);
|
|
|
final Map<String, List<ShardsSyncedFlushResult>> results = ConcurrentCollections.newConcurrentMap();
|
|
|
@@ -123,7 +123,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
|
|
|
}
|
|
|
if (numberOfShards == 0) {
|
|
|
- listener.onResponse(new IndicesSyncedFlushResult(results));
|
|
|
+ listener.onResponse(new SyncedFlushResponse(results));
|
|
|
return;
|
|
|
}
|
|
|
final int finalTotalNumberOfShards = totalNumberOfShards;
|
|
|
@@ -138,7 +138,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
public void onResponse(ShardsSyncedFlushResult syncedFlushResult) {
|
|
|
results.get(index).add(syncedFlushResult);
|
|
|
if (countDown.countDown()) {
|
|
|
- listener.onResponse(new IndicesSyncedFlushResult(results));
|
|
|
+ listener.onResponse(new SyncedFlushResponse(results));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -147,7 +147,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
logger.debug("{} unexpected error while executing synced flush", shardId);
|
|
|
results.get(index).add(new ShardsSyncedFlushResult(shardId, finalTotalNumberOfShards, e.getMessage()));
|
|
|
if (countDown.countDown()) {
|
|
|
- listener.onResponse(new IndicesSyncedFlushResult(results));
|
|
|
+ listener.onResponse(new SyncedFlushResponse(results));
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -297,33 +297,33 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
void sendSyncRequests(final String syncId, final List<ShardRouting> shards, ClusterState state, Map<String, Engine.CommitId> expectedCommitIds,
|
|
|
final ShardId shardId, final int totalShards, final ActionListener<ShardsSyncedFlushResult> listener) {
|
|
|
final CountDown countDown = new CountDown(shards.size());
|
|
|
- final Map<ShardRouting, SyncedFlushResponse> results = ConcurrentCollections.newConcurrentMap();
|
|
|
+ final Map<ShardRouting, ShardSyncedFlushResponse> results = ConcurrentCollections.newConcurrentMap();
|
|
|
for (final ShardRouting shard : shards) {
|
|
|
final DiscoveryNode node = state.nodes().get(shard.currentNodeId());
|
|
|
if (node == null) {
|
|
|
logger.trace("{} is assigned to an unknown node. skipping for sync id [{}]. shard routing {}", shardId, syncId, shard);
|
|
|
- results.put(shard, new SyncedFlushResponse("unknown node"));
|
|
|
+ results.put(shard, new ShardSyncedFlushResponse("unknown node"));
|
|
|
contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
|
|
|
continue;
|
|
|
}
|
|
|
final Engine.CommitId expectedCommitId = expectedCommitIds.get(shard.currentNodeId());
|
|
|
if (expectedCommitId == null) {
|
|
|
logger.trace("{} can't resolve expected commit id for {}, skipping for sync id [{}]. shard routing {}", shardId, syncId, shard);
|
|
|
- results.put(shard, new SyncedFlushResponse("no commit id from pre-sync flush"));
|
|
|
+ results.put(shard, new ShardSyncedFlushResponse("no commit id from pre-sync flush"));
|
|
|
contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
|
|
|
continue;
|
|
|
}
|
|
|
logger.trace("{} sending synced flush request to {}. sync id [{}].", shardId, shard, syncId);
|
|
|
- transportService.sendRequest(node, SYNCED_FLUSH_ACTION_NAME, new SyncedFlushRequest(shard.shardId(), syncId, expectedCommitId),
|
|
|
- new BaseTransportResponseHandler<SyncedFlushResponse>() {
|
|
|
+ transportService.sendRequest(node, SYNCED_FLUSH_ACTION_NAME, new ShardSyncedFlushRequest(shard.shardId(), syncId, expectedCommitId),
|
|
|
+ new BaseTransportResponseHandler<ShardSyncedFlushResponse>() {
|
|
|
@Override
|
|
|
- public SyncedFlushResponse newInstance() {
|
|
|
- return new SyncedFlushResponse();
|
|
|
+ public ShardSyncedFlushResponse newInstance() {
|
|
|
+ return new ShardSyncedFlushResponse();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void handleResponse(SyncedFlushResponse response) {
|
|
|
- SyncedFlushResponse existing = results.put(shard, response);
|
|
|
+ public void handleResponse(ShardSyncedFlushResponse response) {
|
|
|
+ ShardSyncedFlushResponse existing = results.put(shard, response);
|
|
|
assert existing == null : "got two answers for node [" + node + "]";
|
|
|
// count after the assert so we won't decrement twice in handleException
|
|
|
contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
|
|
|
@@ -332,7 +332,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
@Override
|
|
|
public void handleException(TransportException exp) {
|
|
|
logger.trace("{} error while performing synced flush on [{}], skipping", exp, shardId, shard);
|
|
|
- results.put(shard, new SyncedFlushResponse(exp.getMessage()));
|
|
|
+ results.put(shard, new ShardSyncedFlushResponse(exp.getMessage()));
|
|
|
contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
|
|
|
}
|
|
|
|
|
|
@@ -346,7 +346,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
}
|
|
|
|
|
|
private void contDownAndSendResponseIfDone(String syncId, List<ShardRouting> shards, ShardId shardId, int totalShards,
|
|
|
- ActionListener<ShardsSyncedFlushResult> listener, CountDown countDown, Map<ShardRouting, SyncedFlushResponse> results) {
|
|
|
+ ActionListener<ShardsSyncedFlushResult> listener, CountDown countDown, Map<ShardRouting, ShardSyncedFlushResponse> results) {
|
|
|
if (countDown.countDown()) {
|
|
|
assert results.size() == shards.size();
|
|
|
listener.onResponse(new ShardsSyncedFlushResult(shardId, syncId, totalShards, results));
|
|
|
@@ -369,7 +369,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
- transportService.sendRequest(node, PRE_SYNCED_FLUSH_ACTION_NAME, new PreSyncedFlushRequest(shard.shardId()), new BaseTransportResponseHandler<PreSyncedFlushResponse>() {
|
|
|
+ transportService.sendRequest(node, PRE_SYNCED_FLUSH_ACTION_NAME, new PreShardSyncedFlushRequest(shard.shardId()), new BaseTransportResponseHandler<PreSyncedFlushResponse>() {
|
|
|
@Override
|
|
|
public PreSyncedFlushResponse newInstance() {
|
|
|
return new PreSyncedFlushResponse();
|
|
|
@@ -401,7 +401,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private PreSyncedFlushResponse performPreSyncedFlush(PreSyncedFlushRequest request) {
|
|
|
+ private PreSyncedFlushResponse performPreSyncedFlush(PreShardSyncedFlushRequest request) {
|
|
|
IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).getShard(request.shardId().id());
|
|
|
FlushRequest flushRequest = new FlushRequest().force(false).waitIfOngoing(true);
|
|
|
logger.trace("{} performing pre sync flush", request.shardId());
|
|
|
@@ -410,7 +410,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
return new PreSyncedFlushResponse(commitId);
|
|
|
}
|
|
|
|
|
|
- private SyncedFlushResponse performSyncedFlush(SyncedFlushRequest request) {
|
|
|
+ private ShardSyncedFlushResponse performSyncedFlush(ShardSyncedFlushRequest request) {
|
|
|
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
|
|
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
|
|
logger.trace("{} performing sync flush. sync id [{}], expected commit id {}", request.shardId(), request.syncId(), request.expectedCommitId());
|
|
|
@@ -418,11 +418,11 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
logger.trace("{} sync flush done. sync id [{}], result [{}]", request.shardId(), request.syncId(), result);
|
|
|
switch (result) {
|
|
|
case SUCCESS:
|
|
|
- return new SyncedFlushResponse();
|
|
|
+ return new ShardSyncedFlushResponse();
|
|
|
case COMMIT_MISMATCH:
|
|
|
- return new SyncedFlushResponse("commit has changed");
|
|
|
+ return new ShardSyncedFlushResponse("commit has changed");
|
|
|
case PENDING_OPERATIONS:
|
|
|
- return new SyncedFlushResponse("pending operations");
|
|
|
+ return new ShardSyncedFlushResponse("pending operations");
|
|
|
default:
|
|
|
throw new ElasticsearchException("unknown synced flush result [" + result + "]");
|
|
|
}
|
|
|
@@ -439,19 +439,19 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
return new InFlightOpsResponse(opCount);
|
|
|
}
|
|
|
|
|
|
- public final static class PreSyncedFlushRequest extends TransportRequest {
|
|
|
+ public final static class PreShardSyncedFlushRequest extends TransportRequest {
|
|
|
private ShardId shardId;
|
|
|
|
|
|
- public PreSyncedFlushRequest() {
|
|
|
+ public PreShardSyncedFlushRequest() {
|
|
|
}
|
|
|
|
|
|
- public PreSyncedFlushRequest(ShardId shardId) {
|
|
|
+ public PreShardSyncedFlushRequest(ShardId shardId) {
|
|
|
this.shardId = shardId;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
- return "PreSyncedFlushRequest{" +
|
|
|
+ return "PreShardSyncedFlushRequest{" +
|
|
|
"shardId=" + shardId +
|
|
|
'}';
|
|
|
}
|
|
|
@@ -504,16 +504,16 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static final class SyncedFlushRequest extends TransportRequest {
|
|
|
+ public static final class ShardSyncedFlushRequest extends TransportRequest {
|
|
|
|
|
|
private String syncId;
|
|
|
private Engine.CommitId expectedCommitId;
|
|
|
private ShardId shardId;
|
|
|
|
|
|
- public SyncedFlushRequest() {
|
|
|
+ public ShardSyncedFlushRequest() {
|
|
|
}
|
|
|
|
|
|
- public SyncedFlushRequest(ShardId shardId, String syncId, Engine.CommitId expectedCommitId) {
|
|
|
+ public ShardSyncedFlushRequest(ShardId shardId, String syncId, Engine.CommitId expectedCommitId) {
|
|
|
this.expectedCommitId = expectedCommitId;
|
|
|
this.shardId = shardId;
|
|
|
this.syncId = syncId;
|
|
|
@@ -549,7 +549,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
- return "SyncedFlushRequest{" +
|
|
|
+ return "ShardSyncedFlushRequest{" +
|
|
|
"shardId=" + shardId +
|
|
|
",syncId='" + syncId + '\'' +
|
|
|
'}';
|
|
|
@@ -559,18 +559,18 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
/**
|
|
|
* Response for third step of synced flush (writing the sync id) for one shard copy
|
|
|
*/
|
|
|
- public static final class SyncedFlushResponse extends TransportResponse {
|
|
|
+ public static final class ShardSyncedFlushResponse extends TransportResponse {
|
|
|
|
|
|
/**
|
|
|
* a non null value indicates a failure to sync flush. null means success
|
|
|
*/
|
|
|
String failureReason;
|
|
|
|
|
|
- public SyncedFlushResponse() {
|
|
|
+ public ShardSyncedFlushResponse() {
|
|
|
failureReason = null;
|
|
|
}
|
|
|
|
|
|
- public SyncedFlushResponse(String failureReason) {
|
|
|
+ public ShardSyncedFlushResponse(String failureReason) {
|
|
|
this.failureReason = failureReason;
|
|
|
}
|
|
|
|
|
|
@@ -596,11 +596,17 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
- return "SyncedFlushResponse{" +
|
|
|
+ return "ShardSyncedFlushResponse{" +
|
|
|
"success=" + success() +
|
|
|
", failureReason='" + failureReason + '\'' +
|
|
|
'}';
|
|
|
}
|
|
|
+
|
|
|
+ public static ShardSyncedFlushResponse readSyncedFlushResponse(StreamInput in) throws IOException {
|
|
|
+ ShardSyncedFlushResponse shardSyncedFlushResponse = new ShardSyncedFlushResponse();
|
|
|
+ shardSyncedFlushResponse.readFrom(in);
|
|
|
+ return shardSyncedFlushResponse;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -677,18 +683,18 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private final class PreSyncedFlushTransportHandler implements TransportRequestHandler<PreSyncedFlushRequest> {
|
|
|
+ private final class PreSyncedFlushTransportHandler implements TransportRequestHandler<PreShardSyncedFlushRequest> {
|
|
|
|
|
|
@Override
|
|
|
- public void messageReceived(PreSyncedFlushRequest request, TransportChannel channel) throws Exception {
|
|
|
+ public void messageReceived(PreShardSyncedFlushRequest request, TransportChannel channel) throws Exception {
|
|
|
channel.sendResponse(performPreSyncedFlush(request));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private final class SyncedFlushTransportHandler implements TransportRequestHandler<SyncedFlushRequest> {
|
|
|
+ private final class SyncedFlushTransportHandler implements TransportRequestHandler<ShardSyncedFlushRequest> {
|
|
|
|
|
|
@Override
|
|
|
- public void messageReceived(SyncedFlushRequest request, TransportChannel channel) throws Exception {
|
|
|
+ public void messageReceived(ShardSyncedFlushRequest request, TransportChannel channel) throws Exception {
|
|
|
channel.sendResponse(performSyncedFlush(request));
|
|
|
}
|
|
|
}
|