This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 144d5957876 Fix schema query stuck when system is readonly #12842
144d5957876 is described below
commit 144d595787699242dc60d1a595826cc21083f045
Author: Potato <[email protected]>
AuthorDate: Wed Jul 3 15:37:00 2024 +0800
Fix schema query stuck when system is readonly #12842
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 */