Skip to content

Commit 8e726a1

Browse files
committed
Merge branch 'master' into feature/iotconsensus-recv-snap
# Conflicts: # iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java # iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/util/LoadUtil.java
2 parents b779a1e + f4d628a commit 8e726a1

File tree

211 files changed

+7515
-3414
lines changed

Some content is hidden

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

211 files changed

+7515
-3414
lines changed

dependencies.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
"com.nimbusds:nimbus-jose-jwt",
3333
"com.nimbusds:oauth2-oidc-sdk",
3434
"com.sun.istack:istack-commons-runtime",
35-
"com.timecho.ratis:ratis-client",
36-
"com.timecho.ratis:ratis-common",
37-
"com.timecho.ratis:ratis-grpc",
38-
"com.timecho.ratis:ratis-metrics-api",
39-
"com.timecho.ratis:ratis-proto",
40-
"com.timecho.ratis:ratis-server",
41-
"com.timecho.ratis:ratis-server-api",
35+
"org.apache.ratis:ratis-client",
36+
"org.apache.ratis:ratis-common",
37+
"org.apache.ratis:ratis-grpc",
38+
"org.apache.ratis:ratis-metrics-api",
39+
"org.apache.ratis:ratis-proto",
40+
"org.apache.ratis:ratis-server",
41+
"org.apache.ratis:ratis-server-api",
4242
"com.zaxxer:HikariCP",
4343
"commons-cli:commons-cli",
4444
"commons-codec:commons-codec",

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBLoadTsFileIT.java

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
2424
import org.apache.iotdb.db.it.utils.TestUtils;
2525
import org.apache.iotdb.it.env.EnvFactory;
26+
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
2627
import org.apache.iotdb.it.framework.IoTDBTestRunner;
2728
import org.apache.iotdb.it.utils.TsFileGenerator;
2829
import org.apache.iotdb.itbase.category.ClusterIT;
@@ -67,6 +68,7 @@
6768
import static org.apache.iotdb.db.it.utils.TestUtils.executeNonQuery;
6869
import static org.apache.iotdb.db.it.utils.TestUtils.grantUserSeriesPrivilege;
6970
import static org.apache.iotdb.db.it.utils.TestUtils.grantUserSystemPrivileges;
71+
import static org.apache.iotdb.it.env.cluster.ClusterConstant.USER_DIR;
7072

7173
@RunWith(IoTDBTestRunner.class)
7274
@Category({LocalStandaloneIT.class, ClusterIT.class})
@@ -261,6 +263,108 @@ public void testLoad() throws Exception {
261263
}
262264
}
263265

266+
@Test
267+
// Shall succeed with tablet conversion
268+
public void testLoadWithAlignmentMismatch() throws Exception {
269+
registerSchema();
270+
271+
final long writtenPoint1;
272+
// device 0, sg 0
273+
try (final TsFileGenerator generator =
274+
new TsFileGenerator(new File(tmpDir, "1-0-0-0.tsfile"))) {
275+
// Wrong, with 04-07 non-exist
276+
generator.registerAlignedTimeseries(
277+
SchemaConfig.DEVICE_0,
278+
Arrays.asList(
279+
SchemaConfig.MEASUREMENT_00,
280+
SchemaConfig.MEASUREMENT_01,
281+
SchemaConfig.MEASUREMENT_02,
282+
SchemaConfig.MEASUREMENT_03,
283+
SchemaConfig.MEASUREMENT_04,
284+
SchemaConfig.MEASUREMENT_05,
285+
SchemaConfig.MEASUREMENT_06,
286+
SchemaConfig.MEASUREMENT_07));
287+
generator.generateData(SchemaConfig.DEVICE_0, 100000, PARTITION_INTERVAL / 10_000, false);
288+
writtenPoint1 = generator.getTotalNumber();
289+
}
290+
291+
final long writtenPoint2;
292+
// device 2, device 3, device4, sg 1
293+
try (final TsFileGenerator generator =
294+
new TsFileGenerator(new File(tmpDir, "2-0-0-0.tsfile"))) {
295+
// right
296+
generator.registerTimeseries(
297+
SchemaConfig.DEVICE_2, Collections.singletonList(SchemaConfig.MEASUREMENT_20));
298+
// right
299+
generator.registerTimeseries(
300+
SchemaConfig.DEVICE_3, Collections.singletonList(SchemaConfig.MEASUREMENT_30));
301+
// Wrong, with 06 non-exist
302+
generator.registerTimeseries(
303+
SchemaConfig.DEVICE_4,
304+
Arrays.asList(SchemaConfig.MEASUREMENT_40, SchemaConfig.MEASUREMENT_06));
305+
generator.generateData(SchemaConfig.DEVICE_2, 10000, PARTITION_INTERVAL / 10_000, false);
306+
generator.generateData(SchemaConfig.DEVICE_3, 10000, PARTITION_INTERVAL / 10_000, false);
307+
generator.generateData(SchemaConfig.DEVICE_4, 10000, PARTITION_INTERVAL / 10_000, true);
308+
for (int i = 0; i < 1000; i++) {
309+
generator.generateData(SchemaConfig.DEVICE_4, 1, PARTITION_INTERVAL - 10, true);
310+
}
311+
writtenPoint2 = generator.getTotalNumber();
312+
}
313+
314+
try (final Connection connection = EnvFactory.getEnv().getConnection();
315+
final Statement statement = connection.createStatement()) {
316+
317+
try {
318+
statement.execute(
319+
String.format(
320+
"load \"%s\" with ('database-level'='2', 'convert-on-type-mismatch'='false')",
321+
tmpDir.getAbsolutePath() + File.separator + "1-0-0-0.tsfile"));
322+
Assert.fail();
323+
} catch (final Exception e) {
324+
Assert.assertTrue(
325+
e.getMessage()
326+
.contains(
327+
"TimeSeries under this device is not aligned, please use createTimeSeries or change device. (Path: root.sg.test_0.d_0)."));
328+
}
329+
330+
try {
331+
statement.execute(
332+
String.format(
333+
"load \"%s\" with ('database-level'='2', 'convert-on-type-mismatch'='false')",
334+
tmpDir.getAbsolutePath() + File.separator + "2-0-0-0.tsfile"));
335+
Assert.fail();
336+
} catch (final Exception e) {
337+
Assert.assertTrue(
338+
e.getMessage()
339+
.contains(
340+
"TimeSeries under this device is aligned, please use createAlignedTimeSeries or change device. (Path: root.sg.test_1.a_4)."));
341+
}
342+
343+
statement.execute(String.format("load \"%s\" sglevel=2", tmpDir.getAbsolutePath()));
344+
345+
try (final ResultSet resultSet =
346+
statement.executeQuery("select count(*) from root.sg.** group by level=1,2")) {
347+
if (resultSet.next()) {
348+
long sg1Count = resultSet.getLong("count(root.sg.test_0.*.*)");
349+
Assert.assertEquals(writtenPoint1, sg1Count);
350+
long sg2Count = resultSet.getLong("count(root.sg.test_1.*.*)");
351+
Assert.assertEquals(writtenPoint2, sg2Count);
352+
} else {
353+
Assert.fail("This ResultSet is empty.");
354+
}
355+
}
356+
}
357+
358+
// Try to delete after loading. Expect no deadlock
359+
try (final Connection connection = EnvFactory.getEnv().getConnection();
360+
final Statement statement = connection.createStatement()) {
361+
statement.execute(
362+
String.format(
363+
"delete timeseries %s.%s",
364+
SchemaConfig.DEVICE_0, SchemaConfig.MEASUREMENT_00.getMeasurementName()));
365+
}
366+
}
367+
264368
@Test
265369
public void testLoadAcrossMultipleTimePartitions() throws Exception {
266370
registerSchema();
@@ -742,6 +846,47 @@ public void testLoadWithOnNonStandardTsFileName() throws Exception {
742846
}
743847
}
744848

849+
@Test
850+
public void testLoadWithRelativePathName() throws Exception {
851+
DataNodeWrapper dataNodeWrapper = EnvFactory.getEnv().getDataNodeWrapper(0);
852+
853+
registerSchema();
854+
855+
final long writtenPoint1;
856+
// device 0, device 1, sg 0
857+
File relativePathFile = new File(System.getProperty(USER_DIR), "1-0-0-0.tsfile");
858+
try {
859+
try (final TsFileGenerator generator = new TsFileGenerator(relativePathFile)) {
860+
generator.registerTimeseries(
861+
SchemaConfig.DEVICE_0, Collections.singletonList(SchemaConfig.MEASUREMENT_00));
862+
generator.generateData(SchemaConfig.DEVICE_0, 1, PARTITION_INTERVAL / 10_000, false);
863+
writtenPoint1 = generator.getTotalNumber();
864+
}
865+
866+
try (final Connection connection =
867+
EnvFactory.getEnv().getConnectionWithSpecifiedDataNode(dataNodeWrapper);
868+
final Statement statement = connection.createStatement()) {
869+
870+
statement.execute(String.format("load \"%s\" sglevel=2", "1-0-0-0.tsfile"));
871+
872+
try (final ResultSet resultSet =
873+
statement.executeQuery("select count(*) from root.sg.** group by level=1,2")) {
874+
if (resultSet.next()) {
875+
final long sg1Count = resultSet.getLong("count(root.sg.test_0.*.*)");
876+
Assert.assertEquals(writtenPoint1, sg1Count);
877+
} else {
878+
Assert.fail("This ResultSet is empty.");
879+
}
880+
}
881+
}
882+
883+
} finally {
884+
if (relativePathFile.exists()) {
885+
relativePathFile.delete();
886+
}
887+
}
888+
}
889+
745890
@Test
746891
public void testLoadWithMods() throws Exception {
747892
final long writtenPoint1;

integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBAuthIT.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static org.apache.iotdb.commons.auth.entity.User.INTERNAL_USER_END_ID;
5555
import static org.apache.iotdb.db.audit.DNAuditLogger.PREFIX_PASSWORD_HISTORY;
5656
import static org.apache.iotdb.db.it.utils.TestUtils.createUser;
57+
import static org.apache.iotdb.db.it.utils.TestUtils.executeNonQuery;
5758
import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
5859
import static org.junit.Assert.assertEquals;
5960
import static org.junit.Assert.assertFalse;
@@ -980,6 +981,8 @@ public void testGrantAndGrantOpt() throws SQLException {
980981
adminStmt.execute("CREATE USER user1 'password123456'");
981982
adminStmt.execute("CREATE USER user2 'password123456'");
982983
adminStmt.execute("CREATE USER user3 'password123456'");
984+
adminStmt.execute("CREATE USER user4 'password123456'");
985+
adminStmt.execute("CREATE USER user5 'password123456'");
983986
adminStmt.execute("CREATE ROLE testRole");
984987
adminStmt.execute("GRANT system ON root.** TO ROLE testRole WITH GRANT OPTION");
985988
adminStmt.execute("GRANT READ_DATA ON root.t1.** TO ROLE testRole");
@@ -1094,6 +1097,18 @@ public void testGrantAndGrantOpt() throws SQLException {
10941097
}
10951098
}
10961099

1100+
try (Connection userCon = EnvFactory.getEnv().getConnection("user4", "password123456");
1101+
Statement userStmt = userCon.createStatement()) {
1102+
adminStmt.execute("GRANT SYSTEM ON root.** TO USER user4");
1103+
try {
1104+
Assert.assertThrows(
1105+
SQLException.class, () -> userStmt.execute("GRANT SYSTEM ON root.** TO USER user5"));
1106+
adminStmt.execute("GRANT SYSTEM ON root.** TO USER user5");
1107+
} finally {
1108+
userStmt.close();
1109+
}
1110+
}
1111+
10971112
adminStmt.close();
10981113
}
10991114

@@ -1381,6 +1396,7 @@ public void noNeedPrivilegeTest() {
13811396
"tempuser,",
13821397
};
13831398
resultSetEqualTest("show current_user", expectedHeader, retArray, "tempuser", "temppw123456");
1399+
executeNonQuery("SHOW AVAILABLE URLS", "tempuser", "temppw123456");
13841400
}
13851401

13861402
@Ignore

integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBCreateAlignedTimeseriesIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.iotdb.db.it.schema;
2020

2121
import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
22+
import org.apache.iotdb.db.it.utils.TestUtils;
2223
import org.apache.iotdb.it.env.EnvFactory;
2324
import org.apache.iotdb.itbase.category.ClusterIT;
2425
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
@@ -34,6 +35,9 @@
3435
import java.sql.ResultSet;
3536
import java.sql.SQLException;
3637
import java.sql.Statement;
38+
import java.util.Collections;
39+
40+
import static org.junit.Assert.fail;
3741

3842
/**
3943
* Notice that, all test begins with "IoTDB" is integration test. All test which will start the
@@ -141,4 +145,22 @@ private void assertTimeseriesEquals(String[] timeSeriesArray) throws SQLExceptio
141145
}
142146
Assert.assertEquals(timeSeriesArray.length, count);
143147
}
148+
149+
@Test
150+
public void testDifferentDeviceAlignment() {
151+
try (Connection connection = EnvFactory.getEnv().getConnection();
152+
Statement statement = connection.createStatement()) {
153+
// Should ignore the alignment difference
154+
statement.execute("create aligned timeseries root.sg2.d (s2 int64, s3 int64)");
155+
// Should use the existing alignment
156+
statement.execute("create timeseries root.sg2.d.s1 with datatype=INT64");
157+
statement.execute("insert into root.sg2.d (time, s4) values (-1, 1)");
158+
TestUtils.assertResultSetEqual(
159+
statement.executeQuery("select * from root.sg2.d"),
160+
"Time,root.sg2.d.s3,root.sg2.d.s4,root.sg2.d.s1,root.sg2.d.s2,",
161+
Collections.singleton("-1,null,1.0,null,null,"));
162+
} catch (SQLException ignored) {
163+
fail();
164+
}
165+
}
144166
}

integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBCreateTimeseriesIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.iotdb.db.it.schema;
2121

2222
import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
23+
import org.apache.iotdb.db.it.utils.TestUtils;
2324
import org.apache.iotdb.it.env.EnvFactory;
2425
import org.apache.iotdb.itbase.category.ClusterIT;
2526
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
@@ -35,6 +36,7 @@
3536
import java.sql.ResultSet;
3637
import java.sql.SQLException;
3738
import java.sql.Statement;
39+
import java.util.Collections;
3840
import java.util.HashSet;
3941
import java.util.Set;
4042

@@ -308,6 +310,12 @@ public void testDifferentDeviceAlignment() {
308310
statement.execute("create timeseries root.sg2.d.s1 with datatype=INT64");
309311
// Should ignore the alignment difference
310312
statement.execute("create aligned timeseries root.sg2.d (s2 int64, s3 int64)");
313+
// Should use the existing alignment
314+
statement.execute("insert into root.sg2.d (time, s4) aligned values (-1, 1)");
315+
TestUtils.assertResultSetEqual(
316+
statement.executeQuery("select * from root.sg2.d"),
317+
"Time,root.sg2.d.s3,root.sg2.d.s4,root.sg2.d.s1,root.sg2.d.s2,",
318+
Collections.singleton("-1,null,1.0,null,null,"));
311319
} catch (SQLException ignored) {
312320
fail();
313321
}

integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.apache.iotdb.db.it.selectinto;
2121

22+
import org.apache.iotdb.db.it.utils.TSDataTypeTestUtils;
2223
import org.apache.iotdb.it.env.EnvFactory;
2324
import org.apache.iotdb.it.framework.IoTDBTestRunner;
2425
import org.apache.iotdb.itbase.category.ClusterIT;
@@ -104,13 +105,11 @@ public class IoTDBSelectIntoIT {
104105
static {
105106
SELECT_INTO_SQL_LIST.add("CREATE DATABASE root.sg_type");
106107
for (int deviceId = 0; deviceId < 6; deviceId++) {
107-
for (TSDataType dataType : TSDataType.values()) {
108-
if (!dataType.equals(TSDataType.VECTOR) && !dataType.equals(TSDataType.UNKNOWN)) {
109-
SELECT_INTO_SQL_LIST.add(
110-
String.format(
111-
"CREATE TIMESERIES root.sg_type.d_%d.s_%s %s",
112-
deviceId, dataType.name().toLowerCase(), dataType));
113-
}
108+
for (TSDataType dataType : TSDataTypeTestUtils.getSupportedTypes()) {
109+
SELECT_INTO_SQL_LIST.add(
110+
String.format(
111+
"CREATE TIMESERIES root.sg_type.d_%d.s_%s %s",
112+
deviceId, dataType.name().toLowerCase(), dataType));
114113
}
115114
}
116115
for (int time = 0; time < 12; time++) {

0 commit comments

Comments
 (0)