From 68e82d9aa089c7b8731fc7d1a31c60bb15eb2ab3 Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Fri, 18 Apr 2008 11:19:11 +0000 Subject: [PATCH] new call resolveQueue added --- zypp/Resolver.cc | 2 + zypp/Resolver.h | 25 +- zypp/solver/detail/Resolver.cc | 32 +-- zypp/solver/detail/Resolver.h | 4 + zypp/solver/detail/SATResolver.cc | 249 +++++++++++-------- zypp/solver/detail/SATResolver.h | 12 + zypp/solver/detail/SolverQueueItemInstall.cc | 2 +- 7 files changed, 202 insertions(+), 124 deletions(-) diff --git a/zypp/Resolver.cc b/zypp/Resolver.cc index 4c48bf0db..1235cac77 100644 --- a/zypp/Resolver.cc +++ b/zypp/Resolver.cc @@ -64,6 +64,8 @@ namespace zypp { return _pimpl->verifySystem(); } bool Resolver::resolvePool () { return _pimpl->resolvePool(); } + bool Resolver::resolveQueue (zypp::solver::detail::SolverQueueItemList & queue) + { return _pimpl->resolveQueue(queue); } void Resolver::undo() { _pimpl->undo(); } ResolverProblemList Resolver::problems () diff --git a/zypp/Resolver.h b/zypp/Resolver.h index b94ba91dc..3d829913d 100644 --- a/zypp/Resolver.h +++ b/zypp/Resolver.h @@ -21,6 +21,7 @@ #include "zypp/ResPool.h" #include "zypp/UpgradeStatistics.h" #include "zypp/solver/detail/Resolver.h" +#include "zypp/solver/detail/SolverQueueItem.h" #include "zypp/ProblemTypes.h" /////////////////////////////////////////////////////////////////// @@ -58,18 +59,30 @@ namespace zypp * * Try to execute all pending transactions (there may be more than * one!). - * The solver pays attention to the BEST packages only in order to - * come to a solution. - * If there has not been found a valid results all other branches - * (e.G. packages with older version numbers, worse architecture) - * will be regarded. + * The solver collects all transactions (install/delete resolvables) + * from the pool, generates task, solving it and writes the + * results back to pool * * Returns "true" on success (i.e., if there were no problems that * need user interaction) and "false" if there were problems. In * the latter case, use problems() and later applySolutions() * below. **/ - bool resolvePool (void); + bool resolvePool (void); + + + /** + * Resolve package dependencies: + * + * The solver works off the given queue and writes back the solution + * to pool. + * + * Returns "true" on success (i.e., if there were no problems that + * need user interaction) and "false" if there were problems. In + * the latter case, use problems() and later applySolutions() + * below. + **/ + bool resolveQueue (solver::detail::SolverQueueItemList & queue); /* * Undo solver changes done in resolvePool() diff --git a/zypp/solver/detail/Resolver.cc b/zypp/solver/detail/Resolver.cc index acd50e1f4..076b3a309 100644 --- a/zypp/solver/detail/Resolver.cc +++ b/zypp/solver/detail/Resolver.cc @@ -256,11 +256,9 @@ Resolver::undo(void) return; } - -bool -Resolver::resolvePool() +void +Resolver::solverInit() { - // Solving with the satsolver static bool poolDumped = false; MIL << "-------------- Calling SAT Solver -------------------" << endl; @@ -273,14 +271,7 @@ Resolver::resolvePool() testcase.createTestcase (*this, false, false); // write control file only } } -#if 0 - MIL << "------SAT-Pool------" << endl; - for (sat::Pool::SolvableIterator i = satPool.solvablesBegin(); - i != satPool.solvablesEnd(); i++ ) { - MIL << *i << " ID: " << i->id() << endl; - } - MIL << "------SAT-Pool end------" << endl; -#endif + _satResolver->setFixsystem(false); _satResolver->setAllowdowngrade(false); _satResolver->setAllowarchchange(false); @@ -310,10 +301,23 @@ Resolver::resolvePool() if (_verifying) _satResolver->setFixsystem(true); - - return _satResolver->resolvePool(_extra_requires, _extra_conflicts); } +bool +Resolver::resolvePool() +{ + solverInit(); + return _satResolver->resolvePool(_extra_requires, _extra_conflicts); +} + +bool +Resolver::resolveQueue(solver::detail::SolverQueueItemList & queue) +{ + solverInit(); + return _satResolver->resolveQueue(queue); +} + + /////////////////////////////////////////////////////////////////// // diff --git a/zypp/solver/detail/Resolver.h b/zypp/solver/detail/Resolver.h index c26646318..6423e6b06 100644 --- a/zypp/solver/detail/Resolver.h +++ b/zypp/solver/detail/Resolver.h @@ -35,6 +35,7 @@ #include "zypp/base/SerialNumber.h" #include "zypp/solver/detail/Types.h" +#include "zypp/solver/detail/SolverQueueItem.h" #include "zypp/ProblemTypes.h" #include "zypp/ResolverProblem.h" @@ -113,6 +114,8 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable { // (broken dependencies) will be deleted. void checkUnmaintainedItems (); + void solverInit(); + public: Resolver (const ResPool & pool); @@ -156,6 +159,7 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable { bool verifySystem (); bool resolvePool(); + bool resolveQueue(solver::detail::SolverQueueItemList & queue); bool doUpdate(); void doUpgrade( zypp::UpgradeStatistics & opt_stats_r ); diff --git a/zypp/solver/detail/SATResolver.cc b/zypp/solver/detail/SATResolver.cc index 5b05b0131..071010876 100644 --- a/zypp/solver/detail/SATResolver.cc +++ b/zypp/solver/detail/SATResolver.cc @@ -454,100 +454,9 @@ class SetValidate : public resfilter::PoolItemFilterFunctor } }; - bool -SATResolver::resolvePool(const CapabilitySet & requires_caps, - const CapabilitySet & conflict_caps) +SATResolver::solving() { - SATCollectTransact info (*this); - - MIL << "SATResolver::resolvePool()" << endl; - - if (_solv) { - // remove old stuff - solver_free(_solv); - _solv = NULL; - queue_free( &(_jobQueue) ); - } - - queue_init( &_jobQueue ); - _items_to_install.clear(); - _items_to_remove.clear(); - _items_to_lock.clear(); - _items_to_keep.clear(); - - invokeOnEach ( _pool.begin(), _pool.end(), - functor::functorRef(info) ); - - for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) { - PoolItem r = *iter; - - Id id = (*iter)->satSolvable().id(); - if (id == ID_NULL) { - ERR << "Install: " << *iter << " not found" << endl; - } - MIL << "Install " << *iter << " with the SAT-Pool ID: " << id << endl; - queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE ); - queue_push( &(_jobQueue), id ); - } - - for (PoolItemList::const_iterator iter = _items_to_update.begin(); iter != _items_to_update.end(); iter++) { - PoolItem r = *iter; - - Id id = (*iter)->satSolvable().id(); - if (id == ID_NULL) { - ERR << "Update explicit: " << *iter << " not found" << endl; - } - MIL << "Update explicit " << *iter << " with the SAT-Pool ID: " << id << endl; - queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_UPDATE ); - queue_push( &(_jobQueue), id ); - } - - for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) { - sat::detail::IdType ident( (*iter)->satSolvable().ident().id() ); - MIL << "Delete " << *iter << " with the string ID: " << ident << endl; - queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME ); - queue_push( &(_jobQueue), ident); - } - - for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) { - queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES ); - queue_push( &(_jobQueue), iter->id() ); - MIL << "Requires " << *iter << endl; - } - - for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) { - queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES); - queue_push( &(_jobQueue), iter->id() ); - MIL << "Conflicts " << *iter << endl; - } - - for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) { - sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() ); - if (iter->status().isInstalled()) { - MIL << "Lock installed item " << *iter << " with the string ID: " << ident << endl; - queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE ); - queue_push( &(_jobQueue), ident ); - } else { - MIL << "Lock NOT installed item " << *iter << " with the string ID: " << ident << endl; - queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE ); - queue_push( &(_jobQueue), ident ); - } - } - - for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) { - sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() ); - if (iter->status().isInstalled()) { - MIL << "Keep installed item " << *iter << " with the string ID: " << ident << endl; - queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK); - queue_push( &(_jobQueue), ident ); - } else { - MIL << "Keep NOT installed item " << *iter << " with the string ID: " << ident << endl; - queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK); - queue_push( &(_jobQueue), ident ); - } - } - _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() ); _solv->vendorCheckCb = &vendorCheck; _solv->fixsystem = _fixsystem; @@ -661,20 +570,17 @@ SATResolver::resolvePool(const CapabilitySet & requires_caps, _pool.end(), functor::not_c(resfilter::byKind()), // every solvable BUT packages functor::functorRef (infoValidate) ); - - // cleanup - solver_free(_solv); - _solv = NULL; - queue_free( &(_jobQueue) ); - MIL << "SATResolver::resolvePool() done" << endl; return true; } -bool SATResolver::doUpdate() +void +SATResolver::solverInit() { - MIL << "SATResolver::doUpdate()" << endl; + SATCollectTransact info (*this); + + MIL << "SATResolver::solverInit()" << endl; if (_solv) { // remove old stuff @@ -684,6 +590,145 @@ bool SATResolver::doUpdate() } queue_init( &_jobQueue ); + _items_to_install.clear(); + _items_to_remove.clear(); + _items_to_lock.clear(); + _items_to_keep.clear(); + + invokeOnEach ( _pool.begin(), _pool.end(), + functor::functorRef(info) ); +} + +void +SATResolver::solverEnd() +{ + // cleanup + solver_free(_solv); + _solv = NULL; + queue_free( &(_jobQueue) ); +} + + +bool +SATResolver::resolvePool(const CapabilitySet & requires_caps, + const CapabilitySet & conflict_caps) +{ + MIL << "SATResolver::resolvePool()" << endl; + + // initialize + solverInit(); + + for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) { + PoolItem r = *iter; + + Id id = (*iter)->satSolvable().id(); + if (id == ID_NULL) { + ERR << "Install: " << *iter << " not found" << endl; + } + MIL << "Install " << *iter << " with the SAT-Pool ID: " << id << endl; + queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE ); + queue_push( &(_jobQueue), id ); + } + + for (PoolItemList::const_iterator iter = _items_to_update.begin(); iter != _items_to_update.end(); iter++) { + PoolItem r = *iter; + + Id id = (*iter)->satSolvable().id(); + if (id == ID_NULL) { + ERR << "Update explicit: " << *iter << " not found" << endl; + } + MIL << "Update explicit " << *iter << " with the SAT-Pool ID: " << id << endl; + queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_UPDATE ); + queue_push( &(_jobQueue), id ); + } + + for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) { + sat::detail::IdType ident( (*iter)->satSolvable().ident().id() ); + MIL << "Delete " << *iter << " with the string ID: " << ident << endl; + queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME ); + queue_push( &(_jobQueue), ident); + } + + for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) { + queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES ); + queue_push( &(_jobQueue), iter->id() ); + MIL << "Requires " << *iter << endl; + } + + for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) { + queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES); + queue_push( &(_jobQueue), iter->id() ); + MIL << "Conflicts " << *iter << endl; + } + + for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) { + sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() ); + if (iter->status().isInstalled()) { + MIL << "Lock installed item " << *iter << " with the string ID: " << ident << endl; + queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE ); + queue_push( &(_jobQueue), ident ); + } else { + MIL << "Lock NOT installed item " << *iter << " with the string ID: " << ident << endl; + queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE ); + queue_push( &(_jobQueue), ident ); + } + } + + for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) { + sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() ); + if (iter->status().isInstalled()) { + MIL << "Keep installed item " << *iter << " with the string ID: " << ident << endl; + queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK); + queue_push( &(_jobQueue), ident ); + } else { + MIL << "Keep NOT installed item " << *iter << " with the string ID: " << ident << endl; + queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK); + queue_push( &(_jobQueue), ident ); + } + } + + // solving + bool ret = solving(); + // cleanup + if (ret) + solverEnd(); // remove solver only if no errors happend. Need it for solving problems + + MIL << "SATResolver::resolvePool() done. Ret:" << ret << endl; + return ret; +} + + +bool +SATResolver::resolveQueue(const SolverQueueItemList &requestQueue) +{ + MIL << "SATResolver::resolvQueue()" << endl; + + // initialize + solverInit(); + + // generate solver queue + for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) { + (*iter)->addRule(_jobQueue,_SATPool); + } + + // solving + bool ret = solving(); + + // cleanup + if (ret) + solverEnd(); // remove solver only if no errors happend. Need it for solving problems + + MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl; + return ret; +} + + +bool SATResolver::doUpdate() +{ + MIL << "SATResolver::doUpdate()" << endl; + + // initialize + solverInit(); _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() ); _solv->vendorCheckCb = &vendorCheck; @@ -746,9 +791,7 @@ bool SATResolver::doUpdate() } // cleanup - solver_free(_solv); - _solv = NULL; - queue_free( &(_jobQueue) ); + solverEnd(); MIL << "SATResolver::doUpdate() done" << endl; return true; diff --git a/zypp/solver/detail/SATResolver.h b/zypp/solver/detail/SATResolver.h index 562de140b..d6a31d204 100644 --- a/zypp/solver/detail/SATResolver.h +++ b/zypp/solver/detail/SATResolver.h @@ -35,6 +35,7 @@ #include "zypp/ResolverProblem.h" #include "zypp/ProblemSolution.h" #include "zypp/Capability.h" +#include "zypp/solver/detail/SolverQueueItem.h" extern "C" { #include "satsolver/solver.h" #include "satsolver/pool.h" @@ -86,6 +87,13 @@ class SATResolver : public base::ReferenceCounted, private base::NonCopyable { std::string SATprobleminfoString (Id problem, std::string &detail); void resetItemTransaction (PoolItem item); + // Create a SAT solver and reset solver selection in the pool (Collecting + void solverInit(); + // common solver run with the _jobQueue; Save results back to pool + bool solving(); + // cleanup solver + void solverEnd(); + public: SATResolver (const ResPool & pool, Pool *SATPool); @@ -100,8 +108,12 @@ class SATResolver : public base::ReferenceCounted, private base::NonCopyable { ResPool pool (void) const; void setPool (const ResPool & pool) { _pool = pool; } + // solver run with pool selected items bool resolvePool(const CapabilitySet & requires_caps, const CapabilitySet & conflict_caps); + // solver run with the given request queue + bool resolveQueue(const SolverQueueItemList &requestQueue); + // searching for new packages bool doUpdate(); ResolverProblemList problems (); diff --git a/zypp/solver/detail/SolverQueueItemInstall.cc b/zypp/solver/detail/SolverQueueItemInstall.cc index f90232769..de2366bc1 100644 --- a/zypp/solver/detail/SolverQueueItemInstall.cc +++ b/zypp/solver/detail/SolverQueueItemInstall.cc @@ -74,7 +74,7 @@ bool SolverQueueItemInstall::addRule (Queue & q, Pool *SATPool) queue_push( &(q), id); MIL << "Install " << _name << (_soft ? "(soft)" : "") - << " with SAT-Pooly: " << id << endl; + << " with SAT-PoolID: " << id << endl; return true; } -- 2.34.1