Skip to content

Commit 7b5e52a

Browse files
committed
Merge branch 'master' of https://github.com/apache/iotdb into fix-audit-logger
2 parents 87bbb4b + 664f485 commit 7b5e52a

File tree

92 files changed

+1868
-1095
lines changed

Some content is hidden

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

92 files changed

+1868
-1095
lines changed

integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppDataNodeConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,10 @@ public DataNodeConfig setDataNodeMemoryProportion(String dataNodeMemoryProportio
137137
setProperty("datanode_memory_proportion", dataNodeMemoryProportion);
138138
return this;
139139
}
140+
141+
@Override
142+
public DataNodeConfig setQueryCostStatWindow(int queryCostStatWindow) {
143+
setProperty("query_cost_stat_window", String.valueOf(queryCostStatWindow));
144+
return this;
145+
}
140146
}

integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteDataNodeConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ public DataNodeConfig setDeleteWalFilesPeriodInMs(long deleteWalFilesPeriodInMs)
9393
public DataNodeConfig setDataNodeMemoryProportion(String dataNodeMemoryProportion) {
9494
return this;
9595
}
96+
97+
@Override
98+
public DataNodeConfig setQueryCostStatWindow(int queryCostStatWindow) {
99+
return this;
100+
}
96101
}

integration-test/src/main/java/org/apache/iotdb/itbase/env/DataNodeConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ DataNodeConfig setLoadTsFileAnalyzeSchemaMemorySizeInBytes(
5151
DataNodeConfig setDeleteWalFilesPeriodInMs(long deleteWalFilesPeriodInMs);
5252

5353
DataNodeConfig setDataNodeMemoryProportion(String dataNodeMemoryProportion);
54+
55+
DataNodeConfig setQueryCostStatWindow(int queryCostStatWindow);
5456
}

integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeClusterConfigIT.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,4 @@ private void aiNodeRegisterAndRemoveTest(Statement statement) throws SQLExceptio
107107
}
108108
Assert.fail("The target AINode is not removed successfully after all retries.");
109109
}
110-
111-
// TODO: We might need to add remove unknown test in the future, but current infrastructure is too
112-
// hard to implement it.
113110
}

integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeConcurrentForecastIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class AINodeConcurrentForecastIT {
4949
private static final Logger LOGGER = LoggerFactory.getLogger(AINodeConcurrentForecastIT.class);
5050

5151
private static final String FORECAST_TABLE_FUNCTION_SQL_TEMPLATE =
52-
"SELECT * FROM FORECAST(model_id=>'%s', input=>(SELECT time,s FROM root.AI) ORDER BY time, forecast_length=>%d)";
52+
"SELECT * FROM FORECAST(model_id=>'%s', input=>(SELECT time,s FROM root.AI) ORDER BY time, output_length=>%d)";
5353

5454
@BeforeClass
5555
public static void setUp() throws Exception {

integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeModelManageIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ private void userDefinedModelManagementTest(Statement statement)
131131
public void dropBuiltInModelErrorTestInTree() throws SQLException {
132132
try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TREE_SQL_DIALECT);
133133
Statement statement = connection.createStatement()) {
134-
errorTest(statement, "drop model sundial", "1510: Cannot delete built-in model: sundial");
134+
errorTest(statement, "drop model sundial", "1506: Cannot delete built-in model: sundial");
135135
}
136136
}
137137

138138
@Test
139139
public void dropBuiltInModelErrorTestInTable() throws SQLException {
140140
try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
141141
Statement statement = connection.createStatement()) {
142-
errorTest(statement, "drop model sundial", "1510: Cannot delete built-in model: sundial");
142+
errorTest(statement, "drop model sundial", "1506: Cannot delete built-in model: sundial");
143143
}
144144
}
145145

integration-test/src/test/java/org/apache/iotdb/ainode/utils/AINodeTestUtils.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.iotdb.ainode.utils;
2121

2222
import com.google.common.collect.ImmutableSet;
23+
import org.junit.Assert;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

@@ -34,6 +35,7 @@
3435
import java.util.Objects;
3536
import java.util.Set;
3637
import java.util.concurrent.TimeUnit;
38+
import java.util.concurrent.atomic.AtomicBoolean;
3739
import java.util.stream.Collectors;
3840
import java.util.stream.Stream;
3941

@@ -101,6 +103,7 @@ public static void errorTest(Statement statement, String sql, String errorMessag
101103
public static void concurrentInference(
102104
Statement statement, String sql, int threadCnt, int loop, int expectedOutputLength)
103105
throws InterruptedException {
106+
AtomicBoolean allPass = new AtomicBoolean(true);
104107
Thread[] threads = new Thread[threadCnt];
105108
for (int i = 0; i < threadCnt; i++) {
106109
threads[i] =
@@ -113,12 +116,23 @@ public static void concurrentInference(
113116
while (resultSet.next()) {
114117
outputCnt++;
115118
}
116-
assertEquals(expectedOutputLength, outputCnt);
119+
if (expectedOutputLength != outputCnt) {
120+
allPass.set(false);
121+
fail(
122+
"Output count mismatch for SQL: "
123+
+ sql
124+
+ ". Expected: "
125+
+ expectedOutputLength
126+
+ ", but got: "
127+
+ outputCnt);
128+
}
117129
} catch (SQLException e) {
130+
allPass.set(false);
118131
fail(e.getMessage());
119132
}
120133
}
121134
} catch (Exception e) {
135+
allPass.set(false);
122136
fail(e.getMessage());
123137
}
124138
});
@@ -130,6 +144,7 @@ public static void concurrentInference(
130144
fail("Thread timeout after 10 minutes");
131145
}
132146
}
147+
Assert.assertTrue(allPass.get());
133148
}
134149

135150
public static void checkModelOnSpecifiedDevice(Statement statement, String modelId, String device)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.junit.After;
3333
import org.junit.Assert;
3434
import org.junit.Before;
35+
import org.junit.Ignore;
3536
import org.junit.Test;
3637
import org.junit.experimental.categories.Category;
3738
import org.junit.runner.RunWith;
@@ -52,6 +53,7 @@
5253
* This test class ensures the audit log behave exactly the same as we expected, including the
5354
* number, sequence and content of the audit logs.
5455
*/
56+
@Ignore
5557
@RunWith(IoTDBTestRunner.class)
5658
@Category({LocalStandaloneIT.class})
5759
public class IoTDBAuditLogBasicIT {
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.relational.it.query.recent.informationschema;
21+
22+
import org.apache.iotdb.commons.conf.CommonDescriptor;
23+
import org.apache.iotdb.db.queryengine.execution.QueryState;
24+
import org.apache.iotdb.it.env.EnvFactory;
25+
import org.apache.iotdb.it.framework.IoTDBTestRunner;
26+
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
27+
import org.apache.iotdb.itbase.env.BaseEnv;
28+
29+
import org.junit.AfterClass;
30+
import org.junit.Assert;
31+
import org.junit.BeforeClass;
32+
import org.junit.Test;
33+
import org.junit.experimental.categories.Category;
34+
import org.junit.runner.RunWith;
35+
36+
import java.sql.Connection;
37+
import java.sql.ResultSet;
38+
import java.sql.ResultSetMetaData;
39+
import java.sql.SQLException;
40+
import java.sql.Statement;
41+
42+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.END_TIME_TABLE_MODEL;
43+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.NUMS;
44+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.STATEMENT_TABLE_MODEL;
45+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.STATE_TABLE_MODEL;
46+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.USER_TABLE_MODEL;
47+
import static org.apache.iotdb.commons.schema.table.InformationSchema.getSchemaTables;
48+
import static org.apache.iotdb.db.it.utils.TestUtils.createUser;
49+
import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT;
50+
import static org.junit.Assert.fail;
51+
52+
@RunWith(IoTDBTestRunner.class)
53+
@Category({TableLocalStandaloneIT.class})
54+
// This IT will run at least 60s, so we only run it in 1C1D
55+
public class IoTDBCurrentQueriesIT {
56+
private static final int CURRENT_QUERIES_COLUMN_NUM =
57+
getSchemaTables().get("current_queries").getColumnNum();
58+
private static final int QUERIES_COSTS_HISTOGRAM_COLUMN_NUM =
59+
getSchemaTables().get("queries_costs_histogram").getColumnNum();
60+
private static final String ADMIN_NAME =
61+
CommonDescriptor.getInstance().getConfig().getDefaultAdminName();
62+
private static final String ADMIN_PWD =
63+
CommonDescriptor.getInstance().getConfig().getAdminPassword();
64+
65+
@BeforeClass
66+
public static void setUp() throws Exception {
67+
EnvFactory.getEnv().initClusterEnvironment();
68+
createUser("test", "test123123456");
69+
}
70+
71+
@AfterClass
72+
public static void tearDown() throws Exception {
73+
EnvFactory.getEnv().cleanClusterEnvironment();
74+
}
75+
76+
@Test
77+
public void testCurrentQueries() {
78+
try {
79+
Assert.assertEquals(3, QUERIES_COSTS_HISTOGRAM_COLUMN_NUM);
80+
81+
Connection connection =
82+
EnvFactory.getEnv().getConnection(ADMIN_NAME, ADMIN_PWD, BaseEnv.TABLE_SQL_DIALECT);
83+
Statement statement = connection.createStatement();
84+
statement.execute("USE information_schema");
85+
statement.execute("set configuration \"query_cost_stat_window\"='1'");
86+
87+
// 1. query current_queries table
88+
String sql = "SELECT * FROM current_queries WHERE state='RUNNING'";
89+
ResultSet resultSet = statement.executeQuery(sql);
90+
ResultSetMetaData metaData = resultSet.getMetaData();
91+
Assert.assertEquals(CURRENT_QUERIES_COLUMN_NUM, metaData.getColumnCount());
92+
int rowNum = 0;
93+
while (resultSet.next()) {
94+
Assert.assertEquals(QueryState.RUNNING.name(), resultSet.getString(STATE_TABLE_MODEL));
95+
Assert.assertEquals(null, resultSet.getString(END_TIME_TABLE_MODEL));
96+
Assert.assertEquals(sql, resultSet.getString(STATEMENT_TABLE_MODEL));
97+
Assert.assertEquals(ADMIN_NAME, resultSet.getString(USER_TABLE_MODEL));
98+
rowNum++;
99+
}
100+
Assert.assertEquals(1, rowNum);
101+
resultSet.close();
102+
103+
// 2. query queries_costs_histogram table
104+
sql = "SELECT * FROM queries_costs_histogram";
105+
resultSet = statement.executeQuery(sql);
106+
metaData = resultSet.getMetaData();
107+
Assert.assertEquals(QUERIES_COSTS_HISTOGRAM_COLUMN_NUM, metaData.getColumnCount());
108+
rowNum = 0;
109+
int queriesCount = 0;
110+
while (resultSet.next()) {
111+
int nums = resultSet.getInt(NUMS);
112+
if (nums > 0) {
113+
queriesCount++;
114+
}
115+
rowNum++;
116+
}
117+
Assert.assertEquals(1, queriesCount);
118+
Assert.assertEquals(61, rowNum);
119+
120+
// 3. requery current_queries table
121+
sql = "SELECT * FROM current_queries WHERE state='FINISHED'";
122+
resultSet = statement.executeQuery(sql);
123+
metaData = resultSet.getMetaData();
124+
Assert.assertEquals(CURRENT_QUERIES_COLUMN_NUM, metaData.getColumnCount());
125+
rowNum = 0;
126+
int finishedQueries = 0;
127+
while (resultSet.next()) {
128+
if (QueryState.FINISHED.name().equals(resultSet.getString(STATE_TABLE_MODEL))) {
129+
finishedQueries++;
130+
}
131+
rowNum++;
132+
}
133+
// two rows in the result, 2 FINISHED
134+
Assert.assertEquals(2, rowNum);
135+
Assert.assertEquals(2, finishedQueries);
136+
resultSet.close();
137+
138+
// 4. test the expired QueryInfo was evicted
139+
Thread.sleep(61_001);
140+
sql = "SELECT * FROM current_queries";
141+
resultSet = statement.executeQuery(sql);
142+
rowNum = 0;
143+
while (resultSet.next()) {
144+
rowNum++;
145+
}
146+
// one row in the result, current query
147+
Assert.assertEquals(1, rowNum);
148+
resultSet.close();
149+
150+
sql = "SELECT * FROM queries_costs_histogram";
151+
resultSet = statement.executeQuery(sql);
152+
queriesCount = 0;
153+
while (resultSet.next()) {
154+
int nums = resultSet.getInt(NUMS);
155+
if (nums > 0) {
156+
queriesCount++;
157+
}
158+
}
159+
// the last current_queries table query was recorded, others are evicted
160+
Assert.assertEquals(1, queriesCount);
161+
} catch (Exception e) {
162+
fail(e.getMessage());
163+
}
164+
165+
// 5. test privilege
166+
testPrivilege();
167+
168+
// 6. test more configurations
169+
testMoreConfigurations();
170+
}
171+
172+
private void testPrivilege() {
173+
// 1. test current_queries table
174+
try (Connection connection =
175+
EnvFactory.getEnv().getConnection("test", "test123123456", TABLE_SQL_DIALECT);
176+
Statement statement = connection.createStatement()) {
177+
String sql = "SELECT * FROM information_schema.current_queries";
178+
179+
// another user executes a query
180+
try (Connection connection2 =
181+
EnvFactory.getEnv().getConnection(ADMIN_NAME, ADMIN_PWD, BaseEnv.TABLE_SQL_DIALECT)) {
182+
ResultSet resultSet = connection2.createStatement().executeQuery(sql);
183+
resultSet.close();
184+
} catch (Exception e) {
185+
fail(e.getMessage());
186+
}
187+
188+
// current user query current_queries table
189+
ResultSet resultSet = statement.executeQuery(sql);
190+
int rowNum = 0;
191+
while (resultSet.next()) {
192+
rowNum++;
193+
}
194+
// only current query in the result
195+
Assert.assertEquals(1, rowNum);
196+
} catch (SQLException e) {
197+
fail(e.getMessage());
198+
}
199+
200+
// 2. test queries_costs_histogram table
201+
try (Connection connection =
202+
EnvFactory.getEnv().getConnection("test", "test123123456", TABLE_SQL_DIALECT);
203+
Statement statement = connection.createStatement()) {
204+
statement.executeQuery("SELECT * FROM information_schema.queries_costs_histogram");
205+
} catch (SQLException e) {
206+
Assert.assertEquals(
207+
"803: Access Denied: No permissions for this operation, please add privilege SYSTEM",
208+
e.getMessage());
209+
}
210+
}
211+
212+
private void testMoreConfigurations() {
213+
try {
214+
Connection connection =
215+
EnvFactory.getEnv().getConnection(ADMIN_NAME, ADMIN_PWD, BaseEnv.TABLE_SQL_DIALECT);
216+
Statement statement = connection.createStatement();
217+
statement.execute("USE information_schema");
218+
219+
statement.execute("set configuration \"query_cost_stat_window\"='0'");
220+
Thread.sleep(1_001);
221+
222+
// query_cost_stat_window = 0, history queries are cleared
223+
String sql = "SELECT * FROM current_queries WHERE state='FINISHED'";
224+
ResultSet resultSet = statement.executeQuery(sql);
225+
ResultSetMetaData metaData = resultSet.getMetaData();
226+
Assert.assertEquals(CURRENT_QUERIES_COLUMN_NUM, metaData.getColumnCount());
227+
int rowNum = 0;
228+
while (resultSet.next()) {
229+
rowNum++;
230+
}
231+
Assert.assertEquals(0, rowNum);
232+
resultSet.close();
233+
234+
statement.execute("set configuration \"query_cost_stat_window\"='1040000000'");
235+
// make query_cost_stat_window very large but not overflow
236+
resultSet = statement.executeQuery(sql);
237+
while (resultSet.next()) {
238+
rowNum++;
239+
}
240+
resultSet.close();
241+
242+
resultSet = statement.executeQuery(sql);
243+
rowNum = 0;
244+
while (resultSet.next()) {
245+
rowNum++;
246+
}
247+
// the history SQL is recorded
248+
Assert.assertEquals(1, rowNum);
249+
resultSet.close();
250+
251+
// make query_cost_stat_window overflow
252+
try {
253+
statement.execute("set configuration \"query_cost_stat_window\"='10400000000'");
254+
} catch (Exception e) {
255+
Assert.assertTrue(
256+
e.getMessage()
257+
.contains("java.lang.NumberFormatException: For input string: \"10400000000\""));
258+
}
259+
} catch (Exception e) {
260+
fail(e.getMessage());
261+
}
262+
}
263+
}

0 commit comments

Comments
 (0)