8000 new: salt.sqlalchemy base implementation (+ returner & cache) by mattp- · Pull Request #68068 · saltstack/salt · GitHub
[go: up one dir, main page]

Skip to content

new: salt.sqlalchemy base implementation (+ returner & cache) #68068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

mattp-
Copy link
Contributor
@mattp- mattp- commented Jun 12, 2025

What does this PR do?

this is the foundation for a shared sqlalchemy model that can be used across (at least, from current testing) postgresql, mysql, sqlite. The eventual goal would be to deprecate the redundant mysql, pgjsonb, postgres returners & cache implementations. In the longer future, possibly defaulting to sqlite and removing file based cache &
returner mechanisms could lead to simplifying the salt codebase, but thats a much larger discussion.

NOTE: this PR is rebased on #68039 and #68030 , please merge them first, thanks 👍

NOTE: this pr only runs against sqlite and pymysql at the moment; I can't figure out how to get psycopg installing with the static reqs. I'll try to work with someone from salt-co to get that added. once psycopg gets installed the pg tests should run automatically.

I've got a separate changeset that implements sql optimizations for salt.key/salt.utils.minions, I'll be working on that next

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

@mattp- mattp- requested a review from a team as a code owner June 12, 2025 18:55
@mattp- mattp- changed the title new: salt.sqlalchemy base implementation new: salt.sqlalchemy base implementation (+ returner & cache) Jun 12, 2025
@mattp- mattp- changed the title new: salt.sqlalchemy base implementation (+ returner & cache) WIP: new: salt.sqlalchemy base implementation (+ returner & cache) Jun 12, 2025
@mattp- mattp- force-pushed the sqla branch 2 times, most recently from e0c1ccb to 9b8f4df Compare June 13, 2025 00:54
mattp- added 2 commits June 16, 2025 12:18
rather than force a cache.cache() interface and a uniform expiry across
the cache, we add a more common per store() expiry that can also be used
instead or in addition to the original cache-wide expiry.
previously 'bank' was minions/$minion, and key was 'data', which was a
merge of both pillar and grains. rather than do that, we organize pillar
and grains into separate banks for better index optimizations for
backends that can take advantage of it. it also just makes more sense
this way
mattp- added 3 commits June 23, 2025 15:50
took the liberty of making it a proper subclass in the process. this now
uses the salt.cache infrastructure such that it can be driven by the
base cache driver or a different one if so desired. functionality should
be equivalent, including using the base bank=pillar key=minion_id for
merged pillar, such that minion_data_cache can take advantage of the
same cache. because we are updating the cache at the source, we no
longer need to update the cache in master/masterapi.
the loops involved dont use sets which seems to have an oversized impact
on lookup performance. using sets for containment checks makes this
function go 15x faster on a 50k dataset (from 30+ sec to 2~ sec).
Rather than implement custom drivers for tokens, the existing cache
drivers can be leveraged for token management. This also moves token
expiry responsibility to the token(cache) implementation with a naive
fallback.

Implicitly the default token backend will move to either what the global
'cache' is set to, or, if overridden, the eauth_tokens.cache_driver
opt. This means on upgrade, tokens will be invalidated. The only other
token driver is 'rediscluster', which I've added a deprecation for,
since cache.redis_cache provides the same functionality.
mattp- added 6 commits June 23, 2025 15:57
this is the foundation for a shared sqlalchemy model that can be used
across (at least, from current testing) postgresql, mysql, sqlite. The
eventual goal would be to deprecate the redundant mysql, pgjsonb,
postgres returners & cache implementations. In the longer future,
possibly defaulting to sqlite and removing file based cache &
returner mechanisms could lead to simplifying the salt codebase, but
thats a much larger discussion.
in order to ease moving between cache backends, particularly for
master_keys (e.g. moving from localfs to a database), this handles
slurping all contents from each bank and moving it to the target cache
backend.
the mysql fixture was useful as a base, but making it database agnostic
required some changes. now it supports postgres, and easily others in
the future if desired. reworked the way versions work as well so it can
be consumed from different tests more easily.
cache implementation leveraging the newly introduced sqlalchemy models.
Tested with mysql, postgresql and sqlite.
also, adds a simple cache.migrate function for migrating a masters
caches into a new backend, if one wanted to move over to a new cache.
returner implementation leveraging the newly introduced sqlalchemy
models. one useful thing offered not by the other database returner
implementations is a lock based prep_jid to assure no jid collisions in
a high volume multi-master/clustered setup. tested with mysql, postgres
& sqlite.
I'd like to add psycopg but can't figure out how to get the wheel to
install / I think we need to add libs to salt-ci-container-images
instead.
@ITJamie
Copy link
Contributor
ITJamie commented Jun 24, 2025

I can't figure out how to get psycopg installing with the static reqs.

try adding psycopg-binary that will bypass the compile steps and let you add tests for it

@mattp-
Copy link
Contributor Author
mattp- commented Jun 24, 2025

I can't figure out how to get psycopg installing with the static reqs.

try adding psycopg-binary that will bypass the compile steps and let you add tests for it

tried that, unfortunately it craps out for reasons I can't figure out where it cannot find the right wheel (I'm pretty sure are related to the hacks https://github.com/saltstack/pip-tools-compile-impersonate are doing but couldn't figure it out / wasted enough time on it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test:full Run the full test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0