Skip to content

Commit eda0433

Browse files
committed
Merge branch 'master' of https://github.com/apache/iotdb into time-partition-boundary-overflow-fix
# Conflicts: # iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceTest.java
2 parents 44fff3b + 4c1f833 commit eda0433

94 files changed

Lines changed: 3919 additions & 965 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

integration-test/src/test/java/org/apache/iotdb/confignode/it/database/IoTDBDatabaseRegionControlIT.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import java.io.IOException;
4141
import java.sql.Connection;
42+
import java.sql.ResultSet;
4243
import java.sql.SQLException;
4344
import java.sql.Statement;
4445
import java.util.Collections;
@@ -164,6 +165,53 @@ public void testRegionGroupNumControlThroughCreation()
164165
}
165166
}
166167

168+
@Test
169+
public void testRecreateWithPartialMaxRegionGroupNumUsesDefaultCounterpart() throws SQLException {
170+
try (final Connection connection = EnvFactory.getEnv().getConnection();
171+
final Statement statement = connection.createStatement()) {
172+
final String database = "root.rg_tree_create_schema";
173+
statement.execute(String.format("CREATE DATABASE %s;", database));
174+
175+
try (final ResultSet resultSet =
176+
statement.executeQuery("SHOW DATABASES DETAILS " + database)) {
177+
Assert.assertTrue(resultSet.next());
178+
Assert.assertEquals(
179+
testDefaultSchemaRegionGroupNumPerDatabase,
180+
resultSet.getInt("MaxSchemaRegionGroupNum"));
181+
Assert.assertEquals(
182+
testDefaultDataRegionGroupNumPerDatabase, resultSet.getInt("MaxDataRegionGroupNum"));
183+
Assert.assertFalse(resultSet.next());
184+
}
185+
186+
statement.execute(String.format("DROP DATABASE %s;", database));
187+
statement.execute(
188+
String.format("CREATE DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=3;", database));
189+
190+
try (final ResultSet resultSet =
191+
statement.executeQuery("SHOW DATABASES DETAILS " + database)) {
192+
Assert.assertTrue(resultSet.next());
193+
Assert.assertEquals(3, resultSet.getInt("MaxSchemaRegionGroupNum"));
194+
Assert.assertEquals(
195+
testDefaultDataRegionGroupNumPerDatabase, resultSet.getInt("MaxDataRegionGroupNum"));
196+
Assert.assertFalse(resultSet.next());
197+
}
198+
199+
final String dataDatabase = "root.rg_tree_create_data";
200+
statement.execute(
201+
String.format("CREATE DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=4;", dataDatabase));
202+
203+
try (final ResultSet resultSet =
204+
statement.executeQuery("SHOW DATABASES DETAILS " + dataDatabase)) {
205+
Assert.assertTrue(resultSet.next());
206+
Assert.assertEquals(
207+
testDefaultSchemaRegionGroupNumPerDatabase,
208+
resultSet.getInt("MaxSchemaRegionGroupNum"));
209+
Assert.assertEquals(4, resultSet.getInt("MaxDataRegionGroupNum"));
210+
Assert.assertFalse(resultSet.next());
211+
}
212+
}
213+
}
214+
167215
@Test
168216
public void testRegionGroupNumControlThroughAlter()
169217
throws SQLException, ClientManagerException, IOException, InterruptedException, TException {
@@ -236,6 +284,69 @@ public void testRegionGroupNumControlThroughAlter()
236284
}
237285
}
238286

287+
@Test
288+
public void testAlterMaxDataRegionGroupNumCannotDecrease() throws SQLException {
289+
try (final Connection connection = EnvFactory.getEnv().getConnection();
290+
final Statement statement = connection.createStatement()) {
291+
final String database = "root.rg_tree_decrease";
292+
statement.execute(
293+
String.format("CREATE DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=8;", database));
294+
statement.execute(
295+
String.format("ALTER DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=16;", database));
296+
297+
final SQLException exception =
298+
Assert.assertThrows(
299+
SQLException.class,
300+
() ->
301+
statement.execute(
302+
String.format(
303+
"ALTER DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=12;", database)));
304+
Assert.assertTrue(
305+
exception.getMessage(),
306+
exception
307+
.getMessage()
308+
.contains(
309+
"MaxDataRegionGroupNum should be greater than or equal to current max "
310+
+ "DataRegionGroupNum: 16."));
311+
312+
try (final ResultSet resultSet =
313+
statement.executeQuery("SHOW DATABASES DETAILS " + database)) {
314+
Assert.assertTrue(resultSet.next());
315+
Assert.assertEquals(16, resultSet.getInt("MaxDataRegionGroupNum"));
316+
Assert.assertFalse(resultSet.next());
317+
}
318+
319+
final String schemaDatabase = "root.rg_tree_decrease_schema";
320+
statement.execute(
321+
String.format("CREATE DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=4;", schemaDatabase));
322+
statement.execute(
323+
String.format("ALTER DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=5;", schemaDatabase));
324+
325+
final SQLException schemaException =
326+
Assert.assertThrows(
327+
SQLException.class,
328+
() ->
329+
statement.execute(
330+
String.format(
331+
"ALTER DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=3;",
332+
schemaDatabase)));
333+
Assert.assertTrue(
334+
schemaException.getMessage(),
335+
schemaException
336+
.getMessage()
337+
.contains(
338+
"MaxSchemaRegionGroupNum should be greater than or equal to current max "
339+
+ "SchemaRegionGroupNum: 5."));
340+
341+
try (final ResultSet resultSet =
342+
statement.executeQuery("SHOW DATABASES DETAILS " + schemaDatabase)) {
343+
Assert.assertTrue(resultSet.next());
344+
Assert.assertEquals(5, resultSet.getInt("MaxSchemaRegionGroupNum"));
345+
Assert.assertFalse(resultSet.next());
346+
}
347+
}
348+
}
349+
239350
@Test
240351
public void testDeprecatedRegionGroupNumSqlRejected() throws SQLException {
241352
try (final Connection connection = EnvFactory.getEnv().getConnection();

integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBMigrateMultiRegionForIoTV1IT.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import java.sql.Connection;
3939
import java.sql.Statement;
40+
import java.util.ArrayList;
4041
import java.util.List;
4142
import java.util.Map;
4243
import java.util.Optional;
@@ -51,6 +52,7 @@
5152
@RunWith(IoTDBTestRunner.class)
5253
public class IoTDBMigrateMultiRegionForIoTV1IT extends IoTDBRegionOperationReliabilityITFramework {
5354
private static final String MULTI_REGION_MIGRATE_FORMAT = "migrate region %s from %d to %d";
55+
private static final String EXPAND_FORMAT = "extend region %d to %d";
5456

5557
private static final Logger LOGGER =
5658
LoggerFactory.getLogger(IoTDBMigrateMultiRegionForIoTV1IT.class);
@@ -90,6 +92,10 @@ public void multiRegionMigrateTest() throws Exception {
9092
Map<Integer, Set<Integer>> regionMap = getAllRegionMap(statement);
9193
Set<Integer> allDataNodeId = getAllDataNodes(statement);
9294

95+
// INSERTION1 only creates one schema region and one data region; with replication factor 1
96+
// they are often placed on different DataNodes. Colocate them before multi-region migrate.
97+
regionMap = ensureDataNodeHostsMultipleRegions(statement, client, regionMap);
98+
9399
// With replication factor 1 every region lives on exactly one DataNode. Pick a source
94100
// DataNode that hosts at least two regions, then migrate all its regions to a fresh
95101
// destination DataNode.
@@ -177,6 +183,66 @@ public void multiRegionMigrateTest() throws Exception {
177183
}
178184
}
179185

186+
private Map<Integer, Set<Integer>> ensureDataNodeHostsMultipleRegions(
187+
Statement statement,
188+
SyncConfigNodeIServiceClient client,
189+
Map<Integer, Set<Integer>> regionMap)
190+
throws Exception {
191+
if (hasDataNodeHostingMultipleRegions(regionMap)) {
192+
return regionMap;
193+
}
194+
List<Integer> regionIds = new ArrayList<>(regionMap.keySet());
195+
Assert.assertTrue("Need at least two regions to colocate", regionIds.size() >= 2);
196+
197+
int firstRegion = regionIds.get(0);
198+
int secondRegion = regionIds.get(1);
199+
int targetDataNode = regionMap.get(secondRegion).iterator().next();
200+
regionGroupExpand(statement, client, firstRegion, targetDataNode);
201+
return getAllRegionMap(statement);
202+
}
203+
204+
private boolean hasDataNodeHostingMultipleRegions(Map<Integer, Set<Integer>> regionMap) {
205+
return regionMap.values().stream()
206+
.flatMap(Set::stream)
207+
.collect(Collectors.groupingBy(dataNodeId -> dataNodeId, Collectors.counting()))
208+
.values()
209+
.stream()
210+
.anyMatch(count -> count >= 2);
211+
}
212+
213+
private void regionGroupExpand(
214+
Statement statement,
215+
SyncConfigNodeIServiceClient client,
216+
int selectedRegion,
217+
int targetDataNode)
218+
throws Exception {
219+
Awaitility.await()
220+
.atMost(10, TimeUnit.SECONDS)
221+
.pollInterval(1, TimeUnit.SECONDS)
222+
.until(
223+
() -> {
224+
statement.execute(String.format(EXPAND_FORMAT, selectedRegion, targetDataNode));
225+
return true;
226+
});
227+
228+
Predicate<TShowRegionResp> expandRegionPredicate =
229+
tShowRegionResp -> {
230+
Map<Integer, Set<Integer>> newRegionMap =
231+
getRunningRegionMap(tShowRegionResp.getRegionInfoList());
232+
Set<Integer> dataNodes = newRegionMap.get(selectedRegion);
233+
return dataNodes != null && dataNodes.contains(targetDataNode);
234+
};
235+
236+
awaitUntilSuccess(
237+
client,
238+
selectedRegion,
239+
expandRegionPredicate,
240+
Optional.of(targetDataNode),
241+
Optional.empty());
242+
243+
LOGGER.info("Region {} has expanded to DataNode {}", selectedRegion, targetDataNode);
244+
}
245+
180246
private int selectDataNodeHostingMultipleRegions(Map<Integer, Set<Integer>> regionMap) {
181247
Map<Integer, Long> regionCountPerDataNode =
182248
regionMap.values().stream()

integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/daily/iotv1/IoTDBRegionMigrateWithDeletionMultiDataDirIT.java renamed to integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1;
20+
package org.apache.iotdb.confignode.it.regionmigration.pass.commit;
2121

2222
import org.apache.iotdb.consensus.ConsensusFactory;
2323
import org.apache.iotdb.it.env.EnvFactory;
@@ -43,12 +43,12 @@
4343

4444
import static org.apache.iotdb.confignode.it.regionmigration.IoTDBRegionOperationReliabilityITFramework.getAllDataNodes;
4545
import static org.apache.iotdb.confignode.it.regionmigration.IoTDBRegionOperationReliabilityITFramework.getDataRegionMapWithLeader;
46-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.MULTI_DATA_DIRS;
47-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.awaitModsVisibleOnReplicas;
48-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.awaitRegionReplicas;
49-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.awaitTsFileResourceVisibleOnReplicas;
50-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.awaitTsFileVisibleOnReplicas;
51-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.getReplicaDataNodeIds;
46+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.MULTI_DATA_DIRS;
47+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.awaitModsVisibleOnReplicas;
48+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.awaitRegionReplicas;
49+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.awaitTsFileResourceVisibleOnReplicas;
50+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.awaitTsFileVisibleOnReplicas;
51+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.getReplicaDataNodeIds;
5252

5353
/**
5454
* Tree-model coverage for IoTConsensus region migration over multiple data dirs: a deletion (mods)

integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/daily/iotv1/IoTDBRegionMigrateWithDeletionMultiDataDirTableIT.java renamed to integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDBRegionMigrateWithDeletionMultiDataDirTableIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1;
20+
package org.apache.iotdb.confignode.it.regionmigration.pass.commit;
2121

2222
import org.apache.iotdb.consensus.ConsensusFactory;
2323
import org.apache.iotdb.isession.SessionConfig;
@@ -45,12 +45,12 @@
4545

4646
import static org.apache.iotdb.confignode.it.regionmigration.IoTDBRegionOperationReliabilityITFramework.getAllDataNodes;
4747
import static org.apache.iotdb.confignode.it.regionmigration.IoTDBRegionOperationReliabilityITFramework.getDataRegionMapWithLeader;
48-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.MULTI_DATA_DIRS;
49-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.awaitModsVisibleOnReplicas;
50-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.awaitRegionReplicas;
51-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.awaitTsFileResourceVisibleOnReplicas;
52-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.awaitTsFileVisibleOnReplicas;
53-
import static org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1.RegionMigrateFileAssertions.getReplicaDataNodeIds;
48+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.MULTI_DATA_DIRS;
49+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.awaitModsVisibleOnReplicas;
50+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.awaitRegionReplicas;
51+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.awaitTsFileResourceVisibleOnReplicas;
52+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.awaitTsFileVisibleOnReplicas;
53+
import static org.apache.iotdb.confignode.it.regionmigration.pass.commit.RegionMigrateFileAssertions.getReplicaDataNodeIds;
5454

5555
/**
5656
* Table-model twin of {@link IoTDBRegionMigrateWithDeletionMultiDataDirIT}: a deletion (mods) must

integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/daily/iotv1/RegionMigrateFileAssertions.java renamed to integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/RegionMigrateFileAssertions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.apache.iotdb.confignode.it.regionmigration.pass.daily.iotv1;
20+
package org.apache.iotdb.confignode.it.regionmigration.pass.commit;
2121

2222
import org.apache.iotdb.it.env.EnvFactory;
2323
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;

integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/batch/IoTDBRegionMigrateNormalITForIoTV2BatchIT.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@
2121

2222
import org.apache.iotdb.commons.utils.KillPoint.KillNode;
2323
import org.apache.iotdb.confignode.it.regionmigration.IoTDBRegionOperationReliabilityITFramework;
24+
import org.apache.iotdb.it.env.EnvFactory;
2425
import org.apache.iotdb.it.framework.IoTDBTestRunner;
2526
import org.apache.iotdb.itbase.category.ClusterIT;
2627

28+
import org.junit.Assert;
2729
import org.junit.Test;
2830
import org.junit.experimental.categories.Category;
2931
import org.junit.runner.RunWith;
3032

33+
import java.sql.Connection;
34+
import java.sql.ResultSet;
35+
import java.sql.Statement;
36+
37+
import static org.apache.iotdb.util.MagicUtils.makeItCloseQuietly;
38+
3139
@Category({ClusterIT.class})
3240
@RunWith(IoTDBTestRunner.class)
3341
public class IoTDBRegionMigrateNormalITForIoTV2BatchIT
@@ -41,4 +49,30 @@ public void normal1C2DTest() throws Exception {
4149
public void normal3C3DTest() throws Exception {
4250
successTest(2, 3, 3, 3, noKillPoints(), noKillPoints(), KillNode.ALL_NODES);
4351
}
52+
53+
@Test
54+
public void migrateRegionWithDegradedTimeIndexTest() throws Exception {
55+
// set TsFileResource memory to 0 to trigger degrading
56+
EnvFactory.getEnv().getConfig().getCommonConfig().setQueryMemoryProportion("1:1:1:1:1:1:0");
57+
58+
successTest(1, 1, 1, 2, noKillPoints(), noKillPoints(), KillNode.ALL_NODES);
59+
60+
try (final Connection connection = makeItCloseQuietly(EnvFactory.getEnv().getConnection());
61+
final Statement statement = makeItCloseQuietly(connection.createStatement())) {
62+
assertCounts(statement, 1, 1);
63+
statement.execute("INSERT INTO root.sg.d1(timestamp,speed,temperature) values(101, 3, 4)");
64+
assertCounts(statement, 2, 2);
65+
}
66+
}
67+
68+
private static void assertCounts(
69+
final Statement statement, final long expectedSpeedCount, final long expectedTemperatureCount)
70+
throws Exception {
71+
try (final ResultSet resultSet =
72+
statement.executeQuery("select count(speed), count(temperature) from root.sg.d1")) {
73+
Assert.assertTrue(resultSet.next());
74+
Assert.assertEquals(expectedSpeedCount, resultSet.getLong(1));
75+
Assert.assertEquals(expectedTemperatureCount, resultSet.getLong(2));
76+
}
77+
}
4478
}

integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeDoubleLivingIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testDoubleLivingInvalidForwardingParameter() throws Exception {
7171
"create pipe %s"
7272
+ " with source ("
7373
+ "'capture.tree'='false',"
74-
+ "'mode.double-living'='true')"
74+
+ "'double-living'='true')"
7575
+ " with sink ("
7676
+ "'node-urls'='%s')",
7777
"p1", receiverDataNode.getIpAndPortString()));
@@ -84,7 +84,7 @@ public void testDoubleLivingInvalidForwardingParameter() throws Exception {
8484
"create pipe %s"
8585
+ " with source ("
8686
+ "'capture.table'='false',"
87-
+ "'mode.double-living'='true')"
87+
+ "'source.mode.double-living'='true')"
8888
+ " with sink ("
8989
+ "'node-urls'='%s')",
9090
"p2", receiverDataNode.getIpAndPortString()));
@@ -286,7 +286,7 @@ public void testDoubleLivingIsolation() throws Exception {
286286
String.format(
287287
"create pipe %s"
288288
+ " with source ("
289-
+ "'mode.double-living'='true')"
289+
+ "'double-living'='true')"
290290
+ " with sink ("
291291
+ "'node-urls'='%s')",
292292
treePipeName, receiverDataNode.getIpAndPortString()));
@@ -308,7 +308,7 @@ public void testDoubleLivingIsolation() throws Exception {
308308
String.format(
309309
"create pipe %s"
310310
+ " with source ("
311-
+ "'mode.double-living'='true')"
311+
+ "'source.mode.double-living'='true')"
312312
+ " with sink ("
313313
+ "'node-urls'='%s')",
314314
tablePipeName, receiverDataNode.getIpAndPortString()));
@@ -350,7 +350,7 @@ public void testDoubleLivingCreatesSameNamePipesWithSeparateDialects() throws Ex
350350
statement.execute(
351351
String.format(
352352
"create pipe %s"
353-
+ " with source ('mode.double-living'='true')"
353+
+ " with source ('extractor.double-living'='true')"
354354
+ " with sink ('node-urls'='%s')",
355355
pipeName, receiverDataNode.getIpAndPortString()));
356356
}

0 commit comments

Comments
 (0)