Skip to content

Commit

Permalink
mysql 5.7 onwards has a 64 character limit
Browse files Browse the repository at this point in the history
for the lockstring, so use a hash for the key
  • Loading branch information
jaygooby authored Feb 13, 2023
1 parent 1acab41 commit 54957d4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sqlock
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ children=( "$!" $(jobs -rp) )
disown

# Now try and get the lock
echo "SELECT IF(GET_LOCK('$lockstring',$LOCKTIMEOUT_SECONDS)=1,'Got lock', concat('Already locked by connection: ', IS_USED_LOCK('$lockstring')));" >$fifo
echo "SELECT IF(GET_LOCK(sha1('$lockstring'),$LOCKTIMEOUT_SECONDS)=1,'Got lock', concat('Already locked by connection: ', IS_USED_LOCK('$lockstring')));" >$fifo

# Sleep for long enough to see whether we got the lock - we add 1 second
# to the timeout, because the fifo output can still suffer from a slight delay
Expand All @@ -107,6 +107,6 @@ grep -q "Got lock" "$tmpdir"/sql.log || (grep "Already locked" "$tmpdir"/sql.log
"$@"

# release the lock
echo "SELECT RELEASE_LOCK('$lockstring');" >$fifo
echo "SELECT RELEASE_LOCK(sha1('$lockstring'));" >$fifo

tidyup

0 comments on commit 54957d4

Please sign in to comment.