Skip to content

Commit

Permalink
evaluate shouldRetry() first before testing if instanceof ServerConne…
Browse files Browse the repository at this point in the history
…ctionException, allowing for users to decide if certain ServerConnectionexceptions should be retried for transient connection issues by setting the appropriate value for QUERY-RETRY-ERROR-MESSAGE
  • Loading branch information
hansenmc committed Mar 28, 2022
1 parent fbf7279 commit 797a2ed
Show file tree
Hide file tree
Showing 2 changed files with 262 additions and 202 deletions.
18 changes: 7 additions & 11 deletions src/main/java/com/marklogic/developer/corb/AbstractTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected String[] invokeModule() throws CorbException {
try (Session session = newSession()) {

Request request = generateRequest(session);
//This is how the long running uris can be populated
//This is how the long-running uris can be populated
Thread.currentThread().setName(urisAsString(inputUris));

Thread.yield();// try to avoid thread starvation
Expand Down Expand Up @@ -280,7 +280,7 @@ protected XdmItem[] toXdmItems(String... inputUris) throws CorbException {
} catch (ParserConfigurationException ex) {
throw new CorbException("Unable to parse loader document", ex);
}
return docs.toArray(new XdmItem[docs.size()]);
return docs.toArray(new XdmItem[0]);
}

protected XdmItem toXdmItem(DocumentBuilder builder, String input) throws CorbException {
Expand Down Expand Up @@ -366,13 +366,9 @@ protected boolean shouldRetry(RequestPermissionException requestPermissionExcept
}

protected String[] handleRequestException(RequestException requestException) throws CorbException {

if (requestException instanceof ServerConnectionException) {
Thread.currentThread().setName(FAILED_URI_TOKEN + Thread.currentThread().getName());
throw wrapProcessException(requestException, inputUris);
} else if (shouldRetry(requestException)) {
if (shouldRetry(requestException)) {
return handleRetry(requestException);
} else if (failOnError) {
} else if (requestException instanceof ServerConnectionException || failOnError) {
Thread.currentThread().setName(FAILED_URI_TOKEN + Thread.currentThread().getName());
throw wrapProcessException(requestException, inputUris);
} else {
Expand All @@ -381,7 +377,7 @@ protected String[] handleRequestException(RequestException requestException) thr
String message = requestException.getMessage();
String errorMessage = message;
if (message != null && code != null) {
errorMessage = code + ":" + message;
errorMessage = code + ':' + message;
} else if (code != null) {
errorMessage = code;
}
Expand All @@ -398,7 +394,7 @@ protected String[] handleRetry(RequestException requestException) throws CorbExc
if (retryCount < getQueryRetryLimit()) {
retryCount++;

String errorCode = requestException instanceof QueryException ? ((QueryException)requestException).getCode() + ":" : "";
String errorCode = requestException instanceof QueryException ? ((QueryException)requestException).getCode() + ':' : "";
LOG.log(WARNING,
"Encountered {0} from MarkLogic Server. Retrying attempt {1} after {2} seconds..: {3}{4}{5}{6}",
new Object[]{exceptionName, retryCount, retryInterval, errorCode, requestException.getMessage(), AT_URI, urisAsString(inputUris)});
Expand Down Expand Up @@ -441,7 +437,7 @@ private String failOnErrorIsFalseMessage(final String name, final String... inpu
* @return
*/
protected String urisAsString(String... uris) {
return (uris == null | StringUtils.stringToBoolean(getProperty(Options.URIS_REDACTED)) ) ? "" : StringUtils.join(uris, ",");
return (uris == null || StringUtils.stringToBoolean(getProperty(Options.URIS_REDACTED)) ) ? "" : StringUtils.join(uris, ",");
}

protected abstract String processResult(ResultSequence seq) throws CorbException;
Expand Down
Loading

0 comments on commit 797a2ed

Please sign in to comment.