From f870bd44522d195199987b0e073d495eed060495 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 5 Feb 2025 20:11:35 +0100 Subject: solver3: Defer version selection where possible If a dependency can be satisfied by all versions of a package, add the package to the clause instead of the version object. This works only if there are no providers for the package: Providers are quite hard to enumerate over and make sure that all versions of a package satisfy the provider dependency. Implement arbitrary selection between packages and versions for the CompareProviders class: We pick the best version for each package and then pit them against each other. --- doc/examples/configure-index | 1 + 1 file changed, 1 insertion(+) (limited to 'doc') diff --git a/doc/examples/configure-index b/doc/examples/configure-index index ba51a9881..1573eaa8b 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -698,6 +698,7 @@ apt::list-cleanup ""; apt::authentication::trustcdrom ""; apt::solver::strict-pinning ""; apt::solver::enqueue-common-dependencies ""; +apt::solver::defer-version-selection ""; apt::solver::upgrade ""; apt::solver::remove ""; apt::solver::removemanual ""; -- cgit v1.2.3-70-g09d2 From a9587b39ea6776b1d1324288786176102f65cee5 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 10 Feb 2025 19:56:16 +0100 Subject: solver3: Implement a timeout, default 10s A SAT solver can run more or less forever, but that's not a good user experience. --- apt-pkg/solver3.cc | 8 +++++++- apt-pkg/solver3.h | 5 +++++ doc/examples/configure-index | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index b4a69d844..d363cdee7 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -32,8 +32,9 @@ #include #include -#include #include +#include +#include #include // FIXME: Helpers stolen from DepCache, please give them back. @@ -740,6 +741,10 @@ bool APT::Solver::Pop() for (std::string msg; _error->PopMessage(msg);) std::cerr << "Branch failed: " << msg << std::endl; + time_t now = time(nullptr); + if (now - startTime >= Timeout) + return _error->Error("Solver timed out."); + _error->RevertToStack(); assert(choices.back() < solved.size()); @@ -834,6 +839,7 @@ void APT::Solver::RescoreWorkIfNeeded() bool APT::Solver::Solve() { + startTime = time(nullptr); while (true) { while (not Propagate()) diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h index 34da03ea0..da75179d5 100644 --- a/apt-pkg/solver3.h +++ b/apt-pkg/solver3.h @@ -213,6 +213,9 @@ class Solver // This is an index into the solved vector. std::vector choices{}; + // \brief The time we called Solve() + time_t startTime; + /// Various configuration options // \brief Debug level int debug{_config->FindI("Debug::APT::Solver")}; @@ -232,6 +235,8 @@ class Solver bool FixPolicyBroken{_config->FindB("APT::Get::Fix-Policy-Broken")}; // \brief If set, we use strict pinning. bool DeferVersionSelection{_config->FindB("APT::Solver::Defer-Version-Selection", true)}; + // \brief If set, we use strict pinning. + int Timeout{_config->FindI("APT::Solver::Timeout", 10)}; // \brief Discover a variable, translating the underlying dependencies to the SAT presentation // diff --git a/doc/examples/configure-index b/doc/examples/configure-index index 1573eaa8b..8476d733a 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -703,6 +703,7 @@ apt::solver::upgrade ""; apt::solver::remove ""; apt::solver::removemanual ""; apt::solver::install ""; +apt::solver::timeout ""; apt::keep-downloaded-packages ""; apt::solver ""; apt::planner ""; -- cgit v1.2.3-70-g09d2