|
27 | 27 | import org.apache.iotdb.it.env.EnvFactory; |
28 | 28 | import org.apache.iotdb.it.framework.IoTDBTestRunner; |
29 | 29 | import org.apache.iotdb.itbase.category.ClusterIT; |
| 30 | +import org.apache.iotdb.itbase.env.BaseEnv; |
30 | 31 | import org.apache.iotdb.rpc.TSStatusCode; |
31 | 32 |
|
32 | 33 | import org.junit.After; |
|
45 | 46 | @Category({ClusterIT.class}) |
46 | 47 | public class IoTDBPartitionTableAutoCleanIT { |
47 | 48 |
|
| 49 | + private static final String TREE_DATABASE_PREFIX = "root.db.g_"; |
| 50 | + private static final String TABLE_DATABASE_PREFIX = "database_"; |
| 51 | + |
48 | 52 | private static final int TEST_REPLICATION_FACTOR = 1; |
49 | 53 | private static final long TEST_TIME_PARTITION_INTERVAL = 604800000; |
50 | 54 | private static final long TEST_TTL_CHECK_INTERVAL = 5_000; |
@@ -73,46 +77,86 @@ public void tearDown() { |
73 | 77 | } |
74 | 78 |
|
75 | 79 | @Test |
76 | | - public void testAutoCleanPartitionTable() throws Exception { |
77 | | - try (Connection connection = EnvFactory.getEnv().getConnection(); |
| 80 | + public void testAutoCleanPartitionTableForTreeModel() throws Exception { |
| 81 | + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TREE_SQL_DIALECT); |
78 | 82 | Statement statement = connection.createStatement()) { |
79 | | - // Create db1 |
80 | | - statement.execute("CREATE DATABASE root.db1"); |
81 | | - statement.execute("CREATE TIMESERIES root.db1.s WITH DATATYPE=INT64,ENCODING=PLAIN"); |
82 | | - // Insert expired data |
83 | | - statement.execute( |
84 | | - String.format( |
85 | | - "INSERT INTO root.db1(timestamp, s) VALUES (%d, %d)", |
86 | | - TEST_CURRENT_TIME_SLOT.getStartTime() - TEST_TTL * 2, -1)); |
87 | | - // Insert existed data |
88 | | - statement.execute( |
89 | | - String.format( |
90 | | - "INSERT INTO root.db1(timestamp, s) VALUES (%d, %d)", |
91 | | - TEST_CURRENT_TIME_SLOT.getStartTime(), 1)); |
92 | | - // Let db.TTL > device.TTL, the valid TTL should be the bigger one |
93 | | - statement.execute("SET TTL TO root.db1 " + TEST_TTL); |
94 | | - statement.execute("SET TTL TO root.db1.s " + 10); |
95 | | - // Create db2 |
96 | | - statement.execute("CREATE DATABASE root.db2"); |
97 | | - statement.execute("CREATE TIMESERIES root.db2.s WITH DATATYPE=INT64,ENCODING=PLAIN"); |
| 83 | + // Create databases and insert test data |
| 84 | + for (int i = 0; i < 3; i++) { |
| 85 | + String databaseName = String.format("%s%d", TREE_DATABASE_PREFIX, i); |
| 86 | + statement.execute(String.format("CREATE DATABASE %s", databaseName)); |
| 87 | + statement.execute( |
| 88 | + String.format( |
| 89 | + "CREATE TIMESERIES %s.s WITH DATATYPE=INT64,ENCODING=PLAIN", databaseName)); |
| 90 | + // Insert expired data |
| 91 | + statement.execute( |
| 92 | + String.format( |
| 93 | + "INSERT INTO %s(timestamp, s) VALUES (%d, %d)", |
| 94 | + databaseName, TEST_CURRENT_TIME_SLOT.getStartTime() - TEST_TTL * 2, -1)); |
| 95 | + // Insert existed data |
| 96 | + statement.execute( |
| 97 | + String.format( |
| 98 | + "INSERT INTO %s(timestamp, s) VALUES (%d, %d)", |
| 99 | + databaseName, TEST_CURRENT_TIME_SLOT.getStartTime(), 1)); |
| 100 | + } |
| 101 | + // Let db0.TTL > device.TTL, the valid TTL should be the bigger one |
| 102 | + statement.execute(String.format("SET TTL TO %s0 %d", TREE_DATABASE_PREFIX, TEST_TTL)); |
| 103 | + statement.execute(String.format("SET TTL TO %s0.s %d", TREE_DATABASE_PREFIX, 10)); |
| 104 | + // Let db1.TTL < device.TTL, the valid TTL should be the bigger one |
| 105 | + statement.execute(String.format("SET TTL TO %s1 %d", TREE_DATABASE_PREFIX, 10)); |
| 106 | + statement.execute(String.format("SET TTL TO %s1.s %d", TREE_DATABASE_PREFIX, TEST_TTL)); |
| 107 | + // Set TTL to path db2.** |
| 108 | + statement.execute(String.format("SET TTL TO %s2.** %d", TREE_DATABASE_PREFIX, TEST_TTL)); |
| 109 | + } |
| 110 | + |
| 111 | + TDataPartitionReq req = new TDataPartitionReq(); |
| 112 | + for (int i = 0; i < 3; i++) { |
| 113 | + req.putToPartitionSlotsMap(String.format("%s%d", TREE_DATABASE_PREFIX, i), new TreeMap<>()); |
| 114 | + } |
| 115 | + try (SyncConfigNodeIServiceClient client = |
| 116 | + (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) { |
| 117 | + for (int retry = 0; retry < 120; retry++) { |
| 118 | + boolean partitionTableAutoCleaned = true; |
| 119 | + TDataPartitionTableResp resp = client.getDataPartitionTable(req); |
| 120 | + if (TSStatusCode.SUCCESS_STATUS.getStatusCode() == resp.getStatus().getCode()) { |
| 121 | + partitionTableAutoCleaned = |
| 122 | + resp.getDataPartitionTable().entrySet().stream() |
| 123 | + .flatMap(e1 -> e1.getValue().entrySet().stream()) |
| 124 | + .allMatch(e2 -> e2.getValue().size() == 1); |
| 125 | + } |
| 126 | + if (partitionTableAutoCleaned) { |
| 127 | + return; |
| 128 | + } |
| 129 | + TimeUnit.SECONDS.sleep(1); |
| 130 | + } |
| 131 | + } |
| 132 | + Assert.fail("The PartitionTable in the ConfigNode is not auto cleaned!"); |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + public void testAutoCleanPartitionTableForTableModel() throws Exception { |
| 137 | + try (final Connection connection = |
| 138 | + EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); |
| 139 | + final Statement statement = connection.createStatement()) { |
| 140 | + // Create databases and insert test data |
| 141 | + String databaseName = TABLE_DATABASE_PREFIX; |
| 142 | + statement.execute(String.format("CREATE DATABASE IF NOT EXISTS %s", databaseName)); |
| 143 | + statement.execute(String.format("USE %s", databaseName)); |
| 144 | + statement.execute("CREATE TABLE tb (time TIMESTAMP TIME, s int64 FIELD)"); |
98 | 145 | // Insert expired data |
99 | 146 | statement.execute( |
100 | 147 | String.format( |
101 | | - "INSERT INTO root.db2(timestamp, s) VALUES (%d, %d)", |
| 148 | + "INSERT INTO tb(time, s) VALUES (%d, %d)", |
102 | 149 | TEST_CURRENT_TIME_SLOT.getStartTime() - TEST_TTL * 2, -1)); |
103 | 150 | // Insert existed data |
104 | 151 | statement.execute( |
105 | 152 | String.format( |
106 | | - "INSERT INTO root.db2(timestamp, s) VALUES (%d, %d)", |
107 | | - TEST_CURRENT_TIME_SLOT.getStartTime(), 1)); |
108 | | - // Let db.TTL < device.TTL, the valid TTL should be the bigger one |
109 | | - statement.execute("SET TTL TO root.db2 " + 10); |
110 | | - statement.execute("SET TTL TO root.db2.s " + TEST_TTL); |
| 153 | + "INSERT INTO tb(time, s) VALUES (%d, %d)", TEST_CURRENT_TIME_SLOT.getStartTime(), 1)); |
| 154 | + statement.execute(String.format("USE %s", TABLE_DATABASE_PREFIX)); |
| 155 | + statement.execute(String.format("ALTER TABLE tb SET PROPERTIES TTL=%d", TEST_TTL)); |
111 | 156 | } |
112 | 157 |
|
113 | 158 | TDataPartitionReq req = new TDataPartitionReq(); |
114 | | - req.putToPartitionSlotsMap("root.db1", new TreeMap<>()); |
115 | | - req.putToPartitionSlotsMap("root.db2", new TreeMap<>()); |
| 159 | + req.putToPartitionSlotsMap(TABLE_DATABASE_PREFIX, new TreeMap<>()); |
116 | 160 | try (SyncConfigNodeIServiceClient client = |
117 | 161 | (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) { |
118 | 162 | for (int retry = 0; retry < 120; retry++) { |
|
0 commit comments