mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-06 21:18:31 +00:00
Update API: Update through an alias with routing configured on it fail to use the routing, closes #2155.
This commit is contained in:
parent
a1ab48c804
commit
fedd1965ea
@ -85,6 +85,15 @@ public abstract class TransportInstanceSingleOperationAction<Request extends Ins
|
||||
|
||||
protected abstract ClusterBlockException checkRequestBlock(ClusterState state, Request request);
|
||||
|
||||
/**
|
||||
* Resolves the request, by default, simply setting the concrete index (if its aliased one). If the resolve
|
||||
* means a different execution, then return false here to indicate not to continue and execute this request.
|
||||
*/
|
||||
protected boolean resolveRequest(ClusterState state, Request request, ActionListener<Response> listener) {
|
||||
request.index(state.metaData().concreteIndex(request.index()));
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean retryOnFailure(Throwable e) {
|
||||
return false;
|
||||
}
|
||||
@ -132,7 +141,10 @@ public abstract class TransportInstanceSingleOperationAction<Request extends Ins
|
||||
throw blockException;
|
||||
}
|
||||
}
|
||||
request.index(clusterState.metaData().concreteIndex(request.index()));
|
||||
// check if we need to execute, and if not, return
|
||||
if (!resolveRequest(clusterState, request, listener)) {
|
||||
return true;
|
||||
}
|
||||
blockException = checkRequestBlock(clusterState, request);
|
||||
if (blockException != null) {
|
||||
if (blockException.retryable()) {
|
||||
|
@ -36,6 +36,7 @@ import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.routing.PlainShardIterator;
|
||||
import org.elasticsearch.cluster.routing.ShardIterator;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
@ -134,6 +135,15 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean resolveRequest(ClusterState state, UpdateRequest request, ActionListener<UpdateResponse> listener) {
|
||||
MetaData metaData = clusterService.state().metaData();
|
||||
String aliasOrIndex = request.index();
|
||||
request.routing((metaData.resolveIndexRouting(request.routing(), aliasOrIndex)));
|
||||
request.index(metaData.concreteIndex(request.index()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShardIterator shards(ClusterState clusterState, UpdateRequest request) throws ElasticSearchException {
|
||||
if (request.shardId() != -1) {
|
||||
|
@ -88,6 +88,17 @@ public class AliasRoutingTests extends AbstractNodesTests {
|
||||
assertThat(client.prepareGet("alias0", "type1", "1").execute().actionGet().exists(), equalTo(true));
|
||||
}
|
||||
|
||||
logger.info("--> updating with id [1] and routing through alias");
|
||||
client.prepareUpdate("alias0", "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.setScript("ctx._source.field = 'value2'")
|
||||
.execute().actionGet();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client.prepareGet("alias0", "type1", "1").execute().actionGet().exists(), equalTo(true));
|
||||
assertThat(client.prepareGet("alias0", "type1", "1").execute().actionGet().sourceAsMap().get("field").toString(), equalTo("value2"));
|
||||
}
|
||||
|
||||
|
||||
logger.info("--> deleting with no routing, should not delete anything");
|
||||
client.prepareDelete("test", "type1", "1").setRefresh(true).execute().actionGet();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user