Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyuan.liu committed Aug 6, 2024
1 parent e6f0a6d commit 608b174
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alipay.remoting.exception.RemotingException;
import com.alipay.sofa.jraft.Status;
import com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure;
import com.alipay.sofa.jraft.rhea.client.pd.AbstractPlacementDriverClient;
Expand Down Expand Up @@ -139,7 +140,12 @@ public void complete(final Object result, final Throwable err) {
closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response));
}
} else {
closure.failure(err);
if (err instanceof RemotingException) {
closure.setError(Errors.RPC_CONNECTION_ERROR);
closure.run(new Status(-1, "RPC failed occur exception %s", err.getMessage()));
} else {
closure.failure(err);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alipay.remoting.exception.RemotingException;
import com.alipay.sofa.jraft.Status;
import com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure;
import com.alipay.sofa.jraft.rhea.client.failover.RetryRunner;
Expand Down Expand Up @@ -92,12 +91,7 @@ public void success(final T result) {

@Override
public void failure(final Throwable cause) {
if (cause instanceof RemotingException) {
setError(Errors.RPC_ERROR);
run(new Status(-1, "RPC failed occur exception %s", cause.getMessage()));
} else {
this.future.completeExceptionally(cause);
}
this.future.completeExceptionally(cause);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alipay.remoting.exception.RemotingException;
import com.alipay.sofa.jraft.Status;
import com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure;
import com.alipay.sofa.jraft.rhea.cmd.pd.BaseRequest;
Expand Down Expand Up @@ -110,7 +111,12 @@ public void complete(final Object result, final Throwable err) {
closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response));
}
} else {
closure.failure(err);
if (err instanceof RemotingException) {
closure.setError(Errors.RPC_CONNECTION_ERROR);
closure.run(new Status(-1, "RPC failed occur exception %s", err.getMessage()));
} else {
closure.failure(err);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* Do not add exceptions that occur only on the client or only on the server here.
*/
public enum Errors {
RPC_ERROR(-2, "Server unavailable (RPC connection disconnected).",
RPC_CONNECTION_ERROR(-2, "RPC connection disconnected.",
UnknownServerException::new),

UNKNOWN_SERVER_ERROR(-1, "The server experienced an unexpected error when processing the request.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static boolean isInvalidPeer(final Errors error) {
return error == Errors.CALL_SELF_ENDPOINT_ERROR //
|| error == Errors.NOT_LEADER //
|| error == Errors.NO_REGION_FOUND //
|| error == Errors.RPC_ERROR //
|| error == Errors.RPC_CONNECTION_ERROR //
|| error == Errors.LEADER_NOT_AVAILABLE;
}

Expand Down

0 comments on commit 608b174

Please sign in to comment.