diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-11-28 12:20:46 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-12-05 11:49:14 -0500 |
commit | 009d23df45969036c70e4cf59eb4019aaace9a55 (patch) | |
tree | 4541c4fb24a99b5c14da107e43952e572f4da692 /oslo_db/tests | |
parent | a191d2e629f55c999b37a7a795ad6fbee2807b98 (diff) | |
download | oslo-db-009d23df45969036c70e4cf59eb4019aaace9a55.tar.gz |
Add option for wsrep_sync_wait
When using Galera, the wsrep_sync_wait option [1]
can change the behavior of a variety of Galera DQL/DML statements
such that a particular operation will pause until outstanding
write-sets are fully persisted to the local node. The setting
supersedes the previous boolean parameter wsrep_causal_reads
which only affected SELECT, with an updated approach that allows
for fine-grained control of so-called "causality checks"
on individual statement types. The legacy-compatible setting
of '1' indicates that READ/SELECT/BEGIN operations should
proceed only after any pending writesets are fully available.
The use case for this setting is for an application that
is running operations on multiple Galera nodes simultaenously.
An application that commits data on one node, and then immediately
uses a different connection (on a potentially different node)
to SELECT that data, may fail to see those changes if
"causality checks" for SELECT are not enabled. While
a COMMIT operation in Galera will block locally until all other
nodes approve of the writeset, the operation does not block
for the subsequent period of time when other nodes are actually
persisting that writeset. Setting up "causal reads"
in this case indicates that a SELECT operation will wait until
any writesets in progress are available, thus maintaining
serialization between the COMMIT and subsequent SELECT.
As the name implies, wsrep_sync_wait adds...waiting! to the
operation, and thus directly impacts performance by adding
latency to SELECT operations or to the operations that have
been selected for causality checks, to the degree that
concurrent writesets are expected to be present.
Since it's not expected that most if any Openstack applications
actually need this setting in order to be effective with
Galera multi-master operation, and as the setting is available
within client session scope and also impacts performance,
making it available on a per-application basis means that
specific applications which may see issues under load can
choose to enable this setting, much in the way any other
"transaction isolation" settings might be made, without having
to add a cluster-wide performance penalty by setting it at the
Galera server level.
[1] https://mariadb.com/docs/ent/ref/mdb/system-variables/wsrep_sync_wait/
Change-Id: Iee7afcac8ba952a2d67a9ad9dd0e4eae3f42518e
Diffstat (limited to 'oslo_db/tests')
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_sqlalchemy.py | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py index 7b634f1..d954700 100644 --- a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py +++ b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py @@ -24,6 +24,7 @@ from unittest import mock import fixtures from oslo_config import cfg import sqlalchemy +from sqlalchemy import exc from sqlalchemy import sql from sqlalchemy import Column, MetaData, Table from sqlalchemy.engine import url @@ -415,6 +416,7 @@ class EngineFacadeTestCase(test_base.BaseTestCase): connection_debug=100, max_pool_size=10, mysql_sql_mode='TRADITIONAL', + mysql_wsrep_sync_wait=None, mysql_enable_ndb=False, sqlite_fk=False, connection_recycle_time=mock.ANY, @@ -519,8 +521,15 @@ class SQLiteConnectTest(test_base.BaseTestCase): class MysqlConnectTest(db_test_base._MySQLOpportunisticTestCase): - def _fixture(self, sql_mode): - return session.create_engine(self.engine.url, mysql_sql_mode=sql_mode) + def _fixture(self, sql_mode=None, mysql_wsrep_sync_wait=None): + + kw = {} + if sql_mode is not None: + kw["mysql_sql_mode"] = sql_mode + if mysql_wsrep_sync_wait is not None: + kw["mysql_wsrep_sync_wait"] = mysql_wsrep_sync_wait + + return session.create_engine(self.engine.url, **kw) def _assert_sql_mode(self, engine, sql_mode_present, sql_mode_non_present): with engine.connect() as conn: @@ -535,6 +544,36 @@ class MysqlConnectTest(db_test_base._MySQLOpportunisticTestCase): sql_mode_non_present, mode ) + def test_mysql_wsrep_sync_wait_listener(self): + with self.engine.connect() as conn: + try: + conn.execute( + sql.text("show variables like '%wsrep_sync_wait%'") + ).scalars(1).one() + except exc.NoResultFound: + self.skipTest("wsrep_sync_wait option is not available") + + engine = self._fixture() + + with engine.connect() as conn: + self.assertEqual( + "0", + conn.execute( + sql.text("show variables like '%wsrep_sync_wait%'") + ).scalars(1).one(), + ) + + for wsrep_val in (2, 1, 5): + engine = self._fixture(mysql_wsrep_sync_wait=wsrep_val) + + with engine.connect() as conn: + self.assertEqual( + str(wsrep_val), + conn.execute( + sql.text("show variables like '%wsrep_sync_wait%'") + ).scalars(1).one(), + ) + def test_set_mode_traditional(self): engine = self._fixture(sql_mode='TRADITIONAL') self._assert_sql_mode(engine, "TRADITIONAL", "ANSI") |