Bladeren bron

[Fix] fix bug #3487 Create folder duplicate name under multithreading (#3697)

* add state

* fixed bug "jackson enum conversion  : InvalidFormatException"

* Word spelling modification
Comment modification
Word spelling modification,Comment modification,Log level modification

* Update EmailManager.java

* Update FlinkParameters.java

* Update SqlTask.java

* fixed  "getNotifyGroupList cache"  bug

* fix bug "Creating folders with multiple threads will result in multiple identical folders #3487"

* fix "Creating folders with multiple threads will result in multiple identical folders" #3487

* fix "Creating folders with multiple threads will result in multiple identical folders" #3487

* fix bug  #3487   Create folder duplicate name under multithreading

* fix bug  #3487   Create folder duplicate name under multithreading

* fix bug  #3487   Create folder duplicate name under multithreading

* fix bug  #3487   Create folder duplicate name under multithreading

Co-authored-by: mzjnumber1@163.com <mzjnumber1@163.com>
Co-authored-by: dailidong <dailidong66@gmail.com>
muzhongjiang 4 jaren geleden
bovenliggende
commit
c42e769ced

+ 5 - 0
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java

@@ -37,6 +37,7 @@ import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
@@ -139,6 +140,10 @@ public class ResourcesService extends BaseService {
                 }
                 }
             }
             }
             result.setData(resultMap);
             result.setData(resultMap);
+        } catch (DuplicateKeyException e) {
+            logger.error("resource directory {} has exist, can't recreate", fullName);
+            putMsg(result, Status.RESOURCE_EXIST);
+            return result;
         } catch (Exception e) {
         } catch (Exception e) {
             logger.error("resource already exists, can't recreate ", e);
             logger.error("resource already exists, can't recreate ", e);
             throw new RuntimeException("resource already exists, can't recreate");
             throw new RuntimeException("resource already exists, can't recreate");

+ 2 - 1
sql/dolphinscheduler-postgre.sql

@@ -523,7 +523,8 @@ CREATE TABLE t_ds_resources (
   pid int,
   pid int,
   full_name varchar(64),
   full_name varchar(64),
   is_directory int,
   is_directory int,
-  PRIMARY KEY (id)
+  PRIMARY KEY (id),
+  CONSTRAINT t_ds_resources_un UNIQUE (full_name, type)
 ) ;
 ) ;
 
 
 
 

+ 2 - 1
sql/dolphinscheduler_mysql.sql

@@ -657,7 +657,8 @@ CREATE TABLE `t_ds_resources` (
   `pid` int(11) DEFAULT NULL,
   `pid` int(11) DEFAULT NULL,
   `full_name` varchar(64) DEFAULT NULL,
   `full_name` varchar(64) DEFAULT NULL,
   `is_directory` tinyint(4) DEFAULT NULL,
   `is_directory` tinyint(4) DEFAULT NULL,
-  PRIMARY KEY (`id`)
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `t_ds_resources_un` (`full_name`,`type`)
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 
 
 -- ----------------------------
 -- ----------------------------

+ 26 - 0
sql/upgrade/1.3.3_schema/mysql/dolphinscheduler_ddl.sql

@@ -87,3 +87,29 @@ delimiter ;
 CALL ct_dolphin_T_t_ds_process_definition_version;
 CALL ct_dolphin_T_t_ds_process_definition_version;
 DROP PROCEDURE ct_dolphin_T_t_ds_process_definition_version;
 DROP PROCEDURE ct_dolphin_T_t_ds_process_definition_version;
 
 
+
+
+
+--    add t_ds_resources_un
+DROP PROCEDURE IF EXISTS uc_dolphin_T_t_ds_resources_un;
+delimiter d//
+CREATE PROCEDURE uc_dolphin_T_t_ds_resources_un()
+BEGIN
+    IF NOT EXISTS (
+            SELECT * FROM information_schema.KEY_COLUMN_USAGE
+            WHERE  TABLE_NAME = 't_ds_resources'
+              AND CONSTRAINT_NAME = 't_ds_resources_un'
+        )
+    THEN
+        ALTER TABLE t_ds_resources ADD CONSTRAINT t_ds_resources_un UNIQUE KEY (full_name,`type`);
+    END IF;
+END;
+
+d//
+
+delimiter ;
+CALL uc_dolphin_T_t_ds_resources_un();
+DROP PROCEDURE IF EXISTS uc_dolphin_T_t_ds_resources_un;
+
+
+

+ 27 - 1
sql/upgrade/1.3.3_schema/postgresql/dolphinscheduler_ddl.sql

@@ -79,4 +79,30 @@ d//
 
 
 delimiter ;
 delimiter ;
 SELECT ct_dolphin_T_t_ds_process_definition_version();
 SELECT ct_dolphin_T_t_ds_process_definition_version();
-DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_process_definition_version();
+DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_process_definition_version();
+
+
+
+
+--  add t_ds_resources_un
+CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_resources_un() RETURNS void AS $$
+BEGIN
+    IF NOT EXISTS (
+                    SELECT 1 FROM information_schema.KEY_COLUMN_USAGE
+                    WHERE  TABLE_NAME = 't_ds_resources'
+                    AND CONSTRAINT_NAME = 't_ds_resources_un'
+                )
+    THEN
+ALTER TABLE t_ds_resources ADD CONSTRAINT t_ds_resources_un UNIQUE (full_name,"type");
+END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+SELECT uc_dolphin_T_t_ds_resources_un();
+DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_resources_un();
+
+
+
+
+
+