Home > database > Ask a about the deadlock deadlock problem
Ask a about the deadlock deadlock problem
Time:09-20
For some reason, don't use the concurrency, but by the mysql database table instead of queue,
Specific statements is
To execute SQL='SELECT * FROM resource_trading_center_yeji where is_deleted is null and project_source="' + center_name + 'for update' After executing SQL='update resource_trading_center_yeji set is_deleted=1 where url=% s. ' No commit
Lock waiting timeout for 1 second
Scene: a bunch of instance traversal plugins, plugs have their own center_name, traversal process may be repeated
Project_source and is_deleted index, arguably, will only add a row lock and even perform 'update resource_trading_center_yeji set is_deleted=1 where url=% s. 'when adding a table lock (url no index), but more than one session did not cross waiting for locks,
Don't know why deadlock, it should wait for the lock timeout, Thank you for your answer
CodePudding user response:
I think a scene: A: A session in the execution, had not performed, so is the table locks; B at the same time, the session also launched A SQL, due to the session is A table lock, so for the session B for update statement is blocked, the second SQL execution; At the same time, the session also launched A SQL, C because the session is A table lock, so for the session C for update statement is blocked, the second SQL execution;
Suppose center_name different session B and C;
B: Session A performed, release all locks; At the same time: The corresponding row lock session B obtained center_name1; Session C to obtain the corresponding row locking center_name2;
When session B want to perform the update, need access to table locks, but blocked by session C row locks, waiting for the session C release row locks; When the session C want to perform the update, need access to table locks, but blocked by session B row locks, waiting for the session B release row locks;
Wait for each other, more than 1 second, deadlock rollback,