Skip to content

Commit a64b844

Browse files
authored
[To dev/1.3] Fix setting illegal default_storage_group_level does not report an error (#14483)
* Fix setting illegal default_storage_group_level does not report an error (cherry picked from commit 391d153) * spotless * allow illegal config during startup
1 parent bc966a6 commit a64b844

File tree

11 files changed

+110
-11
lines changed

11 files changed

+110
-11
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,12 @@ public CommonConfig setQueryMemoryProportion(String queryMemoryProportion) {
490490
return this;
491491
}
492492

493+
@Override
494+
public CommonConfig setDefaultStorageGroupLevel(int defaultStorageGroupLevel) {
495+
setProperty("default_storage_group_level", String.valueOf(defaultStorageGroupLevel));
496+
return this;
497+
}
498+
493499
// For part of the log directory
494500
public String getClusterConfigStr() {
495501
return fromConsensusFullNameToAbbr(properties.getProperty(CONFIG_NODE_CONSENSUS_PROTOCOL_CLASS))

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,11 @@ public CommonConfig setQueryMemoryProportion(String queryMemoryProportion) {
498498
cnConfig.setQueryMemoryProportion(queryMemoryProportion);
499499
return this;
500500
}
501+
502+
@Override
503+
public CommonConfig setDefaultStorageGroupLevel(int defaultStorageGroupLevel) {
504+
dnConfig.setDefaultStorageGroupLevel(defaultStorageGroupLevel);
505+
cnConfig.setDefaultStorageGroupLevel(defaultStorageGroupLevel);
506+
return this;
507+
}
501508
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,8 @@ CommonConfig setPipeConnectorRequestSliceThresholdBytes(
155155
int pipeConnectorRequestSliceThresholdBytes);
156156

157157
CommonConfig setQueryMemoryProportion(String queryMemoryProportion);
158+
159+
default CommonConfig setDefaultStorageGroupLevel(int defaultStorageGroupLevel) {
160+
return this;
161+
}
158162
}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@
3939
import java.nio.file.Files;
4040
import java.sql.Connection;
4141
import java.sql.ResultSet;
42+
import java.sql.SQLException;
4243
import java.sql.Statement;
4344
import java.util.Arrays;
4445
import java.util.Properties;
4546
import java.util.concurrent.TimeUnit;
4647

48+
import static org.junit.Assert.assertEquals;
49+
import static org.junit.Assert.assertFalse;
50+
import static org.junit.Assert.assertTrue;
51+
4752
@RunWith(IoTDBTestRunner.class)
4853
@Category({LocalStandaloneIT.class})
4954
public class IoTDBSetConfigurationIT {
@@ -202,4 +207,48 @@ private static File getConfigFile(AbstractNodeWrapper nodeWrapper) {
202207
+ CommonConfig.SYSTEM_CONFIG_NAME;
203208
return new File(systemPropertiesPath);
204209
}
210+
211+
@Test
212+
public void testSetDefaultSGLevel() throws SQLException {
213+
try (Connection connection = EnvFactory.getEnv().getConnection();
214+
Statement statement = connection.createStatement()) {
215+
// legal value
216+
statement.execute("set configuration \"default_storage_group_level\"=\"3\"");
217+
statement.execute("INSERT INTO root.a.b.c.d1(timestamp, s1) VALUES (1, 1)");
218+
ResultSet databases = statement.executeQuery("show databases");
219+
databases.next();
220+
Assert.assertEquals("root.a.b.c", databases.getString(1));
221+
assertFalse(databases.next());
222+
223+
// path too short
224+
try {
225+
statement.execute("INSERT INTO root.fail(timestamp, s1) VALUES (1, 1)");
226+
} catch (SQLException e) {
227+
assertEquals(
228+
"509: root.fail is not a legal path, because it is no longer than default sg level: 3",
229+
e.getMessage());
230+
}
231+
232+
// illegal value
233+
try {
234+
statement.execute("set configuration \"default_storage_group_level\"=\"-1\"");
235+
} catch (SQLException e) {
236+
assertTrue(e.getMessage().contains("Illegal defaultStorageGroupLevel: -1, should >= 1"));
237+
}
238+
}
239+
240+
// can start with an illegal value
241+
EnvFactory.getEnv().cleanClusterEnvironment();
242+
EnvFactory.getEnv().getConfig().getCommonConfig().setDefaultStorageGroupLevel(-1);
243+
EnvFactory.getEnv().initClusterEnvironment();
244+
try (Connection connection = EnvFactory.getEnv().getConnection();
245+
Statement statement = connection.createStatement()) {
246+
statement.execute("INSERT INTO root.a.b.c.d1(timestamp, s1) VALUES (1, 1)");
247+
ResultSet databases = statement.executeQuery("show databases");
248+
databases.next();
249+
// the default value should take effect
250+
Assert.assertEquals("root.a", databases.getString(1));
251+
assertFalse(databases.next());
252+
}
253+
}
205254
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,19 @@ public int getDefaultStorageGroupLevel() {
24332433
return defaultStorageGroupLevel;
24342434
}
24352435

2436-
void setDefaultStorageGroupLevel(int defaultStorageGroupLevel) {
2436+
void setDefaultStorageGroupLevel(int defaultStorageGroupLevel, boolean startUp) {
2437+
if (defaultStorageGroupLevel < 1) {
2438+
if (startUp) {
2439+
logger.warn(
2440+
"Illegal defaultStorageGroupLevel: {}, should >= 1, use default value 1",
2441+
defaultStorageGroupLevel);
2442+
defaultStorageGroupLevel = 1;
2443+
} else {
2444+
throw new IllegalArgumentException(
2445+
String.format(
2446+
"Illegal defaultStorageGroupLevel: %d, should >= 1", defaultStorageGroupLevel));
2447+
}
2448+
}
24372449
this.defaultStorageGroupLevel = defaultStorageGroupLevel;
24382450
}
24392451

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ public void loadProperties(Properties properties) throws BadNodeUrlException, IO
806806

807807
conf.setRpcMaxConcurrentClientNum(maxConcurrentClientNum);
808808

809-
loadAutoCreateSchemaProps(properties);
809+
boolean startUp = true;
810+
loadAutoCreateSchemaProps(properties, startUp);
810811

811812
conf.setTsFileStorageFs(
812813
properties.getProperty("tsfile_storage_fs", conf.getTsFileStorageFs().toString()));
@@ -1627,7 +1628,8 @@ public long getThrottleThresholdWithDirs() {
16271628
return Math.max(Math.min(newThrottleThreshold, MAX_THROTTLE_THRESHOLD), MIN_THROTTLE_THRESHOLD);
16281629
}
16291630

1630-
private void loadAutoCreateSchemaProps(Properties properties) throws IOException {
1631+
private void loadAutoCreateSchemaProps(Properties properties, boolean startUp)
1632+
throws IOException {
16311633
conf.setAutoCreateSchemaEnabled(
16321634
Boolean.parseBoolean(
16331635
properties.getProperty(
@@ -1659,7 +1661,8 @@ private void loadAutoCreateSchemaProps(Properties properties) throws IOException
16591661
properties.getProperty(
16601662
"default_storage_group_level",
16611663
ConfigurationFileUtils.getConfigurationDefaultValue(
1662-
"default_storage_group_level"))));
1664+
"default_storage_group_level"))),
1665+
startUp);
16631666
conf.setDefaultBooleanEncoding(
16641667
properties.getProperty(
16651668
"default_boolean_encoding",
@@ -1899,7 +1902,8 @@ public synchronized void loadHotModifiedProps(Properties properties)
18991902
loadTimedService(properties);
19001903
StorageEngine.getInstance().rebootTimedService();
19011904
// update params of creating schema automatically
1902-
loadAutoCreateSchemaProps(properties);
1905+
boolean startUp = false;
1906+
loadAutoCreateSchemaProps(properties, startUp);
19031907

19041908
// update tsfile-format config
19051909
loadTsFileProps(properties);

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/sql/StatementAnalyzeException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ public StatementAnalyzeException(String message) {
2828
public StatementAnalyzeException(Exception cause) {
2929
super(cause);
3030
}
31+
32+
public StatementAnalyzeException(String message, Throwable cause) {
33+
super(message, cause);
34+
}
3135
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ private void getStorageGroupCacheResult(
384384
}
385385
} catch (TException | MetadataException | ClientManagerException e) {
386386
throw new StatementAnalyzeException(
387-
"An error occurred when executing getDeviceToStorageGroup():" + e.getMessage());
387+
"An error occurred when executing getDeviceToDatabase():" + e.getMessage(), e);
388388
}
389389
}
390390
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/MetaUtils.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ private MetaUtils() {}
6161
public static PartialPath getStorageGroupPathByLevel(PartialPath path, int level)
6262
throws MetadataException {
6363
String[] nodeNames = path.getNodes();
64-
if (nodeNames.length <= level || !nodeNames[0].equals(IoTDBConstant.PATH_ROOT)) {
65-
throw new IllegalPathException(path.getFullPath());
64+
if (nodeNames.length <= level) {
65+
throw new IllegalPathException(
66+
path.getFullPath(), "it is no longer than default sg level: " + level);
67+
}
68+
if (!nodeNames[0].equals(IoTDBConstant.PATH_ROOT)) {
69+
throw new IllegalPathException(
70+
path.getFullPath(), "it does not start with " + IoTDBConstant.PATH_ROOT);
6671
}
6772
String[] storageGroupNodes = new String[level + 1];
6873
System.arraycopy(nodeNames, 0, storageGroupNodes, 0, level + 1);

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/MetaUtilsTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class MetaUtilsTest {
4545

4646
private final IMNodeFactory<IMemMNode> nodeFactory =
4747
MNodeFactoryLoader.getInstance().getMemMNodeIMNodeFactory();
48-
;
4948

5049
@Test
5150
public void testGetMultiFullPaths() {
@@ -128,7 +127,9 @@ public void testGetStorageGroupPathByLevel() {
128127
MetaUtils.getStorageGroupPathByLevel(new PartialPath("root1.laptop.d1.s1"), level);
129128
} catch (MetadataException e) {
130129
caughtException = true;
131-
assertEquals("root1.laptop.d1.s1 is not a legal path", e.getMessage());
130+
assertEquals(
131+
"root1.laptop.d1.s1 is not a legal path, because it does not start with root",
132+
e.getMessage());
132133
}
133134
assertTrue(caughtException);
134135

@@ -137,7 +138,9 @@ public void testGetStorageGroupPathByLevel() {
137138
MetaUtils.getStorageGroupPathByLevel(new PartialPath("root"), level);
138139
} catch (MetadataException e) {
139140
caughtException = true;
140-
assertEquals("root is not a legal path", e.getMessage());
141+
assertEquals(
142+
"root is not a legal path, because it is no longer than default sg level: 1",
143+
e.getMessage());
141144
}
142145
assertTrue(caughtException);
143146
}

0 commit comments

Comments
 (0)