From fc2e2c35cfa0933a18b4dc3a87d029c89f361742 Mon Sep 17 00:00:00 2001 From: Peng Junzhi <201250214@smail.nju.edu.cn> Date: Wed, 25 Nov 2026 12:40:51 +0800 Subject: [PATCH 1/4] Make IoTConsensusV2 the default DataRegion consensus protocol --- integration-test/pom.xml | 4 +- .../env/cluster/node/ConfigNodeWrapper.java | 3 +- .../it/env/cluster/node/DataNodeWrapper.java | 3 +- .../it/env/remote/env/RemoteServerEnv.java | 6 + .../org/apache/iotdb/itbase/env/BaseEnv.java | 11 ++ ...gionMigrateWithDeletionMultiDataDirIT.java | 32 +++-- ...igrateWithDeletionMultiDataDirTableIT.java | 32 +++-- .../it/utils/ConfigNodeTestUtils.java | 4 +- .../iotdb/db/it/GrafanaApiServiceIT.java | 20 ++- .../iotdb/db/it/IoTDBRestServiceIT.java | 128 ++++++++---------- .../iotdb/edge/it/IoTDBEdgeBasicIT.java | 2 +- .../confignode/conf/ConfigNodeConfig.java | 2 +- .../org/apache/iotdb/db/conf/IoTDBConfig.java | 2 +- .../dataregion/DataExecutionVisitor.java | 16 +++ .../processor/PipeProcessorSubtask.java | 4 +- ...HistoricalDeletionProgressReportEvent.java | 32 +++++ .../dataregion/IoTDBDataRegionSource.java | 6 + ...icalDataRegionTsFileAndDeletionSource.java | 35 ++++- .../storageengine/dataregion/DataRegion.java | 13 ++ .../conf/iotdb-system.properties.template | 2 +- 20 files changed, 248 insertions(+), 109 deletions(-) create mode 100644 iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/deletion/HistoricalDeletionProgressReportEvent.java diff --git a/integration-test/pom.xml b/integration-test/pom.xml index ac33138e0811e..7a6b63dcf936b 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -58,14 +58,14 @@ Ratis 1 1 - IoT + IoTV2 1 Ratis 1 Ratis 1 3 - IoT + IoTV2 2 Ratis 3 diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/ConfigNodeWrapper.java b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/ConfigNodeWrapper.java index 0f344364eba66..8cb02f33a7b28 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/ConfigNodeWrapper.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/ConfigNodeWrapper.java @@ -30,6 +30,7 @@ import java.util.Arrays; import java.util.List; +import static org.apache.iotdb.consensus.ConsensusFactory.IOT_CONSENSUS_V2; import static org.apache.iotdb.consensus.ConsensusFactory.SIMPLE_CONSENSUS; import static org.apache.iotdb.it.env.cluster.ClusterConstant.CN_CONNECTION_TIMEOUT_MS; import static org.apache.iotdb.it.env.cluster.ClusterConstant.CN_CONSENSUS_DIR; @@ -167,7 +168,7 @@ String getNodeType() { protected void reloadMutableFields() { mutableCommonProperties.setProperty(CONFIG_NODE_CONSENSUS_PROTOCOL_CLASS, SIMPLE_CONSENSUS); mutableCommonProperties.setProperty(SCHEMA_REGION_CONSENSUS_PROTOCOL_CLASS, SIMPLE_CONSENSUS); - mutableCommonProperties.setProperty(DATA_REGION_CONSENSUS_PROTOCOL_CLASS, SIMPLE_CONSENSUS); + mutableCommonProperties.setProperty(DATA_REGION_CONSENSUS_PROTOCOL_CLASS, IOT_CONSENSUS_V2); mutableCommonProperties.setProperty(SCHEMA_REPLICATION_FACTOR, "1"); mutableCommonProperties.setProperty(DATA_REPLICATION_FACTOR, "1"); diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java index d205044bd5290..4537e6515116b 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.List; +import static org.apache.iotdb.consensus.ConsensusFactory.IOT_CONSENSUS_V2; import static org.apache.iotdb.consensus.ConsensusFactory.SIMPLE_CONSENSUS; import static org.apache.iotdb.it.env.cluster.ClusterConstant.CONFIG_NODE_CONSENSUS_PROTOCOL_CLASS; import static org.apache.iotdb.it.env.cluster.ClusterConstant.DATANODE_INIT_HEAP_SIZE; @@ -211,7 +212,7 @@ String getNodeType() { protected void reloadMutableFields() { mutableCommonProperties.setProperty(CONFIG_NODE_CONSENSUS_PROTOCOL_CLASS, SIMPLE_CONSENSUS); mutableCommonProperties.setProperty(SCHEMA_REGION_CONSENSUS_PROTOCOL_CLASS, SIMPLE_CONSENSUS); - mutableCommonProperties.setProperty(DATA_REGION_CONSENSUS_PROTOCOL_CLASS, SIMPLE_CONSENSUS); + mutableCommonProperties.setProperty(DATA_REGION_CONSENSUS_PROTOCOL_CLASS, IOT_CONSENSUS_V2); mutableCommonProperties.setProperty(SCHEMA_REPLICATION_FACTOR, "1"); mutableCommonProperties.setProperty(DATA_REPLICATION_FACTOR, "1"); diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java index cc092d00d7214..dc4f1ee17a46f 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java @@ -64,6 +64,7 @@ public class RemoteServerEnv implements BaseEnv { private final String ip_addr = System.getProperty("RemoteIp", "127.0.0.1"); private final String port = System.getProperty("RemotePort", "6667"); + private final String restPort = System.getProperty("RemoteRestPort", "18080"); private final String configNodeMetricPort = System.getProperty("RemoteConfigNodeMetricPort", "9091"); @@ -233,6 +234,11 @@ public List getDataNodeWrapperList() { return null; } + @Override + public List getRestUrls() { + return Collections.singletonList("http://" + remoteEndpointUrl(restPort)); + } + @Override public IConfigNodeRPCService.Iface getLeaderConfigNodeConnection() throws ClientManagerException { return clientManager.borrowClient(new TEndPoint(ip_addr, 10710)); diff --git a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java index 1e20d2152b36d..74393cee939dd 100644 --- a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java +++ b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java @@ -33,6 +33,7 @@ import org.apache.iotdb.jdbc.Config; import org.apache.iotdb.jdbc.Constant; import org.apache.iotdb.rpc.IoTDBConnectionException; +import org.apache.iotdb.rpc.UrlUtils; import reactor.util.annotation.Nullable; @@ -239,6 +240,16 @@ default void setTestClassName(String testClassName) { List getDataNodeWrapperList(); + default List getRestUrls() { + return getDataNodeWrapperList().stream() + .map( + node -> + "http://" + + UrlUtils.formatTEndPointIpv4AndIpv6Url( + node.getIp(), node.getRestServicePort())) + .toList(); + } + IConfigNodeRPCService.Iface getLeaderConfigNodeConnection() throws ClientManagerException, IOException, InterruptedException; diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirIT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirIT.java index d5c3a1b9c476c..72184c761418f 100644 --- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirIT.java @@ -24,12 +24,12 @@ import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.env.CommonConfig; import org.apache.tsfile.utils.Pair; import org.awaitility.Awaitility; import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -61,13 +61,12 @@ @Category({ClusterIT.class}) public class IoTDBRegionMigrateWithDeletionMultiDataDirIT { - @Before - public void setUp() throws Exception { - EnvFactory.getEnv() - .getConfig() - .getCommonConfig() - .setDataReplicationFactor(2) - .setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS); + private void startCluster(String protocol, String mode) throws Exception { + final CommonConfig config = EnvFactory.getEnv().getConfig().getCommonConfig(); + config.setDataReplicationFactor(2).setDataRegionConsensusProtocolClass(protocol); + if (ConsensusFactory.IOT_CONSENSUS_V2.equals(protocol)) { + config.setIoTConsensusV2Mode(mode); + } EnvFactory.getEnv().getConfig().getDataNodeConfig().setDnDataDirs(MULTI_DATA_DIRS); EnvFactory.getEnv().initClusterEnvironment(1, 3); } @@ -79,6 +78,23 @@ public void tearDown() throws Exception { @Test public void testRegionMigratePreservesDeletionWithMultiDataDirs() throws Exception { + startCluster(ConsensusFactory.IOT_CONSENSUS, null); + assertRegionMigratePreservesDeletion(); + } + + @Test + public void testIoTV2BatchRegionMigratePreservesDeletion() throws Exception { + startCluster(ConsensusFactory.IOT_CONSENSUS_V2, ConsensusFactory.IOT_CONSENSUS_V2_BATCH_MODE); + assertRegionMigratePreservesDeletion(); + } + + @Test + public void testIoTV2StreamRegionMigratePreservesDeletion() throws Exception { + startCluster(ConsensusFactory.IOT_CONSENSUS_V2, ConsensusFactory.IOT_CONSENSUS_V2_STREAM_MODE); + assertRegionMigratePreservesDeletion(); + } + + private void assertRegionMigratePreservesDeletion() throws Exception { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { statement.execute("CREATE DATABASE root.db"); diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirTableIT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirTableIT.java index 8407d37d0f598..5ee20c3da7c85 100644 --- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirTableIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirTableIT.java @@ -26,12 +26,12 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.TableClusterIT; import org.apache.iotdb.itbase.env.BaseEnv; +import org.apache.iotdb.itbase.env.CommonConfig; import org.apache.tsfile.utils.Pair; import org.awaitility.Awaitility; import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -61,13 +61,12 @@ @Category({TableClusterIT.class}) public class IoTDBRegionMigrateWithDeletionMultiDataDirTableIT { - @Before - public void setUp() throws Exception { - EnvFactory.getEnv() - .getConfig() - .getCommonConfig() - .setDataReplicationFactor(2) - .setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS); + private void startCluster(String protocol, String mode) throws Exception { + final CommonConfig config = EnvFactory.getEnv().getConfig().getCommonConfig(); + config.setDataReplicationFactor(2).setDataRegionConsensusProtocolClass(protocol); + if (ConsensusFactory.IOT_CONSENSUS_V2.equals(protocol)) { + config.setIoTConsensusV2Mode(mode); + } EnvFactory.getEnv().getConfig().getDataNodeConfig().setDnDataDirs(MULTI_DATA_DIRS); EnvFactory.getEnv().initClusterEnvironment(1, 3); } @@ -79,6 +78,23 @@ public void tearDown() throws Exception { @Test public void testRegionMigratePreservesDeletionWithMultiDataDirs() throws Exception { + startCluster(ConsensusFactory.IOT_CONSENSUS, null); + assertRegionMigratePreservesDeletion(); + } + + @Test + public void testIoTV2BatchRegionMigratePreservesDeletion() throws Exception { + startCluster(ConsensusFactory.IOT_CONSENSUS_V2, ConsensusFactory.IOT_CONSENSUS_V2_BATCH_MODE); + assertRegionMigratePreservesDeletion(); + } + + @Test + public void testIoTV2StreamRegionMigratePreservesDeletion() throws Exception { + startCluster(ConsensusFactory.IOT_CONSENSUS_V2, ConsensusFactory.IOT_CONSENSUS_V2_STREAM_MODE); + assertRegionMigratePreservesDeletion(); + } + + private void assertRegionMigratePreservesDeletion() throws Exception { try (Connection connection = EnvFactory.getEnv().getTableConnection(); Statement statement = connection.createStatement()) { statement.execute("CREATE DATABASE test"); diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/utils/ConfigNodeTestUtils.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/utils/ConfigNodeTestUtils.java index 0697a6c674d24..c54fc4ae0d08b 100644 --- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/utils/ConfigNodeTestUtils.java +++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/utils/ConfigNodeTestUtils.java @@ -37,6 +37,7 @@ import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionReq; import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionTableResp; import org.apache.iotdb.confignode.rpc.thrift.TTimeSlotList; +import org.apache.iotdb.consensus.ConsensusFactory; import org.apache.iotdb.it.env.EnvFactory; import org.apache.iotdb.it.env.cluster.node.ConfigNodeWrapper; import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; @@ -315,8 +316,7 @@ public static TClusterParameters generateClusterParameters() { clusterParameters.setClusterName("defaultCluster"); clusterParameters.setConfigNodeConsensusProtocolClass( "org.apache.iotdb.consensus.simple.SimpleConsensus"); - clusterParameters.setDataRegionConsensusProtocolClass( - "org.apache.iotdb.consensus.simple.SimpleConsensus"); + clusterParameters.setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS_V2); clusterParameters.setSchemaRegionConsensusProtocolClass( "org.apache.iotdb.consensus.simple.SimpleConsensus"); clusterParameters.setSeriesPartitionSlotNum(1000); diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/GrafanaApiServiceIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/GrafanaApiServiceIT.java index 8d821062b2b6c..193f4ae4600da 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/GrafanaApiServiceIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/GrafanaApiServiceIT.java @@ -19,7 +19,6 @@ package org.apache.iotdb.db.it; import org.apache.iotdb.it.env.EnvFactory; -import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; @@ -62,15 +61,14 @@ @Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) public class GrafanaApiServiceIT { - private static int port = 18080; + private static String restUrl; @BeforeClass public static void setUp() throws Exception { BaseEnv baseEnv = EnvFactory.getEnv(); baseEnv.getConfig().getDataNodeConfig().setEnableRestService(true); baseEnv.initClusterEnvironment(); - DataNodeWrapper portConflictDataNodeWrapper = EnvFactory.getEnv().getDataNodeWrapper(0); - port = portConflictDataNodeWrapper.getRestServicePort(); + restUrl = baseEnv.getRestUrls().get(0); } @AfterClass @@ -112,7 +110,7 @@ private HttpPost getHttpPost(String url) { @Test public void login() { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpGet httpGet = new HttpGet("http://127.0.0.1:" + port + "/grafana/v1/login"); + HttpGet httpGet = new HttpGet(restUrl + "/grafana/v1/login"); CloseableHttpResponse response = null; try { String authorization = getAuthorization("root", "root"); @@ -158,7 +156,7 @@ public void login() { public void rightInsertTablet(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/insertTablet"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/insertTablet"); String json = "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s4\",\"s5\"],\"dataTypes\":[\"INT32\",\"INT32\"],\"values\":[[11,2],[15,13]],\"isAligned\":false,\"deviceId\":\"root.sg25\"}"; httpPost.setEntity(new StringEntity(json, Charset.defaultCharset())); @@ -199,7 +197,7 @@ public void rightInsertTablet(CloseableHttpClient httpClient) { public void expressionGroupByLevel(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/grafana/v1/query/expression"); + HttpPost httpPost = getHttpPost(restUrl + "/grafana/v1/query/expression"); String sql = "{\"expression\":[\"count(s4)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232143960,\"endTime\":1635232153960,\"control\":\"group by([1635232143960,1635232153960),1s),level=1\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); @@ -233,7 +231,7 @@ public void expressionGroupByLevel(CloseableHttpClient httpClient) { public void expression(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/grafana/v1/query/expression"); + HttpPost httpPost = getHttpPost(restUrl + "/grafana/v1/query/expression"); String sql = "{\"expression\":[\"s4\",\"s5\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232133960,\"endTime\":1635232163960}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); @@ -286,7 +284,7 @@ public void expression(CloseableHttpClient httpClient) { public void expressionWithControl(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/grafana/v1/query/expression"); + HttpPost httpPost = getHttpPost(restUrl + "/grafana/v1/query/expression"); String sql = "{\"expression\":[\"sum(s4)\",\"avg(s5)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232133960,\"endTime\":1635232163960,\"control\":\"group by([1635232133960,1635232163960),20s)\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); @@ -340,7 +338,7 @@ public void expressionWithControl(CloseableHttpClient httpClient) { public void expressionWithConditionControl(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/grafana/v1/query/expression"); + HttpPost httpPost = getHttpPost(restUrl + "/grafana/v1/query/expression"); String sql = "{\"expression\":[\"sum(s4)\",\"avg(s5)\"],\"prefixPath\":[\"root.sg25\"],\"condition\":\"timestamp=1635232143960\",\"startTime\":1635232133960,\"endTime\":1635232163960,\"control\":\"group by([1635232133960,1635232163960),20s)\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); @@ -391,7 +389,7 @@ public void expressionWithConditionControl(CloseableHttpClient httpClient) { public void variable(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/grafana/v1/variable"); + HttpPost httpPost = getHttpPost(restUrl + "/grafana/v1/variable"); String sql = "{\"sql\":\"show child paths root.sg25\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java index b40ad802b8b01..16498e88a6b1a 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java @@ -21,7 +21,6 @@ import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant; import org.apache.iotdb.db.it.utils.TestUtils; import org.apache.iotdb.it.env.EnvFactory; -import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; @@ -73,7 +72,7 @@ @Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) public class IoTDBRestServiceIT { - private static int port = 18080; + private static String restUrl; @BeforeClass public static void setUp() throws Exception { @@ -81,8 +80,7 @@ public static void setUp() throws Exception { baseEnv.getConfig().getDataNodeConfig().setEnableRestService(true); baseEnv.getConfig().getCommonConfig().setEnforceStrongPassword(false); baseEnv.initClusterEnvironment(); - DataNodeWrapper portConflictDataNodeWrapper = EnvFactory.getEnv().getDataNodeWrapper(0); - port = portConflictDataNodeWrapper.getRestServicePort(); + restUrl = baseEnv.getRestUrls().get(0); } @AfterClass @@ -124,7 +122,7 @@ public static String getAuthorization(String username, String password) { @Test public void ping() { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpGet httpGet = new HttpGet("http://127.0.0.1:" + port + "/ping"); + HttpGet httpGet = new HttpGet(restUrl + "/ping"); CloseableHttpResponse response = null; try { for (int i = 0; i < 30; i++) { @@ -285,16 +283,10 @@ public void errorInsertRecords() throws SQLException { CloseableHttpResponse response = null; CloseableHttpClient httpClient = HttpClientBuilder.create().build(); try { - for (int i = 0; i < EnvFactory.getEnv().getDataNodeWrapperList().size(); i++) { - DataNodeWrapper wrapper = EnvFactory.getEnv().getDataNodeWrapperList().get(i); + final List restUrls = EnvFactory.getEnv().getRestUrls(); + for (int i = 0; i < restUrls.size(); i++) { try { - HttpPost httpPost = - getHttpPost( - "http://" - + wrapper.getIp() - + ":" - + wrapper.getRestServicePort() - + "/rest/v2/insertRecords"); + HttpPost httpPost = getHttpPost(restUrls.get(i) + "/rest/v2/insertRecords"); String json = "{\"timestamps\":[" + i @@ -338,9 +330,7 @@ public void errorInsertRecords() throws SQLException { ResultSet resultSet = statement.executeQuery("select count(s33) from root.s1"); resultSet.next(); - assertEquals( - EnvFactory.getEnv().getDataNodeWrapperList().size(), - resultSet.getInt("count(root.s1.s33)")); + assertEquals(restUrls.size(), resultSet.getInt("count(root.s1.s33)")); } } finally { cleanupAllData(); @@ -374,7 +364,7 @@ public void rightInsertTablet(CloseableHttpClient httpClient, String json, HttpP public void rightInsertTablet(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/insertTablet"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/insertTablet"); String json = "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s3\",\"s4\",\"s5\",\"s6\",\"s7\",\"s8\"],\"dataTypes\":[\"TEXT\",\"INT32\",\"INT64\",\"FLOAT\",\"BOOLEAN\",\"DOUBLE\"],\"values\":[[\"2aa\",\"\"],[11,2],[1635000012345555,1635000012345556],[1.41,null],[null,false],[null,3.5555]],\"isAligned\":false,\"deviceId\":\"root.sg25\"}"; httpPost.setEntity(new StringEntity(json, Charset.defaultCharset())); @@ -440,7 +430,7 @@ public void errorInsertTablet() { CloseableHttpResponse response = null; CloseableHttpClient httpClient = HttpClientBuilder.create().build(); try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/insertTablet"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/insertTablet"); String json = "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s3\",\"s4\",\"s5\",\"s6\",\"s7\",\"s8\"],\"dataTypes\":[\"TEXT\",\"INT32\",\"INT64\",\"FLOAT\",\"BOOLEAN\",\"DOUBLE\"],\"values\":[[\"2aa\",\"\"],[111111112312312442352545452323123,2],[16,15],[1.41,null],[null,false],[null,3.55555555555555555555555555555555555555555555312234235345123127318927461482308478123645555555555555555555555555555555555555555555531223423534512312731892746148230847812364]],\"isAligned\":false,\"deviceId\":\"root.sg25\"}"; httpPost.setEntity(new StringEntity(json, Charset.defaultCharset())); @@ -480,8 +470,8 @@ public void errorInsertTablet() { } public void perData(CloseableHttpClient httpClient) { - HttpPost httpPost2 = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); - HttpPost httpPostV2 = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/nonQuery"); + HttpPost httpPost2 = getHttpPost(restUrl + "/rest/v1/nonQuery"); + HttpPost httpPostV2 = getHttpPost(restUrl + "/rest/v2/nonQuery"); nonQuery(httpClient, "{\"sql\":\"CREATE USER `root1` 'rooT@11234567'\"}", httpPost2); nonQuery(httpClient, "{\"sql\":\"GRANT WRITE ON root.** to user root1\"}", httpPostV2); @@ -759,8 +749,8 @@ public void insertAndQuery() { nonQuery_error_json_list_v2.add( "{\"sql\":\"insert into root.aa(time,root) values(111,1)\"}"); } - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/insertTablet"); - HttpPost httpPost1 = getHttpPost_1("http://127.0.0.1:" + port + "/rest/v1/insertTablet"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/insertTablet"); + HttpPost httpPost1 = getHttpPost_1(restUrl + "/rest/v1/insertTablet"); List httpPosts = new ArrayList<>(); httpPosts.add(httpPost); @@ -774,8 +764,8 @@ public void insertAndQuery() { } } - HttpPost httpPost3 = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); - HttpPost httpPost4 = getHttpPost_1("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); + HttpPost httpPost3 = getHttpPost(restUrl + "/rest/v1/nonQuery"); + HttpPost httpPost4 = getHttpPost_1(restUrl + "/rest/v1/nonQuery"); List httpPosts1 = new ArrayList<>(); httpPosts1.add(httpPost3); httpPosts1.add(httpPost4); @@ -789,14 +779,14 @@ public void insertAndQuery() { } } - HttpPost httpPost5 = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/insertRecords"); - HttpPost httpPost6 = getHttpPost_1("http://127.0.0.1:" + port + "/rest/v1/insertRecords"); + HttpPost httpPost5 = getHttpPost(restUrl + "/rest/v1/insertRecords"); + HttpPost httpPost6 = getHttpPost_1(restUrl + "/rest/v1/insertRecords"); List httpPosts2 = new ArrayList<>(); httpPosts2.add(httpPost5); httpPosts2.add(httpPost6); - HttpPost httpPostV2 = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/insertTablet"); - HttpPost httpPost1V2 = getHttpPost_1("http://127.0.0.1:" + port + "/rest/v2/insertTablet"); + HttpPost httpPostV2 = getHttpPost(restUrl + "/rest/v2/insertTablet"); + HttpPost httpPost1V2 = getHttpPost_1(restUrl + "/rest/v2/insertTablet"); List httpPostsV2 = new ArrayList<>(); httpPostsV2.add(httpPostV2); @@ -810,8 +800,8 @@ public void insertAndQuery() { } } - HttpPost httpPost3V2 = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/nonQuery"); - HttpPost httpPost4V2 = getHttpPost_1("http://127.0.0.1:" + port + "/rest/v2/nonQuery"); + HttpPost httpPost3V2 = getHttpPost(restUrl + "/rest/v2/nonQuery"); + HttpPost httpPost4V2 = getHttpPost_1(restUrl + "/rest/v2/nonQuery"); List httpPosts1V2 = new ArrayList<>(); httpPosts1V2.add(httpPost3V2); httpPosts1V2.add(httpPost4V2); @@ -824,8 +814,8 @@ public void insertAndQuery() { } } - HttpPost httpPost5V2 = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/insertRecords"); - HttpPost httpPost6V2 = getHttpPost_1("http://127.0.0.1:" + port + "/rest/v2/insertRecords"); + HttpPost httpPost5V2 = getHttpPost(restUrl + "/rest/v2/insertRecords"); + HttpPost httpPost6V2 = getHttpPost_1(restUrl + "/rest/v2/insertRecords"); List httpPosts2V2 = new ArrayList<>(); httpPosts2V2.add(httpPost5V2); httpPosts2V2.add(httpPost6V2); @@ -855,7 +845,7 @@ public void queryWithUnsetAuthorization() { CloseableHttpResponse response = null; try { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpPost httpPost = new HttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = new HttpPost(restUrl + "/rest/v1/query"); httpPost.addHeader("Content-type", "application/json; charset=utf-8"); httpPost.setHeader("Accept", "application/json"); String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}"; @@ -900,7 +890,7 @@ public void queryWithWrongAuthorization() { CloseableHttpResponse response = null; try { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpPost httpPost = new HttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = new HttpPost(restUrl + "/rest/v1/query"); httpPost.addHeader("Content-type", "application/json; charset=utf-8"); httpPost.setHeader("Accept", "application/json"); String authorization = getAuthorization("abc", "def"); @@ -949,7 +939,7 @@ public void queryFastLastWithWrongAuthorization() { TestUtils.executeNonQuery("create user abcd 'strongPassword@1234'"); try { final CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - final HttpPost httpPost = new HttpPost("http://127.0.0.1:" + port + "/rest/v2/fastLastQuery"); + final HttpPost httpPost = new HttpPost(restUrl + "/rest/v2/fastLastQuery"); httpPost.addHeader("Content-type", "application/json; charset=utf-8"); httpPost.setHeader("Accept", "application/json"); final String authorization = getAuthorization("abcd", "strongPassword@1234"); @@ -1011,7 +1001,7 @@ public void queryFastLastWithWrongAuthorization() { public void query(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/query"); String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); @@ -1113,7 +1103,7 @@ public void query(CloseableHttpClient httpClient) { public void queryGroupByLevel(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/query"); String sql = "{\"sql\":\"select count(s4) from root.sg25 group by([1635232143960,1635232153960),1s),level=1\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); @@ -1147,7 +1137,7 @@ public void queryGroupByLevel(CloseableHttpClient httpClient) { public void queryRowLimit(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/query"); String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\",\"rowLimit\":1}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); @@ -1172,7 +1162,7 @@ public void queryRowLimit(CloseableHttpClient httpClient) { public Map queryMetaData(CloseableHttpClient httpClient, String sql) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/query"); httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); HttpEntity responseEntity = response.getEntity(); @@ -1674,7 +1664,7 @@ public void selectLast(CloseableHttpClient httpClient) { public void queryV2(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v2/query"); String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); @@ -1775,12 +1765,12 @@ public void queryV2(CloseableHttpClient httpClient) { public void selectFastLast(CloseableHttpClient httpClient) { // Only used in 1D scenarios - if (EnvFactory.getEnv().getDataNodeWrapperList().size() > 1) { + if (EnvFactory.getEnv().getRestUrls().size() > 1) { return; } CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/fastLastQuery"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v2/fastLastQuery"); String sql = "{\"prefix_paths\":[\"root\",\"sg25\"]}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); @@ -1868,7 +1858,7 @@ public void selectFastLast(CloseableHttpClient httpClient) { public void queryGroupByLevelV2(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v2/query"); String sql = "{\"sql\":\"select count(s4) from root.sg25 group by([1635232143960,1635232153960),1s),level=1\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); @@ -1902,7 +1892,7 @@ public void queryGroupByLevelV2(CloseableHttpClient httpClient) { public void queryRowLimitV2(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v2/query"); String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\",\"row_limit\":1}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); @@ -1927,7 +1917,7 @@ public void queryRowLimitV2(CloseableHttpClient httpClient) { public Map queryMetaDataV2(CloseableHttpClient httpClient, String sql) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v2/query"); httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); HttpEntity responseEntity = response.getEntity(); @@ -2429,8 +2419,8 @@ public void selectLastV2(CloseableHttpClient httpClient) { public void insertDate() { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpPost httpPost2 = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); - HttpPost httpPostV2 = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/nonQuery"); + HttpPost httpPost2 = getHttpPost(restUrl + "/rest/v1/nonQuery"); + HttpPost httpPostV2 = getHttpPost(restUrl + "/rest/v2/nonQuery"); nonQuery( httpClient, "{\"sql\":\"CREATE TIMESERIES root.sg1.d1.s4 WITH DATATYPE=DATE, ENCODING=PLAIN, COMPRESSOR=SNAPPY\"}", @@ -2450,7 +2440,7 @@ public void insertDate() { public void queryDateAndBlob(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/query"); String sql = "{\"sql\":\"select s4,s5 from root.sg1.d1\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); @@ -2511,7 +2501,7 @@ public void queryDateAndBlob(CloseableHttpClient httpClient) { public void queryDateAndBlobV2(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v2/query"); String sql = "{\"sql\":\"select s4,s5 from root.sg1.d1\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); response = httpClient.execute(httpPost); @@ -2574,7 +2564,7 @@ public void queryWithValidTimeZoneHeader(CloseableHttpClient httpClient) { try { long expectedTimestamp = ZonedDateTime.of(2026, 3, 28, 0, 0, 0, 0, ZoneId.of("+05:00")).toInstant().toEpochMilli(); - HttpPost insertPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); + HttpPost insertPost = getHttpPost(restUrl + "/rest/v1/nonQuery"); String insertSql = String.format( "{\"sql\":\"INSERT INTO root.sg_tz.d2(timestamp, s3) VALUES(%d, 10.5)\"}", @@ -2583,7 +2573,7 @@ public void queryWithValidTimeZoneHeader(CloseableHttpClient httpClient) { try (CloseableHttpResponse insertResponse = httpClient.execute(insertPost)) { assertEquals(200, insertResponse.getStatusLine().getStatusCode()); } - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/query"); httpPost.setHeader("Time-Zone", "+05:00"); String sql = "{\"sql\":\"SELECT count(s3) FROM root.sg_tz.d2 GROUP BY ([2026-03-28T00:00:00, 2026-03-29T00:00:00), 1d)\"}"; @@ -2616,20 +2606,20 @@ public void queryWithValidTimeZoneHeader(CloseableHttpClient httpClient) { public void nonQueryWithValidTimeZoneHeader(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost createPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); + HttpPost createPost = getHttpPost(restUrl + "/rest/v1/nonQuery"); nonQuery( httpClient, "{\"sql\":\"CREATE TIMESERIES root.sg_tz.d1.s1 WITH DATATYPE=INT32\"}", createPost); - HttpPost insertPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); + HttpPost insertPost = getHttpPost(restUrl + "/rest/v1/nonQuery"); insertPost.setHeader("Time-Zone", "+05:00"); nonQuery( httpClient, "{\"sql\":\"INSERT INTO root.sg_tz.d1(time, s1) VALUES (2026-03-28T00:00:00, 123)\"}", insertPost); - HttpPost queryPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost queryPost = getHttpPost(restUrl + "/rest/v1/query"); queryPost.setEntity( new StringEntity("{\"sql\":\"SELECT s1 FROM root.sg_tz.d1\"}", StandardCharsets.UTF_8)); response = httpClient.execute(queryPost); @@ -2659,7 +2649,7 @@ public void queryWithValidTimeZoneHeaderV2(CloseableHttpClient httpClient) { try { long expectedTimestamp = ZonedDateTime.of(2026, 3, 28, 0, 0, 0, 0, ZoneId.of("+05:00")).toInstant().toEpochMilli(); - HttpPost insertPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); + HttpPost insertPost = getHttpPost(restUrl + "/rest/v1/nonQuery"); String insertSql = String.format( "{\"sql\":\"INSERT INTO root.sg_tz.d3(timestamp, s3) VALUES(%d, 10.5)\"}", @@ -2668,7 +2658,7 @@ public void queryWithValidTimeZoneHeaderV2(CloseableHttpClient httpClient) { try (CloseableHttpResponse insertResponse = httpClient.execute(insertPost)) { assertEquals(200, insertResponse.getStatusLine().getStatusCode()); } - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v2/query"); httpPost.setHeader("Time-Zone", "+05:00"); String sql = "{\"sql\":\"SELECT count(s3) FROM root.sg_tz.d3 GROUP BY ([2026-03-28T00:00:00, 2026-03-29T00:00:00), 1d)\"}"; @@ -2701,20 +2691,20 @@ public void queryWithValidTimeZoneHeaderV2(CloseableHttpClient httpClient) { public void nonQueryWithValidTimeZoneHeaderV2(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost createPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/nonQuery"); + HttpPost createPost = getHttpPost(restUrl + "/rest/v2/nonQuery"); nonQuery( httpClient, "{\"sql\":\"CREATE TIMESERIES root.sg_tz.d2.s1 WITH DATATYPE=INT32\"}", createPost); - HttpPost insertPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/nonQuery"); + HttpPost insertPost = getHttpPost(restUrl + "/rest/v2/nonQuery"); insertPost.setHeader("Time-Zone", "+05:00"); nonQuery( httpClient, "{\"sql\":\"INSERT INTO root.sg_tz.d2(time, s1) VALUES (2026-03-28T00:00:00, 123)\"}", insertPost); - HttpPost queryPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); + HttpPost queryPost = getHttpPost(restUrl + "/rest/v2/query"); queryPost.setEntity( new StringEntity("{\"sql\":\"SELECT s1 FROM root.sg_tz.d2\"}", StandardCharsets.UTF_8)); response = httpClient.execute(queryPost); @@ -2742,7 +2732,7 @@ public void nonQueryWithValidTimeZoneHeaderV2(CloseableHttpClient httpClient) { public void queryWithInvalidTimeZoneHeader(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v1/query"); httpPost.setHeader("Time-Zone", "Invalid/Zone"); String sql = "{\"sql\":\"SELECT s3 FROM root.sg25\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); @@ -2770,7 +2760,7 @@ public void queryWithInvalidTimeZoneHeader(CloseableHttpClient httpClient) { public void queryWithInvalidTimeZoneHeaderV2(CloseableHttpClient httpClient) { CloseableHttpResponse response = null; try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); + HttpPost httpPost = getHttpPost(restUrl + "/rest/v2/query"); httpPost.setHeader("Time-Zone", "Invalid/Zone"); String sql = "{\"sql\":\"SELECT s3 FROM root.sg25\"}"; httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); @@ -2799,20 +2789,20 @@ private void nonQueryWithValidTimeZoneHeaderTableV1(CloseableHttpClient httpClie nonQuery( httpClient, "{\"database\":\"\", \"sql\":\"CREATE DATABASE table_tz\"}", - getHttpPost("http://127.0.0.1:" + port + "/rest/table/v1/nonQuery")); + getHttpPost(restUrl + "/rest/table/v1/nonQuery")); nonQuery( httpClient, "{\"database\":\"table_tz\", \"sql\":\"CREATE TABLE d1 (s1 INT32)\"}", - getHttpPost("http://127.0.0.1:" + port + "/rest/table/v1/nonQuery")); + getHttpPost(restUrl + "/rest/table/v1/nonQuery")); - HttpPost insertPost = getHttpPost("http://127.0.0.1:" + port + "/rest/table/v1/nonQuery"); + HttpPost insertPost = getHttpPost(restUrl + "/rest/table/v1/nonQuery"); insertPost.setHeader("Time-Zone", "+05:00"); nonQuery( httpClient, "{\"database\":\"table_tz\", \"sql\":\"INSERT INTO d1(time, s1) VALUES ('2026-03-28T00:00:00', 123)\"}", insertPost); - HttpPost queryPost = getHttpPost("http://127.0.0.1:" + port + "/rest/table/v1/query"); + HttpPost queryPost = getHttpPost(restUrl + "/rest/table/v1/query"); queryPost.setEntity( new StringEntity( "{\"database\":\"table_tz\", \"sql\":\"SELECT time, s1 FROM d1\"}", @@ -2832,7 +2822,7 @@ private void nonQueryWithValidTimeZoneHeaderTableV1(CloseableHttpClient httpClie } private void queryWithValidTimeZoneHeaderTableV1(CloseableHttpClient httpClient) { - HttpPost preparePost = getHttpPost("http://127.0.0.1:" + port + "/rest/table/v1/nonQuery"); + HttpPost preparePost = getHttpPost(restUrl + "/rest/table/v1/nonQuery"); nonQuery(httpClient, "{\"database\":\"\", \"sql\":\"CREATE DATABASE table_tz2\"}", preparePost); nonQuery( httpClient, @@ -2847,7 +2837,7 @@ private void queryWithValidTimeZoneHeaderTableV1(CloseableHttpClient httpClient) absoluteTimestamp); nonQuery(httpClient, insertSql, preparePost); - HttpPost queryPost = getHttpPost("http://127.0.0.1:" + port + "/rest/table/v1/query"); + HttpPost queryPost = getHttpPost(restUrl + "/rest/table/v1/query"); queryPost.setHeader("Time-Zone", "+05:00"); String sql = "{\"database\":\"table_tz2\", \"sql\":\"SELECT COUNT(s1) FROM d2 WHERE time = 2026-03-28T00:00:00\"}"; @@ -2864,7 +2854,7 @@ private void queryWithValidTimeZoneHeaderTableV1(CloseableHttpClient httpClient) } private void queryWithInvalidTimeZoneHeaderTableV1(CloseableHttpClient httpClient) { - HttpPost queryPost = getHttpPost("http://127.0.0.1:" + port + "/rest/table/v1/query"); + HttpPost queryPost = getHttpPost(restUrl + "/rest/table/v1/query"); queryPost.setHeader("Time-Zone", "Invalid/Zone"); String sql = "{\"database\":\"table_tz\", \"sql\":\"SELECT 1\"}"; queryPost.setEntity(new StringEntity(sql, StandardCharsets.UTF_8)); diff --git a/integration-test/src/test/java/org/apache/iotdb/edge/it/IoTDBEdgeBasicIT.java b/integration-test/src/test/java/org/apache/iotdb/edge/it/IoTDBEdgeBasicIT.java index 07ab860655d6d..e76c1394ec6a2 100644 --- a/integration-test/src/test/java/org/apache/iotdb/edge/it/IoTDBEdgeBasicIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/edge/it/IoTDBEdgeBasicIT.java @@ -385,7 +385,7 @@ public void testRatisMetadataConsensus() throws SQLException { "org.apache.iotdb.consensus.ratis.RatisConsensus", variables.get("SchemaRegionConsensusProtocolClass")); assertEquals( - "org.apache.iotdb.consensus.iot.IoTConsensus", + "org.apache.iotdb.consensus.iot.IoTConsensusV2", variables.get("DataRegionConsensusProtocolClass")); } diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java index d12fb0821d927..21fe6a87e0f08 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java @@ -78,7 +78,7 @@ public class ConfigNodeConfig { private int schemaReplicationFactor = 1; /** Data region consensus protocol. */ - private String dataRegionConsensusProtocolClass = ConsensusFactory.IOT_CONSENSUS; + private String dataRegionConsensusProtocolClass = ConsensusFactory.IOT_CONSENSUS_V2; /** IoTConsensusV2 replicate mode: "batch" or "stream". */ private String iotConsensusV2Mode = "batch"; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java index c6a0d4878969f..3a26c1e5a7ff2 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java @@ -928,7 +928,7 @@ public class IoTDBConfig implements DefaultEncodingProvider { * on startup and set this variable so that the correct class name can be obtained later when the * data region consensus layer singleton is initialized */ - private String dataRegionConsensusProtocolClass = ConsensusFactory.IOT_CONSENSUS; + private String dataRegionConsensusProtocolClass = ConsensusFactory.IOT_CONSENSUS_V2; /** * The consensus protocol class for schema region. The Datanode should communicate with ConfigNode diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/statemachine/dataregion/DataExecutionVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/statemachine/dataregion/DataExecutionVisitor.java index 7b3e883bb3546..7994159511c79 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/statemachine/dataregion/DataExecutionVisitor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/statemachine/dataregion/DataExecutionVisitor.java @@ -36,6 +36,7 @@ import org.apache.iotdb.db.exception.runtime.TableLostRuntimeException; import org.apache.iotdb.db.i18n.DataNodeMiscMessages; import org.apache.iotdb.db.i18n.DataNodePipeMessages; +import org.apache.iotdb.db.pipe.consensus.deletion.DeletionResource; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.load.LoadTsFileConsensusNode; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.pipe.PipeEnrichedDeleteDataNode; @@ -348,6 +349,9 @@ public TSStatus visitDeleteData(DeleteDataNode node, DataRegion dataRegion) { } } dataRegion.insertSeparatorToWAL(node); + if (DeletionResource.isDeleteNodeGeneratedInLocalByIoTV2(node)) { + dataRegion.recordAppliedLocalDeletion(node.getProgressIndex()); + } succeeded = true; return StatusUtils.OK; } catch (WriteProcessRejectException e) { @@ -369,14 +373,26 @@ public TSStatus visitDeleteData(DeleteDataNode node, DataRegion dataRegion) { @Override public TSStatus visitDeleteData( final RelationalDeleteDataNode node, final DataRegion dataRegion) { + final boolean isLocalIoTV2Delete = DeletionResource.isDeleteNodeGeneratedInLocalByIoTV2(node); + if (isLocalIoTV2Delete) { + // Keep history extraction out until the DELETE has materialized its mods and progress. + dataRegion.writeLock("deleteData"); + } try { dataRegion.deleteByTable(node); + if (isLocalIoTV2Delete) { + dataRegion.recordAppliedLocalDeletion(node.getProgressIndex()); + } return StatusUtils.OK; } catch (final WriteProcessRejectException e) { return RpcUtils.getStatus(e.getErrorCode(), e.getMessage()); } catch (final IOException e) { LOGGER.error(DataNodeMiscMessages.ERROR_EXECUTING_PLAN_NODE, node, e); return RpcUtils.getStatus(TSStatusCode.WRITE_PROCESS_ERROR, e.getMessage()); + } finally { + if (isLocalIoTV2Delete) { + dataRegion.writeUnlock(); + } } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtask.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtask.java index 96c46698877d4..565d514060bc0 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtask.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtask.java @@ -35,6 +35,7 @@ import org.apache.iotdb.db.pipe.agent.PipeDataNodeAgent; import org.apache.iotdb.db.pipe.agent.task.connection.PipeEventCollector; import org.apache.iotdb.db.pipe.event.UserDefinedEnrichedEvent; +import org.apache.iotdb.db.pipe.event.common.deletion.HistoricalDeletionProgressReportEvent; import org.apache.iotdb.db.pipe.event.common.heartbeat.PipeHeartbeatEvent; import org.apache.iotdb.db.pipe.event.common.tablet.PipeInsertNodeTabletInsertionEvent; import org.apache.iotdb.db.pipe.event.common.terminate.PipeTerminateEvent; @@ -264,7 +265,8 @@ protected boolean executeOnce() throws Exception { // been released, and the progress of the event can not be reported. && !outputEventCollector.isFailedToIncreaseReferenceCount() // Events generated from consensusPipe's transferred data should never be reported. - && !(pipeProcessor instanceof IoTConsensusV2Processor); + && (!(pipeProcessor instanceof IoTConsensusV2Processor) + || event instanceof HistoricalDeletionProgressReportEvent); if (shouldReport && event instanceof EnrichedEvent && outputEventCollector.hasNoCollectInvocationAfterReset()) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/deletion/HistoricalDeletionProgressReportEvent.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/deletion/HistoricalDeletionProgressReportEvent.java new file mode 100644 index 0000000000000..45c42f045d049 --- /dev/null +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/deletion/HistoricalDeletionProgressReportEvent.java @@ -0,0 +1,32 @@ +/* + * 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.event.common.deletion; + +import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTaskMeta; +import org.apache.iotdb.commons.pipe.event.ProgressReportEvent; + +/** Reports locally materialized DELETE progress after the consensus history has committed. */ +public class HistoricalDeletionProgressReportEvent extends ProgressReportEvent { + + public HistoricalDeletionProgressReportEvent( + final String pipeName, final long creationTime, final PipeTaskMeta pipeTaskMeta) { + super(pipeName, creationTime, pipeTaskMeta); + } +} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/IoTDBDataRegionSource.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/IoTDBDataRegionSource.java index ed8f5e84406aa..dc76f14802eb3 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/IoTDBDataRegionSource.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/IoTDBDataRegionSource.java @@ -589,6 +589,12 @@ private void startHistoricalExtractorAndRealtimeExtractor( DataNodePipeMessages.MESSAGE_PIPE_STARTING_ARG_A09517B7, IoTDBDataRegionSource.class.getName())); try { + if (historicalSource instanceof PipeHistoricalDataRegionTsFileAndDeletionSource + && ((PipeHistoricalDataRegionTsFileAndDeletionSource) historicalSource) + .shouldReportHistoricalDeletionProgress(dataRegion)) { + // Close existing files before realtime subscribes to file-close events. + dataRegion.syncCloseAllWorkingAndClosingTsFileProcessors(); + } realtimeSource.start(); } finally { dataRegion.writeUnlock(); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java index 7e62a4d2e1023..59fb1f341fcb6 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java @@ -50,6 +50,7 @@ import org.apache.iotdb.db.pipe.consensus.ReplicateProgressDataNodeManager; import org.apache.iotdb.db.pipe.consensus.deletion.DeletionResource; import org.apache.iotdb.db.pipe.consensus.deletion.DeletionResourceManager; +import org.apache.iotdb.db.pipe.event.common.deletion.HistoricalDeletionProgressReportEvent; import org.apache.iotdb.db.pipe.event.common.deletion.PipeDeleteDataNodeEvent; import org.apache.iotdb.db.pipe.event.common.terminate.PipeTerminateEvent; import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent; @@ -186,6 +187,7 @@ public class PipeHistoricalDataRegionTsFileAndDeletionSource private ProgressIndex maxSuppliedHistoricalProgressReportIndex = MinimumProgressIndex.INSTANCE; private ProgressIndex pendingHistoricalProgressIndexToReport; private boolean shouldReportMaxHistoricalProgressIndex = false; + private ProgressIndex historicalDeletionProgress = MinimumProgressIndex.INSTANCE; private int extractedHistoricalTsFileCount = 0; private int extractedHistoricalDeletionCount = 0; @@ -537,6 +539,15 @@ private ProgressIndex extractRecoverProgressIndex(RecoverProgressIndex toBeTrans .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } + public boolean shouldReportHistoricalDeletionProgress(final DataRegion dataRegion) { + return pipeName.startsWith(PipeStaticMeta.CONSENSUS_PIPE_PREFIX) + && shouldExtractInsertion + && shouldExtractDeletion + && isHistoricalSourceEnabled + && shouldTransferModFile + && !startIndex.isEqualOrAfter(dataRegion.getAppliedLocalDeletionProgress()); + } + @Override public synchronized void start() { if (!shouldExtractInsertion && !shouldExtractDeletion) { @@ -555,6 +566,7 @@ public synchronized void start() { maxSuppliedHistoricalProgressReportIndex = MinimumProgressIndex.INSTANCE; pendingHistoricalProgressIndexToReport = null; shouldReportMaxHistoricalProgressIndex = false; + historicalDeletionProgress = MinimumProgressIndex.INSTANCE; historicalProgressReportResources.clear(); final DataRegion dataRegion = @@ -577,6 +589,9 @@ public synchronized void start() { pendingQueue = new ArrayDeque<>(); return; } + if (shouldReportHistoricalDeletionProgress(dataRegion)) { + historicalDeletionProgress = dataRegion.getAppliedLocalDeletionProgress(); + } if (shouldExtractInsertion) { flushTsFilesForExtraction(dataRegion); tsFileManager.readLock(); @@ -897,6 +912,9 @@ private void extractTsFiles( } originalResourceList.addAll(extractedSequenceResources); originalResourceList.addAll(extractedUnsequenceResources); + if (statistics.pinFailedCount > 0) { + historicalDeletionProgress = MinimumProgressIndex.INSTANCE; + } extractedHistoricalTsFileCount = filteredTsFileResources2TableNames.size(); LOGGER.info( @@ -1401,6 +1419,13 @@ public synchronized Event supply() { while (true) { final PersistentResource resource = pendingQueue.peek(); if (resource == null) { + if (!(historicalDeletionProgress instanceof MinimumProgressIndex)) { + final ProgressIndex progress = historicalDeletionProgress; + historicalDeletionProgress = MinimumProgressIndex.INSTANCE; + return supplyProgressReportEvent( + new HistoricalDeletionProgressReportEvent(pipeName, creationTime, pipeTaskMeta), + progress); + } if (shouldReportMaxHistoricalProgressIndex) { shouldReportMaxHistoricalProgressIndex = false; if (!maxSuppliedHistoricalProgressReportIndex.isEqualOrAfter( @@ -1414,6 +1439,8 @@ public synchronized Event supply() { if (resource instanceof TsFileResource) { final TsFileResource tsFileResource = (TsFileResource) resource; if (consumeSkippedHistoricalTsFileEventIfNecessary(tsFileResource)) { + // The realtime source owns this file; the historical commit cannot cover it. + historicalDeletionProgress = MinimumProgressIndex.INSTANCE; clearReplicateIndexForResource(tsFileResource); pendingQueue.poll(); if (shouldUseHistoricalTsFileQueryPriorityOrder()) { @@ -1513,8 +1540,12 @@ protected boolean consumeSkippedHistoricalTsFileEventIfNecessary(final TsFileRes } protected Event supplyProgressReportEvent(final ProgressIndex progressIndex) { - final ProgressReportEvent progressReportEvent = - new ProgressReportEvent(pipeName, creationTime, pipeTaskMeta); + return supplyProgressReportEvent( + new ProgressReportEvent(pipeName, creationTime, pipeTaskMeta), progressIndex); + } + + private Event supplyProgressReportEvent( + final ProgressReportEvent progressReportEvent, final ProgressIndex progressIndex) { progressReportEvent.bindProgressIndex(progressIndex); final boolean isReferenceCountIncreased = progressReportEvent.increaseReferenceCount( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java index bd31b2f474af7..713c4ed7dfe67 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java @@ -30,6 +30,7 @@ import org.apache.iotdb.commons.conf.IoTDBConstant; import org.apache.iotdb.commons.consensus.DataRegionId; import org.apache.iotdb.commons.consensus.index.ProgressIndex; +import org.apache.iotdb.commons.consensus.index.impl.MinimumProgressIndex; import org.apache.iotdb.commons.exception.DiskSpaceInsufficientException; import org.apache.iotdb.commons.exception.MetadataException; import org.apache.iotdb.commons.exception.MetadataLeaseFencedException.LeaseFencedRetryPolicy; @@ -310,6 +311,9 @@ public class DataRegion implements IDataRegionForQuery { private final Map modFileDeletionProgress = new ConcurrentHashMap<>(); + // Guarded by the region write lock, like history extraction that snapshots it. + private ProgressIndex appliedLocalDeletionProgress = MinimumProgressIndex.INSTANCE; + /** closeStorageGroupCondition is used to wait for all currently closing TsFiles to be done. */ private final Object closeStorageGroupCondition = new Object(); @@ -3363,6 +3367,15 @@ public void writeLock(String holder) { insertWriteLockHolder = holder; } + public ProgressIndex getAppliedLocalDeletionProgress() { + return appliedLocalDeletionProgress; + } + + public void recordAppliedLocalDeletion(ProgressIndex progressIndex) { + appliedLocalDeletionProgress = + appliedLocalDeletionProgress.updateToMinimumEqualOrIsAfterProgressIndex(progressIndex); + } + /** unlock the write lock of the insert lock */ public void writeUnlock() { insertWriteLockHolder = ""; diff --git a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template index ee4ef9256e5be..e7b3e3e813a2c 100644 --- a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template +++ b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template @@ -157,7 +157,7 @@ data_replication_factor=1 # 4. org.apache.iotdb.consensus.iot.IoTConsensusV2 # effectiveMode: first_start # Datatype: string -data_region_consensus_protocol_class=org.apache.iotdb.consensus.iot.IoTConsensus +data_region_consensus_protocol_class=org.apache.iotdb.consensus.iot.IoTConsensusV2 #################### ### Directory configuration From 63fb7a5974356ba80c809bcf0a2ad336a434f85f Mon Sep 17 00:00:00 2001 From: Peng Junzhi <201250214@smail.nju.edu.cn> Date: Wed, 25 Nov 2026 14:13:38 +0800 Subject: [PATCH 2/4] Recompute TsFile emptiness from current time bounds --- .../dataregion/tsfile/TsFileResource.java | 8 ++------ .../dataregion/tsfile/TsFileResourceTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java index 72c7022e5b5b5..bcc17f61fe7fc 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java @@ -131,8 +131,6 @@ public class TsFileResource implements PersistentResource, Cloneable { /** time index */ private volatile ITimeIndex timeIndex; - private final AtomicReference isEmpty = new AtomicReference<>(); - private Future exclusiveModFileFuture; // this future suggest when the async recovery ends private CompletableFuture sharedModFilePathFuture; @@ -1485,9 +1483,8 @@ public ProgressIndex getMaxProgressIndex() { } public boolean isEmpty() { - isEmpty.compareAndSet( - null, getFileStartTime() == Long.MAX_VALUE && getFileEndTime() == Long.MIN_VALUE); - return isEmpty.get(); + // An open file can acquire data after the first check during Pipe extraction. + return getFileStartTime() == Long.MAX_VALUE && getFileEndTime() == Long.MIN_VALUE; } public String getDatabaseName() { @@ -1698,7 +1695,6 @@ public TsFileResource shallowClone() { cloned.lastValues = this.lastValues; cloned.maxProgressIndex.set(this.maxProgressIndex.get()); cloned.atomicStatus.set(this.atomicStatus.get()); - cloned.isEmpty.set(this.isEmpty.get()); cloned.tsFileID = this.tsFileID; cloned.prev = null; cloned.next = null; diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceTest.java index f0149f799c13d..6517538ebabf4 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceTest.java @@ -99,6 +99,21 @@ public void tearDown() throws IOException { } } + @Test + public void testEmptyResourceCanAcquireDataBeforeClosing() { + final TsFileResource resource = new TsFileResource(file); + resource.setStatusForTest(TsFileResourceStatus.UNCLOSED); + assertTrue(resource.isEmpty()); + + final IDeviceID device = Factory.DEFAULT_FACTORY.create("root.sg.d0"); + resource.updateStartTime(device, 1); + resource.updateEndTime(device, 2); + assertFalse(resource.isEmpty()); + + resource.setStatusForTest(TsFileResourceStatus.NORMAL); + assertFalse(resource.isEmpty()); + } + @Test(expected = IOException.class) public void testDeserializeMissingResource() throws IOException { tsFileResource.deserialize(); From 818e55ccb1664997b2628596cd4c49d93a3280d2 Mon Sep 17 00:00:00 2001 From: Peng Junzhi <201250214@smail.nju.edu.cn> Date: Wed, 25 Nov 2026 20:00:18 +0800 Subject: [PATCH 3/4] Make protocol-specific DataNode tests explicit --- .../DataNodeInternalRPCServiceImplTest.java | 15 ++++++++++++--- .../InsertionCrossSpaceCompactionTest.java | 19 +++++++++++++++++-- .../load/LoadTsFileCleanerTest.java | 4 +++- .../LoadTsFileManagerSplitCoverageTest.java | 2 ++ .../load/LoadTsFileManagerTest.java | 6 ++++-- .../load/TsFileWriterManagerRecoveryTest.java | 7 +++++++ 6 files changed, 45 insertions(+), 8 deletions(-) diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/service/DataNodeInternalRPCServiceImplTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/service/DataNodeInternalRPCServiceImplTest.java index ff337f3454c97..64713d5dd6923 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/service/DataNodeInternalRPCServiceImplTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/service/DataNodeInternalRPCServiceImplTest.java @@ -101,6 +101,7 @@ public class DataNodeInternalRPCServiceImplTest { private static final IoTDBConfig conf = IoTDBDescriptor.getInstance().getConfig(); DataNodeInternalRPCServiceImpl dataNodeInternalRPCServiceImpl; private static IConsensus instance; + private static String originalDataRegionConsensusProtocol; private static final int dataNodeId = 0; private static final File storageDir = new File("target" + java.io.File.separator + "impl"); private static DataRegion dataRegion; @@ -120,8 +121,10 @@ public static void setUpBeforeClass() throws IOException, MetadataException, Con SchemaEngine.getInstance().init(); SchemaEngine.getInstance().createSchemaRegion("root.ln", new SchemaRegionId(0)); final DataRegionId id = new DataRegionId(1); - dataRegion = new DataRegion("root.ln", "1"); instance = DataRegionConsensusImpl.getInstance(); + originalDataRegionConsensusProtocol = conf.getDataRegionConsensusProtocolClass(); + conf.setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS); + dataRegion = new DataRegion("root.ln", "1"); DataRegionConsensusImpl.setInstance( ConsensusFactory.getConsensusImpl( ConsensusFactory.IOT_CONSENSUS, @@ -174,8 +177,14 @@ public void tearDown() throws Exception { @AfterClass public static void tearDownAfterClass() throws IOException, StorageEngineException { DataNodeRegionManager.getInstance().clear(); - DataRegionConsensusImpl.getInstance().stop(); - DataRegionConsensusImpl.setInstance(instance); + try { + DataRegionConsensusImpl.getInstance().stop(); + } finally { + DataRegionConsensusImpl.setInstance(instance); + if (originalDataRegionConsensusProtocol != null) { + conf.setDataRegionConsensusProtocolClass(originalDataRegionConsensusProtocol); + } + } SchemaRegionConsensusImpl.getInstance().stop(); SchemaEngine.getInstance().clear(); EnvironmentUtils.cleanEnv(); diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/cross/InsertionCrossSpaceCompactionTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/cross/InsertionCrossSpaceCompactionTest.java index 73c0bc2a721c3..deaf6de8c471c 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/cross/InsertionCrossSpaceCompactionTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/cross/InsertionCrossSpaceCompactionTest.java @@ -20,6 +20,7 @@ package org.apache.iotdb.db.storageengine.dataregion.compaction.cross; import org.apache.iotdb.commons.exception.MetadataException; +import org.apache.iotdb.consensus.ConsensusFactory; import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.StorageEngineException; @@ -508,8 +509,22 @@ public void testInsertionCompactionScheduleWithMultiTimePartitions1() @Test public void testInsertionCompactionScheduleWithMultiTimePartitions2() throws IOException, InterruptedException { + // IoTV1 skips ordinary compaction in the partition that submitted insertion tasks. + assertInsertionCompactionSchedule(ConsensusFactory.IOT_CONSENSUS, 3); + } + + @Test + public void testIoTV2SchedulesOrdinaryCompactionAlongsideInsertion() + throws IOException, InterruptedException { + assertInsertionCompactionSchedule(ConsensusFactory.IOT_CONSENSUS_V2, 4); + } + + private void assertInsertionCompactionSchedule(String protocol, int expectedTaskCount) + throws IOException, InterruptedException { IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig(); int innerCompactionCandidateFileNum = config.getInnerCompactionCandidateFileNum(); + String originalProtocol = config.getDataRegionConsensusProtocolClass(); + config.setDataRegionConsensusProtocolClass(protocol); config.setInnerCompactionCandidateFileNum(2); try { TsFileResource unseqResource1 = @@ -552,9 +567,9 @@ public void testInsertionCompactionScheduleWithMultiTimePartitions2() tsFileManager.getOrCreateUnsequenceListByTimePartition(0).keepOrderInsert(unseqResource2); tsFileManager.getOrCreateSequenceListByTimePartition(2808).keepOrderInsert(unseqResource3); tsFileManager.getOrCreateSequenceListByTimePartition(2808).keepOrderInsert(unseqResource4); - // 2 insertion task + 1 inner task - Assert.assertEquals(3, dataRegion.executeCompaction()); + Assert.assertEquals(expectedTaskCount, dataRegion.executeCompaction()); } finally { + config.setDataRegionConsensusProtocolClass(originalProtocol); config.setInnerCompactionCandidateFileNum(innerCompactionCandidateFileNum); } } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileCleanerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileCleanerTest.java index 01482f2dfe045..c8d98abfb0273 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileCleanerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileCleanerTest.java @@ -68,6 +68,7 @@ public class LoadTsFileCleanerTest { @Before public void setUp() throws Exception { + LoadConsensusCompat.setIoTConsensusV2ForTest(false); tempDir = Files.createTempDirectory("load-cleaner-test").toFile(); config = IoTDBDescriptor.getInstance().getConfig(); originalLoadBaseDirs = config.getLoadTsFileDirs(); @@ -87,6 +88,7 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { + LoadConsensusCompat.setIoTConsensusV2ForTest(null); config.setLoadTsFileDirs(originalLoadBaseDirs); deleteRecursively(tempDir); } @@ -224,7 +226,7 @@ public void testIoTConsensusV2DoesNotWaitForAWALWatermark() throws Exception { cleaner.sweepRegisteredTasks(); Assert.assertFalse("V2 does not expand staged references from the WAL", taskDir.exists()); } finally { - LoadConsensusCompat.setIoTConsensusV2ForTest(null); + LoadConsensusCompat.setIoTConsensusV2ForTest(false); } } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManagerSplitCoverageTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManagerSplitCoverageTest.java index 7db4d160748cf..8f70aa35a0912 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManagerSplitCoverageTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManagerSplitCoverageTest.java @@ -140,6 +140,7 @@ public class LoadTsFileManagerSplitCoverageTest { @Before public void setUp() throws Exception { + LoadConsensusCompat.setIoTConsensusV2ForTest(false); tempDir = Files.createTempDirectory("load-split-coverage-test").toFile(); config = IoTDBDescriptor.getInstance().getConfig(); originalLoadBaseDirs = config.getLoadTsFileDirs(); @@ -167,6 +168,7 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { + LoadConsensusCompat.setIoTConsensusV2ForTest(null); final TSFileConfig tsFileConfig = TSFileDescriptor.getInstance().getConfig(); tsFileConfig.setPageSizeInByte(originalPageSize); tsFileConfig.setMaxNumberOfPointsInPage(originalMaxPointsInPage); diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManagerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManagerTest.java index 9c0060c5fa9f2..120fa659c0766 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManagerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/LoadTsFileManagerTest.java @@ -116,6 +116,7 @@ public class LoadTsFileManagerTest { @Before public void setUp() throws Exception { + LoadConsensusCompat.setIoTConsensusV2ForTest(false); tempDir = Files.createTempDirectory("load-tsfile-manager-test").toFile(); config = IoTDBDescriptor.getInstance().getConfig(); originalLoadBaseDirs = config.getLoadTsFileDirs(); @@ -130,6 +131,7 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { + LoadConsensusCompat.setIoTConsensusV2ForTest(null); config.setLoadTsFileDirs(originalLoadBaseDirs); deleteRecursively(tempDir); } @@ -783,7 +785,7 @@ public void testIoTConsensusV2WaitsForNoIndexBeforeReleasing() { "IoTConsensusV2 replicates through pipe, so there is no index to wait for", retention.mustRetain(10L)); } finally { - LoadConsensusCompat.setIoTConsensusV2ForTest(null); + LoadConsensusCompat.setIoTConsensusV2ForTest(false); } } @@ -900,7 +902,7 @@ private void assertCommittedProgress(final boolean useIoTConsensusV2, final int } } finally { manager.stop(); - LoadConsensusCompat.setIoTConsensusV2ForTest(null); + LoadConsensusCompat.setIoTConsensusV2ForTest(false); } } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/TsFileWriterManagerRecoveryTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/TsFileWriterManagerRecoveryTest.java index 9c76b75c6a172..8c33e16bba0b6 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/TsFileWriterManagerRecoveryTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/TsFileWriterManagerRecoveryTest.java @@ -39,6 +39,7 @@ import org.apache.tsfile.read.common.RowRecord; import org.apache.tsfile.read.expression.QueryExpression; import org.apache.tsfile.read.query.dataset.QueryDataSet; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -71,11 +72,17 @@ public class TsFileWriterManagerRecoveryTest { @Before public void setUp() { + LoadConsensusCompat.setIoTConsensusV2ForTest(false); dataRegion = Mockito.mock(DataRegion.class); Mockito.when(dataRegion.getDatabaseName()).thenReturn(DATABASE); Mockito.when(dataRegion.getDataRegionIdString()).thenReturn("0"); } + @After + public void tearDown() { + LoadConsensusCompat.setIoTConsensusV2ForTest(null); + } + @Test public void testResumeNegativeTimePartition() throws Exception { assertTimePartitionResumes(-604_800_000L); From 2ff3701c8e6ee6dd6c3735aa4df7af59a0a8713b Mon Sep 17 00:00:00 2001 From: Peng Junzhi <201250214@smail.nju.edu.cn> Date: Wed, 25 Nov 2026 20:00:18 +0800 Subject: [PATCH 4/4] Allow enough direct memory for IoTV2 standalone ITs --- .github/workflows/cluster-it-1c1d.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cluster-it-1c1d.yml b/.github/workflows/cluster-it-1c1d.yml index 815da70a811e8..3fc5a2288222b 100644 --- a/.github/workflows/cluster-it-1c1d.yml +++ b/.github/workflows/cluster-it-1c1d.yml @@ -69,6 +69,7 @@ jobs: -P with-integration-tests \ -DskipUTs \ -DintegrationTest.forkCount=2 \ + -DDataNodeMaxDirectMemorySize=768 \ -pl integration-test \ -am - name: Upload Artifact @@ -119,6 +120,7 @@ jobs: -P with-integration-tests \ -DskipUTs \ -DintegrationTest.forkCount=2 \ + -DDataNodeMaxDirectMemorySize=768 \ -Dfailsafe.includesFile="$RUNNER_TEMP/it-shard.txt" \ -DfailIfNoTests=false \ -Dfailsafe.failIfNoSpecifiedTests=false \