node.js mysql并发死锁

hgtggwj0  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(208)

我有一个node.js应用程序,它将大量数据导入mysql数据库。我最近将表的主键更改为一个自动递增的整数。自从做了这个改动之后,mysql给了我大量的死锁,并且没有导入所有的数据。
er\u lock\u deadlock:试图获取锁时发现的死锁;尝试重新启动事务
下面是对mysql存储过程的node.js调用。这被称为多次,同时:

pool.query(
    "CALL AddItineraryDayLocation(?,?,?,?)",
    [itineraryId, location.name, location.longitude, location.latitude],
    function(error, results, fields) {
        if (error) 
            console.log(error);    
    }
);

以下是存储过程:

CREATE PROCEDURE `AddItineraryDayLocation`(
    IN tourItineraryId int,
    IN name VARCHAR(50),
    IN longitude decimal(12,8),
    IN latitude decimal(12,8)
)
BEGIN

    INSERT INTO
        touritinerarylocation (`tourItineraryId`, `name`, `longitude`, `latitude`)
    VALUES
        (tourItineraryId, name, longitude, latitude)
    ON DUPLICATE KEY UPDATE
        `tourItineraryId` = tourItineraryId,
        `name` = name,
        `longitude` = longitude,
        `latitude` = latitude;

END

还有table:

CREATE TABLE `touritinerarylocation` (
  `tourItineraryLocationId` int(11) NOT NULL AUTO_INCREMENT,
  `tourItineraryId` int(11) NOT NULL,
  `name` varchar(50) DEFAULT NULL,
  `longitude` decimal(12,8) NOT NULL,
  `latitude` decimal(12,8) NOT NULL,
  PRIMARY KEY (`tourItineraryLocationId`),
  UNIQUE KEY `tourItineraryId_longitude_latitude_UNIQUE` (`tourItineraryId`,`longitude`,`latitude`),
  KEY `fk_tourItineraryLocation_tourItinerary_idx` (`tourItineraryId`),
  CONSTRAINT `fk_tourItineraryLocation_tourItinerary` FOREIGN KEY (`tourItineraryId`) REFERENCES `touritinerary` (`tourItineraryId`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=11674 DEFAULT CHARSET=utf8;

我尝试过向存储过程中添加事务,但没有帮助。我也尝试过在while循环中 Package node.js查询以尝试重试该操作,但是我在范围界定方面遇到了问题,代码似乎在查询的第一次调用时就停止了(回调从未命中)。
有没有一种处理这种设置死锁的标准方法?我试过寻找类似的问题,但找不到任何相关或有用的东西。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题