Skip to content

fix(0152_alter_repositoryversion_content_ids): add a batch size to avoid timeout on large update - #8017

Open
bmx0r wants to merge 1 commit into
pulp:mainfrom
bmx0r:fix/migration152
Open

fix(0152_alter_repositoryversion_content_ids): add a batch size to avoid timeout on large update#8017
bmx0r wants to merge 1 commit into
pulp:mainfrom
bmx0r:fix/migration152

Conversation

@bmx0r

@bmx0r bmx0r commented Aug 27, 2026

Copy link
Copy Markdown

While trying to upgrade pulp this migration was killed after 10min, even after trying to tune db keepalives* parameters
We are using an internal dbaas service so we do not have full access to the Database so this was the best solution maybe this could be integrated into guidelines for future migration script

Assisted By: Claude Opus 4.8

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • Follows the Pulp policy on AI Usage

…oid timeout on large update

While trying to upgrade pulp this migration was killed after 10min, even after trying to tune
db keepalives* parameters
We are using an internal dbaas service so we do not have full access to the Database so this was the best solution
maybe this could be integrated into guidelines for future migration script

Assisted By: Claude Opus 4.8
@mdellweg

Copy link
Copy Markdown
Member

For this specific migration we have a solution in place, where you can do the change beforehand to make the actual migration basically no-op.

Classic RT*M:

https://pulpproject.org/pulpcore/docs/admin/guides/data-repair/?h=content_id#repair-7465-populate-missing-
repository-version-caches

Here it was introduced as a management command:
https://pulpproject.org/pulpcore/changes/?h=datarepair#3.106.0-rest-api-bugfix

The one thing I would think is missing here is a hint in the migration to maybe running this command in case the migration failed.

@bmx0r

bmx0r commented Aug 27, 2026

Copy link
Copy Markdown
Author

@mdellweg we went from 3.76.1 → 3.116.0 and therefore we hadnt this endpoint available yet...
best practice for upgrade path are not always clear to me for pulp in general, maybe i was doing something wrong
so when we realize this we were already halfway, so we had to move forward as we were in the middle of the upgrade

Also I kinda expect that it run more or less the same kind of code resulting in the same kind of long transaction (I havent checked)

so even if I totally agree there was something already this MR was more to give the idea to allways add batch mode to future migration of that kind :)

about adding a hint, the migration was blocked so all changeset after 152 where not apply so we were probably not in a situation where we want the app to start...
Cheers
Mike

@mdellweg

Copy link
Copy Markdown
Member

So the batching may make the operation faster, but i think it does not necessarily solve the issue completely. OTOH batching it up may further the chance to hit the 65536-parameter limit of a Postgres operation (not so sure about that one, but there are definitely other resource constraints involved.). OTOH, the whole "transform the rest of the repository-versions before changing the field definition" really needs to go into one transaction (as these migrations usually do). As long as we cannot guarantee the runtime below the timeout, we are kind of stuck. And the sadest part is these errors only turn up in the actual production environment. On the small test boxes we will never run into that timeout.

In general, yes it's a good idea to keep migrations performant, and we have had similar issues before. The specifics with this one are (as you already noted with the small batchsizes) it is impossible to predict what the right batch is.

@bmx0r

bmx0r commented Aug 28, 2026

Copy link
Copy Markdown
Author

Hi,
First of all i want to thank you and all the pulp community, wheter it is on forum or github there is always someone to answer and that is really appreciated :)

Luckilly, I experience this on my "small" sandbox, so I will need to reproduce my workaroud in my production soon
for the record :
SB
public | core_repositorycontent | table | core_pulp_adm | permanent | 389 MB |
public | core_repositoryversion | table | core_pulp_adm | permanent | 1767 MB |
core_pulp=> select count() from core_repositorycontent; --> 2988832
core_pulp=> select count(
) from core_repositoryversion; --> 6742
PR
public | core_repositorycontent | table | core_pulp_adm | permanent | 1096 MB |
public | core_repositoryversion | table | core_pulp_adm | permanent | 1104 kb |
core_pulp=> select count() from core_repositorycontent; -->8207555
core_pulp=> select count(
) from core_repositoryversion; --> 10496

about the sizing of the table or the number of version per repo: could it be an idea to add it to https://analytics.pulpproject.org/ ? maybe that would give data to improve testing ar dev. guidelines in the future

This situation also lead me to this: https://pulpproject.org/pulpcore/docs/user/guides/update-repo-retention/ (yes I read sometimes the docs ;) ) which i believe is the real root cause of my problem.
In our env by default all repo have been created without any --retain-repo-versions as we use a simple workflow where we promote from Sandbox/preprod/prod that run over 2 weeks chances are that I dont need to keep all the repo versions, so i will dig that part to free the database and the upgrade burden ;)

again some data if it can help :) (The totals below don't match the raw core_repositoryversion counts because I filtered to a subset of repos via the label selector )

for i in $(pulp rpm repository list --label-select xxxx=xxxxxx --field name | jq -r .[].name); do echo $i;pulp rpm repository version list --repository "$i" --limit 10000| jq length; done

RepositoryVersion counts Sandbox

Repository Versions
MR-el-8-x86_64-epel 1418
MR-rhel-8-x86_64-appstream_os 633
MR-el-7-x86_64-epel 578
MR-rhel-8-x86_64-codeready_builder_os 496
MR-rhel-8-x86_64-baseos_os 405
MR-rhel-8-x86_64-baseos_debug-rpms 303
MR-centos-7-x86_64-updates 270
MR-rhel-10-x86_64-baseos_os 142
MR-centos-7-x86_64-els 124
MR-rhel-8-x86_64-highavailability_os 70
MR-el-7-x86_64-puppet6 23
MR-el-10-x86_64-openvox8 22
MR-el-9-x86_64-openvox8 22
MR-rhel-8-x86_64-baseos_kickstart 12
MR-centos-8-x86_64-highavailability_os 4
MR-centos-8-x86_64-powertools_os 4
MR-centos-8-x86_64-baseos_os 4
MR-centos-8-x86_64-appstream_os 4
MR-centos-7-x86_64-os 3
MR-centos-7-x86_64-extras 2
Total 4539

RepositoryVersion counts — prod

Repository Versions
MR-el-8-x86_64-epel 1527
MR-el-9-x86_64-epel 1037
MR-el-7-x86_64-epel 819
MR-rhel-8-x86_64-appstream_os 748
MR-rhel-9-x86_64-appstream_os 636
MR-rhel-8-x86_64-baseos_os 558
MR-rhel-8-x86_64-codeready_builder_os 530
MR-rhel-9-x86_64-codeready_builder_os 457
MR-rhel-9-x86_64-baseos_os 457
MR-rhel-9-x86_64-baseos_debug-rpms 371
MR-el-10-x86_64-epel 348
MR-rhel-8-x86_64-baseos_debug-rpms 334
MR-centos-7-x86_64-updates 298
MR-rhel-7-x86-64-els 212
MR-rhel-10-x86_64-appstream_os 210
MR-rhel-7-x86_64-os 202
MR-rhel-7-x86_64-optional 187
MR-rhel-7-x86_64-highavailability 184
MR-rhel-7-x86-64-elsoptional 175
MR-rhel-10-x86_64-baseos_os 154
MR-rhel-10-x86_64-codeready_builder 151
MR-centos-7-x86_64-els 135
MR-rhel-7-x86_64-rhscl 115
MR-rhel-8-x86_64-highavailability_os 70
MR-el-7-x86_64-jbeap_7.4_os 58
MR-el-8-x86_64-puppet7 55
MR-el-7-x86_64-puppet7 55
MR-rhel-7-x86_64-extras 52
MR-rhel-9-x86_64-highavailability_os 45
MR-rhel-7-x86_64-dotnet 37
MR-el-9-x86_64-puppet7 32
MR-el-8-x86_64-puppet6 24
MR-el-7-x86_64-puppet6 24
MR-el-10-x86_64-openvox8 22
MR-rhel-7-x86_64-supplementary 22
MR-rhel-9-x86_64-baseos_kickstart 10
MR-rhel-9-x86_64-appstream_kickstart 10
MR-rhel-8-x86_64-appstream_kickstart 10
MR-rhel-8-x86_64-baseos_kickstart 9
MR-el-9-x86_64-puppet8 6
MR-el-8-x86_64-puppet8 6
MR-el-7-x86_64-puppet8 6
MR-rhel-10-x86_64-baseos_kickstart 4
MR-rhel-7-x86_64-kickstart 4
MR-rhel-10-x86_64-appstream_kickstart 3
MR-rhel-7-x86_64-gluster3client 3
MR-centos-8-x86_64-appstream_os 3
MR-centos-7-x86_64-os 3
MR-centos-8-x86_64-baseos_os 3
MR-centos-8-x86_64-powertools_os 3
MR-centos-8-x86_64-highavailability_os 3
MR-el-7-x86_64-pg96 2
MR-el-9-x86_64-puppet6 2
MR-rhel-8-x86_64-gluster3client_os 2
MR-centos-7-x86_64-extras 2
Total 10435

plotwist: applying retain_repo_versions synchronously deletes the excess versions inline, which blows the 5s immediate-task limit

❯ pulp rpm repository update  --name MR-rhel-8-x86_64-baseos_os  --retain-repo-versions  50
Started background task /pulp/api/v3/tasks/01a047e9-7f6d-76c3-bc85-e3f31594cfb4/
Error: Task /pulp/api/v3/tasks/01a047e9-7f6d-76c3-bc85-e3f31594cfb4/ failed: '[PLP0024] Immediate task 01a047e9-7f6d-76c3-bc85-e3f31594cfb4 (type: pulpcore.app.tasks.base.ageneral_update) timed out after 5 seconds.'

I can do a loop and reduce it bit by bit, yet while i found this issue maybe this is a task that is a good candidate to be moved to deffered ( I saw TASK_PREFER_DEFER but it seems to be a server side task)

That is a lot of thinks/thought, if some of it is usefull and you want me to open dedicated issues feel free to shoot, I'll be happy to do it if it can help

Cheers
Mike

@dralley

dralley commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Yeah, there is a workaround to disable the "immediate" running of tasks (https://pulpproject.org/pulpcore/docs/admin/reference/settings/#task_prefer_defer) but it would be a good idea to remove the behavior entirely for large repo version deletes. You're not the first to run into this.

#7897

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.

3 participants