Dependencies

- Added TDB::gc code to remove dangling dependencies.
This commit is contained in:
Paul Beckingham 2010-08-04 00:43:38 -04:00
parent cade134f40
commit b050d67ba9
3 changed files with 38 additions and 9 deletions

View file

@ -569,6 +569,7 @@ int TDB::commit ()
// Scans the pending tasks for any that are completed or deleted, and if so,
// moves them to the completed.data file. Returns a count of tasks moved.
// Now reverts expired waiting tasks to pending.
// Now cleans up dangling dependencies.
int TDB::gc ()
{
Timer t ("TDB::gc");
@ -589,6 +590,27 @@ int TDB::gc ()
std::vector <Task> ignore;
loadPending (ignore, filter);
// Search for dangling dependencies. These are dependencies whose uuid cannot
// be converted to an id by TDB.
std::vector <std::string> deps;
foreach (task, mPending)
{
if (task->has ("depends"))
{
deps.clear ();
task->getDependencies (deps);
foreach (dep, deps)
if (id (*dep) == 0)
{
task->removeDependency (*dep);
context.debug ("GC: Removed dangling dependency "
+ *dep
+ " from "
+ task->get ("uuid"));
}
}
}
// Now move completed and deleted tasks from the pending list to the
// completed list. Isn't garbage collection easy?
std::vector <Task> still_pending;

View file

@ -495,16 +495,8 @@ void Task::addDependency (int id)
}
////////////////////////////////////////////////////////////////////////////////
void Task::removeDependency (int id)
void Task::removeDependency (const std::string& uuid)
{
std::string uuid = context.tdb.uuid (id);
if (uuid == "")
{
std::stringstream s;
s << "Could not find a UUID for id " << id << ".";
throw s.str ();
}
std::vector <std::string> deps;
split (deps, get ("depends"), ',');
@ -519,6 +511,20 @@ void Task::removeDependency (int id)
}
}
////////////////////////////////////////////////////////////////////////////////
void Task::removeDependency (int id)
{
std::string uuid = context.tdb.uuid (id);
if (uuid != "")
removeDependency (uuid);
else
{
std::stringstream s;
s << "Could not find a UUID for id " << id << ".";
throw s.str ();
}
}
////////////////////////////////////////////////////////////////////////////////
void Task::getDependencies (std::vector <int>& all) const
{

View file

@ -75,6 +75,7 @@ public:
void addDependency (int);
void removeDependency (int);
void removeDependency (const std::string&);
void getDependencies (std::vector <int>&) const;
void getDependencies (std::vector <std::string>&) const;