Rethrow original exception when it fails the engine during write operations

This commit is contained in:
Areek Zillur 2016-10-27 16:38:15 -04:00
parent 947a17ee37
commit 2f883fcb85
2 changed files with 10 additions and 8 deletions

View File

@ -411,8 +411,7 @@ public class InternalEngine extends Engine {
* Inspects exception thrown when executing index or delete operations
*
* @return failure if the failure is a document specific failure (e.g. analysis chain failure)
* @throws ElasticsearchException if the failure caused the engine to fail
* (e.g. out of disk, lucene tragic event)
* or throws Exception if the failure caused the engine to fail (e.g. out of disk, lucene tragic event)
*
* Note: pkg-private for testing
*/
@ -435,12 +434,16 @@ public class InternalEngine extends Engine {
if (isDocumentFailure) {
return failure;
} else {
ElasticsearchException exception = new ElasticsearchException(failure);
exception.setShard(shardId);
throw exception;
rethrow(failure);
return null;
}
}
@SuppressWarnings("unchecked")
static <T extends Throwable> void rethrow(Throwable t) throws T {
throw (T) t;
}
private boolean canOptimizeAddDocument(Index index) {
if (index.getAutoGeneratedIdTimestamp() != IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP) {
assert index.getAutoGeneratedIdTimestamp() >= 0 : "autoGeneratedIdTimestamp must be positive but was: "

View File

@ -2153,9 +2153,8 @@ public class InternalEngineTests extends ESTestCase {
try {
engine.checkIfDocumentFailureOrThrow(new Engine.Index(newUid("1"), doc), new CorruptIndexException("simulated environment failure", ""));
fail("expected exception to be thrown");
} catch (ElasticsearchException envirnomentException) {
assertThat(envirnomentException.getShardId(), equalTo(engine.shardId));
assertThat(envirnomentException.getCause().getMessage(), containsString("simulated environment failure"));
} catch (Exception envirnomentException) {
assertThat(envirnomentException.getMessage(), containsString("simulated environment failure"));
}
}