Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport ShardRecoveryHandlerrefactorings to 1.x #8570

Merged
merged 4 commits into from Nov 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/org/elasticsearch/ExceptionsHelper.java
Expand Up @@ -19,11 +19,13 @@

package org.elasticsearch;

import org.apache.lucene.index.CorruptIndexException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.rest.RestStatus;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
Expand Down Expand Up @@ -161,6 +163,9 @@ public static <T extends Throwable> T useOrSupress(T first, T second) {
return first;
}

public static IOException unwrapCorruption(Throwable t) {
return (IOException) unwrap(t, CorruptIndexException.class);
}

public static <T extends Throwable> T unwrap(Throwable t, Class<T> clazz) {
if (t != null) {
Expand Down
Expand Up @@ -39,9 +39,19 @@ public final void run() {
onFailure(ex);
} catch (Throwable t) {
onFailure(t);
} finally {
onAfter();
}
}

/**
* This method is called in a finally block after successful execution
* or on a rejection.
*/
public void onAfter() {
// nothing by default
}

/**
* This method is invoked for all exception thrown by {@link #doRun()}
*/
Expand Down
Expand Up @@ -81,7 +81,12 @@ public void execute(Runnable command) {
if (command instanceof AbstractRunnable) {
// If we are an abstract runnable we can handle the rejection
// directly and don't need to rethrow it.
((AbstractRunnable)command).onRejection(ex);
try {
((AbstractRunnable) command).onRejection(ex);
} finally {
((AbstractRunnable) command).onAfter();

}
} else {
throw ex;
}
Expand Down