Skip to content

Commit

Permalink
rh客户端 发生 RemotingException 时,重试 (#1135)
Browse files Browse the repository at this point in the history
* fix: make rheakv client retry on RemotingException

---------

Co-authored-by: yuanyuan.liu <yuanyuan.liu@signalplus.com>
  • Loading branch information
shihuili1218 and yuanyuan.liu committed Aug 7, 2024
1 parent 38c0867 commit 4d53aa5
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 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 @@ -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
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.jraft.rhea.errors;

/**
* Rpc connection failure exception.
*/
public class ConnectionFailureException extends ApiException {
private static final long serialVersionUID = -5958618149334588246L;

public ConnectionFailureException() {
}

public ConnectionFailureException(String message) {
super(message);
}

public ConnectionFailureException(String message, Throwable cause) {
super(message, cause);
}

public ConnectionFailureException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
* Do not add exceptions that occur only on the client or only on the server here.
*/
public enum Errors {
UNKNOWN_SERVER_ERROR(-1, "The server experienced an unexpected error when processing the request",

UNKNOWN_SERVER_ERROR(-1, "The server experienced an unexpected error when processing the request.",
UnknownServerException::new),

NONE(0, null, message -> null),
Expand Down Expand Up @@ -64,13 +65,13 @@ public enum Errors {

INVALID_REGION_EPOCH(9, "Invalid region epoch (membership or version changed).", InvalidRegionEpochException::new),

INVALID_STORE_STATS(10, "Placement driver: invalid store stats", InvalidStoreStatsException::new),
INVALID_STORE_STATS(10, "Placement driver: invalid store stats.", InvalidStoreStatsException::new),

INVALID_REGION_STATS(11, "Placement driver: invalid region stats", InvalidStoreStatsException::new),
INVALID_REGION_STATS(11, "Placement driver: invalid region stats.", InvalidStoreStatsException::new),

STORE_HEARTBEAT_OUT_OF_DATE(12, "The store heartbeat info is out of date", StoreHeartbeatOutOfDateException::new),
STORE_HEARTBEAT_OUT_OF_DATE(12, "The store heartbeat info is out of date.", StoreHeartbeatOutOfDateException::new),

REGION_HEARTBEAT_OUT_OF_DATE(13, "The region heartbeat info is out of date", RegionHeartbeatOutOfDateException::new),
REGION_HEARTBEAT_OUT_OF_DATE(13, "The region heartbeat info is out of date.", RegionHeartbeatOutOfDateException::new),

CALL_SELF_ENDPOINT_ERROR(14, "The usual reason is that the rpc call selected the self endpoint.",
CallSelfEndpointException::new),
Expand All @@ -84,7 +85,10 @@ public enum Errors {
+ "The new region cannot be created.", RangeSplitFailException::new),

TOO_SMALL_TO_SPLIT(18, "The region size is too small to split. See the server logs for more details.",
RangeSplitFailException::new);
RangeSplitFailException::new),

RPC_CONNECTION_ERROR(19, "RPC connection disconnected.",
ConnectionFailureException::new);

private interface ApiExceptionBuilder {
ApiException build(final String message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +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_CONNECTION_ERROR //
|| error == Errors.LEADER_NOT_AVAILABLE;
}

Expand Down

0 comments on commit 4d53aa5

Please sign in to comment.