database - If a MySQL/InnoDB 'lock wait timeout' happens, is the lock given anyway when it's free? -
we have high performance django web application makes use of mysql's innodb's row level locking. @ point in our code see (in process a) if particular row in table available using select … update. if there process (b) using row, , got there first, there exclusive lock on row, , have 'lock wait timeout' exception. catch this, , move on try row (with similar select … update approach).
however, i'm not 100% sure happens when lock wait timeout happens. after b finished , releases it's locks, exclusive lock given a, though a's 'select … update' query has timed out, , has moved on lock row?
or (and think intuitively happens), after a's attempt lock fails, , moves on, , b commits , finishes: there no further attempt give lock a?
preferable reference/quote offical mysql documentation best, since it's canonical source. couldn't find in docs specifically addressing happens when attempt lock , times out.
the lock requested statement timed out never acquired:
when lock wait timeout occurs, current statement rolled back.
the below test exhibits fact:
-- "atable" innodb table -- connection #1 begin; update atable set acol = 1 acol = 2; -- connection #2 begin; select * atable update; -- hangs -- connection #3 begin; select * atable update; -- hangs -- wait until connection #2 times out -- connection #2 -- "lock wait timeout exceeded" -- connection #1 commit; -- connection #3 resumes execution , data displayed
Comments
Post a Comment