Remove `IndexTemplateAlreadyExistsException` and `IndexShardAlreadyExistsException` (#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
This commit is contained in:
parent
26375256ff
commit
1d8c8529ed
|
@ -523,16 +523,14 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
org.elasticsearch.index.shard.IndexShardRelocatedException::new, 45),
|
||||
NODE_SHOULD_NOT_CONNECT_EXCEPTION(org.elasticsearch.transport.NodeShouldNotConnectException.class,
|
||||
org.elasticsearch.transport.NodeShouldNotConnectException::new, 46),
|
||||
INDEX_TEMPLATE_ALREADY_EXISTS_EXCEPTION(org.elasticsearch.indices.IndexTemplateAlreadyExistsException.class,
|
||||
org.elasticsearch.indices.IndexTemplateAlreadyExistsException::new, 47),
|
||||
// 47 used to be for IndexTemplateAlreadyExistsException which was deprecated in 5.1 removed in 6.0
|
||||
TRANSLOG_CORRUPTED_EXCEPTION(org.elasticsearch.index.translog.TranslogCorruptedException.class,
|
||||
org.elasticsearch.index.translog.TranslogCorruptedException::new, 48),
|
||||
CLUSTER_BLOCK_EXCEPTION(org.elasticsearch.cluster.block.ClusterBlockException.class,
|
||||
org.elasticsearch.cluster.block.ClusterBlockException::new, 49),
|
||||
FETCH_PHASE_EXECUTION_EXCEPTION(org.elasticsearch.search.fetch.FetchPhaseExecutionException.class,
|
||||
org.elasticsearch.search.fetch.FetchPhaseExecutionException::new, 50),
|
||||
INDEX_SHARD_ALREADY_EXISTS_EXCEPTION(org.elasticsearch.index.IndexShardAlreadyExistsException.class,
|
||||
org.elasticsearch.index.IndexShardAlreadyExistsException::new, 51),
|
||||
// 51 used to be for IndexShardAlreadyExistsException which was deprecated in 5.1 removed in 6.0
|
||||
VERSION_CONFLICT_ENGINE_EXCEPTION(org.elasticsearch.index.engine.VersionConflictEngineException.class,
|
||||
org.elasticsearch.index.engine.VersionConflictEngineException::new, 52),
|
||||
ENGINE_EXCEPTION(org.elasticsearch.index.engine.EngineException.class, org.elasticsearch.index.engine.EngineException::new, 53),
|
||||
|
@ -553,7 +551,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
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),
|
||||
|
|
|
@ -150,7 +150,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
|
|||
|
||||
/**
|
||||
* 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;
|
||||
|
|
|
@ -76,7 +76,7 @@ public class PutIndexTemplateRequestBuilder
|
|||
|
||||
/**
|
||||
* 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);
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.elasticsearch.index.Index;
|
|||
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;
|
||||
|
@ -161,7 +160,7 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
|
|||
@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);
|
||||
|
|
|
@ -330,7 +330,7 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
|
|||
}
|
||||
|
||||
if (shards.containsKey(shardId.id())) {
|
||||
throw new IndexShardAlreadyExistsException(shardId + " already exists");
|
||||
throw new IllegalStateException(shardId + " already exists");
|
||||
}
|
||||
|
||||
logger.debug("creating shard_id {}", shardId);
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.index;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IndexShardAlreadyExistsException extends ElasticsearchException {
|
||||
|
||||
public IndexShardAlreadyExistsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public IndexShardAlreadyExistsException(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.indices;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IndexTemplateAlreadyExistsException extends ElasticsearchException {
|
||||
|
||||
private final String name;
|
||||
|
||||
public IndexTemplateAlreadyExistsException(String name) {
|
||||
super("index_template [" + name + "] already exists");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public IndexTemplateAlreadyExistsException(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
name = in.readOptionalString();
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestStatus status() {
|
||||
return RestStatus.BAD_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeOptionalString(name);
|
||||
}
|
||||
}
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.cluster.action.shard.ShardStateAction;
|
|||
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;
|
||||
|
@ -40,7 +39,6 @@ import org.elasticsearch.cluster.service.ClusterService;
|
|||
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;
|
||||
|
@ -52,7 +50,6 @@ import org.elasticsearch.index.Index;
|
|||
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;
|
||||
|
@ -532,10 +529,6 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ import org.elasticsearch.index.shard.IllegalIndexShardStateException;
|
|||
import org.elasticsearch.index.shard.IndexShardState;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.shard.TranslogRecoveryPerformer;
|
||||
import org.elasticsearch.indices.IndexTemplateAlreadyExistsException;
|
||||
import org.elasticsearch.indices.IndexTemplateMissingException;
|
||||
import org.elasticsearch.indices.InvalidIndexTemplateException;
|
||||
import org.elasticsearch.indices.recovery.RecoverFilesRecoveryException;
|
||||
|
@ -336,16 +335,6 @@ public class ExceptionSerializationTests extends ESTestCase {
|
|||
assertTrue(ex.getCause() instanceof NullPointerException);
|
||||
}
|
||||
|
||||
public void testIndexTemplateAlreadyExistsException() throws IOException {
|
||||
IndexTemplateAlreadyExistsException ex = serialize(new IndexTemplateAlreadyExistsException("the dude abides!"));
|
||||
assertEquals("the dude abides!", ex.name());
|
||||
assertEquals("index_template [the dude abides!] already exists", ex.getMessage());
|
||||
|
||||
ex = serialize(new IndexTemplateAlreadyExistsException((String) null));
|
||||
assertNull(ex.name());
|
||||
assertEquals("index_template [null] already exists", ex.getMessage());
|
||||
}
|
||||
|
||||
public void testBatchOperationException() throws IOException {
|
||||
ShardId id = new ShardId("foo", "_na_", 1);
|
||||
TranslogRecoveryPerformer.BatchOperationException ex = serialize(
|
||||
|
@ -683,11 +672,11 @@ public class ExceptionSerializationTests extends ESTestCase {
|
|||
ids.put(44, org.elasticsearch.indices.recovery.RecoveryFailedException.class);
|
||||
ids.put(45, org.elasticsearch.index.shard.IndexShardRelocatedException.class);
|
||||
ids.put(46, org.elasticsearch.transport.NodeShouldNotConnectException.class);
|
||||
ids.put(47, org.elasticsearch.indices.IndexTemplateAlreadyExistsException.class);
|
||||
ids.put(47, null);
|
||||
ids.put(48, org.elasticsearch.index.translog.TranslogCorruptedException.class);
|
||||
ids.put(49, org.elasticsearch.cluster.block.ClusterBlockException.class);
|
||||
ids.put(50, org.elasticsearch.search.fetch.FetchPhaseExecutionException.class);
|
||||
ids.put(51, org.elasticsearch.index.IndexShardAlreadyExistsException.class);
|
||||
ids.put(51, null);
|
||||
ids.put(52, org.elasticsearch.index.engine.VersionConflictEngineException.class);
|
||||
ids.put(53, org.elasticsearch.index.engine.EngineException.class);
|
||||
ids.put(54, null); // was DocumentAlreadyExistsException, which is superseded with VersionConflictEngineException
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
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;
|
||||
|
@ -109,7 +108,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
|||
.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();
|
||||
|
|
Loading…
Reference in New Issue