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

goal: Do not add lower versions to upgrade jobs #878

Closed
wants to merge 2 commits into from
Closed
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
36 changes: 32 additions & 4 deletions libdnf5/base/goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ void add_obsoletes_to_data(const libdnf5::rpm::PackageQuery & base_query, libdnf
data |= obsoletes_query;
}

/// Removes from the query available packages with versions lower than or equal
/// to the installed ones. Similar to filter_upgrades(), but retains also
/// installed packages and packages whose names are not installed.
/// The method is called during processing UPGRADE* actions to prune versions
/// available to the solver only to real upgrades. There are edge cases
/// where adding old versions to solver job cause problems.
/// See https://issues.redhat.com/browse/RHEL-1448 for details about such case.
static void remove_older_versions(libdnf5::rpm::PackageQuery & query) {
libdnf5::rpm::PackageQuery installed(query.get_base(), libdnf5::rpm::PackageQuery::ExcludeFlags::IGNORE_EXCLUDES);
installed.filter_installed();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very weak suggestion because it does not change the result.
What about to add additional filter - latest()? Installonly packages will be handled in the next query only once.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added. (although I did not measure impact on performance here).

installed.filter_latest_evr();

// Keep only packages from priority repositories. Otherwise libsolv may
// upgrade to higher version of package from non-priority repo.
// Previously we passed to libsolv all versions of package and it was libsolv's
// responsibility to select correct upgrade.
query.filter_priority();

libdnf5::rpm::PackageQuery to_remove(query);
to_remove.filter_available();
to_remove.filter_nevra(installed, libdnf5::sack::QueryCmp::LTE);

query.difference(to_remove);
}

} // namespace

Expand Down Expand Up @@ -509,6 +533,8 @@ GoalProblem Goal::Impl::add_specs_to_goal(base::Transaction & transaction) {
base, query, settings.advisory_filter.value(), cfg_main.get_obsoletes_option().get_value());
}

remove_older_versions(query);
j-mracek marked this conversation as resolved.
Show resolved Hide resolved

// Make the smallest possible upgrade
if (action == GoalAction::UPGRADE_ALL_MINIMAL) {
query.filter_earliest_evr();
Expand Down Expand Up @@ -1452,14 +1478,16 @@ GoalProblem Goal::Impl::add_up_down_distrosync_to_goal(
filter_candidates_for_advisory_upgrade(base, query, settings.advisory_filter.value(), obsoletes);
}

if (minimal) {
query.filter_earliest_evr();
}

switch (action) {
case GoalAction::UPGRADE_MINIMAL:
case GoalAction::UPGRADE:
query.filter_available();
remove_older_versions(query);

if (minimal) {
query.filter_earliest_evr();
}

// Given that we use libsolv's targeted transactions, we need to ensure that the transaction contains both
// the new targeted version and also the current installed version (for the upgraded package). This is
// because if it only contained the new version, libsolv would decide to reinstall the package even if it
Expand Down