From a9918f2332277bd211bf959a55e1b6c4c1357fea Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Sun, 19 Apr 2020 09:25:28 +0800 Subject: [PATCH] refactor: request forwarding logic adjustment --- .../server/filter/TransferToLeaderFilter.java | 4 +- .../consistency/ConsistencyProtocol.java | 2 +- .../nacos/consistency/ProtocolMetaData.java | 9 -- .../src/main/resources/application.properties | 30 +++---- .../lookup/AddressServerMemberLookup.java | 4 +- .../cluster/lookup/DiscoveryMemberLookup.java | 2 +- .../id/SnakeFlowerIdGenerator.java | 86 +++++++++++-------- .../core/distributed/raft/JRaftServer.java | 2 + 8 files changed, 72 insertions(+), 67 deletions(-) diff --git a/config/src/main/java/com/alibaba/nacos/config/server/filter/TransferToLeaderFilter.java b/config/src/main/java/com/alibaba/nacos/config/server/filter/TransferToLeaderFilter.java index ce944634d..98d34704b 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/filter/TransferToLeaderFilter.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/filter/TransferToLeaderFilter.java @@ -135,7 +135,9 @@ public class TransferToLeaderFilter implements Filter { String val = req.getHeader(Constants.FORWARD_LEADER); final int transferCnt = Integer.parseInt(StringUtils.isEmpty(val) ? "0" : val) + 1; - if (transferCnt > MAX_TRANSFER_CNT) { + + // Requests can only be forwarded once if a downgrade is not triggered + if (transferCnt > MAX_TRANSFER_CNT && !downgrading) { resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Exceeded forwarding times:" + req.getMethod() + ":" + req.getRequestURI()); return; diff --git a/consistency/src/main/java/com/alibaba/nacos/consistency/ConsistencyProtocol.java b/consistency/src/main/java/com/alibaba/nacos/consistency/ConsistencyProtocol.java index e18bdf697..a199c9637 100644 --- a/consistency/src/main/java/com/alibaba/nacos/consistency/ConsistencyProtocol.java +++ b/consistency/src/main/java/com/alibaba/nacos/consistency/ConsistencyProtocol.java @@ -26,7 +26,7 @@ import java.util.concurrent.CompletableFuture; /** * Has nothing to do with the specific implementation of the consistency protocol - * Initialization sequence: init(Config) => loadLogProcessor(List) + * Initialization sequence: init(Config) * *