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

fix: Ensure intra-cluster InternalExceptions are propagated properly #58

Merged
merged 2 commits into from
Oct 15, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<guava-version>31.1-jre</guava-version>
<jackson-databind-version>2.13.4</jackson-databind-version>
<gson-version>2.9.1</gson-version>
<thrift-version>0.16.0</thrift-version>
<eclipse-collections-version>11.1.0</eclipse-collections-version>
<log4j2-version>2.19.0</log4j2-version>
<slf4j-version>1.7.36</slf4j-version>
Expand Down Expand Up @@ -516,6 +517,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<!-- override litelinks' version with latest -->
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>${thrift-version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
47 changes: 26 additions & 21 deletions src/main/java/com/ibm/watson/modelmesh/ModelMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,7 @@ static <T extends Throwable> T noStack(T exception) {
static final ApplierException QUEUE_BREACH_EXCEPTION = noStack(
new ApplierException("Model queue overload", null, RESOURCE_EXHAUSTED));

static boolean isExhausted(Exception e) {
static boolean isExhausted(Throwable e) {
return e instanceof ApplierException && RESOURCE_EXHAUSTED.equals(((ApplierException) e).getGrpcStatusCode());
}

Expand Down Expand Up @@ -3551,15 +3551,18 @@ protected Object invokeModel(final String modelId, final Method method, final Me
Object result = invokeRemote(runtimeClient, method, remoteMeth, modelId, args);
return method == null && externalReq ? updateWithModelCopyInfo(result, mr) : result;
} catch (Exception e) {
boolean callFailed = processRemoteInvocationException(e, modelId); // this may throw
final Throwable t = e instanceof InvocationTargetException ? e.getCause() : e;
final boolean callFailed = processRemoteInvocationException(t, modelId); // this may throw
if (callFailed) {
if (e instanceof ModelLoadException) {
loadFailureSeen = (ModelLoadException) e;
if (t instanceof ModelLoadException) {
loadFailureSeen = (ModelLoadException) t;
updateLocalModelRecordAfterRemoteLoadFailure(mr, loadFailureSeen);
} else if (e instanceof InternalException) {
internalFailureSeen = (InternalException) e;
} else if (isExhausted(e) && ++resExaustedCount >= MAX_RES_EXHAUSTED) {
throw e;
} else if (t instanceof InternalException) {
internalFailureSeen = (InternalException) t;
} else if (isExhausted(t) && ++resExaustedCount >= MAX_RES_EXHAUSTED) {
Throwables.throwIfInstanceOf(t, Error.class);
Throwables.throwIfInstanceOf(t, Exception.class);
throw new IllegalStateException(t); // should not happen
}
continue;
}
Expand Down Expand Up @@ -3717,16 +3720,19 @@ else if (mr.getInstanceIds().containsKey(instanceId)) {
Object result = invokeRemote(cacheMissClient, method, remoteMeth, modelId, args);
return method == null && externalReq ? updateWithModelCopyInfo(result, mr) : result;
} catch (Exception e) {
boolean callFailed = processRemoteInvocationException(e, modelId); // this may throw
final Throwable t = e instanceof InvocationTargetException ? e.getCause() : e;
final boolean callFailed = processRemoteInvocationException(t, modelId); // this may throw
//TODO handle "stale" case here
if (callFailed) {
if (e instanceof ModelLoadException) {
loadFailureSeen = (ModelLoadException) e;
if (t instanceof ModelLoadException) {
loadFailureSeen = (ModelLoadException) t;
updateLocalModelRecordAfterRemoteLoadFailure(mr, loadFailureSeen);
} else if (e instanceof InternalException) {
internalFailureSeen = (InternalException) e;
} else if (isExhausted(e) && ++resExaustedCount >= MAX_RES_EXHAUSTED) {
throw e;
} else if (t instanceof InternalException) {
internalFailureSeen = (InternalException) t;
} else if (isExhausted(t) && ++resExaustedCount >= MAX_RES_EXHAUSTED) {
Throwables.throwIfInstanceOf(t, Error.class);
Throwables.throwIfInstanceOf(t, Exception.class);
throw new IllegalStateException(t); // should not happen
}
// continue inner loop
if (++n >= MAX_ITERATIONS) {
Expand Down Expand Up @@ -4113,17 +4119,16 @@ static Map<String, String> ensureContextMapIsMutable(Map<String, String> context
}

/**
* @param e
* @param t
* @return true if remote call failed, false if call wasn't made (due to unavailability or
* indication that local attempt should be made)
* @throws TException
*/
protected boolean processRemoteInvocationException(Exception e, String modelId) throws TException {
if (e instanceof IllegalAccessException || e instanceof RuntimeException) {
protected boolean processRemoteInvocationException(Throwable t, String modelId) throws TException {
if (t instanceof IllegalAccessException || t instanceof RuntimeException) {
throw newInternalException(
"Unexpected exception while attempting remote invocation for model " + modelId, e);
"Unexpected exception while attempting remote invocation for model " + modelId, t);
} else {
Throwable t = e instanceof InvocationTargetException ? e.getCause() : e;
if (t.getCause() instanceof ServiceUnavailableException) {
return false;
} else if (t instanceof ModelNotHereException) {
Expand Down Expand Up @@ -4155,7 +4160,7 @@ protected boolean processRemoteInvocationException(Exception e, String modelId)
}
Throwables.throwIfInstanceOf(t, Error.class);
Throwables.throwIfInstanceOf(t, TException.class); // other app-defined exceptions or ModelNotFoundException
throw new IllegalStateException(e); // should not happen
throw new IllegalStateException(t); // should not happen
}
}

Expand Down
Loading