summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/index
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/elasticsearch/index
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/elasticsearch/index')
-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/IndexShardMissingException.java46
-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
19 files changed, 105 insertions, 276 deletions
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/IndexShardMissingException.java b/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java
deleted file mode 100644
index 6b356ee685..0000000000
--- a/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java
+++ /dev/null
@@ -1,46 +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.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;
-
-/**
- *
- */
-public class IndexShardMissingException extends IndexShardException {
-
- public IndexShardMissingException(ShardId shardId) {
- super(shardId, "missing");
- }
-
- public IndexShardMissingException(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/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{