Optimize API: Don't execute concurrent optimize operations (shard level) on the same node, closes #846.

This commit is contained in:
kimchy 2011-04-10 23:12:00 +03:00
parent 7d8726a5e8
commit decb5fa898
1 changed files with 13 additions and 9 deletions

View File

@ -51,6 +51,8 @@ public class TransportOptimizeAction extends TransportBroadcastOperationAction<O
private final IndicesService indicesService;
private final Object optimizeMutex = new Object();
@Inject public TransportOptimizeAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
TransportService transportService, IndicesService indicesService) {
super(settings, threadPool, clusterService, transportService);
@ -111,15 +113,17 @@ public class TransportOptimizeAction extends TransportBroadcastOperationAction<O
}
@Override protected ShardOptimizeResponse shardOperation(ShardOptimizeRequest request) throws ElasticSearchException {
IndexShard indexShard = indicesService.indexServiceSafe(request.index()).shardSafe(request.shardId());
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());
synchronized (optimizeMutex) {
IndexShard indexShard = indicesService.indexServiceSafe(request.index()).shardSafe(request.shardId());
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());
}
}
/**