Skip to content

Invalidate the content cache once a new repository version is complete - #8247

Merged
dralley merged 1 commit into
pulp:mainfrom
AVSystem:pr/8246-cache-invalidation-order
Oct 21, 2026
Merged

dralley merged 1 commit into
pulp:mainfrom
AVSystem:pr/8246-cache-invalidation-order

Conversation

@aevnsvi

@aevnsvi aevnsvi commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Closes #8246

Repository.new_version() cleared the content cache of the distributions serving the repository when the new version was started. Until the version is complete, those distributions still serve the previous one. A request in that window therefore put the previous answer back into the cache, and it was served until it expired (ten minutes by default). Details and a reproducer are in #8246.

What changes

  • The call to invalidate_cache() moves from new_version() to RepositoryVersion.__exit__. It runs through transaction.on_commit after the version is complete, so no request can see the previous version after the cache is cleared.
  • A version that changes nothing is discarded and no longer clears the cache.
  • Publications already invalidate after complete=True is saved. They are not touched.

Why version deletion needs no change
RepositoryVersion.delete() also clears the cache before its own transaction commits. But a version that any distribution serves cannot be deleted:

  • protected_versions() covers versions set on a distribution, versions behind distributed publications and checkpoints, and the version a repository distribution serves;
  • the API, cleanup_old_versions and a model hook all refuse to delete them.

Tests

  • pulpcore/tests/unit/models/test_repository_cache.py:

    • the cache is cleared while the new version is already complete;
    • a version without changes leaves the cache alone.

    Both fail without the change.

  • The pulpcore and pulp_file unit suites pass.

Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

@gerrod3 gerrod3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you used AI for this please add an attribution in your commit, otherwise some minor changes and I think we will be good. @dralley This cache invalidation issue might be the problem with replicas.

Comment thread CHANGES/8246.bugfix Outdated
Comment on lines +1 to +2
Fixed responses for a distribution being cached from the previous repository version, and served
until the cache entry expired, when they were requested while a new version was being created.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this on one line.

Comment thread pulpcore/app/models/repository.py Outdated
Comment on lines +1535 to +1537
# Only now: until the new version is complete and committed, a request
# is answered from the previous version, and clearing the cache earlier
# would let that answer be cached again and served until it expires.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment.

@aevnsvi
aevnsvi force-pushed the pr/8246-cache-invalidation-order branch from 3c4dd54 to af41170 Compare October 20, 2026 19:56
@@ -0,0 +1,65 @@
import hashlib

@dralley dralley Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a handful of similar tests in pulpcore/tests/unit/models/test_publication_retention.py

Could you move these tests there, and group them together in a class as those tests are? The file name should probably be changed but for now I'd rather prioritize keeping the tests together.

Maybe rename the file to test_caching_and_retention.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved them into a TestCacheInvalidationOnRepositoryVersionCreate class in test_caching_and_retention.py (renamed from test_publication_retention.py).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dralley

dralley commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

The patch looks good to me, just small requested test changes.

@dralley

dralley commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

@aevnsvi ^

Repository.new_version() cleared the cache of the distributions serving
the repository when the new version was started. Until that version is
complete, those distributions are still served from the previous one, so
a response computed in that window was put back into the cache and served
until it expired (ten minutes by default), although the new version had
been created in the meantime.

Clear the cache once the new version is complete and committed instead.
A version that changes nothing is discarded and no longer clears the
cache.

Closes: pulp#8246
@aevnsvi
aevnsvi force-pushed the pr/8246-cache-invalidation-order branch from af41170 to 4279fa4 Compare October 21, 2026 18:56
@dralley
dralley merged commit 55e78bb into pulp:main Oct 21, 2026
25 of 27 checks passed
@patchback

patchback Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Backport to 3.85: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 55e78bb on top of patchback/backports/3.85/55e78bb483687549ca3b94cae453018331d49b36/pr-8247

Backporting merged PR #8247 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    git remote add upstream https://github.com/pulp/pulpcore.git
    
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    git fetch upstream
    git checkout -b patchback/backports/3.85/55e78bb483687549ca3b94cae453018331d49b36/pr-8247 upstream/3.85
    
  4. Now, cherry-pick PR Invalidate the content cache once a new repository version is complete #8247 contents into that branch:
    git cherry-pick -x 55e78bb483687549ca3b94cae453018331d49b36
    
    If it'll yell at you with something like fatal: Commit 55e78bb483687549ca3b94cae453018331d49b36 is a merge but no -m option was given., add -m 1 as follows instead:
    git cherry-pick -m1 -x 55e78bb483687549ca3b94cae453018331d49b36
    
  5. At this point, you'll encounter some merge conflicts. You must
    resolve them in order to preserve the patch from PR Invalidate the content cache once a new repository version is complete #8247 as close to the
    original as possible.
  6. Once conflicts are resolved and git added, run:
    git cherry-pick --continue
    
  7. Push this branch to your fork on GitHub:
    git push origin patchback/backports/3.85/55e78bb483687549ca3b94cae453018331d49b36/pr-8247
    
  8. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback

patchback Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Backport to 3.123: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.123/55e78bb483687549ca3b94cae453018331d49b36/pr-8247

Backported as #8251

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback

patchback Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Backport to 3.118: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.118/55e78bb483687549ca3b94cae453018331d49b36/pr-8247

Backported as #8252

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback

patchback Bot commented Oct 21, 2026

Copy link
Copy Markdown

Beep beep boop!
🤖 Hi, I'm @patchback — your friendly neighborhood robot!

Somebody's just asked me to create a backport of this pull request
into the 3.105 branch. So in this comment I report that
I'm on it!

Please, expect to see further updates regarding my progress in updates
to this comment. Stay tuned!

If you think I'm experiencing problems, ping @webknjaz — my creator.

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback

patchback Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Backport to 3.105: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 55e78bb on top of patchback/backports/3.105/55e78bb483687549ca3b94cae453018331d49b36/pr-8247

Backporting merged PR #8247 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    git remote add upstream https://github.com/pulp/pulpcore.git
    
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    git fetch upstream
    git checkout -b patchback/backports/3.105/55e78bb483687549ca3b94cae453018331d49b36/pr-8247 upstream/3.105
    
  4. Now, cherry-pick PR Invalidate the content cache once a new repository version is complete #8247 contents into that branch:
    git cherry-pick -x 55e78bb483687549ca3b94cae453018331d49b36
    
    If it'll yell at you with something like fatal: Commit 55e78bb483687549ca3b94cae453018331d49b36 is a merge but no -m option was given., add -m 1 as follows instead:
    git cherry-pick -m1 -x 55e78bb483687549ca3b94cae453018331d49b36
    
  5. At this point, you'll encounter some merge conflicts. You must
    resolve them in order to preserve the patch from PR Invalidate the content cache once a new repository version is complete #8247 as close to the
    original as possible.
  6. Once conflicts are resolved and git added, run:
    git cherry-pick --continue
    
  7. Push this branch to your fork on GitHub:
    git push origin patchback/backports/3.105/55e78bb483687549ca3b94cae453018331d49b36/pr-8247
    
  8. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Content cache is cleared when a repository version is started, so concurrent requests re-cache the previous version

3 participants