Caideyipi commented on code in PR #13085:
URL: https://github.com/apache/iotdb/pull/13085#discussion_r1701126874
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java:
##########
@@ -82,6 +82,7 @@ public enum ServiceType {
PIPE_RUNTIME_DATA_NODE_AGENT("Pipe Runtime Data Node Agent",
"PipeRuntimeDataNodeAgent"),
PIPE_RUNTIME_CONFIG_NODE_AGENT("Pipe Runtime Config Node Agent",
"PipeRuntimeConfigNodeAgent"),
SUBSCRIPTION_RUNTIME_AGENT("Subscription Runtime Agent",
"SubscriptionRuntimeAgent"),
+ AUTO_LOAD_TSFILE_SERVICE("Auto Load TSFile Service",
"AutoLoadTSFileService"),
Review Comment:
Better unify the "TsFile" related cases
##########
iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template:
##########
@@ -1867,6 +1867,38 @@ load_clean_up_task_execution_delay_time_seconds=1800
# Datatype: int
load_write_throughput_bytes_per_second=-1
+# Whether to enable the DataNode to actively listen for and load
tsfile(default is enabled).
+# effectiveMode: hot_reload
+# Datatype: Boolean
+load_active_listening_enable=true
+
+# The directory to be monitored for tsfile to be loaded.
+# Multiple directories should be separated by a ','.
+# The default directory is 'ext/load/pending'.
+# effectiveMode: hot_reload
+# Datatype: String
+load_active_listening_dirs=ext/load/pending
Review Comment:
Consider windows platform and provide the "\\" default form in comments.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/load/AutoLoadTsFileService.java:
##########
@@ -0,0 +1,397 @@
+/*
+ * 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.
+ */
+
+package org.apache.iotdb.db.pipe.receiver.load;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.concurrent.IoTThreadFactory;
+import org.apache.iotdb.commons.concurrent.ThreadName;
+import
org.apache.iotdb.commons.concurrent.threadpool.WrappedThreadPoolExecutor;
+import org.apache.iotdb.commons.exception.StartupException;
+import org.apache.iotdb.commons.service.IService;
+import org.apache.iotdb.commons.service.ServiceType;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.pipe.agent.runtime.PipePeriodicalJobExecutor;
+import org.apache.iotdb.db.pipe.receiver.protocol.thrift.IoTDBDataNodeReceiver;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class AutoLoadTsFileService implements IService {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(AutoLoadTsFileService.class);
+
+ private static final IoTDBDataNodeReceiver receiver = new
IoTDBDataNodeReceiver();
+
+ private static final IoTDBConfig IOTDB_CONFIG =
IoTDBDescriptor.getInstance().getConfig();
+
+ private static String[] LOAD_ACTIVE_LISTENING_DIRS = new String[0];
+ private static String LOAD_ACTIVE_LISTENING_FAIL_DIR = "";
+
+ private static final Long LOAD_ACTIVE_LISTENING_CHECK_INTERVAL_SECONDS =
+ IOTDB_CONFIG.getLoadActiveListeningCheckIntervalSeconds();
+ private static final Integer LOAD_ACTIVE_LISTENING_MAX_THREAD_NUM =
+ Math.min(
+ IOTDB_CONFIG.getLoadActiveListeningMaxThreadNum(),
+ Math.max(1, Runtime.getRuntime().availableProcessors() / 2));
+
+ // the maximum number of times a thread attempts to retrieve an element
+ // end the current thread after exceeding the maximum number of times
+ private static final int RETRY_MAX_NUM = 60;
+ // max length of waitingLoadTsFileQueue
+ private static final int QUEUE_MAX_NUM = 200;
+ // the rest space size of waitingLoadTsFileQueue
+ private int QUEUE_REST_NUM = QUEUE_MAX_NUM;
+
+ // whether the load tsfile thread enable
+ private final AtomicBoolean isShutdown = new AtomicBoolean(false);
+ // whether the tsfileSet and resourceOrModsSet get enough file
+ private final AtomicBoolean isFileListFull = new AtomicBoolean(false);
+
+ private static final String RESOURCE = ".resource";
+ private static final String MODS = ".mods";
+
+ private static final Set<String> tsfileSet = new HashSet<>();
+ private static final Set<String> resourceOrModsSet = new HashSet<>();
+
+ private static final PipePeriodicalJobExecutor
checkTsFilePeriodicalJobExecutor =
+ new PipePeriodicalJobExecutor();
+ private static WrappedThreadPoolExecutor loadTsFileExecutor;
+
+ private static final LinkedHashSet<String> waitingLoadTsFileQueue =
+ new LinkedHashSet<>(QUEUE_MAX_NUM);
+
+ private static final Lock lock = new ReentrantLock();
+
+ @Override
+ public void start() throws StartupException {
+ registerPeriodicalJob(this::monitoringTsFile);
+ checkTsFilePeriodicalJobExecutor.start();
+ isShutdown.set(false);
+ }
+
+ @Override
+ public void stop() {
+ if (isShutdown.get()) {
+ return;
+ }
+ isShutdown.set(true);
+ checkTsFilePeriodicalJobExecutor.stop();
+ loadTsFileExecutor.shutdown();
+ }
+
+ @Override
+ public ServiceType getID() {
+ return ServiceType.AUTO_LOAD_TSFILE_SERVICE;
+ }
+
+ private void registerPeriodicalJob(Runnable periodicalJob) {
+ checkTsFilePeriodicalJobExecutor.register(
+ "AutoLoadTsFileService#loadTsFiles",
+ periodicalJob,
+ AutoLoadTsFileService.LOAD_ACTIVE_LISTENING_CHECK_INTERVAL_SECONDS);
+ }
+
+ // initial directory
+ private void initializeConfiguration() {
+ try {
+ LOAD_ACTIVE_LISTENING_DIRS = IOTDB_CONFIG.getLoadActiveListeningDirs();
+ LOAD_ACTIVE_LISTENING_FAIL_DIR =
IOTDB_CONFIG.getLoadActiveListeningFailDir();
+ for (String listenerFileDir : LOAD_ACTIVE_LISTENING_DIRS) {
+ createDirectoriesIfNotExists(listenerFileDir);
+ }
+ createDirectoriesIfNotExists(LOAD_ACTIVE_LISTENING_FAIL_DIR);
+ } catch (Exception e) {
+ LOGGER.warn("failed to init file folder because all disks of folders are
full.", e);
+ }
+ }
+
+ // create a directory that does not exist in the configuration file
+ private void createDirectoriesIfNotExists(String path) throws
StartupException {
+ File file = new File(path);
+ boolean isNeeded = (file.exists() && file.isDirectory()) || file.mkdirs();
Review Comment:
Why this variable is named "isNeeded"?
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java:
##########
@@ -1140,8 +1140,73 @@ public class IoTDBConfig {
private CompressionType WALCompressionAlgorithm = CompressionType.LZ4;
+ private Boolean loadActiveListeningEnable = true;
+
+ private String[] loadActiveListeningDirs = new String[0];
+
+ private String loadActiveListeningFailDir =
+ IoTDBConstant.EXT_FOLDER_NAME
+ + File.separator
+ + IoTDBConstant.LOAD_TSFILE_FOLDER_NAME
+ + File.separator
+ + "fail";
+
+ private Long loadActiveListeningCheckIntervalSeconds = 5L;
Review Comment:
Use primitive type?
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/load/AutoLoadTsFileService.java:
##########
@@ -0,0 +1,397 @@
+/*
+ * 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.
+ */
+
+package org.apache.iotdb.db.pipe.receiver.load;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.concurrent.IoTThreadFactory;
+import org.apache.iotdb.commons.concurrent.ThreadName;
+import
org.apache.iotdb.commons.concurrent.threadpool.WrappedThreadPoolExecutor;
+import org.apache.iotdb.commons.exception.StartupException;
+import org.apache.iotdb.commons.service.IService;
+import org.apache.iotdb.commons.service.ServiceType;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.pipe.agent.runtime.PipePeriodicalJobExecutor;
+import org.apache.iotdb.db.pipe.receiver.protocol.thrift.IoTDBDataNodeReceiver;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class AutoLoadTsFileService implements IService {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(AutoLoadTsFileService.class);
+
+ private static final IoTDBDataNodeReceiver receiver = new
IoTDBDataNodeReceiver();
+
+ private static final IoTDBConfig IOTDB_CONFIG =
IoTDBDescriptor.getInstance().getConfig();
+
+ private static String[] LOAD_ACTIVE_LISTENING_DIRS = new String[0];
+ private static String LOAD_ACTIVE_LISTENING_FAIL_DIR = "";
+
+ private static final Long LOAD_ACTIVE_LISTENING_CHECK_INTERVAL_SECONDS =
+ IOTDB_CONFIG.getLoadActiveListeningCheckIntervalSeconds();
+ private static final Integer LOAD_ACTIVE_LISTENING_MAX_THREAD_NUM =
+ Math.min(
+ IOTDB_CONFIG.getLoadActiveListeningMaxThreadNum(),
+ Math.max(1, Runtime.getRuntime().availableProcessors() / 2));
+
+ // the maximum number of times a thread attempts to retrieve an element
+ // end the current thread after exceeding the maximum number of times
+ private static final int RETRY_MAX_NUM = 60;
+ // max length of waitingLoadTsFileQueue
+ private static final int QUEUE_MAX_NUM = 200;
+ // the rest space size of waitingLoadTsFileQueue
+ private int QUEUE_REST_NUM = QUEUE_MAX_NUM;
+
+ // whether the load tsfile thread enable
+ private final AtomicBoolean isShutdown = new AtomicBoolean(false);
+ // whether the tsfileSet and resourceOrModsSet get enough file
+ private final AtomicBoolean isFileListFull = new AtomicBoolean(false);
+
+ private static final String RESOURCE = ".resource";
+ private static final String MODS = ".mods";
+
+ private static final Set<String> tsfileSet = new HashSet<>();
+ private static final Set<String> resourceOrModsSet = new HashSet<>();
+
+ private static final PipePeriodicalJobExecutor
checkTsFilePeriodicalJobExecutor =
+ new PipePeriodicalJobExecutor();
+ private static WrappedThreadPoolExecutor loadTsFileExecutor;
+
+ private static final LinkedHashSet<String> waitingLoadTsFileQueue =
+ new LinkedHashSet<>(QUEUE_MAX_NUM);
+
+ private static final Lock lock = new ReentrantLock();
+
+ @Override
+ public void start() throws StartupException {
+ registerPeriodicalJob(this::monitoringTsFile);
+ checkTsFilePeriodicalJobExecutor.start();
+ isShutdown.set(false);
+ }
+
+ @Override
+ public void stop() {
+ if (isShutdown.get()) {
+ return;
+ }
+ isShutdown.set(true);
+ checkTsFilePeriodicalJobExecutor.stop();
+ loadTsFileExecutor.shutdown();
+ }
+
+ @Override
+ public ServiceType getID() {
+ return ServiceType.AUTO_LOAD_TSFILE_SERVICE;
+ }
+
+ private void registerPeriodicalJob(Runnable periodicalJob) {
+ checkTsFilePeriodicalJobExecutor.register(
+ "AutoLoadTsFileService#loadTsFiles",
+ periodicalJob,
+ AutoLoadTsFileService.LOAD_ACTIVE_LISTENING_CHECK_INTERVAL_SECONDS);
+ }
+
+ // initial directory
+ private void initializeConfiguration() {
+ try {
+ LOAD_ACTIVE_LISTENING_DIRS = IOTDB_CONFIG.getLoadActiveListeningDirs();
+ LOAD_ACTIVE_LISTENING_FAIL_DIR =
IOTDB_CONFIG.getLoadActiveListeningFailDir();
+ for (String listenerFileDir : LOAD_ACTIVE_LISTENING_DIRS) {
+ createDirectoriesIfNotExists(listenerFileDir);
+ }
+ createDirectoriesIfNotExists(LOAD_ACTIVE_LISTENING_FAIL_DIR);
+ } catch (Exception e) {
+ LOGGER.warn("failed to init file folder because all disks of folders are
full.", e);
+ }
+ }
+
+ // create a directory that does not exist in the configuration file
+ private void createDirectoriesIfNotExists(String path) throws
StartupException {
+ File file = new File(path);
+ boolean isNeeded = (file.exists() && file.isDirectory()) || file.mkdirs();
+ if (isShutdown.get()) return;
Review Comment:
Better use {} in if
##########
iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template:
##########
@@ -1867,6 +1867,38 @@ load_clean_up_task_execution_delay_time_seconds=1800
# Datatype: int
load_write_throughput_bytes_per_second=-1
+# Whether to enable the DataNode to actively listen for and load
tsfile(default is enabled).
+# effectiveMode: hot_reload
Review Comment:
If the effective mode is "hot_reload", the parameters must be reloaded by
"loadHotModifiedProps" and the code shall check the hot modified props and
respond to their changes.
--
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]