This is an automated email from the ASF dual-hosted git repository. luchunliang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push: new 7cbe641d04 [INLONG-9207][Agent] Fix bug: task manager stuck (#9208) 7cbe641d04 is described below commit 7cbe641d04479fe84de6ce66c3944107a3f45868 Author: justinwwhuang <hww_jus...@163.com> AuthorDate: Fri Nov 3 15:44:01 2023 +0800 [INLONG-9207][Agent] Fix bug: task manager stuck (#9208) --- .../inlong/agent/plugin/task/filecollect/LogFileCollectTask.java | 7 +++++++ .../apache/inlong/agent/plugin/task/TestLogfileCollectTask.java | 8 +++++--- .../src/test/resources/testScan/20230928_1/test_1.txt | 3 +++ inlong-agent/agent-plugins/src/test/resources/testScan/temp.txt | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/task/filecollect/LogFileCollectTask.java b/inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/task/filecollect/LogFileCollectTask.java index 11d9330274..54170a5290 100644 --- a/inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/task/filecollect/LogFileCollectTask.java +++ b/inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/task/filecollect/LogFileCollectTask.java @@ -79,6 +79,7 @@ public class LogFileCollectTask extends Task { new ConcurrentHashMap<>(); public static final long DAY_TIMEOUT_INTERVAL = 2 * 24 * 3600 * 1000; public static final int CORE_THREAD_SLEEP_TIME = 1000; + public static final int CORE_THREAD_MAX_GAP_TIME_MS = 60 * 1000; private boolean retry; private long startTime; private long endTime; @@ -87,6 +88,7 @@ public class LogFileCollectTask extends Task { private long lastScanTime = 0; public final long SCAN_INTERVAL = 1 * 60 * 1000; private volatile boolean runAtLeastOneTime = false; + private volatile long coreThreadUpdateTime = 0; private volatile boolean running = false; @Override @@ -196,6 +198,10 @@ public class LogFileCollectTask extends Task { private void releaseWatchers(Map<String, WatchEntity> watchers) { while (running) { + if (AgentUtils.getCurrentTime() - coreThreadUpdateTime > CORE_THREAD_MAX_GAP_TIME_MS) { + LOGGER.error("core thread not update, maybe it has broken"); + break; + } AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME); } watchers.forEach((taskId, watcher) -> { @@ -227,6 +233,7 @@ public class LogFileCollectTask extends Task { Thread.currentThread().setName("directory-task-core-" + getTaskId()); running = true; while (!isFinished()) { + coreThreadUpdateTime = AgentUtils.getCurrentTime(); AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME); if (!initOK) { continue; diff --git a/inlong-agent/agent-plugins/src/test/java/org/apache/inlong/agent/plugin/task/TestLogfileCollectTask.java b/inlong-agent/agent-plugins/src/test/java/org/apache/inlong/agent/plugin/task/TestLogfileCollectTask.java index 8a9ed4c021..29047919cc 100644 --- a/inlong-agent/agent-plugins/src/test/java/org/apache/inlong/agent/plugin/task/TestLogfileCollectTask.java +++ b/inlong-agent/agent-plugins/src/test/java/org/apache/inlong/agent/plugin/task/TestLogfileCollectTask.java @@ -61,6 +61,7 @@ public class TestLogfileCollectTask { private static final Gson GSON = new Gson(); private static TaskManager manager; private static MockInstanceManager instanceManager = new MockInstanceManager(); + private static String tempResourceName; private static String resourceName; private static String fileName; private static String dataTime; @@ -74,9 +75,10 @@ public class TestLogfileCollectTask { public static void setup() { helper = new AgentBaseTestsHelper(TestLogfileCollectTask.class.getName()).setupAgentHome(); Db basicDb = TaskManager.initDb("/localdb"); - resourceName = LOADER.getResource("test/20230928_1.txt").getPath(); - File f = new File(resourceName); - String pattern = f.getParent() + "/YYYYMMDD_[0-9]+.txt"; + resourceName = LOADER.getResource("testScan/20230928_1/test_1.txt").getPath(); + tempResourceName = LOADER.getResource("testScan/temp.txt").getPath(); + File f = new File(tempResourceName); + String pattern = f.getParent() + "/YYYYMMDD_[0-9]+/test_[0-9]+.txt"; TaskProfile taskProfile = helper.getTaskProfile(1, pattern, true, 0L, 0L, TaskStateEnum.RUNNING); try { String startStr = "2023-09-20 00:00:00"; diff --git a/inlong-agent/agent-plugins/src/test/resources/testScan/20230928_1/test_1.txt b/inlong-agent/agent-plugins/src/test/resources/testScan/20230928_1/test_1.txt new file mode 100644 index 0000000000..780b09709f --- /dev/null +++ b/inlong-agent/agent-plugins/src/test/resources/testScan/20230928_1/test_1.txt @@ -0,0 +1,3 @@ +hello line-end-symbol aa +world line-end-symbol +agent line-end-symbol diff --git a/inlong-agent/agent-plugins/src/test/resources/testScan/temp.txt b/inlong-agent/agent-plugins/src/test/resources/testScan/temp.txt new file mode 100644 index 0000000000..780b09709f --- /dev/null +++ b/inlong-agent/agent-plugins/src/test/resources/testScan/temp.txt @@ -0,0 +1,3 @@ +hello line-end-symbol aa +world line-end-symbol +agent line-end-symbol