Skip to content

Commit

Permalink
Print current trusted_uri_pattern is error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
JackieTien97 authored Dec 13, 2024
1 parent b53e1ba commit ac18bbf
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,11 @@ public void loadProperties(TrimProperties properties) throws BadNodeUrlException

loadIoTConsensusProps(properties);
loadIoTConsensusV2Props(properties);

// update query_sample_throughput_bytes_per_sec
loadQuerySampleThroughput(properties);
// update trusted_uri_pattern
loadTrustedUriPattern(properties);
}

private void reloadConsensusProps(TrimProperties properties) throws IOException {
Expand Down Expand Up @@ -2883,48 +2888,9 @@ public synchronized void loadHotModifiedProps(TrimProperties properties)
}

// update query_sample_throughput_bytes_per_sec
String querySamplingRateLimitNumber =
Optional.ofNullable(
properties.getProperty(
"query_sample_throughput_bytes_per_sec",
ConfigurationFileUtils.getConfigurationDefaultValue(
"query_sample_throughput_bytes_per_sec")))
.map(String::trim)
.orElse(
ConfigurationFileUtils.getConfigurationDefaultValue(
"query_sample_throughput_bytes_per_sec"));
if (querySamplingRateLimitNumber != null) {
try {
int rateLimit = Integer.parseInt(querySamplingRateLimitNumber);
commonDescriptor.getConfig().setQuerySamplingRateLimit(rateLimit);
} catch (Exception e) {
LOGGER.warn(
"Failed to parse query_sample_throughput_bytes_per_sec {} to integer",
querySamplingRateLimitNumber);
}
}

loadQuerySampleThroughput(properties);
// update trusted_uri_pattern
String trustedUriPattern =
Optional.ofNullable(
properties.getProperty(
"trusted_uri_pattern",
ConfigurationFileUtils.getConfigurationDefaultValue("trusted_uri_pattern")))
.map(String::trim)
.orElse(ConfigurationFileUtils.getConfigurationDefaultValue("trusted_uri_pattern"));
Pattern pattern;
if (trustedUriPattern != null) {
try {
pattern = Pattern.compile(trustedUriPattern);
} catch (Exception e) {
LOGGER.warn("Failed to parse trusted_uri_pattern {}", trustedUriPattern);
pattern = commonDescriptor.getConfig().getTrustedUriPattern();
}
} else {
pattern = commonDescriptor.getConfig().getTrustedUriPattern();
}
commonDescriptor.getConfig().setTrustedUriPattern(pattern);

loadTrustedUriPattern(properties);
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
Expand All @@ -2933,6 +2899,51 @@ public synchronized void loadHotModifiedProps(TrimProperties properties)
}
}

private void loadQuerySampleThroughput(TrimProperties properties) throws IOException {
String querySamplingRateLimitNumber =
Optional.ofNullable(
properties.getProperty(
"query_sample_throughput_bytes_per_sec",
ConfigurationFileUtils.getConfigurationDefaultValue(
"query_sample_throughput_bytes_per_sec")))
.map(String::trim)
.orElse(
ConfigurationFileUtils.getConfigurationDefaultValue(
"query_sample_throughput_bytes_per_sec"));
if (querySamplingRateLimitNumber != null) {
try {
int rateLimit = Integer.parseInt(querySamplingRateLimitNumber);
commonDescriptor.getConfig().setQuerySamplingRateLimit(rateLimit);
} catch (Exception e) {
LOGGER.warn(
"Failed to parse query_sample_throughput_bytes_per_sec {} to integer",
querySamplingRateLimitNumber);
}
}
}

private void loadTrustedUriPattern(TrimProperties properties) throws IOException {
String trustedUriPattern =
Optional.ofNullable(
properties.getProperty(
"trusted_uri_pattern",
ConfigurationFileUtils.getConfigurationDefaultValue("trusted_uri_pattern")))
.map(String::trim)
.orElse(ConfigurationFileUtils.getConfigurationDefaultValue("trusted_uri_pattern"));
Pattern pattern;
if (trustedUriPattern != null) {
try {
pattern = Pattern.compile(trustedUriPattern);
} catch (Exception e) {
LOGGER.warn("Failed to parse trusted_uri_pattern {}", trustedUriPattern);
pattern = commonDescriptor.getConfig().getTrustedUriPattern();
}
} else {
pattern = commonDescriptor.getConfig().getTrustedUriPattern();
}
commonDescriptor.getConfig().setTrustedUriPattern(pattern);
}

public synchronized void loadHotModifiedProps() throws QueryProcessException {
URL url = getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME);
if (url == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@

import static org.apache.iotdb.commons.conf.IoTDBConstant.MAX_DATABASE_NAME_LENGTH;
import static org.apache.iotdb.commons.conf.IoTDBConstant.TTL_INFINITE;
import static org.apache.iotdb.commons.executable.ExecutableManager.getUnTrustedUriErrorMsg;
import static org.apache.iotdb.commons.executable.ExecutableManager.isUriTrusted;
import static org.apache.iotdb.commons.schema.table.TsTable.TABLE_ALLOWED_PROPERTIES;
import static org.apache.iotdb.commons.schema.table.TsTable.TTL_PROPERTY;
Expand Down Expand Up @@ -759,7 +760,7 @@ protected IConfigTask visitCreatePipePlugin(CreatePipePlugin node, MPPQueryConte
return new CreatePipePluginTask(node);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + node.getUriString());
throw new SemanticException(getUnTrustedUriErrorMsg(node.getUriString()));
}
}

Expand Down Expand Up @@ -866,7 +867,7 @@ protected IConfigTask visitCreateFunction(CreateFunction node, MPPQueryContext c
return new CreateFunctionTask(node);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + node.getUriString().get());
throw new SemanticException(getUnTrustedUriErrorMsg(node.getUriString().get()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@

import org.apache.tsfile.exception.NotImplementedException;

import static org.apache.iotdb.commons.executable.ExecutableManager.getUnTrustedUriErrorMsg;
import static org.apache.iotdb.commons.executable.ExecutableManager.isUriTrusted;

public class TreeConfigTaskVisitor extends StatementVisitor<IConfigTask, MPPQueryContext> {
Expand Down Expand Up @@ -328,7 +329,8 @@ public IConfigTask visitCreateFunction(
return new CreateFunctionTask(createFunctionStatement);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + createFunctionStatement.getUriString().get());
throw new SemanticException(
getUnTrustedUriErrorMsg(createFunctionStatement.getUriString().get()));
}
}

Expand All @@ -355,7 +357,7 @@ && isUriTrusted(createTriggerStatement.getUriString())) {
return new CreateTriggerTask(createTriggerStatement);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + createTriggerStatement.getUriString());
throw new SemanticException(getUnTrustedUriErrorMsg(createTriggerStatement.getUriString()));
}
}

Expand All @@ -381,7 +383,8 @@ && isUriTrusted(createPipePluginStatement.getUriString())) {
return new CreatePipePluginTask(createPipePluginStatement);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + createPipePluginStatement.getUriString());
throw new SemanticException(
getUnTrustedUriErrorMsg(createPipePluginStatement.getUriString()));
}
}

Expand Down Expand Up @@ -677,7 +680,7 @@ public IConfigTask visitCreateModel(
return new CreateModelTask(createModelStatement, context);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + createModelStatement.getUri());
throw new SemanticException(getUnTrustedUriErrorMsg(createModelStatement.getUri()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,10 @@ public String getInstallDir() {
public static boolean isUriTrusted(String uri) {
return CommonDescriptor.getInstance().getConfig().getTrustedUriPattern().matcher(uri).matches();
}

public static String getUnTrustedUriErrorMsg(String uri) {
return String.format(
"Untrusted uri %s, current trusted_uri_pattern is %s",
uri, CommonDescriptor.getInstance().getConfig().getTrustedUriPattern());
}
}

0 comments on commit ac18bbf

Please sign in to comment.