Skip to content

Commit 4d81852

Browse files
authored
Update Lock documentation (#627)
Fixes #507.
1 parent 01651ee commit 4d81852

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

docs/locks.rst

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ The following can be imported from ``django_mysql.locks``.
1818
This class implements a user lock and acts as either a context manager
1919
(recommended), or a plain object with ``acquire`` and ``release`` methods
2020
similar to ``threading.Lock``. These call the MySQL functions ``GET_LOCK``,
21-
``RELEASE_LOCK``, and ``IS_USED_LOCK`` to manage it. It is *not* re-entrant
22-
so don't write code that gains/releases the same lock more than once.
21+
``RELEASE_LOCK``, and ``IS_USED_LOCK`` to manage it.
22+
23+
The lock is only re-entrant (acquirable multiple times) on MariaDB 10.0+.
24+
25+
MySQL before 5.7, and MariaDB before 10.0, only allowed one lock per
26+
connection. On those versions and later, you can hold multiple locks.
2327

2428
Basic usage:
2529

@@ -46,18 +50,6 @@ The following can be imported from ``django_mysql.locks``.
4650
set to ``STATEMENT``. Most environments have ``binlog_format`` set to
4751
``MIXED`` because it can be more performant, but do check.
4852

49-
.. warning::
50-
51-
It's not very well documented, but you can only hold one lock per
52-
database connection at a time. Acquiring a lock releases any other lock
53-
you were holding.
54-
55-
Since there is no MySQL function to tell you if you are currently
56-
holding a lock, this class does not check that you only acquire one
57-
lock. It has been a `more than 10 year feature request
58-
<http://bugs.mysql.com/bug.php?id=1118>`_ to hold more than one lock
59-
per connection, and has been finally announced in MySQL 5.7.5.
60-
6153
.. attribute:: name
6254

6355
This is a required argument.
@@ -68,8 +60,10 @@ The following can be imported from ``django_mysql.locks``.
6860
a full stop, in case multiple apps are using different databases on the
6961
same server.
7062

71-
Whilst not documented, the length limit is somewhere between 1 and 10
72-
million characters, so most sane uses should be fine.
63+
MySQL 5.7+ enforces a maximum length on the total name (including the
64+
DB prefix that Django-MySQL adds) of 64 characters. MariaDB doesn't
65+
enforce any limit. The practical limit on MySQL <5.6 or MariaDB is
66+
maybe 1 million characters or more, so most sane uses should be fine.
7367

7468
.. attribute:: acquire_timeout=10.0
7569

0 commit comments

Comments
 (0)