summaryrefslogtreecommitdiff
path: root/core/src/main/java/org
diff options
context:
space:
mode:
authorSimon Willnauer <simonw@apache.org>2015-07-03 15:40:09 +0200
committerSimon Willnauer <simonw@apache.org>2015-07-14 16:31:49 +0200
commit7db293c6167179bd470bb8a189223fcb67c0fae1 (patch)
tree5275a0b0cb4e49d7b31659cb254c34510283d27c /core/src/main/java/org
parentc6b110c6ef3004807f9257b68385c3d2e52635d5 (diff)
Generify Index and Shard exceptions
Today we have a intermediate hierarchy for shard and index exceptions which makes it hard to introduce generic exceptions like ResourceNotFoundException intoduced in this commit. This commit breaks up the hierarchy by adding index and shard as a special internal header that gets rendered for every exception that fills that header. This commit removes dedicated exceptions like `IndexMissingException` or `IndexShardMissingException` in favour of `ResourceNotFoundException`
Diffstat (limited to 'core/src/main/java/org')
-rw-r--r--core/src/main/java/org/elasticsearch/ElasticsearchException.java124
-rw-r--r--core/src/main/java/org/elasticsearch/ExceptionsHelper.java8
-rw-r--r--core/src/main/java/org/elasticsearch/ResourceNotFoundException.java (renamed from core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java)23
-rw-r--r--core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java11
-rw-r--r--core/src/main/java/org/elasticsearch/action/RoutingMissingException.java14
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java6
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java4
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java4
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java4
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java7
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java5
-rw-r--r--core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java8
-rw-r--r--core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java4
-rw-r--r--core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java2
-rw-r--r--core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java4
-rw-r--r--core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java8
-rw-r--r--core/src/main/java/org/elasticsearch/action/support/TransportActions.java18
-rw-r--r--core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java11
-rw-r--r--core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java12
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java44
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java6
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java5
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java7
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java13
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java6
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java7
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java29
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java27
-rw-r--r--core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java2
-rw-r--r--core/src/main/java/org/elasticsearch/index/IndexException.java73
-rw-r--r--core/src/main/java/org/elasticsearch/index/IndexNotFoundException.java (renamed from core/src/main/java/org/elasticsearch/index/store/StoreException.java)24
-rw-r--r--core/src/main/java/org/elasticsearch/index/IndexService.java23
-rw-r--r--core/src/main/java/org/elasticsearch/index/engine/EngineException.java9
-rw-r--r--core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java3
-rw-r--r--core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java10
-rw-r--r--core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java20
-rw-r--r--core/src/main/java/org/elasticsearch/index/shard/IndexShard.java25
-rw-r--r--core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java76
-rw-r--r--core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java8
-rw-r--r--core/src/main/java/org/elasticsearch/index/shard/ShardNotFoundException.java (renamed from core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java)16
-rw-r--r--core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java5
-rw-r--r--core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java9
-rw-r--r--core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java9
-rw-r--r--core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java7
-rw-r--r--core/src/main/java/org/elasticsearch/index/translog/TranslogException.java9
-rw-r--r--core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java8
-rw-r--r--core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/indices/IndexClosedException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/indices/IndexCreationException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/indices/IndicesService.java6
-rw-r--r--core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/indices/TypeMissingException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java3
-rw-r--r--core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java11
-rw-r--r--core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java7
-rw-r--r--core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java5
-rw-r--r--core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java3
-rw-r--r--core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java60
-rw-r--r--core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesNotFoundException.java (renamed from core/src/main/java/org/elasticsearch/indices/IndexMissingException.java)24
-rw-r--r--core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java4
-rw-r--r--core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java7
64 files changed, 423 insertions, 520 deletions
diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java
index 789589f3f6..57d82c14d7 100644
--- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java
+++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java
@@ -26,7 +26,12 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.support.LoggerMessageFormat;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.index.Index;
+import org.elasticsearch.index.IndexNotFoundException;
+import org.elasticsearch.index.shard.ShardId;
+import org.elasticsearch.index.shard.ShardNotFoundException;
import org.elasticsearch.rest.RestStatus;
+import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesNotFoundException;
import java.io.IOException;
import java.lang.reflect.Constructor;
@@ -39,6 +44,11 @@ import java.util.*;
public class ElasticsearchException extends RuntimeException implements ToXContent {
public static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.skip_cause";
+ private static final String INDEX_HEADER_KEY = "es.index";
+ private static final String SHARD_HEADER_KEY = "es.shard";
+ private static final String RESOURCE_HEADER_TYPE_KEY = "es.resource.type";
+ private static final String RESOURCE_HEADER_ID_KEY = "es.resource.id";
+
private static final Map<String, Constructor<? extends ElasticsearchException>> MAPPING;
private final Map<String, List<String>> headers = new HashMap<>();
@@ -252,7 +262,14 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
} else {
builder.field("type", getExceptionName());
builder.field("reason", getMessage());
+ for (String key : headers.keySet()) {
+ if (key.startsWith("es.")) {
+ List<String> values = headers.get(key);
+ xContentHeader(builder, key.substring("es.".length()), values);
+ }
+ }
innerToXContent(builder, params);
+ renderHeader(builder, params);
}
return builder;
}
@@ -277,6 +294,38 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
}
}
+ protected final void renderHeader(XContentBuilder builder, Params params) throws IOException {
+ boolean hasHeader = false;
+ for (String key : headers.keySet()) {
+ if (key.startsWith("es.")) {
+ continue;
+ }
+ if (hasHeader == false) {
+ builder.startObject("header");
+ hasHeader = true;
+ }
+ List<String> values = headers.get(key);
+ xContentHeader(builder, key, values);
+ }
+ if (hasHeader) {
+ builder.endObject();
+ }
+ }
+
+ private void xContentHeader(XContentBuilder builder, String key, List<String> values) throws IOException {
+ if (values != null && values.isEmpty() == false) {
+ if(values.size() == 1) {
+ builder.field(key, values.get(0));
+ } else {
+ builder.startArray(key);
+ for (String value : values) {
+ builder.value(value);
+ }
+ builder.endArray();
+ }
+ }
+ }
+
/**
* Statis toXContent helper method that also renders non {@link org.elasticsearch.ElasticsearchException} instances as XContent.
*/
@@ -342,7 +391,15 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
@Override
public String toString() {
- return ExceptionsHelper.detailedMessage(this).trim();
+ StringBuilder builder = new StringBuilder();
+ if (headers.containsKey(INDEX_HEADER_KEY)) {
+ builder.append('[').append(getIndex()).append(']');
+ if (headers.containsKey(SHARD_HEADER_KEY)) {
+ builder.append('[').append(getShardId()).append(']');
+ }
+ builder.append(' ');
+ }
+ return builder.append(ExceptionsHelper.detailedMessage(this).trim()).toString();
}
/**
@@ -396,7 +453,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
org.elasticsearch.indices.recovery.RecoverFilesRecoveryException.class,
org.elasticsearch.index.translog.TruncatedTranslogException.class,
org.elasticsearch.repositories.RepositoryException.class,
- org.elasticsearch.index.shard.IndexShardException.class,
org.elasticsearch.index.engine.DocumentSourceMissingException.class,
org.elasticsearch.index.engine.DocumentMissingException.class,
org.elasticsearch.common.util.concurrent.EsRejectedExecutionException.class,
@@ -421,12 +477,10 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
org.elasticsearch.index.snapshots.IndexShardSnapshotException.class,
org.elasticsearch.search.query.QueryPhaseExecutionException.class,
org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException.class,
- org.elasticsearch.index.shard.IndexShardCreationException.class,
org.elasticsearch.index.percolator.PercolatorException.class,
org.elasticsearch.snapshots.ConcurrentSnapshotExecutionException.class,
org.elasticsearch.indices.IndexTemplateAlreadyExistsException.class,
org.elasticsearch.indices.InvalidIndexNameException.class,
- org.elasticsearch.index.IndexException.class,
org.elasticsearch.indices.recovery.DelayRecoveryException.class,
org.elasticsearch.indices.AliasFilterParsingException.class,
org.elasticsearch.indices.InvalidIndexTemplateException.class,
@@ -443,7 +497,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
org.elasticsearch.cluster.block.ClusterBlockException.class,
org.elasticsearch.action.FailedNodeException.class,
org.elasticsearch.indices.TypeMissingException.class,
- org.elasticsearch.index.IndexShardMissingException.class,
org.elasticsearch.indices.InvalidTypeNameException.class,
org.elasticsearch.transport.netty.SizeHeaderFrameDecoder.HttpOnTransportException.class,
org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException.class,
@@ -493,7 +546,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
org.elasticsearch.ElasticsearchTimeoutException.class,
org.elasticsearch.search.SearchContextMissingException.class,
org.elasticsearch.transport.SendRequestTransportException.class,
- org.elasticsearch.indices.IndexMissingException.class,
org.elasticsearch.index.IndexShardAlreadyExistsException.class,
org.elasticsearch.indices.IndexAlreadyExistsException.class,
org.elasticsearch.index.engine.DocumentAlreadyExistsException.class,
@@ -504,7 +556,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
org.elasticsearch.index.shard.IndexShardNotStartedException.class,
org.elasticsearch.index.mapper.StrictDynamicMappingException.class,
org.elasticsearch.index.engine.EngineClosedException.class,
- org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException.class,
+ AliasesNotFoundException.class,
org.elasticsearch.transport.ResponseHandlerFailureTransportException.class,
org.elasticsearch.search.SearchParseException.class,
org.elasticsearch.search.fetch.FetchPhaseExecutionException.class,
@@ -520,7 +572,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
org.elasticsearch.index.engine.RecoveryEngineException.class,
org.elasticsearch.common.blobstore.BlobStoreException.class,
org.elasticsearch.index.snapshots.IndexShardRestoreException.class,
- org.elasticsearch.index.store.StoreException.class,
org.elasticsearch.index.query.QueryParsingException.class,
org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnPrimaryException.class,
org.elasticsearch.index.engine.DeleteByQueryFailedEngineException.class,
@@ -534,6 +585,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
org.elasticsearch.index.engine.CreateFailedEngineException.class,
org.elasticsearch.index.shard.IllegalIndexShardStateException.class,
ElasticsearchSecurityException.class,
+ ResourceNotFoundException.class,
+ IndexNotFoundException.class,
+ ShardNotFoundException.class,
NotSerializableExceptionWrapper.class
};
Map<String, Constructor<? extends ElasticsearchException>> mapping = new HashMap<>(exceptions.length);
@@ -553,4 +607,58 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
MAPPING = Collections.unmodifiableMap(mapping);
}
+ public String getIndex() {
+ List<String> index = getHeader(INDEX_HEADER_KEY);
+ if (index != null && index.isEmpty() == false) {
+ return index.get(0);
+ }
+
+ return null;
+ }
+
+ public ShardId getShardId() {
+ List<String> shard = getHeader(SHARD_HEADER_KEY);
+ if (shard != null && shard.isEmpty() == false) {
+ return new ShardId(getIndex(), Integer.parseInt(shard.get(0)));
+ }
+ return null;
+ }
+
+ public void setIndex(Index index) {
+ if (index != null) {
+ addHeader(INDEX_HEADER_KEY, index.getName());
+ }
+ }
+
+ public void setIndex(String index) {
+ if (index != null) {
+ addHeader(INDEX_HEADER_KEY, index);
+ }
+ }
+
+ public void setShard(ShardId shardId) {
+ if (shardId != null) {
+ addHeader(INDEX_HEADER_KEY, shardId.getIndex());
+ addHeader(SHARD_HEADER_KEY, Integer.toString(shardId.id()));
+ }
+ }
+
+ public void setResources(String type, String... id) {
+ assert type != null;
+ addHeader(RESOURCE_HEADER_ID_KEY, id);
+ addHeader(RESOURCE_HEADER_TYPE_KEY, type);
+ }
+
+ public List<String> getResourceId() {
+ return getHeader(RESOURCE_HEADER_ID_KEY);
+ }
+
+ public String getResourceType() {
+ List<String> header = getHeader(RESOURCE_HEADER_TYPE_KEY);
+ if (header != null && header.isEmpty() == false) {
+ assert header.size() == 1;
+ return header.get(0);
+ }
+ return null;
+ }
}
diff --git a/core/src/main/java/org/elasticsearch/ExceptionsHelper.java b/core/src/main/java/org/elasticsearch/ExceptionsHelper.java
index c9f51cb5d5..df7be834eb 100644
--- a/core/src/main/java/org/elasticsearch/ExceptionsHelper.java
+++ b/core/src/main/java/org/elasticsearch/ExceptionsHelper.java
@@ -26,8 +26,6 @@ import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
-import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -240,12 +238,12 @@ public final class ExceptionsHelper {
static class GroupBy {
final String reason;
- final Index index;
+ final String index;
final Class<? extends Throwable> causeType;
public GroupBy(Throwable t) {
- if (t instanceof IndexException) {
- index = ((IndexException) t).index();
+ if (t instanceof ElasticsearchException) {
+ index = ((ElasticsearchException) t).getIndex();
} else {
index = null;
}
diff --git a/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java b/core/src/main/java/org/elasticsearch/ResourceNotFoundException.java
index 6b356ee685..d38de2e3bc 100644
--- a/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java
+++ b/core/src/main/java/org/elasticsearch/ResourceNotFoundException.java
@@ -16,31 +16,32 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-package org.elasticsearch.index;
+package org.elasticsearch;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
-import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
- *
+ * Generic ResourceNotFoundException corresponding to the {@link RestStatus#NOT_FOUND} status code
*/
-public class IndexShardMissingException extends IndexShardException {
+public class ResourceNotFoundException extends ElasticsearchException {
+
+ public ResourceNotFoundException(String msg, Object... args) {
+ super(msg, args);
+ }
- public IndexShardMissingException(ShardId shardId) {
- super(shardId, "missing");
+ protected ResourceNotFoundException(String msg, Throwable cause, Object... args) {
+ super(msg, cause, args);
}
- public IndexShardMissingException(StreamInput in) throws IOException{
+ public ResourceNotFoundException(StreamInput in) throws IOException {
super(in);
}
@Override
- public RestStatus status() {
+ public final RestStatus status() {
return RestStatus.NOT_FOUND;
}
-} \ No newline at end of file
+}
diff --git a/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java b/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java
index 3ab5869045..00562af99c 100644
--- a/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java
+++ b/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java
@@ -19,8 +19,8 @@
package org.elasticsearch.action;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
@@ -29,18 +29,19 @@ import java.io.IOException;
/**
*
*/
-public class NoShardAvailableActionException extends IndexShardException {
+public class NoShardAvailableActionException extends ElasticsearchException {
public NoShardAvailableActionException(ShardId shardId) {
- super(shardId, null);
+ this(shardId, null);
}
public NoShardAvailableActionException(ShardId shardId, String msg) {
- super(shardId, msg);
+ this(shardId, msg, null);
}
public NoShardAvailableActionException(ShardId shardId, String msg, Throwable cause) {
- super(shardId, msg, cause);
+ super(msg, cause);
+ setShard(shardId);
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java b/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java
index 920d48b952..86bca96d74 100644
--- a/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java
+++ b/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java
@@ -32,8 +32,6 @@ import java.util.Objects;
*/
public class RoutingMissingException extends ElasticsearchException {
- private final String index;
-
private final String type;
private final String id;
@@ -43,20 +41,16 @@ public class RoutingMissingException extends ElasticsearchException {
Objects.requireNonNull(index, "index must not be null");
Objects.requireNonNull(type, "type must not be null");
Objects.requireNonNull(id, "id must not be null");
- this.index = index;
+ setIndex(index);
this.type = type;
this.id = id;
}
- public String index() {
- return index;
- }
-
- public String type() {
+ public String getType() {
return type;
}
- public String id() {
+ public String getId() {
return id;
}
@@ -67,7 +61,6 @@ public class RoutingMissingException extends ElasticsearchException {
public RoutingMissingException(StreamInput in) throws IOException{
super(in);
- index = in.readString();
type = in.readString();
id = in.readString();
}
@@ -75,7 +68,6 @@ public class RoutingMissingException extends ElasticsearchException {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
- out.writeString(index);
out.writeString(type);
out.writeString(id);
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java
index 39d533c79a..06d8d6361b 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java
@@ -32,7 +32,7 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.gateway.GatewayAllocator;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@@ -203,7 +203,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction<
try {
indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.strictExpand(), request.indices());
waitForCounter++;
- } catch (IndexMissingException e) {
+ } catch (IndexNotFoundException e) {
response.status = ClusterHealthStatus.RED; // no indices, make sure its RED
// missing indices, wait a bit more...
}
@@ -269,7 +269,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction<
String[] concreteIndices;
try {
concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request);
- } catch (IndexMissingException e) {
+ } catch (IndexNotFoundException e) {
// one of the specified indices is not there - treat it as RED.
ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState,
numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(settings, clusterState),
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java
index d8f3f7f662..5cabb7f533 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java
@@ -34,7 +34,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException;
+import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesNotFoundException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@@ -102,7 +102,7 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeAction<Ind
}
}
if (hasOnlyDeletesButNoneCanBeDone && actions.size() != 0) {
- throw new AliasesMissingException(aliases.toArray(new String[aliases.size()]));
+ throw new AliasesNotFoundException(aliases.toArray(new String[aliases.size()]));
}
request.aliasActions().clear();
IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest()
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java
index 324ba4431c..254b5fa0c6 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java
@@ -30,7 +30,7 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@@ -70,7 +70,7 @@ public class TransportIndicesExistsAction extends TransportMasterNodeReadAction<
// Similar as the previous behaviour, but now also aliases and wildcards are supported.
indexNameExpressionResolver.concreteIndices(state, request);
exists = true;
- } catch (IndexMissingException e) {
+ } catch (IndexNotFoundException e) {
exists = false;
}
listener.onResponse(new IndicesExistsResponse(exists));
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java
index ec9ae1c6ea..b298cdff75 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java
@@ -38,9 +38,9 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexService;
-import org.elasticsearch.index.IndexShardMissingException;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.ShardId;
+import org.elasticsearch.index.shard.ShardNotFoundException;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@@ -125,7 +125,7 @@ public class TransportIndicesStatsAction extends TransportBroadcastAction<Indice
IndexShard indexShard = indexService.shardSafe(request.shardId().id());
// if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet
if (indexShard.routingEntry() == null) {
- throw new IndexShardMissingException(indexShard.shardId());
+ throw new ShardNotFoundException(indexShard.shardId());
}
CommonStatsFlags flags = new CommonStatsFlags().clear();
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java
index 20bd7c99f4..54a0c4d427 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java
@@ -33,8 +33,7 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.index.Index;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.search.warmer.IndexWarmerMissingException;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.threadpool.ThreadPool;
@@ -96,7 +95,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeAction<Delet
for (String index : concreteIndices) {
IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
if (warmers != null) {
@@ -132,7 +131,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeAction<Delet
for (String index : concreteIndices) {
IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
if (warmers != null) {
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java
index fdcbc418a6..9b0a5e273d 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java
@@ -37,8 +37,7 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.index.Index;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@@ -128,7 +127,7 @@ public class TransportPutWarmerAction extends TransportMasterNodeAction<PutWarme
for (String index : concreteIndices) {
IndexMetaData indexMetaData = metaData.index(index);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
if (warmers == null) {
diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java
index 8e8097f880..67b31a3fac 100644
--- a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java
+++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java
@@ -50,10 +50,10 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AtomicArray;
import org.elasticsearch.index.Index;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.indices.IndexClosedException;
-import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@@ -363,12 +363,10 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
if (concreteIndex == null) {
try {
concreteIndex = concreteIndices.resolveIfAbsent(request);
- } catch (IndexClosedException ice) {
- unavailableException = ice;
- } catch (IndexMissingException ime) {
+ } catch (IndexClosedException | IndexNotFoundException ex) {
// Fix for issue where bulk request references an index that
// cannot be auto-created see issue #8125
- unavailableException = ime;
+ unavailableException = ex;
}
}
if (unavailableException == null) {
diff --git a/core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java b/core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java
index 43ec69d175..c485c747aa 100644
--- a/core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java
+++ b/core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java
@@ -36,9 +36,9 @@ import org.elasticsearch.cluster.routing.ShardIterator;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AtomicArray;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.engine.DocumentMissingException;
import org.elasticsearch.index.shard.ShardId;
-import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.percolator.PercolatorService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@@ -166,7 +166,7 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
String[] concreteIndices;
try {
concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, percolateRequest);
- } catch (IndexMissingException e) {
+ } catch (IndexNotFoundException e) {
reducedResponses.set(slot, e);
responsesByItemAndShard.set(slot, new AtomicReferenceArray(0));
expectedOperationsPerItem.set(slot, new AtomicInteger(0));
diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java
index a8d27c49d8..180bf69d1c 100644
--- a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java
+++ b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java
@@ -25,8 +25,6 @@ import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
diff --git a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java
index 420bc61991..fda34657f1 100644
--- a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java
+++ b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java
@@ -28,8 +28,8 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.IndexClosedException;
-import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@@ -86,7 +86,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
// if we only have one group, then we always want Q_A_F, no need for DFS, and no need to do THEN since we hit one shard
searchRequest.searchType(QUERY_AND_FETCH);
}
- } catch (IndexMissingException|IndexClosedException e) {
+ } catch (IndexNotFoundException | IndexClosedException e) {
// ignore these failures, we will notify the search response if its really the case from the actual action
} catch (Exception e) {
logger.debug("failed to optimize search type, continue as normal", e);
diff --git a/core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java b/core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java
index 313692d75b..7482cfdfdc 100644
--- a/core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java
+++ b/core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java
@@ -24,9 +24,7 @@ import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -49,9 +47,9 @@ public class DefaultShardOperationFailedException implements ShardOperationFaile
private DefaultShardOperationFailedException() {
}
- public DefaultShardOperationFailedException(IndexShardException e) {
- this.index = e.shardId().index().name();
- this.shardId = e.shardId().id();
+ public DefaultShardOperationFailedException(ElasticsearchException e) {
+ this.index = e.getIndex();
+ this.shardId = e.getShardId().id();
this.reason = e;
this.status = e.status();
}
diff --git a/core/src/main/java/org/elasticsearch/action/support/TransportActions.java b/core/src/main/java/org/elasticsearch/action/support/TransportActions.java
index 0b4b72befb..1de3ef1aea 100644
--- a/core/src/main/java/org/elasticsearch/action/support/TransportActions.java
+++ b/core/src/main/java/org/elasticsearch/action/support/TransportActions.java
@@ -21,9 +21,9 @@ package org.elasticsearch.action.support;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.NoShardAvailableActionException;
-import org.elasticsearch.index.IndexShardMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.shard.IllegalIndexShardStateException;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.shard.ShardNotFoundException;
/**
*/
@@ -31,16 +31,10 @@ public class TransportActions {
public static boolean isShardNotAvailableException(Throwable t) {
Throwable actual = ExceptionsHelper.unwrapCause(t);
- if (actual instanceof IllegalIndexShardStateException) {
- return true;
- }
- if (actual instanceof IndexMissingException) {
- return true;
- }
- if (actual instanceof IndexShardMissingException) {
- return true;
- }
- if (actual instanceof NoShardAvailableActionException) {
+ if (actual instanceof ShardNotFoundException ||
+ actual instanceof IndexNotFoundException ||
+ actual instanceof IllegalIndexShardStateException ||
+ actual instanceof NoShardAvailableActionException) {
return true;
}
return false;
diff --git a/core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java b/core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java
index ca761470e2..fb42c7a6e4 100644
--- a/core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java
+++ b/core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java
@@ -19,9 +19,9 @@
package org.elasticsearch.action.support.broadcast;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchWrapperException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
@@ -31,18 +31,19 @@ import java.io.IOException;
*
*
*/
-public class BroadcastShardOperationFailedException extends IndexShardException implements ElasticsearchWrapperException {
+public class BroadcastShardOperationFailedException extends ElasticsearchException implements ElasticsearchWrapperException {
public BroadcastShardOperationFailedException(ShardId shardId, String msg) {
- super(shardId, msg, null);
+ this(shardId, msg, null);
}
public BroadcastShardOperationFailedException(ShardId shardId, Throwable cause) {
- super(shardId, "", cause);
+ this(shardId, "", cause);
}
public BroadcastShardOperationFailedException(ShardId shardId, String msg, Throwable cause) {
- super(shardId, msg, cause);
+ super(msg, cause);
+ setShard(shardId);
}
public BroadcastShardOperationFailedException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java
index 545ce55bda..51155b538d 100644
--- a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java
+++ b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java
@@ -19,6 +19,7 @@
package org.elasticsearch.action.support.replication;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionWriteResponse;
@@ -58,7 +59,6 @@ import org.elasticsearch.index.engine.VersionConflictEngineException;
import org.elasticsearch.index.mapper.Mapping;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.shard.IndexShard;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.indices.IndicesService;
@@ -242,10 +242,11 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
}
}
- public static class RetryOnReplicaException extends IndexShardException {
+ public static class RetryOnReplicaException extends ElasticsearchException {
public RetryOnReplicaException(ShardId shardId, String msg) {
- super(shardId, msg);
+ super(msg);
+ setShard(shardId);
}
public RetryOnReplicaException(StreamInput in) throws IOException{
@@ -325,9 +326,10 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
}
}
- public static class RetryOnPrimaryException extends IndexShardException {
+ public static class RetryOnPrimaryException extends ElasticsearchException {
public RetryOnPrimaryException(ShardId shardId, String msg) {
- super(shardId, msg);
+ super(msg);
+ setShard(shardId);
}
public RetryOnPrimaryException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java
index ea658912c6..77c35fdcf5 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java
@@ -23,7 +23,6 @@ import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.ClusterState;
@@ -33,8 +32,8 @@ import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.index.Index;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.IndexClosedException;
-import org.elasticsearch.indices.IndexMissingException;
import java.util.*;
@@ -54,7 +53,7 @@ public class IndexNameExpressionResolver {
* Same as {@link #concreteIndices(ClusterState, IndicesOptions, String...)}, but the index expressions and options
* are encapsulated in the specified request.
*/
- public String[] concreteIndices(ClusterState state, IndicesRequest request) throws IndexMissingException, IllegalArgumentException {
+ public String[] concreteIndices(ClusterState state, IndicesRequest request) {
Context context = new Context(state, request.indicesOptions());
return concreteIndices(context, request.indices());
}
@@ -66,18 +65,18 @@ public class IndexNameExpressionResolver {
* @param options defines how the aliases or indices need to be resolved to concrete indices
* @param indexExpressions expressions that can be resolved to alias or index names.
* @return the resolved concrete indices based on the cluster state, indices options and index expressions
- * @throws IndexMissingException if one of the index expressions is pointing to a missing index or alias and the
+ * @throws IndexNotFoundException if one of the index expressions is pointing to a missing index or alias and the
* provided indices options in the context don't allow such a case, or if the final result of the indices resolution
* contains no indices and the indices options in the context don't allow such a case.
* @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided
* indices options in the context don't allow such a case.
*/
- public String[] concreteIndices(ClusterState state, IndicesOptions options, String... indexExpressions) throws IndexMissingException, IllegalArgumentException {
+ public String[] concreteIndices(ClusterState state, IndicesOptions options, String... indexExpressions) {
Context context = new Context(state, options);
return concreteIndices(context, indexExpressions);
}
- String[] concreteIndices(Context context, String... indexExpressions) throws IndexMissingException, IllegalArgumentException {
+ String[] concreteIndices(Context context, String... indexExpressions) {
if (indexExpressions == null || indexExpressions.length == 0) {
indexExpressions = new String[]{MetaData.ALL};
}
@@ -99,7 +98,9 @@ public class IndexNameExpressionResolver {
if (expressions.isEmpty()) {
if (!options.allowNoIndices()) {
- throw new IndexMissingException(new Index(Arrays.toString(indexExpressions)));
+ IndexNotFoundException infe = new IndexNotFoundException((String)null);
+ infe.setResources("index_expression", indexExpressions);
+ throw infe;
} else {
return Strings.EMPTY_ARRAY;
}
@@ -113,7 +114,10 @@ public class IndexNameExpressionResolver {
ImmutableOpenMap<String, AliasMetaData> indexAliasMap = metaData.aliases().get(expression);
if (indexAliasMap == null) {
if (failNoIndices) {
- throw new IndexMissingException(new Index(expression));
+ IndexNotFoundException infe = new IndexNotFoundException(expression);
+ infe.setResources("index_expression", expression);
+ throw infe;
+
} else {
continue;
}
@@ -147,7 +151,9 @@ public class IndexNameExpressionResolver {
}
if (options.allowNoIndices() == false && concreteIndices.isEmpty()) {
- throw new IndexMissingException(new Index(Arrays.toString(indexExpressions)));
+ IndexNotFoundException infe = new IndexNotFoundException((String)null);
+ infe.setResources("index_expression", indexExpressions);
+ throw infe;
}
return concreteIndices.toArray(new String[concreteIndices.size()]);
}
@@ -160,11 +166,11 @@ public class IndexNameExpressionResolver {
*
* @param request request containing the index or alias to be resolved to concrete index and
* the indices options to be used for the index resolution
- * @throws IndexMissingException if the resolved index or alias provided doesn't exist
+ * @throws IndexNotFoundException if the resolved index or alias provided doesn't exist
* @throws IllegalArgumentException if the index resolution lead to more than one index
* @return the concrete index obtained as a result of the index resolution
*/
- public String concreteSingleIndex(ClusterState state, IndicesRequest request) throws IndexMissingException, IllegalArgumentException {
+ public String concreteSingleIndex(ClusterState state, IndicesRequest request) {
String indexOrAlias = request.indices() != null && request.indices().length > 0 ? request.indices()[0] : null;
String[] indices = concreteIndices(state, request.indicesOptions(), indexOrAlias);
if (indices.length != 1) {
@@ -197,7 +203,7 @@ public class IndexNameExpressionResolver {
IndexMetaData indexMetaData = state.metaData().getIndices().get(index);
if (indexMetaData == null) {
// Shouldn't happen
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
AliasMetaData aliasMetaData = indexMetaData.aliases().get(alias);
boolean filteringRequired = aliasMetaData != null && aliasMetaData.filteringRequired();
@@ -215,7 +221,7 @@ public class IndexNameExpressionResolver {
IndexMetaData indexMetaData = state.metaData().getIndices().get(index);
if (indexMetaData == null) {
// Shouldn't happen
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
AliasMetaData aliasMetaData = indexMetaData.aliases().get(alias);
@@ -538,7 +544,9 @@ public class IndexNameExpressionResolver {
}
if (!Regex.isSimpleMatchPattern(aliasOrIndex)) {
if (!options.ignoreUnavailable() && !metaData.getAliasAndIndexMap().containsKey(aliasOrIndex)) {
- throw new IndexMissingException(new Index(aliasOrIndex));
+ IndexNotFoundException infe = new IndexNotFoundException(aliasOrIndex);
+ infe.setResources("index_or_alias", aliasOrIndex);
+ throw infe;
}
if (result != null) {
if (add) {
@@ -590,14 +598,18 @@ public class IndexNameExpressionResolver {
}
}
if (!found && !options.allowNoIndices()) {
- throw new IndexMissingException(new Index(aliasOrIndex));
+ IndexNotFoundException infe = new IndexNotFoundException(aliasOrIndex);
+ infe.setResources("index_or_alias", aliasOrIndex);
+ throw infe;
}
}
if (result == null) {
return expressions;
}
if (result.isEmpty() && !options.allowNoIndices()) {
- throw new IndexMissingException(new Index(StringUtils.join(expressions.iterator(), ',')));
+ IndexNotFoundException infe = new IndexNotFoundException((String)null);
+ infe.setResources("index_or_alias", expressions.toArray(new String[0]));
+ throw infe;
}
return new ArrayList<>(result);
}
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java
index b9b5ab346e..a3d839f0d3 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java
@@ -48,7 +48,7 @@ import org.elasticsearch.common.settings.loader.SettingsLoader;
import org.elasticsearch.common.xcontent.*;
import org.elasticsearch.discovery.DiscoverySettings;
import org.elasticsearch.index.Index;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.recovery.RecoverySettings;
import org.elasticsearch.indices.store.IndicesStore;
import org.elasticsearch.indices.ttl.IndicesTTLService;
@@ -943,7 +943,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData> {
for (String index : indices) {
IndexMetaData indexMetaData = this.indices.get(index);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
put(IndexMetaData.builder(indexMetaData)
.settings(settingsBuilder().put(indexMetaData.settings()).put(settings)));
@@ -958,7 +958,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData> {
for (String index : indices) {
IndexMetaData indexMetaData = this.indices.get(index);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
put(IndexMetaData.builder(indexMetaData).numberOfReplicas(numberOfReplicas));
}
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java
index 3d5d938bde..10bc32190a 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java
@@ -34,8 +34,7 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.FutureUtils;
-import org.elasticsearch.index.Index;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.threadpool.ThreadPool;
import java.util.concurrent.ScheduledFuture;
@@ -116,7 +115,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
@Override
public ClusterState execute(final ClusterState currentState) {
if (!currentState.metaData().hasConcreteIndex(request.index)) {
- throw new IndexMissingException(new Index(request.index));
+ throw new IndexNotFoundException(request.index);
}
logger.info("[{}] deleting index", request.index);
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java
index 7ab2c08f56..fb2e933dcf 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java
@@ -33,10 +33,9 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.index.Index;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.IndexService;
-import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.indices.IndicesService;
import java.util.List;
@@ -76,7 +75,7 @@ public class MetaDataIndexAliasesService extends AbstractComponent {
for (AliasAction aliasAction : request.actions()) {
aliasValidator.validateAliasAction(aliasAction, currentState.metaData());
if (!currentState.metaData().hasIndex(aliasAction.index())) {
- throw new IndexMissingException(new Index(aliasAction.index()));
+ throw new IndexNotFoundException(aliasAction.index());
}
}
@@ -85,7 +84,7 @@ public class MetaDataIndexAliasesService extends AbstractComponent {
for (AliasAction aliasAction : request.actions()) {
IndexMetaData indexMetaData = builder.get(aliasAction.index());
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(aliasAction.index()));
+ throw new IndexNotFoundException(aliasAction.index());
}
// TODO: not copy (putAll)
IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(indexMetaData);
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java
index c1113f8e68..f680ac1d5e 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java
@@ -39,8 +39,7 @@ import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException;
import org.elasticsearch.rest.RestStatus;
@@ -87,7 +86,7 @@ public class MetaDataIndexStateService extends AbstractComponent {
for (String index : request.indices()) {
IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
if (indexMetaData.state() != IndexMetaData.State.CLOSE) {
@@ -147,7 +146,7 @@ public class MetaDataIndexStateService extends AbstractComponent {
for (String index : request.indices()) {
IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
if (indexMetaData.state() != IndexMetaData.State.OPEN) {
indicesToOpen.add(index);
@@ -167,11 +166,7 @@ public class MetaDataIndexStateService extends AbstractComponent {
IndexMetaData indexMetaData = IndexMetaData.builder(currentState.metaData().index(index)).state(IndexMetaData.State.OPEN).build();
// The index might be closed because we couldn't import it due to old incompatible version
// We need to check that this index can be upgraded to the current version
- try {
- indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData);
- } catch (Exception ex) {
- throw new IndexException(new Index(index), "cannot open the index due to upgrade failure", ex);
- }
+ indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData);
mdBuilder.put(indexMetaData, true);
blocksBuilder.removeIndexBlock(index, INDEX_CLOSED_BLOCK);
}
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java
index b19f168760..f3af952e8b 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java
@@ -81,7 +81,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
* If the index does not need upgrade it returns the index metadata unchanged, otherwise it returns a modified index metadata. If index
* cannot be updated the method throws an exception.
*/
- public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData) throws Exception {
+ public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData) {
// Throws an exception if there are too-old segments:
checkSupportedVersion(indexMetaData);
IndexMetaData newMetaData = upgradeLegacyRoutingSettings(indexMetaData);
@@ -94,7 +94,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
* that were created before Elasticsearch v0.90.0 should be upgraded using upgrade plugin before they can
* be open by this version of elasticsearch.
*/
- private void checkSupportedVersion(IndexMetaData indexMetaData) throws Exception {
+ private void checkSupportedVersion(IndexMetaData indexMetaData) {
if (indexMetaData.getState() == IndexMetaData.State.OPEN && isSupportedVersion(indexMetaData) == false) {
throw new IllegalStateException("The index [" + indexMetaData.getIndex() + "] was created before v0.90.0 and wasn't upgraded."
+ " This index should be open using a version before " + Version.CURRENT.minimumCompatibilityVersion()
@@ -122,7 +122,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
* Elasticsearch 2.0 deprecated custom routing hash functions. So what we do here is that for old indices, we
* move this old and deprecated node setting to an index setting so that we can keep things backward compatible.
*/
- private IndexMetaData upgradeLegacyRoutingSettings(IndexMetaData indexMetaData) throws Exception {
+ private IndexMetaData upgradeLegacyRoutingSettings(IndexMetaData indexMetaData) {
if (indexMetaData.settings().get(IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION) == null
&& indexMetaData.getCreationVersion().before(Version.V_2_0_0_beta1)) {
// these settings need an upgrade
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java
index 772c8d491c..04d52b0ea5 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java
@@ -37,13 +37,12 @@ import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.index.Index;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
-import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.InvalidTypeNameException;
import org.elasticsearch.percolator.PercolatorService;
@@ -347,7 +346,7 @@ public class MetaDataMappingService extends AbstractComponent {
try {
for (String index : request.indices()) {
if (!currentState.metaData().hasIndex(index)) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
}
@@ -472,7 +471,7 @@ public class MetaDataMappingService extends AbstractComponent {
for (String indexName : request.indices()) {
IndexMetaData indexMetaData = currentState.metaData().index(indexName);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(indexName));
+ throw new IndexNotFoundException(indexName);
}
MappingMetaData mappingMd = mappings.get(indexName);
if (mappingMd != null) {
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java
index 57156f5763..ae12a387b7 100644
--- a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java
+++ b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java
@@ -32,10 +32,9 @@ import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.math.MathUtils;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexShardMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.shard.ShardId;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.shard.ShardNotFoundException;
import java.util.Collections;
import java.util.HashSet;
@@ -57,32 +56,32 @@ public class OperationRouting extends AbstractComponent {
this.awarenessAllocationDecider = awarenessAllocationDecider;
}
- public ShardIterator indexShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) throws IndexMissingException, IndexShardMissingException {
+ public ShardIterator indexShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) {
return shards(clusterState, index, type, id, routing).shardsIt();
}
- public ShardIterator deleteShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) throws IndexMissingException, IndexShardMissingException {
+ public ShardIterator deleteShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) {
return shards(clusterState, index, type, id, routing).shardsIt();
}
- public ShardIterator getShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing, @Nullable String preference) throws IndexMissingException, IndexShardMissingException {
+ public ShardIterator getShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing, @Nullable String preference) {
return preferenceActiveShardIterator(shards(clusterState, index, type, id, routing), clusterState.nodes().localNodeId(), clusterState.nodes(), preference);
}
- public ShardIterator getShards(ClusterState clusterState, String index, int shardId, @Nullable String preference) throws IndexMissingException, IndexShardMissingException {
+ public ShardIterator getShards(ClusterState clusterState, String index, int shardId, @Nullable String preference) {
return preferenceActiveShardIterator(shards(clusterState, index, shardId), clusterState.nodes().localNodeId(), clusterState.nodes(), preference);
}
- public GroupShardsIterator broadcastDeleteShards(ClusterState clusterState, String index) throws IndexMissingException {
+ public GroupShardsIterator broadcastDeleteShards(ClusterState clusterState, String index) {
return indexRoutingTable(clusterState, index).groupByShardsIt();
}
- public int searchShardsCount(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing) throws IndexMissingException {
+ public int searchShardsCount(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing) {
final Set<IndexShardRoutingTable> shards = computeTargetedShards(clusterState, concreteIndices, routing);
return shards.size();
}
- public GroupShardsIterator searchShards(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException {
+ public GroupShardsIterator searchShards(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) {
final Set<IndexShardRoutingTable> shards = computeTargetedShards(clusterState, concreteIndices, routing);
final Set<ShardIterator> set = new HashSet<>(shards.size());
for (IndexShardRoutingTable shard : shards) {
@@ -96,7 +95,7 @@ public class OperationRouting extends AbstractComponent {
private static final Map<String, Set<String>> EMPTY_ROUTING = Collections.emptyMap();
- private Set<IndexShardRoutingTable> computeTargetedShards(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing) throws IndexMissingException {
+ private Set<IndexShardRoutingTable> computeTargetedShards(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing) {
routing = routing == null ? EMPTY_ROUTING : routing; // just use an empty map
final Set<IndexShardRoutingTable> set = new HashSet<>();
// we use set here and not list since we might get duplicates
@@ -108,7 +107,7 @@ public class OperationRouting extends AbstractComponent {
int shardId = shardId(clusterState, index, null, null, r);
IndexShardRoutingTable indexShard = indexRouting.shard(shardId);
if (indexShard == null) {
- throw new IndexShardMissingException(new ShardId(index, shardId));
+ throw new ShardNotFoundException(new ShardId(index, shardId));
}
// we might get duplicates, but that's ok, they will override one another
set.add(indexShard);
@@ -202,7 +201,7 @@ public class OperationRouting extends AbstractComponent {
public IndexMetaData indexMetaData(ClusterState clusterState, String index) {
IndexMetaData indexMetaData = clusterState.metaData().index(index);
if (indexMetaData == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
return indexMetaData;
}
@@ -210,7 +209,7 @@ public class OperationRouting extends AbstractComponent {
protected IndexRoutingTable indexRoutingTable(ClusterState clusterState, String index) {
IndexRoutingTable indexRouting = clusterState.routingTable().index(index);
if (indexRouting == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
return indexRouting;
}
@@ -226,7 +225,7 @@ public class OperationRouting extends AbstractComponent {
protected IndexShardRoutingTable shards(ClusterState clusterState, String index, int shardId) {
IndexShardRoutingTable indexShard = indexRoutingTable(clusterState, index).shard(shardId);
if (indexShard == null) {
- throw new IndexShardMissingException(new ShardId(index, shardId));
+ throw new ShardNotFoundException(new ShardId(index, shardId));
}
return indexShard;
}
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java
index 1327b55620..0359849a6f 100644
--- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java
+++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java
@@ -26,9 +26,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.index.Index;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.shard.ShardId;
-import org.elasticsearch.indices.IndexMissingException;
import java.io.IOException;
import java.util.ArrayList;
@@ -124,7 +123,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
*
* @return All the shards
*/
- public List<ShardRouting> allShards() throws IndexMissingException {
+ public List<ShardRouting> allShards() {
List<ShardRouting> shards = Lists.newArrayList();
String[] indices = indicesRouting.keySet().toArray(new String[indicesRouting.keySet().size()]);
for (String index : indices) {
@@ -139,13 +138,13 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
*
* @param index The index to return all the shards (replicas).
* @return All the shards matching the specific index
- * @throws IndexMissingException If the index passed does not exists
+ * @throws IndexNotFoundException If the index passed does not exists
*/
- public List<ShardRouting> allShards(String index) throws IndexMissingException {
+ public List<ShardRouting> allShards(String index) {
List<ShardRouting> shards = Lists.newArrayList();
IndexRoutingTable indexRoutingTable = index(index);
if (indexRoutingTable == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
for (ShardRouting shardRouting : indexShardRoutingTable) {
@@ -155,7 +154,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
return shards;
}
- public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty) throws IndexMissingException {
+ public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty) {
return allActiveShardsGrouped(indices, includeEmpty, false);
}
@@ -166,7 +165,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
* @param includeRelocationTargets if true, an <b>extra</b> shard iterator will be added for relocating shards. The extra
* iterator contains a single ShardRouting pointing at the relocating target
*/
- public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) throws IndexMissingException {
+ public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) {
// use list here since we need to maintain identity across shards
ArrayList<ShardIterator> set = new ArrayList<>();
for (String index : indices) {
@@ -191,7 +190,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
return new GroupShardsIterator(set);
}
- public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty) throws IndexMissingException {
+ public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty) {
return allAssignedShardsGrouped(indices, includeEmpty, false);
}
@@ -202,7 +201,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
* @param includeRelocationTargets if true, an <b>extra</b> shard iterator will be added for relocating shards. The extra
* iterator contains a single ShardRouting pointing at the relocating target
*/
- public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) throws IndexMissingException {
+ public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) {
// use list here since we need to maintain identity across shards
ArrayList<ShardIterator> set = new ArrayList<>();
for (String index : indices) {
@@ -234,16 +233,16 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
*
* @param indices The indices to return all the shards (replicas)
* @return All the primary shards grouped into a single shard element group each
- * @throws IndexMissingException If an index passed does not exists
+ * @throws IndexNotFoundException If an index passed does not exists
* @see IndexRoutingTable#groupByAllIt()
*/
- public GroupShardsIterator activePrimaryShardsGrouped(String[] indices, boolean includeEmpty) throws IndexMissingException {
+ public GroupShardsIterator activePrimaryShardsGrouped(String[] indices, boolean includeEmpty) {
// use list here since we need to maintain identity across shards
ArrayList<ShardIterator> set = new ArrayList<>();
for (String index : indices) {
IndexRoutingTable indexRoutingTable = index(index);
if (indexRoutingTable == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
ShardRouting primary = indexShardRoutingTable.primaryShard();
@@ -387,7 +386,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
return this;
}
- public Builder updateNumberOfReplicas(int numberOfReplicas, String... indices) throws IndexMissingException {
+ public Builder updateNumberOfReplicas(int numberOfReplicas, String... indices) {
if (indices == null || indices.length == 0) {
indices = indicesRouting.keySet().toArray(new String[indicesRouting.keySet().size()]);
}
diff --git a/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java b/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java
index 705f9a40a3..24e910b905 100644
--- a/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java
+++ b/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java
@@ -36,7 +36,7 @@ public class AlreadyExpiredException extends ElasticsearchException implements I
public AlreadyExpiredException(String index, String type, String id, long timestamp, long ttl, long now) {
super("already expired [" + index + "]/[" + type + "]/[" + id + "] due to expire at [" + (timestamp + ttl) + "] and was processed at [" + now + "]");
- this.index = index;
+ this.setIndex(index);
this.type = type;
this.id = id;
this.timestamp = timestamp;
diff --git a/core/src/main/java/org/elasticsearch/index/IndexException.java b/core/src/main/java/org/elasticsearch/index/IndexException.java
deleted file mode 100644
index c309ebcb7f..0000000000
--- a/core/src/main/java/org/elasticsearch/index/IndexException.java
+++ /dev/null
@@ -1,73 +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 org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-
-import java.io.IOException;
-
-/**
- *
- */
-public class IndexException extends ElasticsearchException {
-
- private final Index index;
-
- public IndexException(Index index, String msg, Object... args) {
- this(index, msg, null, args);
- }
-
- public IndexException(Index index, String msg, Throwable cause, Object... args) {
- super(msg, cause);
- this.index = index;
- }
-
- public Index index() {
- return index;
- }
-
- @Override
- protected void innerToXContent(XContentBuilder builder, Params params) throws IOException {
- if (index != null) {
- builder.field("index", index.getName());
- }
- super.innerToXContent(builder, params);
- }
-
- @Override
- public String toString() {
- return "[" + (index == null ? "_na" : index.name()) + "] " + getMessage();
- }
-
-
- public IndexException(StreamInput in) throws IOException{
- super(in);
- index = in.readBoolean() ? Index.readIndexName(in) : null;
- }
-
- @Override
- public void writeTo(StreamOutput out) throws IOException {
- super.writeTo(out);
- out.writeOptionalStreamable(index);
- }
-}
diff --git a/core/src/main/java/org/elasticsearch/index/store/StoreException.java b/core/src/main/java/org/elasticsearch/index/IndexNotFoundException.java
index d221583e0d..bc7e55d5a0 100644
--- a/core/src/main/java/org/elasticsearch/index/store/StoreException.java
+++ b/core/src/main/java/org/elasticsearch/index/IndexNotFoundException.java
@@ -16,25 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.elasticsearch.index;
-package org.elasticsearch.index.store;
-
+import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
-import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
-/**
- *
- */
-public class StoreException extends IndexShardException {
+public final class IndexNotFoundException extends ResourceNotFoundException {
+
+ public IndexNotFoundException(String index) {
+ this(index, null);
+ }
- public StoreException(ShardId shardId, String msg, Throwable cause) {
- super(shardId, msg, cause);
+ public IndexNotFoundException(String index, Throwable cause) {
+ super("no such index", cause);
+ setIndex(index);
}
- public StoreException(StreamInput in) throws IOException{
+ public IndexNotFoundException(StreamInput in) throws IOException {
super(in);
}
-} \ No newline at end of file
+}
diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java
index 25942e6b35..46f6e90246 100644
--- a/core/src/main/java/org/elasticsearch/index/IndexService.java
+++ b/core/src/main/java/org/elasticsearch/index/IndexService.java
@@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterators;
import org.apache.lucene.util.IOUtils;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
@@ -173,10 +174,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
/**
* Return the shard with the provided id, or throw an exception if it doesn't exist.
*/
- public IndexShard shardSafe(int shardId) throws IndexShardMissingException {
+ public IndexShard shardSafe(int shardId) {
IndexShard indexShard = shard(shardId);
if (indexShard == null) {
- throw new IndexShardMissingException(new ShardId(index, shardId));
+ throw new ShardNotFoundException(new ShardId(index, shardId));
}
return indexShard;
}
@@ -242,10 +243,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
/**
* Return the shard injector for the provided id, or throw an exception if there is no such shard.
*/
- public Injector shardInjectorSafe(int shardId) throws IndexShardMissingException {
+ public Injector shardInjectorSafe(int shardId) {
Tuple<IndexShard, Injector> tuple = shards.get(shardId);
if (tuple == null) {
- throw new IndexShardMissingException(new ShardId(index, shardId));
+ throw new ShardNotFoundException(new ShardId(index, shardId));
}
return tuple.v2();
}
@@ -316,9 +317,13 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
try {
shardInjector = modules.createChildInjector(injector);
} catch (CreationException e) {
- throw new IndexShardCreationException(shardId, Injectors.getFirstErrorFailure(e));
+ ElasticsearchException ex = new ElasticsearchException("failed to create shard", Injectors.getFirstErrorFailure(e));
+ ex.setShard(shardId);
+ throw ex;
} catch (Throwable e) {
- throw new IndexShardCreationException(shardId, e);
+ ElasticsearchException ex = new ElasticsearchException("failed to create shard", e);
+ ex.setShard(shardId);
+ throw ex;
}
IndexShard indexShard = shardInjector.getInstance(IndexShard.class);
@@ -328,8 +333,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
shards = newMapBuilder(shards).put(shardId.id(), new Tuple<>(indexShard, shardInjector)).immutableMap();
success = true;
return indexShard;
- } catch (IOException ex) {
- throw new IndexShardCreationException(shardId, ex);
+ } catch (IOException e) {
+ ElasticsearchException ex = new ElasticsearchException("failed to create shard", e);
+ ex.setShard(shardId);
+ throw ex;
} finally {
if (success == false) {
IOUtils.closeWhileHandlingException(lock);
diff --git a/core/src/main/java/org/elasticsearch/index/engine/EngineException.java b/core/src/main/java/org/elasticsearch/index/engine/EngineException.java
index a856ed190a..d7487ef66f 100644
--- a/core/src/main/java/org/elasticsearch/index/engine/EngineException.java
+++ b/core/src/main/java/org/elasticsearch/index/engine/EngineException.java
@@ -19,8 +19,8 @@
package org.elasticsearch.index.engine;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
@@ -28,14 +28,15 @@ import java.io.IOException;
/**
*
*/
-public class EngineException extends IndexShardException {
+public class EngineException extends ElasticsearchException {
public EngineException(ShardId shardId, String msg) {
- super(shardId, msg);
+ this(shardId, msg, null);
}
public EngineException(ShardId shardId, String msg, Throwable cause) {
- super(shardId, msg, cause);
+ super(msg, cause);
+ setShard(shardId);
}
public EngineException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java b/core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java
index 73921e216b..f89b9ce471 100644
--- a/core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java
+++ b/core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java
@@ -30,7 +30,6 @@ import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.ReleasableLock;
import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.translog.Translog;
import java.io.IOException;
@@ -82,7 +81,7 @@ public class ShadowEngine extends Engine {
this.lastCommittedSegmentInfos = readLastCommittedSegmentInfos(searcherManager, store);
success = true;
} else {
- throw new IndexShardException(shardId, "failed to open a shadow engine after" +
+ throw new IllegalStateException("failed to open a shadow engine after" +
nonexistentRetryTime + "ms, " +
"directory is not an index");
}
diff --git a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java
index 65019be247..3813679d81 100644
--- a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java
+++ b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java
@@ -18,19 +18,20 @@
*/
package org.elasticsearch.index.percolator;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import java.io.IOException;
/**
* Exception during indexing a percolator query.
*/
-public class PercolatorException extends IndexException {
+public class PercolatorException extends ElasticsearchException {
public PercolatorException(Index index, String msg, Throwable cause) {
- super(index, msg, cause);
+ super(msg, cause);
+ setIndex(index);
}
public PercolatorException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java b/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java
index f904b74094..c606953bca 100644
--- a/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java
+++ b/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java
@@ -19,13 +19,13 @@
package org.elasticsearch.index.query;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -33,7 +33,7 @@ import java.io.IOException;
/**
*
*/
-public class QueryParsingException extends IndexException {
+public class QueryParsingException extends ElasticsearchException {
static final int UNKNOWN_POSITION = -1;
private final int lineNumber;
@@ -44,7 +44,8 @@ public class QueryParsingException extends IndexException {
}
public QueryParsingException(QueryParseContext parseContext, String msg, Throwable cause, Object... args) {
- super(parseContext.index(), msg, cause, args);
+ super(msg, cause, args);
+ setIndex(parseContext.index());
int lineNumber = UNKNOWN_POSITION;
int columnNumber = UNKNOWN_POSITION;
XContentParser parser = parseContext.parser();
@@ -64,7 +65,8 @@ public class QueryParsingException extends IndexException {
* {@link QueryParseContext} may not be available
*/
public QueryParsingException(Index index, int line, int col, String msg, Throwable cause) {
- super(index, msg, cause);
+ super(msg, cause);
+ setIndex(index);
this.lineNumber = line;
this.columnNumber = col;
}
diff --git a/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java b/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java
index 0cde08f43c..31c235e09e 100644
--- a/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java
+++ b/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java
@@ -19,6 +19,8 @@
package org.elasticsearch.index.shard;
+import org.elasticsearch.ElasticsearchException;
+import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.rest.RestStatus;
@@ -28,17 +30,17 @@ import java.io.IOException;
/**
*
*/
-public class IllegalIndexShardStateException extends IndexShardException {
+public class IllegalIndexShardStateException extends ElasticsearchException {
private final IndexShardState currentState;
public IllegalIndexShardStateException(ShardId shardId, IndexShardState currentState, String msg) {
- super(shardId, "CurrentState[" + currentState + "] " + msg);
- this.currentState = currentState;
+ this(shardId, currentState, msg, null);
}
public IllegalIndexShardStateException(ShardId shardId, IndexShardState currentState, String msg, Throwable ex) {
- super(shardId, "CurrentState[" + currentState + "] ", ex);
+ super("CurrentState[" + currentState + "] " + msg, ex);
+ setShard(shardId);
this.currentState = currentState;
}
@@ -46,11 +48,6 @@ public class IllegalIndexShardStateException extends IndexShardException {
return currentState;
}
- @Override
- public RestStatus status() {
- return RestStatus.NOT_FOUND;
- }
-
public IllegalIndexShardStateException(StreamInput in) throws IOException{
super(in);
currentState = IndexShardState.fromId(in.readByte());
@@ -61,4 +58,9 @@ public class IllegalIndexShardStateException extends IndexShardException {
super.writeTo(out);
out.writeByte(currentState.id());
}
+
+ @Override
+ public RestStatus status() {
+ return RestStatus.NOT_FOUND;
+ }
}
diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java
index 13b34a48d8..dd4b6bc7dc 100644
--- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java
+++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java
@@ -24,11 +24,13 @@ import com.google.common.base.Preconditions;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.index.CheckIndex;
+import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.search.QueryCachingPolicy;
import org.apache.lucene.search.UsageTrackingQueryCachingPolicy;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.ThreadInterruptedException;
+import org.elasticsearch.ElasticsearchCorruptionException;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
@@ -104,6 +106,7 @@ import org.elasticsearch.indices.IndicesLifecycle;
import org.elasticsearch.indices.IndicesWarmer;
import org.elasticsearch.indices.InternalIndicesLifecycle;
import org.elasticsearch.indices.cache.query.IndicesQueryCache;
+import org.elasticsearch.indices.recovery.RecoveryFailedException;
import org.elasticsearch.indices.recovery.RecoveryState;
import org.elasticsearch.search.suggest.completion.Completion090PostingsFormat;
import org.elasticsearch.search.suggest.completion.CompletionStats;
@@ -839,7 +842,11 @@ public class IndexShard extends AbstractIndexShardComponent {
recoveryState.setStage(RecoveryState.Stage.VERIFY_INDEX);
// also check here, before we apply the translog
if (Booleans.parseBoolean(checkIndexOnStartup, false)) {
- checkIndex();
+ try {
+ checkIndex();
+ } catch (IOException ex) {
+ throw new RecoveryFailedException(recoveryState, "check index failed", ex);
+ }
}
recoveryState.setStage(RecoveryState.Stage.TRANSLOG);
// we disable deletes since we allow for operations to be executed against the shard while recovering
@@ -1182,19 +1189,17 @@ public class IndexShard extends AbstractIndexShardComponent {
}
}
- private void checkIndex() throws IndexShardException {
+ private void checkIndex() throws IOException {
if (store.tryIncRef()) {
try {
doCheckIndex();
- } catch (IOException e) {
- throw new IndexShardException(shardId, "exception during checkindex", e);
} finally {
store.decRef();
}
}
}
- private void doCheckIndex() throws IndexShardException, IOException {
+ private void doCheckIndex() throws IOException {
long timeNS = System.nanoTime();
if (!Lucene.indexExists(store.directory())) {
return;
@@ -1204,7 +1209,7 @@ public class IndexShard extends AbstractIndexShardComponent {
if ("checksum".equalsIgnoreCase(checkIndexOnStartup)) {
// physical verification only: verify all checksums for the latest commit
- boolean corrupt = false;
+ IOException corrupt = null;
MetadataSnapshot metadata = store.getMetadata();
for (Map.Entry<String, StoreFileMetaData> entry : metadata.asMap().entrySet()) {
try {
@@ -1213,13 +1218,13 @@ public class IndexShard extends AbstractIndexShardComponent {
} catch (IOException exc) {
out.println("checksum failed: " + entry.getKey());
exc.printStackTrace(out);
- corrupt = true;
+ corrupt = exc;
}
}
out.flush();
- if (corrupt) {
+ if (corrupt != null) {
logger.warn("check index [failure]\n{}", new String(os.bytes().toBytes(), Charsets.UTF_8));
- throw new IndexShardException(shardId, "index check failure");
+ throw corrupt;
}
} else {
// full checkindex
@@ -1244,7 +1249,7 @@ public class IndexShard extends AbstractIndexShardComponent {
}
} else {
// only throw a failure if we are not going to fix the index
- throw new IndexShardException(shardId, "index check failure");
+ throw new IllegalStateException("index check failure but can't fix it");
}
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java
deleted file mode 100644
index 23fde2abc1..0000000000
--- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java
+++ /dev/null
@@ -1,76 +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.shard;
-
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.index.IndexException;
-
-import java.io.IOException;
-
-/**
- *
- */
-public class IndexShardException extends IndexException {
-
- private final ShardId shardId;
-
- public IndexShardException(ShardId shardId, String msg) {
- this(shardId, msg, null);
- }
-
- public IndexShardException(ShardId shardId, String msg, Throwable cause) {
- super(shardId == null ? null : shardId.index(), msg, cause);
- this.shardId = shardId;
- }
-
- public ShardId shardId() {
- return shardId;
- }
-
- @Override
- public String toString() {
- return (shardId == null ? "_na" : shardId) + " " + getMessage();
- }
-
- @Override
- protected void innerToXContent(XContentBuilder builder, Params params) throws IOException {
- if (shardId != null) {
- builder.field("shard", shardId.getId());
- }
- super.innerToXContent(builder, params);
- }
-
- public IndexShardException(StreamInput in) throws IOException{
- super(in);
- if (in.readBoolean()) {
- shardId = ShardId.readShardId(in);
- } else {
- shardId = null;
- }
- }
-
- @Override
- public void writeTo(StreamOutput out) throws IOException {
- super.writeTo(out);
- out.writeOptionalStreamable(shardId);
- }
-}
diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java
index d53d1eaa6a..8ed3c95f92 100644
--- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java
+++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java
@@ -19,18 +19,18 @@
package org.elasticsearch.index.shard;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
-import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
*
*/
-public class IndexShardRecoveryException extends IndexShardException {
+public class IndexShardRecoveryException extends ElasticsearchException {
public IndexShardRecoveryException(ShardId shardId, String msg, Throwable cause) {
- super(shardId, msg, cause);
+ super(msg, cause);
+ setShard(shardId);
}
public IndexShardRecoveryException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java b/core/src/main/java/org/elasticsearch/index/shard/ShardNotFoundException.java
index a6d879e5b0..fa2c8ce710 100644
--- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java
+++ b/core/src/main/java/org/elasticsearch/index/shard/ShardNotFoundException.java
@@ -19,19 +19,25 @@
package org.elasticsearch.index.shard;
+import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
+ *
*/
-public class IndexShardCreationException extends IndexShardException {
-
- public IndexShardCreationException(ShardId shardId, Throwable cause) {
- super(shardId, "failed to create shard", cause);
+public class ShardNotFoundException extends ResourceNotFoundException {
+ public ShardNotFoundException(ShardId shardId) {
+ this(shardId, null);
}
- public IndexShardCreationException(StreamInput in) throws IOException{
+ public ShardNotFoundException(ShardId shardId, Throwable ex) {
+ super("no such shard", ex);
+ setShard(shardId);
+
+ }
+ public ShardNotFoundException(StreamInput in) throws IOException{
super(in);
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java b/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java
index 91da224ec3..1a54c748c3 100644
--- a/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java
+++ b/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java
@@ -90,12 +90,13 @@ public class TranslogRecoveryPerformer {
return numOps;
}
- public static class BatchOperationException extends IndexShardException {
+ public static class BatchOperationException extends ElasticsearchException {
private final int completedOperations;
public BatchOperationException(ShardId shardId, String msg, int completedOperations, Throwable cause) {
- super(shardId, msg, cause);
+ super(msg, cause);
+ setShard(shardId);
this.completedOperations = completedOperations;
}
diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java
index 92a2ed4ab9..55410b8cb9 100644
--- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java
+++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java
@@ -19,8 +19,8 @@
package org.elasticsearch.index.snapshots;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
@@ -28,13 +28,14 @@ import java.io.IOException;
/**
* Generic shard restore exception
*/
-public class IndexShardRestoreException extends IndexShardException {
+public class IndexShardRestoreException extends ElasticsearchException {
public IndexShardRestoreException(ShardId shardId, String msg) {
- super(shardId, msg);
+ this(shardId, msg, null);
}
public IndexShardRestoreException(ShardId shardId, String msg, Throwable cause) {
- super(shardId, msg, cause);
+ super(msg, cause);
+ setShard(shardId);
}
public IndexShardRestoreException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java
index e915d22753..741350966a 100644
--- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java
+++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java
@@ -19,8 +19,8 @@
package org.elasticsearch.index.snapshots;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
@@ -28,13 +28,14 @@ import java.io.IOException;
/**
* Generic shard snapshot exception
*/
-public class IndexShardSnapshotException extends IndexShardException {
+public class IndexShardSnapshotException extends ElasticsearchException {
public IndexShardSnapshotException(ShardId shardId, String msg) {
- super(shardId, msg);
+ this(shardId, msg, null);
}
public IndexShardSnapshotException(ShardId shardId, String msg, Throwable cause) {
- super(shardId, msg, cause);
+ super(msg, cause);
+ setShard(shardId);
}
public IndexShardSnapshotException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java
index afc2dac335..d40297b8d9 100644
--- a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java
+++ b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java
@@ -22,6 +22,7 @@ package org.elasticsearch.index.store;
import com.google.common.collect.Sets;
import org.apache.lucene.store.*;
import org.apache.lucene.util.Constants;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.metrics.CounterMetric;
import org.elasticsearch.common.settings.Settings;
@@ -74,11 +75,7 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim
}
protected final LockFactory buildLockFactory() throws IOException {
- try {
- return buildLockFactory(indexSettings);
- } catch (IllegalArgumentException e) {
- throw new StoreException(shardId, "unable to build lock factory", e);
- }
+ return buildLockFactory(indexSettings);
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java
index 2e80cb6f78..2ebf279588 100644
--- a/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java
+++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java
@@ -19,8 +19,8 @@
package org.elasticsearch.index.translog;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
@@ -28,14 +28,15 @@ import java.io.IOException;
/**
*
*/
-public class TranslogException extends IndexShardException {
+public class TranslogException extends ElasticsearchException {
public TranslogException(ShardId shardId, String msg) {
- super(shardId, msg);
+ this(shardId, msg, null);
}
public TranslogException(ShardId shardId, String msg, Throwable cause) {
- super(shardId, msg, cause);
+ super(msg, cause);
+ setShard(shardId);
}
public TranslogException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java b/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java
index 54baafe0a0..52e801a4cb 100644
--- a/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java
+++ b/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java
@@ -19,22 +19,22 @@
package org.elasticsearch.indices;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import java.io.IOException;
/**
*
*/
-public class AliasFilterParsingException extends IndexException {
+public class AliasFilterParsingException extends ElasticsearchException {
public AliasFilterParsingException(Index index, String name, String desc, Throwable ex) {
- super(index, "[" + name + "], " + desc, ex);
+ super("[" + name + "], " + desc, ex);
+ setIndex(index);
}
-
public AliasFilterParsingException(StreamInput in) throws IOException{
super(in);
}
diff --git a/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java b/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java
index 5bd12bc3aa..9d6616e4e2 100644
--- a/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java
+++ b/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java
@@ -19,9 +19,9 @@
package org.elasticsearch.indices;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -29,14 +29,15 @@ import java.io.IOException;
/**
*
*/
-public class IndexAlreadyExistsException extends IndexException {
+public class IndexAlreadyExistsException extends ElasticsearchException {
public IndexAlreadyExistsException(Index index) {
this(index, "already exists");
}
public IndexAlreadyExistsException(Index index, String message) {
- super(index, message);
+ super(message);
+ setIndex(index);
}
public IndexAlreadyExistsException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java b/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java
index d522bf2c57..22425ddc46 100644
--- a/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java
+++ b/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java
@@ -19,9 +19,9 @@
package org.elasticsearch.indices;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -29,10 +29,11 @@ import java.io.IOException;
/**
* Exception indicating that one or more requested indices are closed.
*/
-public class IndexClosedException extends IndexException {
+public class IndexClosedException extends ElasticsearchException {
public IndexClosedException(Index index) {
- super(index, "closed");
+ super("closed");
+ setIndex(index);
}
public IndexClosedException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java b/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java
index e681376af0..09b6696e11 100644
--- a/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java
+++ b/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java
@@ -19,19 +19,20 @@
package org.elasticsearch.indices;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchWrapperException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import java.io.IOException;
/**
*/
-public class IndexCreationException extends IndexException implements ElasticsearchWrapperException {
+public class IndexCreationException extends ElasticsearchException implements ElasticsearchWrapperException {
public IndexCreationException(Index index, Throwable cause) {
- super(index, "failed to create index", cause);
+ super("failed to create index", cause);
+ setIndex(index);
}
public IndexCreationException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java b/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java
index 0dda08fe7f..b7dd3e68ce 100644
--- a/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java
+++ b/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java
@@ -19,9 +19,9 @@
package org.elasticsearch.indices;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -30,13 +30,14 @@ import java.io.IOException;
* Thrown when some action cannot be performed because the primary shard of
* some shard group in an index has not been allocated post api action.
*/
-public class IndexPrimaryShardNotAllocatedException extends IndexException {
+public class IndexPrimaryShardNotAllocatedException extends ElasticsearchException {
public IndexPrimaryShardNotAllocatedException(StreamInput in) throws IOException{
super(in);
}
public IndexPrimaryShardNotAllocatedException(Index index) {
- super(index, "primary not allocated post api");
+ super("primary not allocated post api");
+ setIndex(index);
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java
index 505b12aa40..912a1ded50 100644
--- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java
+++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java
@@ -270,12 +270,12 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService> i
}
/**
- * Returns an IndexService for the specified index if exists otherwise a {@link IndexMissingException} is thrown.
+ * Returns an IndexService for the specified index if exists otherwise a {@link IndexNotFoundException} is thrown.
*/
- public IndexService indexServiceSafe(String index) throws IndexMissingException {
+ public IndexService indexServiceSafe(String index) {
IndexService indexService = indexService(index);
if (indexService == null) {
- throw new IndexMissingException(new Index(index));
+ throw new IndexNotFoundException(index);
}
return indexService;
}
diff --git a/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java b/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java
index 179f6ca851..4e2c443ff4 100644
--- a/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java
+++ b/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java
@@ -19,9 +19,9 @@
package org.elasticsearch.indices;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -29,10 +29,11 @@ import java.io.IOException;
/**
*
*/
-public class InvalidAliasNameException extends IndexException {
+public class InvalidAliasNameException extends ElasticsearchException {
public InvalidAliasNameException(Index index, String name, String desc) {
- super(index, "Invalid alias name [" + name + "], " + desc);
+ super("Invalid alias name [{}], {}", name, desc);
+ setIndex(index);
}
public InvalidAliasNameException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java b/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java
index 468d158f38..163f4df26a 100644
--- a/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java
+++ b/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java
@@ -19,9 +19,9 @@
package org.elasticsearch.indices;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -29,10 +29,11 @@ import java.io.IOException;
/**
*
*/
-public class InvalidIndexNameException extends IndexException {
+public class InvalidIndexNameException extends ElasticsearchException {
public InvalidIndexNameException(Index index, String name, String desc) {
- super(index, "Invalid index name [" + name + "], " + desc);
+ super("Invalid index name [" + name + "], " + desc);
+ setIndex(index);
}
public InvalidIndexNameException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java b/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java
index ef4a1d6d8d..0a332dbaf1 100644
--- a/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java
+++ b/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java
@@ -19,9 +19,9 @@
package org.elasticsearch.indices;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@@ -30,10 +30,11 @@ import java.util.Arrays;
/**
*
*/
-public class TypeMissingException extends IndexException {
+public class TypeMissingException extends ElasticsearchException {
public TypeMissingException(Index index, String... types) {
- super(index, "type[" + Arrays.toString(types) + "] missing");
+ super("type[" + Arrays.toString(types) + "] missing");
+ setIndex(index);
}
public TypeMissingException(StreamInput in) throws IOException{
diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
index 0cc3c1d357..a1011e583d 100644
--- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
+++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
@@ -45,7 +45,6 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexShardAlreadyExistsException;
-import org.elasticsearch.index.IndexShardMissingException;
import org.elasticsearch.index.aliases.IndexAliasesService;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.mapper.DocumentMapper;
@@ -803,7 +802,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
if (indexService.hasShard(shardRouting.getId())) {
try {
indexService.removeShard(shardRouting.getId(), message);
- } catch (IndexShardMissingException e) {
+ } catch (ShardNotFoundException e) {
// the node got closed on us, ignore it
} catch (Throwable e1) {
logger.warn("[{}][{}] failed to remove shard after failure ([{}])", e1, shardRouting.getIndex(), shardRouting.getId(), message);
diff --git a/core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java b/core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java
index 054d9d5299..5cd034a153 100644
--- a/core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java
+++ b/core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java
@@ -38,14 +38,13 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.util.concurrent.CountDown;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexService;
-import org.elasticsearch.index.IndexShardMissingException;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.shard.IndexShard;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
+import org.elasticsearch.index.shard.ShardNotFoundException;
import org.elasticsearch.indices.IndexClosedException;
-import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.indices.IndicesLifecycle;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.threadpool.ThreadPool;
@@ -239,11 +238,11 @@ public class SyncedFlushService extends AbstractComponent {
if (index != null && index.state() == IndexMetaData.State.CLOSE) {
throw new IndexClosedException(shardId.index());
}
- throw new IndexMissingException(shardId.index());
+ throw new IndexNotFoundException(shardId.index().getName());
}
final IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id());
if (shardRoutingTable == null) {
- throw new IndexShardMissingException(shardId);
+ throw new ShardNotFoundException(shardId);
}
return shardRoutingTable;
}
@@ -429,7 +428,7 @@ public class SyncedFlushService extends AbstractComponent {
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
IndexShard indexShard = indexService.shardSafe(request.shardId().id());
if (indexShard.routingEntry().primary() == false) {
- throw new IndexShardException(request.shardId(), "expected a primary shard");
+ throw new IllegalStateException("[" + request.shardId() +"] expected a primary shard");
}
int opCount = indexShard.getOperationsCount();
logger.trace("{} in flight operations sampled at [{}]", request.shardId(), opCount);
diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java
index 508e52f359..69a55e03c9 100644
--- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java
+++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java
@@ -19,11 +19,11 @@
package org.elasticsearch.indices.recovery;
+import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchWrapperException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.ByteSizeValue;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
@@ -32,15 +32,16 @@ import java.util.Objects;
/**
*
*/
-public class RecoverFilesRecoveryException extends IndexShardException implements ElasticsearchWrapperException {
+public class RecoverFilesRecoveryException extends ElasticsearchException implements ElasticsearchWrapperException {
private final int numberOfFiles;
private final ByteSizeValue totalFilesSize;
public RecoverFilesRecoveryException(ShardId shardId, int numberOfFiles, ByteSizeValue totalFilesSize, Throwable cause) {
- super(shardId, "Failed to transfer [" + numberOfFiles + "] files with total size of [" + totalFilesSize + "]", cause);
+ super("Failed to transfer [{}] files with total size of [{}]", cause, numberOfFiles, totalFilesSize);
Objects.requireNonNull(totalFilesSize, "totalFilesSize must not be null");
+ setShard(shardId);
this.numberOfFiles = numberOfFiles;
this.totalFilesSize = totalFilesSize;
}
diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java
index 22bd433697..0388265e64 100644
--- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java
+++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java
@@ -43,13 +43,12 @@ import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.CancellableThreads;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
-import org.elasticsearch.index.IndexShardMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.engine.RecoveryEngineException;
import org.elasticsearch.index.mapper.MapperException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.shard.*;
import org.elasticsearch.index.store.Store;
-import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.indices.IndicesLifecycle;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.*;
@@ -231,7 +230,7 @@ public class RecoveryTarget extends AbstractComponent {
// here, we would add checks against exception that need to be retried (and not removeAndClean in this case)
- if (cause instanceof IllegalIndexShardStateException || cause instanceof IndexMissingException || cause instanceof IndexShardMissingException) {
+ if (cause instanceof IllegalIndexShardStateException || cause instanceof IndexNotFoundException || cause instanceof ShardNotFoundException) {
// if the target is not ready yet, retry
retryRecovery(recoveryStatus, "remote shard not ready", recoverySettings.retryDelayStateSync(), request);
return;
diff --git a/core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java b/core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java
index 6c4f1a2c28..7785337122 100644
--- a/core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java
+++ b/core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java
@@ -53,7 +53,6 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
-import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.snapshots.IndexShardRepository;
import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository;
@@ -336,7 +335,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent<Rep
ShardId shardId = new ShardId(index, i);
try {
indexShardRepository.delete(snapshotId, shardId);
- } catch (IndexShardException | SnapshotException ex) {
+ } catch (SnapshotException ex) {
logger.warn("[{}] failed to delete shard data for shard [{}]", ex, snapshotId, shardId);
}
}
diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java
deleted file mode 100644
index d6ac3042d2..0000000000
--- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java
+++ /dev/null
@@ -1,60 +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.rest.action.admin.indices.alias.delete;
-
-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;
-import java.util.Arrays;
-
-/**
- *
- */
-public class AliasesMissingException extends ElasticsearchException {
-
- private final String[] names;
-
- public AliasesMissingException(String... names) {
- super("aliases " + Arrays.toString(names) + " missing");
- this.names = names;
- }
-
- public String[] names() {
- return this.names;
- }
-
- @Override
- public RestStatus status() {
- return RestStatus.NOT_FOUND;
- }
-
- public AliasesMissingException(StreamInput in) throws IOException{
- super(in);
- names = in.readStringArray();
- }
-
- @Override
- public void writeTo(StreamOutput out) throws IOException {
- super.writeTo(out);
- out.writeStringArray(names);
- }
-}
diff --git a/core/src/main/java/org/elasticsearch/indices/IndexMissingException.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesNotFoundException.java
index 8b6d7735c9..6e183786df 100644
--- a/core/src/main/java/org/elasticsearch/indices/IndexMissingException.java
+++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesNotFoundException.java
@@ -16,31 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.elasticsearch.rest.action.admin.indices.alias.delete;
-package org.elasticsearch.indices;
-
+import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.index.Index;
-import org.elasticsearch.index.IndexException;
-import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
+import java.util.Arrays;
/**
*
*/
-public class IndexMissingException extends IndexException {
+public class AliasesNotFoundException extends ResourceNotFoundException {
- public IndexMissingException(Index index) {
- super(index, "no such index");
+ public AliasesNotFoundException(String... names) {
+ super("aliases " + Arrays.toString(names) + " missing");
+ this.setResources("aliases", names);
}
- public IndexMissingException(StreamInput in) throws IOException{
+ public AliasesNotFoundException(StreamInput in) throws IOException{
super(in);
}
-
- @Override
- public RestStatus status() {
- return RestStatus.NOT_FOUND;
- }
-} \ No newline at end of file
+}
diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java
index 3e9b40027f..3cfb6f6da6 100644
--- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java
+++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java
@@ -32,7 +32,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.index.Index;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.TypeMissingException;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestBuilderListener;
@@ -71,7 +71,7 @@ public class RestGetMappingAction extends BaseRestHandler {
if (indices.length != 0 && types.length != 0) {
return new BytesRestResponse(OK, builder.endObject());
} else if (indices.length != 0) {
- return new BytesRestResponse(channel, new IndexMissingException(new Index(indices[0])));
+ return new BytesRestResponse(channel, new IndexNotFoundException(indices[0]));
} else if (types.length != 0) {
return new BytesRestResponse(channel, new TypeMissingException(new Index("_all"), types[0]));
} else {
diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java
index d65225ba0d..84e29063dd 100644
--- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java
+++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java
@@ -21,8 +21,7 @@ package org.elasticsearch.snapshots;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.regex.Regex;
-import org.elasticsearch.index.Index;
-import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.index.IndexNotFoundException;
import java.util.HashSet;
import java.util.List;
@@ -75,7 +74,7 @@ public class SnapshotUtils {
if (indexOrPattern.isEmpty() || !Regex.isSimpleMatchPattern(indexOrPattern)) {
if (!availableIndices.contains(indexOrPattern)) {
if (!indicesOptions.ignoreUnavailable()) {
- throw new IndexMissingException(new Index(indexOrPattern));
+ throw new IndexNotFoundException(indexOrPattern);
} else {
if (result == null) {
// add all the previous ones...
@@ -111,7 +110,7 @@ public class SnapshotUtils {
}
}
if (!found && !indicesOptions.allowNoIndices()) {
- throw new IndexMissingException(new Index(indexOrPattern));
+ throw new IndexNotFoundException(indexOrPattern);
}
}
if (result == null) {