Copilot commented on code in PR #17042:
URL: https://github.com/apache/iotdb/pull/17042#discussion_r2704396592
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/ExternalServiceManagementService.java:
##########
@@ -170,7 +186,8 @@ public void startService(String serviceName) throws
ClientManagerException, TExc
private IExternalService createExternalServiceInstance(String serviceName,
String className) {
// close ClassLoader automatically to release the file handle
- try (ExternalServiceClassLoader classLoader = new
ExternalServiceClassLoader(libRoot); ) {
+ try {
+ ExternalServiceClassLoader classLoader = new
ExternalServiceClassLoader(libRoot);
Review Comment:
The ClassLoader is no longer being closed, which could lead to a resource
leak. The original code used try-with-resources to automatically close the
ExternalServiceClassLoader. Removing this will prevent the file handles from
being released properly. Consider either reverting to try-with-resources or
explicitly closing the classLoader in a finally block.
```suggestion
try (ExternalServiceClassLoader classLoader = new
ExternalServiceClassLoader(libRoot)) {
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/ExternalServiceManagementService.java:
##########
@@ -65,10 +66,25 @@ public class ExternalServiceManagementService {
private static final Logger LOGGER =
LoggerFactory.getLogger(ExternalServiceManagementService.class);
+ public static final String INSTANCE_NULL_ERROR_MSG =
+ "External Service instance is null when state is RUNNING!";
+
private ExternalServiceManagementService(String libRoot) {
this.serviceInfos = new HashMap<>();
restoreBuiltInServices();
this.libRoot = libRoot;
+ makDir(libRoot);
+ }
+
+ private static void makDir(String dir) {
Review Comment:
The method name 'makDir' is misspelled. It should be 'makeDir' or 'mkDir' to
follow standard naming conventions.
```suggestion
makeDir(libRoot);
}
private static void makeDir(String dir) {
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/BuiltinExternalServices.java:
##########
@@ -22,14 +22,10 @@
import java.util.function.Supplier;
public enum BuiltinExternalServices {
- MQTT(
- "MQTT",
- "org.apache.iotdb.externalservice.Mqtt",
- // IoTDBDescriptor.getInstance().getConfig()::isEnableMQTTService
- () -> false),
+ MQTT("MQTT", "org.apache.iotdb.mqtt.MQTTService", () -> true),
Review Comment:
The MQTT service is now hardcoded to always be enabled (supplier returns
true), ignoring the previous configuration check for isEnableMQTTService. This
changes the behavior from the commented-out line and may cause the MQTT service
to start even when users have it disabled in their configuration. The
configuration check should be restored or this change should be documented as
an intentional behavior change.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/ExternalServiceManagementService.java:
##########
@@ -311,11 +328,34 @@ public void restoreRunningServiceInstance() {
serviceInfo -> {
// start services with RUNNING state
if (serviceInfo.getState() == RUNNING) {
- IExternalService serviceInstance =
- createExternalServiceInstance(
- serviceInfo.getServiceName(),
serviceInfo.getClassName());
- serviceInfo.setServiceInstance(serviceInstance);
- serviceInstance.start();
+
+ try {
+ IExternalService serviceInstance =
+ createExternalServiceInstance(
+ serviceInfo.getServiceName(),
serviceInfo.getClassName());
+ serviceInfo.setServiceInstance(serviceInstance);
+ } finally {
+ // set STOPPED to avoid the case: service is RUNNING, but
its instance is null
+ if (serviceInfo.getServiceInstance() == null) {
+ serviceInfo.setState(STOPPED);
+ }
+ }
+
+ serviceInfo.getServiceInstance().start();
Review Comment:
There's a logic issue where serviceInstance.start() is called outside the
try-finally block. If serviceInfo.getServiceInstance() is null (which is
explicitly handled in the finally block by setting state to STOPPED), this will
throw a NullPointerException when trying to call start() on line 344. The
start() call should be inside the try block or checked for null before calling.
```suggestion
if (serviceInstance != null) {
serviceInstance.start();
}
} finally {
// set STOPPED to avoid the case: service is RUNNING, but
its instance is null
if (serviceInfo.getServiceInstance() == null) {
serviceInfo.setState(STOPPED);
}
}
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/ExternalServiceManagementService.java:
##########
@@ -311,11 +328,34 @@ public void restoreRunningServiceInstance() {
serviceInfo -> {
// start services with RUNNING state
if (serviceInfo.getState() == RUNNING) {
- IExternalService serviceInstance =
- createExternalServiceInstance(
- serviceInfo.getServiceName(),
serviceInfo.getClassName());
- serviceInfo.setServiceInstance(serviceInstance);
- serviceInstance.start();
+
+ try {
+ IExternalService serviceInstance =
+ createExternalServiceInstance(
+ serviceInfo.getServiceName(),
serviceInfo.getClassName());
+ serviceInfo.setServiceInstance(serviceInstance);
+ } finally {
+ // set STOPPED to avoid the case: service is RUNNING, but
its instance is null
+ if (serviceInfo.getServiceInstance() == null) {
+ serviceInfo.setState(STOPPED);
+ }
+ }
+
+ serviceInfo.getServiceInstance().start();
+ }
+ });
+ }
+
+ public void stopRunningServices() {
+ serviceInfos
+ .values()
+ .forEach(
+ serviceInfo -> {
+ // start services with RUNNING state
Review Comment:
The comment says 'start services with RUNNING state' but the method actually
stops services. This should be 'stop services with RUNNING state' to accurately
describe what the code does.
```suggestion
// stop services with RUNNING state
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/ExternalServiceManagementService.java:
##########
@@ -65,10 +66,25 @@ public class ExternalServiceManagementService {
private static final Logger LOGGER =
LoggerFactory.getLogger(ExternalServiceManagementService.class);
+ public static final String INSTANCE_NULL_ERROR_MSG =
+ "External Service instance is null when state is RUNNING!";
+
private ExternalServiceManagementService(String libRoot) {
this.serviceInfos = new HashMap<>();
restoreBuiltInServices();
this.libRoot = libRoot;
+ makDir(libRoot);
+ }
+
+ private static void makDir(String dir) {
Review Comment:
The method name 'makDir' is misspelled. It should be 'makeDir' or 'mkDir' to
follow standard naming conventions.
```suggestion
makeDir(libRoot);
}
private static void makeDir(String dir) {
```
##########
external-service-impl/mqtt/pom.xml:
##########
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.iotdb</groupId>
+ <artifactId>external-service-impl</artifactId>
+ <version>2.0.7-SNAPSHOT</version>
+ </parent>
+ <artifactId>mqtt</artifactId>
+ <name>IoTDB: External-Service-Impl: MQTT</name>
+ <properties>
+ <maven.compiler.source>11</maven.compiler.source>
+ <maven.compiler.target>11</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>com.github.moquette-io.moquette</groupId>
+ <artifactId>moquette-broker</artifactId>
+ <exclusions>
+ <!-- exclude dependencies has included by iotdb-server -->
Review Comment:
Grammar issue in the comment: 'dependencies has included' should be
'dependencies already included' or 'dependencies that have been included'.
```suggestion
<!-- exclude dependencies already included by iotdb-server
-->
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/BuiltinExternalServices.java:
##########
@@ -22,14 +22,10 @@
import java.util.function.Supplier;
public enum BuiltinExternalServices {
- MQTT(
- "MQTT",
- "org.apache.iotdb.externalservice.Mqtt",
- // IoTDBDescriptor.getInstance().getConfig()::isEnableMQTTService
- () -> false),
+ MQTT("MQTT", "org.apache.iotdb.mqtt.MQTTService", () -> true),
REST(
"REST",
- "org.apache.iotdb.externalservice.Rest",
+ "org.apache.iotdb.mqtt.RestService",
Review Comment:
The REST service class name 'org.apache.iotdb.mqtt.RestService' appears to
be incorrectly placed in the mqtt package. REST service should have its own
package structure, not be part of the MQTT package. This is misleading and
violates package organization principles.
```suggestion
"org.apache.iotdb.rest.RestService",
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]