From 2a8b88d8d485586b54756fc1d5f1f206393f8f42 Mon Sep 17 00:00:00 2001 From: Weihao Li <60659567+Wei-hao-Li@users.noreply.github.com> Date: Tue, 8 Jul 2025 08:48:31 +0800 Subject: [PATCH] Fix dead lock when take snapshot for Trigger and UDF (cherry picked from commit c5009f3ad617f53e490e99cec4f64bae6974bb2b) --- .../it/IoTDBConfigNodeSnapshot2IT.java | 47 +++++++++++++++++++ .../it/IoTDBConfigNodeSnapshotIT.java | 5 +- .../confignode/persistence/TriggerInfo.java | 3 -- .../iotdb/confignode/persistence/UDFInfo.java | 3 -- 4 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshot2IT.java diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshot2IT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshot2IT.java new file mode 100644 index 0000000000000..c156adbe259fe --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshot2IT.java @@ -0,0 +1,47 @@ +/* + * 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.confignode.it; + +import org.apache.iotdb.consensus.ConsensusFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; + +import org.junit.Before; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +@RunWith(IoTDBTestRunner.class) +@Category({ClusterIT.class}) +public class IoTDBConfigNodeSnapshot2IT extends IoTDBConfigNodeSnapshotIT { + @Before + public void setUp() throws Exception { + // set setConfigNodeRatisSnapshotTriggerThreshold to 1 + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setConfigNodeConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS) + .setConfigNodeRatisSnapshotTriggerThreshold(1) + .setTimePartitionInterval(testTimePartitionInterval); + + // Init 2C2D cluster environment + EnvFactory.getEnv().initClusterEnvironment(2, 2); + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshotIT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshotIT.java index af7cb37669d18..9ff58305bf506 100644 --- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshotIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshotIT.java @@ -78,8 +78,7 @@ @RunWith(IoTDBTestRunner.class) @Category({ClusterIT.class}) public class IoTDBConfigNodeSnapshotIT { - private static final int testRatisSnapshotTriggerThreshold = 100; - private static final long testTimePartitionInterval = 86400; + protected final long testTimePartitionInterval = 86400; @Before public void setUp() throws Exception { @@ -87,7 +86,7 @@ public void setUp() throws Exception { .getConfig() .getCommonConfig() .setConfigNodeConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS) - .setConfigNodeRatisSnapshotTriggerThreshold(testRatisSnapshotTriggerThreshold) + .setConfigNodeRatisSnapshotTriggerThreshold(100) .setTimePartitionInterval(testTimePartitionInterval); // Init 2C2D cluster environment diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TriggerInfo.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TriggerInfo.java index e324c6a7c4db7..065ae826fb804 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TriggerInfo.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TriggerInfo.java @@ -247,7 +247,6 @@ public boolean processTakeSnapshot(File snapshotDir) throws TException, IOExcept return false; } - acquireTriggerTableLock(); try (FileOutputStream fileOutputStream = new FileOutputStream(snapshotFile)) { serializeExistedJarToMD5(fileOutputStream); @@ -257,8 +256,6 @@ public boolean processTakeSnapshot(File snapshotDir) throws TException, IOExcept // fsync fileOutputStream.getFD().sync(); return true; - } finally { - releaseTriggerTableLock(); } } diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/UDFInfo.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/UDFInfo.java index 51f997192a915..1c7682dd35b7c 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/UDFInfo.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/UDFInfo.java @@ -194,7 +194,6 @@ public boolean processTakeSnapshot(File snapshotDir) throws IOException { return false; } - acquireUDFTableLock(); try (FileOutputStream fileOutputStream = new FileOutputStream(snapshotFile)) { serializeExistedJarToMD5(fileOutputStream); @@ -205,8 +204,6 @@ public boolean processTakeSnapshot(File snapshotDir) throws IOException { fileOutputStream.getFD().sync(); return true; - } finally { - releaseUDFTableLock(); } }