-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retry mechanism for neural search inference (#91)
Add basic retry mechanism for neural search inference Signed-off-by: Zan Niu <[email protected]> (cherry picked from commit b207176)
- Loading branch information
1 parent
0e03e3e
commit 97f587e
Showing
4 changed files
with
134 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/org/opensearch/neuralsearch/util/RetryUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.util; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.opensearch.transport.NodeDisconnectedException; | ||
import org.opensearch.transport.NodeNotConnectedException; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
public class RetryUtil { | ||
|
||
private static final int MAX_RETRY = 3; | ||
|
||
private static final List<Class<? extends Throwable>> RETRYABLE_EXCEPTIONS = ImmutableList.of( | ||
NodeNotConnectedException.class, | ||
NodeDisconnectedException.class | ||
); | ||
|
||
/** | ||
* | ||
* @param e {@link Exception} which is the exception received to check if retryable. | ||
* @param retryTime {@link int} which is the current retried times. | ||
* @return {@link boolean} which is the result of if current exception needs retry or not. | ||
*/ | ||
public static boolean shouldRetry(final Exception e, int retryTime) { | ||
boolean hasRetryException = RETRYABLE_EXCEPTIONS.stream().anyMatch(x -> ExceptionUtils.indexOfThrowable(e, x) != -1); | ||
return hasRetryException && retryTime < MAX_RETRY; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters