Commit Graph

35 Commits

Author SHA1 Message Date
Takashi Kajinami 93c9da0a74 Fix handling of timeout and blocking
Change bed303e9b4 introduced the ability
to set timeout without blocking, but this caused a few problems.

- The acquire method has now different arguments according to
  a backend driver being used

- The change broke the existing usage with blocking=<number>

This addresses these two problems.

Change-Id: I8cefa2f4a940082d17cde43d132a818940422176
2023-12-22 21:40:38 +09:00
ricolin bed303e9b4 Fix: Add timeout for mysql driver
The issue with current one is we try to use blocking as timeout
provider.
That make the timeout setting in mysql bound with blocking.
And the lock can't served with scenario that when we don't need timeout
blocking but still timeout required.

Change-Id: I36c80f882a91cd1c63d5a3bc2d1d8cb50f6637c6
2023-07-10 22:56:14 +08:00
ricolin db64c2175c Fix mysql timeout
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
2023-04-14 14:03:54 +08:00
Pavlo Shchelokovskyy 81c629676c Add TLS support for MySQL driver
use pymysql TLS-related arguments as query params in DB connection URL.

Change-Id: I3136df2a9ac4e05daa46f33e47c1438e3b02a321
2021-11-08 19:41:16 +02:00
Dmitry Tantsur d59b283440 Fix breakage with PyMySQL 0.10.0
In this version a Connection is no longer a context manager. Fix
it by simply getting a Cursor out of it (locks don't seem to
interact with transactions, at least according to MariaDB docs).

Change-Id: I5ea06ebd2b976465ff82f10a74e140f30e9e803f
2020-07-20 15:52:32 +02:00
JP Bourget 2546cfc562 Fix mysql driver comparison operator
A test was failing due to L67 in tooz/drivers/mysql.py using `is`
instead of `==`.

Change-Id: I2baa101499f170ece99ccff368103b58f31ca79a
Closes-Bug: 1875749
2020-04-28 16:49:12 -04:00
Ben Nemec e76235b675 More explicitly document driver connection strings
If you're not intimately familiar with RFC 1808 it can be a bit tricky to
write tooz connection strings. In addition, some drivers do not document the
options that they recognize in a connection string. This can force a user to
read the driver code in order to figure out how to configure tooz to use said
driver, which should not be the case.

This change more explicitly documents the format of the connection string,
including which parts of an RFC 1808 URI it recognizes, and the options that
can be passed. It also clarifies which parts of the connection string are
optional (possibly because they have defaults) and which must always be
included.

Note that not every possible configuration is documented. For example, the
postgres driver supports multiple methods of configuring the connection host
and port. For consistency, I only documented the one that matches the other
drivers. This should be sufficient to allow a user to write a working
connection string.

This change also wires the etcd3 and etcd3gw drivers into the doc index since
they were missing before.

Change-Id: I66e54433115f27fb54badc2173f8f6044c49aacb
2018-12-17 22:37:55 +00:00
Julien Danjou 13e23e3087 Mutualize executor code in a mixin class
Change-Id: I364b0ca5a6361a818a084bbcb83c9e7855cb3583
2017-06-21 17:43:26 +02:00
Julien Danjou ee66b6e4e4 {my,pg}sql: close connections when out of retry
The connection is supposedly closed when blocking is False and the lock is not
acquired. Or when an exception happens in the locking code.

But if blocking is e.g. 5 seconds, then RetryError is raised but without
closing any connection at the end. This fixes that.

Change-Id: I7b40e466fe5fc01ee3f8c012f765aafca9ce716a
2017-06-16 11:40:42 +00:00
gord chung 6e3f5ceb75 sql: close connection for lock if not used
each lock creates it's own connection and only gets released when
garbage collection kicks in because of limitations

change logic so if we don't have lock, we don't have connection.

Change-Id: Ibf6eaf3ff3031424917e9fdb6920bf2fc1808b7c
2017-04-27 14:27:30 +00:00
zhangsong e6dc88b2a5 Add shared filelock
Currently each driver in tooz only support exclusive lock, it is
inefficient in some scenarios which only need shared lock.

This patch adds shared lock in file driver.

Change-Id: I55a528977e74b27da736f421d2eee28c7aae8aa3
Implements: blueprint support-shared-lock
Co-Authored-By: Julien Danjou <julien@danjou.info>
2017-03-21 11:27:24 +08:00
Julien Danjou f3dddcffdd Stop making tooz.utils depending on tooz.coordination
Change-Id: I5fdb1174ae1a2a84412f3b3159ad5835b2f7359f
2017-01-01 18:47:16 +01:00
Julien Danjou 04866ab9c3 Move ToozError to root module
Change-Id: I73b1c5a37b75991f79d8a5fb383c605689503333
2016-12-07 23:40:35 +01:00
Julien Danjou ea98b28519 Factorize member_id in the base coordinator class
Any coordinator that implements (and they all should) group membership
needs a member_id field and copy it to self. Just do that by default for
all driver at __init__ time.

Change-Id: I66d82815afd4c6e9354212e5ab3fba17931c1bbc
2016-11-30 14:57:54 +01:00
Julien Danjou da12883f2b coordinator: add join_group_create
This adds a method implement the common pattern of joining a group and
creating it if it does not exist.

Change-Id: Ie46e7c1d07599a20bd8c24e28e5936b9f47a8bf4
2016-11-24 10:25:52 +01:00
Julien Danjou 533341aebb Replace retrying with tenacity
Change-Id: I1f4710ac0b7a3fd32cd3406254ecbd6b7ae1dfa2
Closes-Bug: #1635406
2016-11-24 10:25:52 +01:00
Julien Danjou 756d265232 Expose timeout capabilities and use them for tests
Change-Id: I5b6ee43e6a6b91859dacedb9791da74e247cd12b
2016-06-09 10:40:16 +02:00
Gary Kotton 7f15e34c52 Using LOG.warning instead of LOG.warn
Python 3 deprecated the logger.warn method, see:
https://docs.python.org/3/library/logging.html#logging.warning
so we prefer to use warning to avoid DeprecationWarning.

Change-Id: Iac71d0c6d4209c236f4a4149eec0d08ec1682271
2016-06-06 05:51:11 -07:00
Jenkins 349834f39c Merge "Add programatic introspection of drivers characteristic(s)" 2016-01-08 17:02:01 +00:00
Joshua Harlow a3f22fe90c Add programatic introspection of drivers characteristic(s)
Change-Id: Icf187db9ba7d076b1a0f3cc9343acb0eaa1862cb
2016-01-07 12:38:15 -08:00
Julien Danjou 8d6540f6a9 utils: replace exception_message by exception_to_unicode
This leverages directly oslo_utils.encodeutils.

Change-Id: Id345f4c18cfe98e7359c8934b7148c97e2e1fd99
2016-01-04 18:47:52 +01:00
Julien Danjou df3363e2ea {pg,my}sql: fix AttributeError on connection failure
If connection fails to be established, the acquired attribute does not
exist and then you see warning such has:

Exception AttributeError: "'MySQLLock' object has no attribute 'acquired'" in
<bound method MySQLLock.__del__ of <tooz.drivers.mysql.MySQLLock object at 0x7f79479056d0>>

Change-Id: Id61775483c91ba4127d9dd8cb56d6629a51d7081
2015-11-27 12:13:31 +01:00
Joshua Harlow 32cdf82769 Ensure lock(s) acquire/release returns boolean values
Some of the returns were missing, so to ensure that the
interface is consistent ensure that we always return true
or false as needed, and add tests to ensure this keeps on
being maintained.

Change-Id: I877111c3a1d1d300881625c5900d4a825c5f1684
2015-06-19 12:44:16 -07:00
Kobi Samoray 07a77f02ed Use MySQL default port when not set explicitly
When a port number is not set explicitly in the connect URL to MySQL,
use MySQL default port number 3306

Change-Id: I3a7b50e7b8da00872960051b726e4b08ad9eacd6
2015-06-03 18:28:24 +03:00
Joshua Harlow cdac135a57 Provide and use a options collapsing function
Instead of having each driver index the last value of
each option, when all current drivers do not actually care
about any of the other indexes we can just use and provide
a option collapsing function that we by default apply to
all the existing drivers options (to avoid needing to index
by -1).

This avoids a confusion point for new folks, and one that
does not currently really provide any value (no driver in
tree besides one option in the redis driver uses/consumes
or understands multiple options in the first place).

Change-Id: Ia2898d84fd0e54871b829f4a95786a33accc20b8
2015-05-04 15:19:02 -07:00
Joshua Harlow edd499fdc5 Add + use helper to raise + chain exceptions
Ensure that on python versions that can retain
the exceptions associated chain/causes that we make
an attempt to retain them, on versions of python
that do not have this at least attempt to retain the
chain (but we will not get the nice stack formatting
that comes along with that).

Change-Id: I7b46854c3969463009c39be28a3131d2d3179c82
2015-04-14 23:26:12 -07:00
Jenkins 6bf9f95150 Merge "Beef up the docstrings on the various drivers" 2015-04-10 12:17:18 +00:00
Jenkins e251e2db5c Merge "fix lock concurrency issues with certain drivers" 2015-04-09 10:40:01 +00:00
Joshua Harlow 6569329e9b Beef up the docstrings on the various drivers
Change-Id: I1ca05629cc5f28c1248767bb18384a29801bece2
2015-04-08 12:35:07 -07:00
Mehdi Abaakouk 6bab678e6e fix lock concurrency issues with certain drivers
This change adds a test to ensure that lock acquired from different
threads/processes work as expected. And fixes drivers when they won't.

With file driver, when two threads acquire the lock, when the first one
releases it, the second get a 'ValueError: I/O operation on closed file'
because the first have closed the file after releasing the lock.
Now, the file is open when the lock object is created and we let the GC
to close it when we don't need it anymore

With mysql, postgres, kazoo driver, multiple acquire inside the same
backend session, doesn't work like a exclusive lock, so we track the
status locally when we get the lock inside a process.

Change-Id: Ic990a79c9baebe534409c1a433e21f4a2f9a7d6a
2015-04-08 09:55:07 +02:00
Abhijeet Malawade 6ea2302ccf fix mysql driver url parsing
Used 'parsed_url.hostname' instead of 'parsed_url.netloc' to get hostname.

Changed setup-mysql-env.sh script to start 'mysqld' with networking.

Closes-Bug: 1426351
Change-Id: Ifcf68b10ef5f93864d33d3a1719b9be321db6e5c
2015-03-16 06:16:27 -07:00
Mehdi Abaakouk 3d01a84dd4 Two locks acquired from one coord must works
Multiple calls to get_coord(name) should returns a different lock object
This is not true for all drivers. This change fixes that.

Change-Id: Ie14f0f252cc54317867efb3b0490b90078fff32b
2015-02-27 11:34:04 +01:00
Julien Danjou 26c39acd31 Upgrade to hacking 0.10
Change-Id: I77f50a1a4a5b08bd71d549e62fd471ef445b4bd7
2015-01-13 16:11:53 +01:00
Joshua Harlow 836fec02da Add driver autogenerated docs
Start to add/build a developer oriented doc that
can be further refined to explain to developers how
to use the different tooz drivers (and what the varying
drivers capabilities are).

Change-Id: I49f6bf5b397d6bc5426c074f6196c764c8938d23
2014-12-09 21:25:20 -08:00
Julien Danjou 8deae0f9f7 Add MySQL driver
Change-Id: Ia10be91f8985d4e2159437ad94096a690ee84dc3
2014-11-17 11:09:23 +01:00