Skip to content

Commit

Permalink
Remove IndexTemplateAlreadyExistsException and `IndexShardAlreadyEx…
Browse files Browse the repository at this point in the history
…istsException` (#21539)

Both exception can be replaced with java built-in exception, IAE and ISE respectively.
This should be back ported partially to 5.x which the transport layer code should be preserved.

Relates to #21494
  • Loading branch information
s1monw committed Nov 15, 2016
1 parent 4f82898 commit d80562d
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ enum ElasticsearchExceptionHandle {
org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper::new, 62),
ALIAS_FILTER_PARSING_EXCEPTION(org.elasticsearch.indices.AliasFilterParsingException.class,
org.elasticsearch.indices.AliasFilterParsingException::new, 63),
// 64 was DeleteByQueryFailedEngineException, which was removed in 3.0
// 64 was DeleteByQueryFailedEngineException, which was removed in 5.0
GATEWAY_EXCEPTION(org.elasticsearch.gateway.GatewayException.class, org.elasticsearch.gateway.GatewayException::new, 65),
INDEX_SHARD_NOT_RECOVERING_EXCEPTION(org.elasticsearch.index.shard.IndexShardNotRecoveringException.class,
org.elasticsearch.index.shard.IndexShardNotRecoveringException::new, 66),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Integer version() {

/**
* Set to <tt>true</tt> to force only creation, not an update of an index template. If it already
* exists, it will fail with an {@link org.elasticsearch.indices.IndexTemplateAlreadyExistsException}.
* exists, it will fail with an {@link IllegalArgumentException}.
*/
public PutIndexTemplateRequest create(boolean create) {
this.create = create;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public PutIndexTemplateRequestBuilder setVersion(Integer version) {

/**
* Set to <tt>true</tt> to force only creation, not an update of an index template. If it already
* exists, it will fail with an {@link org.elasticsearch.indices.IndexTemplateAlreadyExistsException}.
* exists, it will fail with an {@link IllegalArgumentException}.
*/
public PutIndexTemplateRequestBuilder setCreate(boolean create) {
request.create(create);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.IndexTemplateAlreadyExistsException;
import org.elasticsearch.indices.IndexTemplateMissingException;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.InvalidIndexTemplateException;
Expand Down Expand Up @@ -161,7 +160,7 @@ public void onFailure(String source, Exception e) {
@Override
public ClusterState execute(ClusterState currentState) throws Exception {
if (request.create && currentState.metaData().templates().containsKey(request.name)) {
throw new IndexTemplateAlreadyExistsException(request.name);
throw new IllegalArgumentException("index_template [" + request.name + "] already exists");
}

validateAndAddTemplate(request, templateBuilder, indicesService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public synchronized IndexShard createShard(ShardRouting routing) throws IOExcept
}

if (shards.containsKey(shardId.id())) {
throw new IndexShardAlreadyExistsException(shardId + " already exists");
throw new IllegalStateException(shardId + " already exists");
}

logger.debug("creating shard_id {}", shardId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

/**
*
* @deprecated use {@link IllegalStateException} instead
*/
@Deprecated
public class IndexShardAlreadyExistsException extends ElasticsearchException {

public IndexShardAlreadyExistsException(String message) {
Expand All @@ -36,4 +38,4 @@ public IndexShardAlreadyExistsException(String message) {
public IndexShardAlreadyExistsException(StreamInput in) throws IOException {
super(in);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import java.io.IOException;

/**
*
* @deprecated use {@link IllegalArgumentException} instead
*/
@Deprecated
public class IndexTemplateAlreadyExistsException extends ElasticsearchException {

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
import org.elasticsearch.cluster.routing.RecoverySource.Type;
import org.elasticsearch.cluster.routing.RoutingNode;
import org.elasticsearch.cluster.routing.RoutingTable;
Expand All @@ -40,7 +39,6 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.Callback;
Expand All @@ -52,7 +50,6 @@
import org.elasticsearch.index.IndexComponent;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexShardAlreadyExistsException;
import org.elasticsearch.index.shard.IndexEventListener;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.IndexShardRelocatedException;
Expand Down Expand Up @@ -532,10 +529,6 @@ private void createShard(DiscoveryNodes nodes, RoutingTable routingTable, ShardR
RecoveryState recoveryState = new RecoveryState(shardRouting, nodes.getLocalNode(), sourceNode);
indicesService.createShard(shardRouting, recoveryState, recoveryTargetService, new RecoveryListener(shardRouting),
repositoriesService, failedShardHandler);
} catch (IndexShardAlreadyExistsException e) {
// ignore this, the method call can happen several times
logger.debug("Trying to create shard that already exists", e);
assert false;
} catch (Exception e) {
failAndRemoveShard(shardRouting, true, "failed to create shard", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.IndexTemplateAlreadyExistsException;
import org.elasticsearch.indices.InvalidAliasNameException;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.test.ESIntegTestCase;
Expand Down Expand Up @@ -110,7 +109,7 @@ public void testSimpleIndexTemplateTests() throws Exception {
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("field2").field("type", "text").field("store", false).endObject()
.endObject().endObject().endObject())
, IndexTemplateAlreadyExistsException.class
, IllegalArgumentException.class
);

response = client().admin().indices().prepareGetTemplates().get();
Expand Down

0 comments on commit d80562d

Please sign in to comment.