Skip to content
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

Remove the is_modular field from the Package model #3525

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/3524.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the is_modular flag from Packages - it's not a reliable source of information, and can be actively incorrect.
1 change: 0 additions & 1 deletion docs/workflows/upload.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ Package GET response (after task complete):
"fox.txt"
]
],
"is_modular": false,
"location_base": "",
"location_href": "fox-1.1-2.noarch.rpm",
"name": "fox",
Expand Down
13 changes: 2 additions & 11 deletions pulp_rpm/app/depsolving.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,9 @@ def _load_from_version(self, repo_version, as_target=False):
"pk"
)

nonmodular_rpms = models.Package.objects.filter(
pk__in=package_ids, is_modular=False
).values(*RPM_FIELDS)
packages = models.Package.objects.filter(pk__in=package_ids).values(*RPM_FIELDS)

for rpm in nonmodular_rpms.iterator(chunk_size=5000):
self._add_unit_to_solver(rpm_to_solvable, rpm, repo, libsolv_repo_name)

modular_rpms = models.Package.objects.filter(pk__in=package_ids, is_modular=True).values(
*RPM_FIELDS
)

dralley marked this conversation as resolved.
Show resolved Hide resolved
for rpm in modular_rpms.iterator(chunk_size=5000):
for rpm in packages.iterator(chunk_size=5000):
self._add_unit_to_solver(rpm_to_solvable, rpm, repo, libsolv_repo_name)

# Load modules into the solver
Expand Down
4 changes: 2 additions & 2 deletions pulp_rpm/app/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Package(Content):
rpm_header_end (BigInteger):
Last byte of the header
is_modular (Bool):
Flag to identify if the package is modular
DEPRECATED: Flag to identify if the package is modular
size_archive (BigInteger):
Size, in bytes, of the archive portion of the original package file
Expand Down Expand Up @@ -229,7 +229,7 @@ class Package(Content):
time_build = models.BigIntegerField(null=True)
time_file = models.BigIntegerField(null=True)

# not part of createrepo_c metadata
# not part of createrepo_c metadata - DEPRECATED
is_modular = models.BooleanField(default=False)

# createrepo_c treats 'nosrc' arch (opensuse specific use) as 'src' so it can seem that two
Expand Down
30 changes: 13 additions & 17 deletions pulp_rpm/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,25 +435,21 @@ def _apply_retention_policy(self, new_version):
), "Cannot apply retention policy to completed repository versions"

if self.retain_package_versions > 0:
# It would be more ideal if, instead of annotating with an age and filtering manually,
# we could use Django to filter the particular Package content we want to delete.
# Something like ".filter(F('age') > self.retain_package_versions)" would be better
# however this is not currently possible with Django. It would be possible with raw
# SQL but the repository version content membership subquery is currently
# django-managed and would be difficult to share.
#
# Instead we have to do the filtering manually.
nonmodular_packages = (
Package.objects.with_age()
.filter(
pk__in=new_version.content.filter(pulp_type=Package.get_pulp_type()),
is_modular=False, # don't want to filter out modular RPMs
)
.only("pk")
)
# This code is likely not as efficient as it could / should be, but it is heavily
# complicated by the lack of a reliable means to determine whether a package is
# modular or not via SQL
packages = new_version.content.filter(pulp_type=Package.get_pulp_type())
modules = new_version.content.filter(pulp_type=Modulemd.get_pulp_type())

modular_packages = set()
for module in Modulemd.objects.filter(pk__in=modules):
modular_packages.update(module.packages.all().values_list("pk", flat=True))

nonmodular_packages = set(packages.values_list("pk", flat=True)) - modular_packages
nonmodular_packages = Package.objects.filter(pk__in=nonmodular_packages)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pedro-psb @ipanova Do either of you see a way to make this more efficient without table changes?

Making the ModulemdPackage table explicit rather than implicit would probably allow us to reduce the number of queries. I'm unsure if it's worth it though.

Copy link
Member

Choose a reason for hiding this comment

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

I did some research to see if I could come up with something but no luck.
There is prefetch_related, but I couldn't figure if this could fit in here.

Also, ideas of caching the context of the last repover crossed my mind, but I'm not aware of a suitable method for doing so.


old_packages = []
for package in nonmodular_packages:
for package in nonmodular_packages.with_age().iterator().only("pk", "age"):
if package.age > self.retain_package_versions:
old_packages.append(package.pk)

Expand Down
6 changes: 0 additions & 6 deletions pulp_rpm/app/serializers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ class PackageSerializer(SingleArtifactContentUploadSerializer, ContentChecksumSe
help_text=_("Last byte of the header"),
read_only=True,
)
is_modular = serializers.BooleanField(
help_text=_("Flag to identify if the package is modular"),
required=False,
read_only=True,
)
dralley marked this conversation as resolved.
Show resolved Hide resolved

size_archive = serializers.IntegerField(
help_text=_("Size, in bytes, of the archive portion of the original package file"),
Expand Down Expand Up @@ -312,7 +307,6 @@ class Meta:
"rpm_vendor",
"rpm_header_start",
"rpm_header_end",
"is_modular",
"size_archive",
"size_installed",
"size_package",
Expand Down
1 change: 0 additions & 1 deletion pulp_rpm/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,6 @@ def verification_and_skip_callback(pkg):

# find if a package relates to a modulemd
if dc.content.nevra in self.nevra_to_module.keys():
dc.content.is_modular = True
for dc_modulemd in self.nevra_to_module[dc.content.nevra]:
dc.extra_data["modulemd_relation"].append(dc_modulemd)
dc_modulemd.extra_data["package_relation"].append(dc)
Expand Down
8 changes: 0 additions & 8 deletions pulp_rpm/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,10 +946,6 @@ def test_core_metadata(init_and_sync, rpm_package_api):
)
assert list(diff) == [], list(diff)

# assert no package is marked modular
for pkg in get_content(repository.to_dict())[RPM_PACKAGE_CONTENT_NAME]:
assert pkg["is_modular"] is False


@pytest.mark.parallel
def test_treeinfo_metadata(init_and_sync, rpm_content_distribution_trees_api):
Expand Down Expand Up @@ -1049,10 +1045,6 @@ def module_obsolete_key(m):
diff = dictdiffer.diff(m1, m2, ignore={"pulp_created", "pulp_last_updated", "pulp_href"})
assert list(diff) == [], list(diff)

# assert all package from modular repo is marked as modular
for pkg in get_content(repository.to_dict())[RPM_PACKAGE_CONTENT_NAME]:
assert pkg["is_modular"] is True


@pytest.mark.parallel
def test_additive_mode(init_and_sync):
Expand Down
1 change: 0 additions & 1 deletion pulp_rpm/tests/functional/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@
["dir", "/var/lib/", "complex"],
["ghost", "/var/log/", "complex.log"],
],
"is_modular": False,
"location_base": "",
"location_href": "complex-package-2.3.4-5.el8.x86_64.rpm",
"md5": None,
Expand Down
1 change: 0 additions & 1 deletion staging_docs/user/guides/02-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Package upload requires a valid RPM package.
"rpm_vendor": "",
"rpm_header_start": 280,
"rpm_header_end": 1697,
"is_modular": false,
"size_archive": 296,
"size_installed": 42,
"size_package": 1846,
Expand Down
Loading