slfan1989 commented on code in PR #5673:
URL: https://github.com/apache/hadoop/pull/5673#discussion_r1209399807


##########
hadoop-yarn-project/hadoop-yarn/bin/FederationStateStore/MySQL/FederationStateStoreStoredProcs.sql:
##########
@@ -92,12 +92,9 @@ CREATE PROCEDURE sp_addApplicationHomeSubCluster(
    IN applicationContext_IN BLOB,
    OUT storedHomeSubCluster_OUT varchar(256), OUT rowCount_OUT int)
 BEGIN
-   INSERT INTO applicationsHomeSubCluster
-      (applicationId, homeSubCluster, createTime, applicationContext)
-      (SELECT applicationId_IN, homeSubCluster_IN, NOW(), applicationContext_IN
-       FROM applicationsHomeSubCluster
-       WHERE applicationId = applicationId_IN
-       HAVING COUNT(*) = 0 );
+   INSERT IGNORE INTO applicationsHomeSubCluster(

Review Comment:
   Thank you very much for helping to review this pr! 
   
   `YARN-8337` describes a scenario where we use the Mysql database, and when 
multiple sessions call the sp_addApplicationHomeSubCluster stored procedure at 
the same time, a deadlock may occur.
   
   MySQL Gap lock is a type of gap lock used to protect a range of gaps instead 
of specific data rows.  We can look at the following picture.
   
   <img width="684" alt="image" 
src="https://github.com/apache/hadoop/assets/55643692/bef31a2d-20b7-40b8-a007-0b3d07bffc65";>
   
   
   



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to