7311: Rework PeerTaskExecutor retry system to be 0-based

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
pull/7628/head
Matilda Clerke 2 months ago
parent 77ed7485af
commit 0896e31de7
  1. 14
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java

@ -34,9 +34,9 @@ import java.util.concurrent.TimeoutException;
/** Manages the execution of PeerTasks, respecting their PeerTaskRetryBehavior */ /** Manages the execution of PeerTasks, respecting their PeerTaskRetryBehavior */
public class PeerTaskExecutor { public class PeerTaskExecutor {
public static final int RETRIES_WITH_SAME_PEER = 3; public static final int RETRIES_WITH_SAME_PEER = 2;
public static final int RETRIES_WITH_OTHER_PEER = 3; public static final int RETRIES_WITH_OTHER_PEER = 2;
public static final int NO_RETRIES = 1; public static final int NO_RETRIES = 0;
private final PeerSelector peerSelector; private final PeerSelector peerSelector;
private final PeerTaskRequestSender requestSender; private final PeerTaskRequestSender requestSender;
private final EthScheduler ethScheduler; private final EthScheduler ethScheduler;
@ -61,7 +61,7 @@ public class PeerTaskExecutor {
public <T> PeerTaskExecutorResult<T> execute(final PeerTask<T> peerTask) { public <T> PeerTaskExecutorResult<T> execute(final PeerTask<T> peerTask) {
PeerTaskExecutorResult<T> executorResult; PeerTaskExecutorResult<T> executorResult;
int triesRemaining = int retriesRemaining =
peerTask.getPeerTaskRetryBehaviors().contains(PeerTaskRetryBehavior.RETRY_WITH_OTHER_PEERS) peerTask.getPeerTaskRetryBehaviors().contains(PeerTaskRetryBehavior.RETRY_WITH_OTHER_PEERS)
? RETRIES_WITH_OTHER_PEER ? RETRIES_WITH_OTHER_PEER
: NO_RETRIES; : NO_RETRIES;
@ -81,7 +81,7 @@ public class PeerTaskExecutor {
new PeerTaskExecutorResult<>( new PeerTaskExecutorResult<>(
Optional.empty(), PeerTaskExecutorResponseCode.NO_PEER_AVAILABLE); Optional.empty(), PeerTaskExecutorResponseCode.NO_PEER_AVAILABLE);
} }
} while (--triesRemaining > 0 } while (retriesRemaining-- > 0
&& executorResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS); && executorResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS);
return executorResult; return executorResult;
@ -96,7 +96,7 @@ public class PeerTaskExecutor {
final PeerTask<T> peerTask, final EthPeer peer) { final PeerTask<T> peerTask, final EthPeer peer) {
MessageData requestMessageData = peerTask.getRequestMessage(); MessageData requestMessageData = peerTask.getRequestMessage();
PeerTaskExecutorResult<T> executorResult; PeerTaskExecutorResult<T> executorResult;
int triesRemaining = int retriesRemaining =
peerTask.getPeerTaskRetryBehaviors().contains(PeerTaskRetryBehavior.RETRY_WITH_SAME_PEER) peerTask.getPeerTaskRetryBehaviors().contains(PeerTaskRetryBehavior.RETRY_WITH_SAME_PEER)
? RETRIES_WITH_SAME_PEER ? RETRIES_WITH_SAME_PEER
: NO_RETRIES; : NO_RETRIES;
@ -136,7 +136,7 @@ public class PeerTaskExecutor {
new PeerTaskExecutorResult<>( new PeerTaskExecutorResult<>(
Optional.empty(), PeerTaskExecutorResponseCode.INTERNAL_SERVER_ERROR); Optional.empty(), PeerTaskExecutorResponseCode.INTERNAL_SERVER_ERROR);
} }
} while (--triesRemaining > 0 } while (retriesRemaining-- > 0
&& executorResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS && executorResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS
&& executorResult.responseCode() != PeerTaskExecutorResponseCode.PEER_DISCONNECTED && executorResult.responseCode() != PeerTaskExecutorResponseCode.PEER_DISCONNECTED
&& sleepBetweenRetries()); && sleepBetweenRetries());

Loading…
Cancel
Save