This is an automated email from the ASF dual-hosted git repository. tanxinyu pushed a commit to branch fix_schema_region_query_hang in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 4ab560b2064bb94a40a2390a4edfa4a2529602e4 Author: OneSizeFitQuorum <[email protected]> AuthorDate: Wed Jul 3 10:41:09 2024 +0800 fix Signed-off-by: OneSizeFitQuorum <[email protected]> --- .../consensus/ratis/ApplicationStateMachineProxy.java | 9 ++++++--- .../org/apache/iotdb/consensus/ratis/RatisConsensus.java | 2 +- .../java/org/apache/iotdb/consensus/ratis/utils/Utils.java | 14 +++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java index 178650bb893..e0e6b542dee 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java @@ -158,13 +158,13 @@ public class ApplicationStateMachineProxy extends BaseStateMachine { new ResponseMessage( new TSStatus(TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode()) .setMessage("internal error. statemachine throws a runtime exception: " + rte)); - if (Utils.stallApply()) { + if (Utils.stallApply(consensusGroupType)) { waitUntilSystemAllowApply(); } else { break; } } - } while (Utils.stallApply()); + } while (Utils.stallApply(consensusGroupType)); if (isLeader) { // only record time cost for data region in Performance Overview Dashboard @@ -183,7 +183,10 @@ public class ApplicationStateMachineProxy extends BaseStateMachine { private void waitUntilSystemAllowApply() { try { Retriable.attemptUntilTrue( - () -> !Utils.stallApply(), TimeDuration.ONE_MINUTE, "waitUntilSystemAllowApply", logger); + () -> !Utils.stallApply(consensusGroupType), + TimeDuration.ONE_MINUTE, + "waitUntilSystemAllowApply", + logger); } catch (InterruptedException e) { logger.warn("{}: interrupted when waiting until system ready: ", this, e); Thread.currentThread().interrupt(); diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java index 863f9c5ebed..9f65281e204 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java @@ -278,7 +278,7 @@ class RatisConsensus implements IConsensus { } // current Peer is group leader and in ReadOnly State - if (isLeader(groupId) && Utils.rejectWrite()) { + if (isLeader(groupId) && Utils.rejectWrite(consensusGroupType)) { try { forceStepDownLeader(raftGroup); } catch (Exception e) { diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/utils/Utils.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/utils/Utils.java index 6ce26f0a2df..7c84ed9a9e5 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/utils/Utils.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/utils/Utils.java @@ -210,18 +210,18 @@ public class Utils { return consensusGroupType; } - public static boolean rejectWrite() { - return config.isReadOnly(); + public static boolean rejectWrite(TConsensusGroupType type) { + return type == TConsensusGroupType.DataRegion && config.isReadOnly(); } /** * Normally, the RatisConsensus should reject write when system is read-only, i.e, {@link - * #rejectWrite()}. However, Ratis RaftServer close() will wait for applyIndex advancing to - * commitIndex. So when the system is shutting down, RatisConsensus should still allow - * statemachine to apply while rejecting new client write requests. + * #rejectWrite(TConsensusGroupType type)}. However, Ratis RaftServer close() will wait for + * applyIndex advancing to commitIndex. So when the system is shutting down, RatisConsensus should + * still allow statemachine to apply while rejecting new client write requests. */ - public static boolean stallApply() { - return config.isReadOnly() && !config.isStopping(); + public static boolean stallApply(TConsensusGroupType type) { + return type == TConsensusGroupType.DataRegion && config.isReadOnly() && !config.isStopping(); } /** return the max wait duration for retry */
