Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ public static boolean isRetriableWithNoFailoverException(Exception e) {
*/
public static boolean checkRetriableWithNoFailoverException(Exception e) {
Throwable t = unwrapException(e);
return RetriableWithNoFailoverException.class.isInstance(t);
// RemoteException cannot be unwrapped to this exception (no String constructor), so also match the class name.
Comment thread
smengcl marked this conversation as resolved.
Outdated
return t instanceof RetriableWithNoFailoverException || (t instanceof RemoteException
&& RetriableWithNoFailoverException.class.getName().equals(((RemoteException) t).getClassName()));
}

public static Throwable getNotLeaderException(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.google.protobuf.ServiceException;
import java.io.IOException;
import java.util.Collection;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ha.RetriableWithNoFailoverException;
import org.apache.hadoop.hdds.scm.ha.SCMHAUtils;
import org.apache.hadoop.io.retry.RetryPolicy.RetryAction;
import org.apache.hadoop.io.retry.RetryPolicy.RetryAction.RetryDecision;
import org.apache.hadoop.ipc_.RemoteException;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -51,4 +57,20 @@ void testRemoveSelfId() {
assertEquals(2, nodesWithoutSelf.size());
assertThat(nodesWithoutSelf).doesNotContain(selfId);
}

@Test
void retriesSameScmOnRetriableWithNoFailoverException() {
Exception e = new ServiceException(new RemoteException(RetriableWithNoFailoverException.class.getName(),
"SCM leader is not ready"));
assertThat(SCMHAUtils.checkRetriableWithNoFailoverException(e)).isTrue();
RetryAction action = SCMHAUtils.getRetryAction(0, 0, e, 15, 2000);
assertEquals(RetryDecision.RETRY, action.action);
assertEquals(2000, action.delayMillis);
// Fails after max retries
assertEquals(RetryDecision.FAIL, SCMHAUtils.getRetryAction(0, 15, e, 15, 2000).action);

// Other exceptions are not matched
Exception other = new ServiceException(new RemoteException(IOException.class.getName(), "error"));
assertThat(SCMHAUtils.checkRetriableWithNoFailoverException(other)).isFalse();
}
}