Victor Romano 0eda87984f Prepare DC queries for sqlalchemy 1.4 upversion
For subcloud scalability purposes, sqlalchemy will be upgraded from
version 1.3 to 1.4. This version change introduces some
incompatibilities from the current version:

- Session management: When calling model_query without providing a
session, a new one would be created inside a context manager. This
means that, upon exiting model_query, the query would be executed and
any new filtering after would reopen the session. Version 1.3 was more
forgiving regarding transactions and this was not an issue.
On version 1.4, sessions called after transaction ended will still
remain open [1], causing the pool to eventually overflow with sessions
stuck in "idle in transaction" state. To fix this, the session
creation inside model_query is changed to only start the context
manager, which will then be closed only when exiting the db function
itself by a decorator.

- Changed deprecated methods like the removal of count() method for
tables, joinedload_all and how values are accessed in rows [2].

- Writing in read sessions: Although sqlalchemy 1.4 still supports
  autocommit, it's being deprecated and removed in version 2.0. Since
  we also need to upversion oslo.db and newer versions disable
  autocommit by default, this commit replaces all write operations
  being done inside a read session with a write session.

Test plan:
  - PASS: Build a custom ISO with the changes and deploy a DX system
          controller and a SX subcloud. Verify the system works as
          expected.
  - PASS: Manage a subcloud and verify the sync_status is "in-sync".
  - PASS: Soak the system and verify there was no connection leak and
          no sessions stuck in "idle in transaction" state.
  - PASS: Run DC sanity and regression.
  - PASS: Run kube-rootca-update orchestration successfully.
  - PASS: Run subcloud prestage --for-sw-install successfully.
  - PASS: Create a subcloud backup and then restore it successfully.

[1]: https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#session-features-new-autobegin-behavior
[2]: https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#rowproxy-is-no-longer-a-proxy-is-now-called-row-and-behaves-like-an-enhanced-named-tuple

Story: 2011311
Task: 51731

Change-Id: I97c88d8f668e9cfc1d9c5682d43c233193a823d7
Signed-off-by: Victor Romano <victor.gluzromano@windriver.com>
2025-03-14 16:14:38 -03:00
2019-04-19 19:52:44 +00:00
2018-08-07 11:51:21 -04:00
2022-11-21 16:58:49 +00:00
2019-03-15 10:56:03 -05:00
2024-06-25 14:49:42 -03:00
Description
StarlingX Distributed Cloud
37 MiB
Languages
Python 95.3%
Shell 4.5%
Makefile 0.2%