summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorricolin <rlin@vexxhost.com>2022-11-23 07:57:31 +0800
committerricolin <rlin@vexxhost.com>2023-04-14 14:03:54 +0800
commitdb64c2175c01f896f40ee2aa420cbb58ce30e4dd (patch)
treedb364a1aacfd5860b0cc4764c1ea4f375d63e365
parent4a18ae10b8d2dc164b4607fcd0728bb24516a723 (diff)
downloadtooz-db64c2175c01f896f40ee2aa420cbb58ce30e4dd.tar.gz
Fix mysql timeout4.0.0
mysql should support customize timeout when acquire lock. Curently we only put 0, which will lead to in crush cases, lock might releases after mysql socket timeout, which is long hrs. Change-Id: I01aaff4af34b89fe82d985276ba356ce85a910de
-rw-r--r--tooz/drivers/mysql.py7
-rw-r--r--tooz/tests/test_mysql.py13
2 files changed, 19 insertions, 1 deletions
diff --git a/tooz/drivers/mysql.py b/tooz/drivers/mysql.py
index 491eecc..8dc2691 100644
--- a/tooz/drivers/mysql.py
+++ b/tooz/drivers/mysql.py
@@ -58,11 +58,16 @@ class MySQLLock(locking.Lock):
raise _retry.TryAgain
return False
+ _, timeout = utils.convert_blocking(blocking)
try:
if not self._conn.open:
self._conn.connect()
cur = self._conn.cursor()
- cur.execute("SELECT GET_LOCK(%s, 0);", self.name)
+ cur.execute(
+ ("SELECT GET_LOCK(%s, "
+ f"{timeout if timeout is not None else '0'});"),
+ self.name
+ )
# Can return NULL on error
if cur.fetchone()[0] == 1:
self.acquired = True
diff --git a/tooz/tests/test_mysql.py b/tooz/tests/test_mysql.py
index 735d9d0..c2a3941 100644
--- a/tooz/tests/test_mysql.py
+++ b/tooz/tests/test_mysql.py
@@ -85,3 +85,16 @@ class TestMySQLDriver(testcase.TestCase):
)
)
+
+ @mock.patch("pymysql.Connect")
+ def test_parsing_timeout_settings(self, sql_mock):
+ c = self._create_coordinator("mysql://localhost:3306/test")
+ c.start()
+
+ name = tests.get_random_uuid()
+ blocking_value = 10.12
+ lock = c.get_lock(name)
+ with mock.patch.object(lock, 'acquire', wraps=True, autospec=True) as \
+ mock_acquire:
+ with lock(blocking_value):
+ mock_acquire.assert_called_once_with(blocking_value)