You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2026/08/25 06:20:36 UTC
(iotdb) branch rc/2.0.11 updated (97125202a54 -> 1d966303d41)
This is an automated email from the ASF dual-hosted git repository.
JackieTien97 pushed a change to branch rc/2.0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
from 97125202a54 [Subscription] Bound consensus prefetch memory usage (#18298)
new 321b52b1bf4 Fix table device recovery from schema snapshots (#18324)
new 97031cb6903 [Pipe] Fix TsFile rate limit accounting (#18344)
new 1b9cc22a5c1 Disable multi-node REMOVE statements (#18360)
new 1d966303d41 Remove Ratis region migration rate limiting (#18365)
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../IoTDBRemoveDataNodeNormalIT.java | 7 --
.../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 | 2 +-
.../consensus/ratis/RateLimitedGrpcFactory.java | 40 -----------
.../ratis/RateLimitedGrpcLogAppender.java | 76 --------------------
.../consensus/ratis/RateLimitedGrpcRpcType.java | 37 ----------
.../iotdb/consensus/ratis/RatisConsensus.java | 2 -
.../ratis/RateLimitedGrpcLogAppenderTest.java | 66 -----------------
.../protocol/airgap/IoTDBDataRegionAirGapSink.java | 2 +-
.../async/handler/PipeTransferTsFileHandler.java | 22 ++++--
.../thrift/sync/IoTDBDataRegionSyncSink.java | 12 ++--
.../db/queryengine/plan/parser/ASTVisitor.java | 3 +-
.../plan/relational/sql/parser/AstBuilder.java | 3 +-
.../impl/mem/snapshot/MemMTreeSnapshotUtil.java | 15 ++--
.../schemaRegion/SchemaRegionManagementTest.java | 38 ++++++++++
.../airgap/IoTDBDataRegionAirGapSinkTest.java | 17 ++++-
.../PipeTransferTsFileHandlerRateLimitTest.java | 83 ++++++++++++++++++++++
...est.java => RemoveNodeSingleNodeParseTest.java} | 27 +++----
...java => RemoveNodeSingleNodeStatementTest.java} | 25 ++++---
.../pipe/sink/protocol/IoTDBAirGapSink.java | 2 +-
.../pipe/sink/protocol/IoTDBSslSyncSink.java | 2 +-
.../db/relational/grammar/sql/RelationalSql.g4 | 2 +-
21 files changed, 206 insertions(+), 277 deletions(-)
delete mode 100644 iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcFactory.java
delete mode 100644 iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppender.java
delete mode 100644 iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcRpcType.java
delete mode 100644 iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppenderTest.java
create mode 100644 iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/handler/PipeTransferTsFileHandlerRateLimitTest.java
rename iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/parser/{RemoveDataNodeMultiNodeParseTest.java => RemoveNodeSingleNodeParseTest.java} (66%)
rename iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/{RemoveDataNodeMultiNodeStatementTest.java => RemoveNodeSingleNodeStatementTest.java} (70%)
(iotdb) 03/04: Disable multi-node REMOVE statements (#18360)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
JackieTien97 pushed a commit to branch rc/2.0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 1b9cc22a5c1f7294b08a1a61b34ed5ac5f0b5ff7
Author: Yongzao <yo...@apache.org>
AuthorDate: Thu Jul 30 16:00:04 2026 +0800
Disable multi-node REMOVE statements (#18360)
---
.../IoTDBRemoveDataNodeNormalIT.java | 7 ------
.../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 | 2 +-
.../db/queryengine/plan/parser/ASTVisitor.java | 3 +--
.../plan/relational/sql/parser/AstBuilder.java | 3 +--
...est.java => RemoveNodeSingleNodeParseTest.java} | 27 ++++++++++++----------
...java => RemoveNodeSingleNodeStatementTest.java} | 25 ++++++++++++--------
.../db/relational/grammar/sql/RelationalSql.g4 | 2 +-
7 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/removedatanode/IoTDBRemoveDataNodeNormalIT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/removedatanode/IoTDBRemoveDataNodeNormalIT.java
index bf0a6ce5527..01eae1fb25d 100644
--- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/removedatanode/IoTDBRemoveDataNodeNormalIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/removedatanode/IoTDBRemoveDataNodeNormalIT.java
@@ -157,13 +157,6 @@ public class IoTDBRemoveDataNodeNormalIT {
successTest(2, 3, 1, 4, 1, 2, true, SQLModel.TABLE_MODEL_SQL, ConsensusFactory.IOT_CONSENSUS);
}
- @Test
- public void success1C5DRemoveTwoDataNodesUseSQL() throws Exception {
- // Setup 1C5D, and remove 2D in a single "remove datanode a, b" statement; 3 DataNodes remain
- // which is enough to keep both the data (factor 2) and schema (factor 3) replicas.
- successTest(2, 3, 1, 5, 2, 2, true, SQLModel.TREE_MODEL_SQL, ConsensusFactory.IOT_CONSENSUS);
- }
-
// @Test
public void success1C4DIoTV2TestUseTableSQL() throws Exception {
// Setup 1C4D, and remove 1D, this test should success
diff --git a/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 b/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
index 5353535ad34..e2ae5144caf 100644
--- a/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
+++ b/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
@@ -598,7 +598,7 @@ verifyConnection
// ---- Remove DataNode
removeDataNode
- : REMOVE DATANODE dataNodeIds+=INTEGER_LITERAL (COMMA dataNodeIds+=INTEGER_LITERAL)*
+ : REMOVE DATANODE dataNodeId=INTEGER_LITERAL
;
// ---- Remove ConfigNode
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
index 6ddd95593a1..e1ef66774f9 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
@@ -4704,8 +4704,7 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
@Override
public Statement visitRemoveDataNode(IoTDBSqlParser.RemoveDataNodeContext ctx) {
- List<Integer> nodeIds =
- ctx.dataNodeIds.stream().map(token -> Integer.parseInt(token.getText())).collect(toList());
+ List<Integer> nodeIds = Collections.singletonList(Integer.parseInt(ctx.dataNodeId.getText()));
return new RemoveDataNodeStatement(nodeIds);
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
index 13ee006af76..7db81826ab6 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
@@ -1608,8 +1608,7 @@ public class AstBuilder extends RelationalSqlBaseVisitor<Node> {
@Override
public Node visitRemoveDataNodeStatement(RelationalSqlParser.RemoveDataNodeStatementContext ctx) {
- List<Integer> nodeIds =
- ctx.dataNodeIds.stream().map(token -> Integer.parseInt(token.getText())).collect(toList());
+ List<Integer> nodeIds = Collections.singletonList(Integer.parseInt(ctx.dataNodeId.getText()));
return new RemoveDataNode(nodeIds);
}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/parser/RemoveDataNodeMultiNodeParseTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/parser/RemoveNodeSingleNodeParseTest.java
similarity index 66%
rename from iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/parser/RemoveDataNodeMultiNodeParseTest.java
rename to iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/parser/RemoveNodeSingleNodeParseTest.java
index d71e4439045..ea67dcc48cf 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/parser/RemoveDataNodeMultiNodeParseTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/parser/RemoveNodeSingleNodeParseTest.java
@@ -20,22 +20,21 @@
package org.apache.iotdb.db.queryengine.plan.parser;
import org.apache.iotdb.db.queryengine.plan.statement.Statement;
+import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveConfigNodeStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveDataNodeStatement;
+import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.junit.Test;
import java.time.ZoneId;
-import java.util.Arrays;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-/**
- * Parsing tests for the tree-model SQL that lets REMOVE DATANODE remove multiple DataNodes in a
- * single statement.
- */
-public class RemoveDataNodeMultiNodeParseTest {
+/** Parsing tests for tree-model REMOVE DATANODE and REMOVE CONFIGNODE statements. */
+public class RemoveNodeSingleNodeParseTest {
private static Statement parse(String sql) {
return StatementGenerator.createStatement(sql, ZoneId.systemDefault());
@@ -49,11 +48,15 @@ public class RemoveDataNodeMultiNodeParseTest {
}
@Test
- public void testRemoveMultipleDataNodes() {
- Statement statement = parse("remove datanode 3, 4, 5");
- assertTrue(statement instanceof RemoveDataNodeStatement);
- RemoveDataNodeStatement removeDataNodeStatement = (RemoveDataNodeStatement) statement;
- assertEquals(3, removeDataNodeStatement.getNodeIds().size());
- assertTrue(removeDataNodeStatement.getNodeIds().containsAll(Arrays.asList(3, 4, 5)));
+ public void testRemoveSingleConfigNode() {
+ Statement statement = parse("remove confignode 3");
+ assertTrue(statement instanceof RemoveConfigNodeStatement);
+ assertEquals(3, ((RemoveConfigNodeStatement) statement).getNodeId().intValue());
+ }
+
+ @Test
+ public void testRejectRemovingMultipleNodes() {
+ assertThrows(ParseCancellationException.class, () -> parse("remove datanode 3, 4"));
+ assertThrows(ParseCancellationException.class, () -> parse("remove confignode 3, 4"));
}
}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/RemoveDataNodeMultiNodeStatementTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/RemoveNodeSingleNodeStatementTest.java
similarity index 70%
rename from iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/RemoveDataNodeMultiNodeStatementTest.java
rename to iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/RemoveNodeSingleNodeStatementTest.java
index 06a794f2bdb..105457c4fca 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/RemoveDataNodeMultiNodeStatementTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/RemoveNodeSingleNodeStatementTest.java
@@ -20,25 +20,24 @@
package org.apache.iotdb.db.queryengine.plan.relational.sql.parser;
import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Statement;
+import org.apache.iotdb.commons.queryengine.plan.relational.sql.parser.ParsingException;
import org.apache.iotdb.db.protocol.session.IClientSession;
import org.apache.iotdb.db.protocol.session.InternalClientSession;
+import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RemoveConfigNode;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RemoveDataNode;
import org.junit.Before;
import org.junit.Test;
import java.time.ZoneId;
-import java.util.Arrays;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-/**
- * Parsing tests for the table-model SQL that lets REMOVE DATANODE remove multiple DataNodes in a
- * single statement.
- */
-public class RemoveDataNodeMultiNodeStatementTest {
+/** Parsing tests for table-model REMOVE DATANODE and REMOVE CONFIGNODE statements. */
+public class RemoveNodeSingleNodeStatementTest {
private SqlParser sqlParser;
private IClientSession clientSession;
@@ -61,9 +60,15 @@ public class RemoveDataNodeMultiNodeStatementTest {
}
@Test
- public void testRemoveMultipleDataNodes() {
- Statement statement = parse("remove datanode 3, 4, 5");
- assertTrue(statement instanceof RemoveDataNode);
- assertEquals(Arrays.asList(3, 4, 5), ((RemoveDataNode) statement).getNodeIds());
+ public void testRemoveSingleConfigNode() {
+ Statement statement = parse("remove confignode 3");
+ assertTrue(statement instanceof RemoveConfigNode);
+ assertEquals(3, ((RemoveConfigNode) statement).getNodeId().intValue());
+ }
+
+ @Test
+ public void testRejectRemovingMultipleNodes() {
+ assertThrows(ParsingException.class, () -> parse("remove datanode 3, 4"));
+ assertThrows(ParsingException.class, () -> parse("remove confignode 3, 4"));
}
}
diff --git a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
index 6bebd2bc08e..e8e3c1937a7 100644
--- a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
+++ b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
@@ -660,7 +660,7 @@ removeRegionStatement
;
removeDataNodeStatement
- : REMOVE DATANODE dataNodeIds+=INTEGER_VALUE (',' dataNodeIds+=INTEGER_VALUE)*
+ : REMOVE DATANODE dataNodeId=INTEGER_VALUE
;
removeConfigNodeStatement
(iotdb) 04/04: Remove Ratis region migration rate limiting (#18365)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
JackieTien97 pushed a commit to branch rc/2.0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 1d966303d417cd41db49e2483c99134fc8458a7d
Author: Yongzao <yo...@apache.org>
AuthorDate: Fri Jul 31 09:47:54 2026 +0800
Remove Ratis region migration rate limiting (#18365)
---
.../consensus/ratis/RateLimitedGrpcFactory.java | 40 ------------
.../ratis/RateLimitedGrpcLogAppender.java | 76 ----------------------
.../consensus/ratis/RateLimitedGrpcRpcType.java | 37 -----------
.../iotdb/consensus/ratis/RatisConsensus.java | 2 -
.../ratis/RateLimitedGrpcLogAppenderTest.java | 66 -------------------
5 files changed, 221 deletions(-)
diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcFactory.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcFactory.java
deleted file mode 100644
index 1124d04b865..00000000000
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcFactory.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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 org.apache.iotdb.consensus.ratis;
-
-import org.apache.ratis.conf.Parameters;
-import org.apache.ratis.grpc.GrpcFactory;
-import org.apache.ratis.server.RaftServer;
-import org.apache.ratis.server.leader.FollowerInfo;
-import org.apache.ratis.server.leader.LeaderState;
-import org.apache.ratis.server.leader.LogAppender;
-
-class RateLimitedGrpcFactory extends GrpcFactory {
-
- RateLimitedGrpcFactory(Parameters parameters) {
- super(parameters);
- }
-
- @Override
- public LogAppender newLogAppender(
- RaftServer.Division server, LeaderState leaderState, FollowerInfo follower) {
- return new RateLimitedGrpcLogAppender(server, leaderState, follower);
- }
-}
diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppender.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppender.java
deleted file mode 100644
index 41830c85dc2..00000000000
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppender.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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 org.apache.iotdb.consensus.ratis;
-
-import org.apache.iotdb.commons.utils.RegionMigrationRateLimiter;
-
-import org.apache.ratis.grpc.server.GrpcLogAppender;
-import org.apache.ratis.proto.RaftProtos.FileChunkProto;
-import org.apache.ratis.proto.RaftProtos.InstallSnapshotRequestProto;
-import org.apache.ratis.server.RaftServer;
-import org.apache.ratis.server.leader.FollowerInfo;
-import org.apache.ratis.server.leader.LeaderState;
-import org.apache.ratis.statemachine.SnapshotInfo;
-
-import java.util.Iterator;
-
-class RateLimitedGrpcLogAppender extends GrpcLogAppender {
-
- private final RegionMigrationRateLimiter rateLimiter = RegionMigrationRateLimiter.getInstance();
-
- RateLimitedGrpcLogAppender(
- RaftServer.Division server, LeaderState leaderState, FollowerInfo follower) {
- super(server, leaderState, follower);
- }
-
- @Override
- public Iterable<InstallSnapshotRequestProto> newInstallSnapshotRequests(
- String requestId, SnapshotInfo snapshot) {
- final Iterable<InstallSnapshotRequestProto> requests =
- super.newInstallSnapshotRequests(requestId, snapshot);
- return () -> {
- final Iterator<InstallSnapshotRequestProto> iterator = requests.iterator();
- return new Iterator<InstallSnapshotRequestProto>() {
- @Override
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- @Override
- public InstallSnapshotRequestProto next() {
- final InstallSnapshotRequestProto request = iterator.next();
- rateLimiter.acquire(getSnapshotChunkDataSize(request));
- return request;
- }
- };
- };
- }
-
- static long getSnapshotChunkDataSize(InstallSnapshotRequestProto request) {
- if (!request.hasSnapshotChunk()) {
- return 0;
- }
-
- return request.getSnapshotChunk().getFileChunksList().stream()
- .map(FileChunkProto::getData)
- .mapToLong(data -> data == null ? 0 : data.size())
- .sum();
- }
-}
diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcRpcType.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcRpcType.java
deleted file mode 100644
index 391ec2faef6..00000000000
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcRpcType.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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 org.apache.iotdb.consensus.ratis;
-
-import org.apache.ratis.conf.Parameters;
-import org.apache.ratis.rpc.RpcFactory;
-import org.apache.ratis.rpc.RpcType;
-
-public class RateLimitedGrpcRpcType implements RpcType {
-
- @Override
- public String name() {
- return RateLimitedGrpcRpcType.class.getName();
- }
-
- @Override
- public RpcFactory newFactory(Parameters parameters) {
- return new RateLimitedGrpcFactory(parameters);
- }
-}
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 4cac559646f..b7369546e7c 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
@@ -56,7 +56,6 @@ import org.apache.iotdb.consensus.ratis.utils.Utils;
import org.apache.iotdb.rpc.TSStatusCode;
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
-import org.apache.ratis.RaftConfigKeys;
import org.apache.ratis.client.RaftClientRpc;
import org.apache.ratis.conf.Parameters;
import org.apache.ratis.conf.RaftProperties;
@@ -160,7 +159,6 @@ class RatisConsensus implements IConsensus {
this.storageDir = new File(config.getStorageDir());
RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(storageDir));
- RaftConfigKeys.Rpc.setType(properties, new RateLimitedGrpcRpcType());
GrpcConfigKeys.Server.setHost(properties, config.getThisNodeEndPoint().getIp());
GrpcConfigKeys.Server.setPort(properties, config.getThisNodeEndPoint().getPort());
diff --git a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppenderTest.java b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppenderTest.java
deleted file mode 100644
index 8b93bdcdd1a..00000000000
--- a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppenderTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 org.apache.iotdb.consensus.ratis;
-
-import org.apache.ratis.RaftConfigKeys;
-import org.apache.ratis.conf.Parameters;
-import org.apache.ratis.conf.RaftProperties;
-import org.apache.ratis.proto.RaftProtos.FileChunkProto;
-import org.apache.ratis.proto.RaftProtos.InstallSnapshotRequestProto;
-import org.apache.ratis.rpc.RpcType;
-import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class RateLimitedGrpcLogAppenderTest {
-
- @Test
- public void testGetSnapshotChunkDataSize() {
- final InstallSnapshotRequestProto request =
- InstallSnapshotRequestProto.newBuilder()
- .setSnapshotChunk(
- InstallSnapshotRequestProto.SnapshotChunkProto.newBuilder()
- .addFileChunks(
- FileChunkProto.newBuilder()
- .setData(ByteString.copyFrom(new byte[3]))
- .build())
- .addFileChunks(
- FileChunkProto.newBuilder()
- .setData(ByteString.copyFrom(new byte[5]))
- .build()))
- .build();
-
- Assert.assertEquals(8, RateLimitedGrpcLogAppender.getSnapshotChunkDataSize(request));
- Assert.assertEquals(
- 0,
- RateLimitedGrpcLogAppender.getSnapshotChunkDataSize(
- InstallSnapshotRequestProto.newBuilder().buildPartial()));
- }
-
- @Test
- public void testRateLimitedGrpcRpcTypeIsResolvedByRatis() {
- final RaftProperties properties = new RaftProperties();
-
- RaftConfigKeys.Rpc.setType(properties, new RateLimitedGrpcRpcType());
- final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, ignored -> {});
-
- Assert.assertTrue(rpcType instanceof RateLimitedGrpcRpcType);
- Assert.assertTrue(rpcType.newFactory(new Parameters()) instanceof RateLimitedGrpcFactory);
- }
-}
(iotdb) 02/04: [Pipe] Fix TsFile rate limit accounting (#18344)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
JackieTien97 pushed a commit to branch rc/2.0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 97031cb6903f4b91564b36e3ba901ce1ed50880b
Author: Caideyipi <87...@users.noreply.github.com>
AuthorDate: Wed Jul 29 14:48:43 2026 +0800
[Pipe] Fix TsFile rate limit accounting (#18344)
---
.../protocol/airgap/IoTDBDataRegionAirGapSink.java | 2 +-
.../async/handler/PipeTransferTsFileHandler.java | 22 ++++--
.../thrift/sync/IoTDBDataRegionSyncSink.java | 12 ++--
.../airgap/IoTDBDataRegionAirGapSinkTest.java | 17 ++++-
.../PipeTransferTsFileHandlerRateLimitTest.java | 83 ++++++++++++++++++++++
.../pipe/sink/protocol/IoTDBAirGapSink.java | 2 +-
.../pipe/sink/protocol/IoTDBSslSyncSink.java | 2 +-
7 files changed, 126 insertions(+), 14 deletions(-)
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSink.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSink.java
index 8689069334e..8eb941cad1d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSink.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSink.java
@@ -512,11 +512,11 @@ public class IoTDBDataRegionAirGapSink extends IoTDBDataNodeAirGapSink {
final byte[] readBuffer = new byte[readFileBufferSize];
long position = 0;
while (true) {
- mayLimitRateAndRecordIO(readFileBufferSize);
final int readLength = reader.read(readBuffer);
if (readLength == -1) {
break;
}
+ mayLimitRateAndRecordIO(readLength);
final byte[] payload =
readLength == readFileBufferSize
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/handler/PipeTransferTsFileHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/handler/PipeTransferTsFileHandler.java
index 4c25d03de53..16ffd0976ec 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/handler/PipeTransferTsFileHandler.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/handler/PipeTransferTsFileHandler.java
@@ -176,11 +176,7 @@ public class PipeTransferTsFileHandler extends PipeTransferTrackableHandler {
client.setShouldReturnSelf(false);
client.setTimeoutDynamically(clientManager.getConnectionTimeout());
- PipeResourceMetrics.getInstance().recordDiskIO(readFileBufferSize);
- if (sink.isEnableSendTsFileLimit()) {
- TsFileSendRateLimiter.getInstance().acquire(readFileBufferSize);
- }
- final int readLength = reader.read(readBuffer);
+ final int readLength = readNextFilePiece(reader, readBuffer);
if (readLength == -1) {
if (currentFile == modFile) {
@@ -250,6 +246,22 @@ public class PipeTransferTsFileHandler extends PipeTransferTrackableHandler {
position += readLength;
}
+ protected int readNextFilePiece(final RandomAccessFile reader, final byte[] readBuffer)
+ throws IOException {
+ final int readLength = reader.read(readBuffer);
+ if (readLength != -1) {
+ mayLimitRateAndRecordIO(readLength);
+ }
+ return readLength;
+ }
+
+ protected void mayLimitRateAndRecordIO(final long requiredBytes) {
+ PipeResourceMetrics.getInstance().recordDiskIO(requiredBytes);
+ if (sink.isEnableSendTsFileLimit()) {
+ TsFileSendRateLimiter.getInstance().acquire(requiredBytes);
+ }
+ }
+
@Override
public void onComplete(final TPipeTransferResp response) {
try {
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/sync/IoTDBDataRegionSyncSink.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/sync/IoTDBDataRegionSyncSink.java
index d13b9664f8a..6d205c36c65 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/sync/IoTDBDataRegionSyncSink.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/sync/IoTDBDataRegionSyncSink.java
@@ -630,7 +630,7 @@ public class IoTDBDataRegionSyncSink extends IoTDBDataNodeSyncSink {
final byte[] readBuffer = new byte[readFileBufferSize];
long position = 0;
int readLength;
- while ((readLength = readNextFilePiece(reader, readBuffer, readFileBufferSize)) != -1) {
+ while ((readLength = readNextFilePiece(reader, readBuffer)) != -1) {
position =
transferFilePiece(
pipe2WeightMap,
@@ -645,11 +645,13 @@ public class IoTDBDataRegionSyncSink extends IoTDBDataNodeSyncSink {
}
}
- private int readNextFilePiece(
- final RandomAccessFile reader, final byte[] readBuffer, final int readFileBufferSize)
+ private int readNextFilePiece(final RandomAccessFile reader, final byte[] readBuffer)
throws IOException {
- mayLimitRateAndRecordIO(readFileBufferSize);
- return reader.read(readBuffer);
+ final int readLength = reader.read(readBuffer);
+ if (readLength != -1) {
+ mayLimitRateAndRecordIO(readLength);
+ }
+ return readLength;
}
private long transferFilePiece(
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSinkTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSinkTest.java
index d49ef82ce05..1e6f3f865c1 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSinkTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSinkTest.java
@@ -27,6 +27,7 @@ import org.apache.iotdb.commons.pipe.sink.payload.thrift.request.PipeRequestType
import org.apache.iotdb.db.pipe.event.common.heartbeat.PipeHeartbeatEvent;
import org.apache.iotdb.db.pipe.event.common.tablet.PipeRawTabletInsertionEvent;
import org.apache.iotdb.db.pipe.sink.payload.evolvable.request.PipeTransferTabletBatchReqV2;
+import org.apache.iotdb.db.pipe.sink.payload.evolvable.request.PipeTransferTsFilePieceReq;
import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
import org.apache.iotdb.service.rpc.thrift.TPipeTransferReq;
@@ -45,6 +46,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
public class IoTDBDataRegionAirGapSinkTest {
@@ -92,8 +94,14 @@ public class IoTDBDataRegionAirGapSinkTest {
sink.transfer(new PipeHeartbeatEvent(-1, false));
final List<Short> requestTypes = new ArrayList<>();
+ long transferredTsFileBytes = 0;
for (final byte[] requestBytes : sink.sentRequests) {
- requestTypes.add(toTPipeTransferReq(requestBytes).type);
+ final TPipeTransferReq req = toTPipeTransferReq(requestBytes);
+ requestTypes.add(req.type);
+ if (req.type == PipeRequestType.TRANSFER_TS_FILE_PIECE.getType()) {
+ transferredTsFileBytes +=
+ PipeTransferTsFilePieceReq.fromTPipeTransferReq(req).getFilePiece().length;
+ }
}
Assert.assertTrue(requestTypes.contains(PipeRequestType.TRANSFER_TS_FILE_PIECE.getType()));
@@ -101,6 +109,7 @@ public class IoTDBDataRegionAirGapSinkTest {
requestTypes.contains(PipeRequestType.TRANSFER_TS_FILE_SEAL_WITH_MOD.getType()));
Assert.assertFalse(requestTypes.contains(PipeRequestType.TRANSFER_TABLET_RAW_V2.getType()));
Assert.assertFalse(requestTypes.contains(PipeRequestType.TRANSFER_TABLET_BATCH_V2.getType()));
+ Assert.assertEquals(transferredTsFileBytes, sink.rateLimitedBytes.get());
}
}
@@ -152,6 +161,7 @@ public class IoTDBDataRegionAirGapSinkTest {
private static class RecordingIoTDBDataRegionAirGapSink extends IoTDBDataRegionAirGapSink {
private final List<byte[]> sentRequests = new ArrayList<>();
+ private final AtomicLong rateLimitedBytes = new AtomicLong(0);
private void prepareSocket() {
sockets.set(0, new TestingAirGapSocket());
@@ -168,6 +178,11 @@ public class IoTDBDataRegionAirGapSinkTest {
return true;
}
+ @Override
+ protected void mayLimitRateAndRecordIO(final long requiredBytes) {
+ rateLimitedBytes.addAndGet(requiredBytes);
+ }
+
private static class TestingAirGapSocket extends AirGapSocket {
private TestingAirGapSocket() {
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/handler/PipeTransferTsFileHandlerRateLimitTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/handler/PipeTransferTsFileHandlerRateLimitTest.java
new file mode 100644
index 00000000000..55cfbcbd28d
--- /dev/null
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/handler/PipeTransferTsFileHandlerRateLimitTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.iotdb.db.pipe.sink.protocol.thrift.async.handler;
+
+import org.apache.iotdb.db.pipe.sink.protocol.thrift.async.IoTDBDataRegionAsyncSink;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.io.File;
+import java.io.RandomAccessFile;
+import java.nio.file.Files;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class PipeTransferTsFileHandlerRateLimitTest {
+
+ @Test
+ public void testRateLimitUsesActualReadLengthAndSkipsEndOfFile() throws Exception {
+ final File file = Files.createTempFile("pipe-transfer-rate-limit", ".tsfile").toFile();
+ Files.write(file.toPath(), new byte[7]);
+
+ final RecordingPipeTransferTsFileHandler handler = new RecordingPipeTransferTsFileHandler(file);
+ try (final RandomAccessFile reader = new RandomAccessFile(file, "r")) {
+ final byte[] readBuffer = new byte[4];
+
+ Assert.assertEquals(4, handler.readNextFilePiece(reader, readBuffer));
+ Assert.assertEquals(3, handler.readNextFilePiece(reader, readBuffer));
+ Assert.assertEquals(-1, handler.readNextFilePiece(reader, readBuffer));
+
+ Assert.assertEquals(file.length(), handler.rateLimitedBytes.get());
+ Assert.assertEquals(2, handler.rateLimitInvocationCount.get());
+ } finally {
+ handler.close();
+ Assert.assertTrue(file.delete());
+ }
+ }
+
+ private static class RecordingPipeTransferTsFileHandler extends PipeTransferTsFileHandler {
+
+ private final AtomicLong rateLimitedBytes = new AtomicLong(0);
+ private final AtomicInteger rateLimitInvocationCount = new AtomicInteger(0);
+
+ private RecordingPipeTransferTsFileHandler(final File file) throws InterruptedException {
+ super(
+ Mockito.mock(IoTDBDataRegionAsyncSink.class),
+ Collections.emptyMap(),
+ Collections.emptyList(),
+ new AtomicInteger(1),
+ new AtomicBoolean(false),
+ file,
+ null,
+ false,
+ null);
+ }
+
+ @Override
+ protected void mayLimitRateAndRecordIO(final long requiredBytes) {
+ rateLimitedBytes.addAndGet(requiredBytes);
+ rateLimitInvocationCount.incrementAndGet();
+ }
+ }
+}
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBAirGapSink.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBAirGapSink.java
index 8bcca0315f4..6919b3b87ce 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBAirGapSink.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBAirGapSink.java
@@ -259,11 +259,11 @@ public abstract class IoTDBAirGapSink extends IoTDBSink {
long position = 0;
try (final RandomAccessFile reader = new RandomAccessFile(file, "r")) {
while (true) {
- mayLimitRateAndRecordIO(readFileBufferSize);
final int readLength = reader.read(readBuffer);
if (readLength == -1) {
break;
}
+ mayLimitRateAndRecordIO(readLength);
final byte[] payload =
readLength == readFileBufferSize
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBSslSyncSink.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBSslSyncSink.java
index a045082b24e..4595a0448ea 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBSslSyncSink.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBSslSyncSink.java
@@ -286,11 +286,11 @@ public abstract class IoTDBSslSyncSink extends IoTDBSink {
long position = 0;
try (final RandomAccessFile reader = new RandomAccessFile(file, "r")) {
while (true) {
- mayLimitRateAndRecordIO(readFileBufferSize);
final int readLength = reader.read(readBuffer);
if (readLength == -1) {
break;
}
+ mayLimitRateAndRecordIO(readLength);
final byte[] payLoad =
readLength == readFileBufferSize
(iotdb) 01/04: Fix table device recovery from schema snapshots (#18324)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
JackieTien97 pushed a commit to branch rc/2.0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 321b52b1bf41079a89e310543e0611e6e2133b27
Author: Caideyipi <87...@users.noreply.github.com>
AuthorDate: Wed Jul 29 10:02:33 2026 +0800
Fix table device recovery from schema snapshots (#18324)
---
.../impl/mem/snapshot/MemMTreeSnapshotUtil.java | 15 +++++----
.../schemaRegion/SchemaRegionManagementTest.java | 38 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/snapshot/MemMTreeSnapshotUtil.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/snapshot/MemMTreeSnapshotUtil.java
index 9589951c36e..96933bdcae1 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/snapshot/MemMTreeSnapshotUtil.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/snapshot/MemMTreeSnapshotUtil.java
@@ -246,9 +246,6 @@ public class MemMTreeSnapshotUtil {
case INTERNAL_MNODE_TYPE:
childrenNum = ReadWriteIOUtils.readInt(inputStream);
node = deserializer.deserializeInternalMNode(inputStream);
- if (ancestors.size() == 1) {
- currentTableName.set(node.getName());
- }
break;
case DATABASE_MNODE_TYPE:
childrenNum = ReadWriteIOUtils.readInt(inputStream);
@@ -277,16 +274,20 @@ public class MemMTreeSnapshotUtil {
case TABLE_MNODE_TYPE:
childrenNum = ReadWriteIOUtils.readInt(inputStream);
node = deserializer.deserializeTableDeviceMNode(inputStream);
- if (ancestors.size() == 1) {
- currentTableName.set(node.getName());
- }
deviceProcess.accept(node.getAsDeviceMNode());
- tableDeviceProcess.accept(node.getAsDeviceMNode(), currentTableName.get());
break;
default:
throw new IOException(DataNodeSchemaMessages.UNRECOGNIZED_MNODE_TYPE + type);
}
+ // The table-name node may also be a tree-model device in legacy mixed-model metadata.
+ if (ancestors.size() == 1) {
+ currentTableName.set(node.getName());
+ }
+ if (type == TABLE_MNODE_TYPE) {
+ tableDeviceProcess.accept(node.getAsDeviceMNode(), currentTableName.get());
+ }
+
regionStatistics.requestMemory(node.estimateSize());
if (!ancestors.isEmpty()) {
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
index 0c0b3a5b953..1bbb17bca4a 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
@@ -140,6 +140,44 @@ public class SchemaRegionManagementTest extends AbstractSchemaRegionTest {
}
}
+ @Test
+ public void testLoadSnapshotWithTableDeviceBelowTopLevelTreeDevice() throws Exception {
+ if (!testParams.getTestModeName().equals("MemoryMode")) {
+ return;
+ }
+
+ final String schemaRegionConsensusProtocolClass =
+ config.getSchemaRegionConsensusProtocolClass();
+ config.setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS);
+ try {
+ final ISchemaRegion schemaRegion = getSchemaRegion("root.sg", 0);
+
+ // Build a mixed-model tree where the table-name node is also a tree-model device.
+ schemaRegion.createTimeSeries(
+ SchemaRegionWritePlanFactory.getCreateTimeSeriesPlan(
+ new MeasurementPath("root.sg.t.s1"),
+ TSDataType.INT32,
+ TSEncoding.PLAIN,
+ CompressionType.UNCOMPRESSED,
+ null,
+ null,
+ null,
+ null),
+ -1);
+ SchemaRegionTestUtil.createTableDevice(
+ schemaRegion, "t", new String[] {"d1"}, Collections.emptyMap());
+
+ final File snapshotDir = new File(config.getSchemaDir() + File.separator + "snapshot");
+ Assert.assertTrue(snapshotDir.mkdir());
+ Assert.assertTrue(schemaRegion.createSnapshot(snapshotDir));
+
+ Assert.assertTrue(schemaRegion.loadSnapshot(snapshotDir));
+ Assert.assertEquals(1, schemaRegion.getSchemaRegionStatistics().getTableDevicesNumber("t"));
+ } finally {
+ config.setSchemaRegionConsensusProtocolClass(schemaRegionConsensusProtocolClass);
+ }
+ }
+
private Template generateTemplate() throws IllegalPathException {
Template template =
new Template(