Added possibility to specify garbage collection levels for store paths; so packages can share intermediate results of compilation and GC will collect it automatically while never touching tarballs, for example.

This commit is contained in:
Michael Raskin 2007-11-15 03:47:12 +00:00
parent 5b74a59570
commit 6fc60e2060
2 changed files with 21 additions and 4 deletions

View file

@ -4,6 +4,7 @@
#include "local-store.hh" #include "local-store.hh"
#include "db.hh" #include "db.hh"
#include "util.hh" #include "util.hh"
#include "gc.hh"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -445,6 +446,8 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
queryBoolSetting("gc-keep-outputs", false); queryBoolSetting("gc-keep-outputs", false);
bool gcKeepDerivations = bool gcKeepDerivations =
queryBoolSetting("gc-keep-derivations", true); queryBoolSetting("gc-keep-derivations", true);
unsigned int gcKeepOutputsThreshold =
queryIntSetting ("gc-keep-outputs-threshold", defaultGcLevel);
/* Acquire the global GC root. This prevents /* Acquire the global GC root. This prevents
a) New roots from being added. a) New roots from being added.
@ -496,10 +499,18 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
i != livePaths.end(); ++i) i != livePaths.end(); ++i)
if (isDerivation(*i)) { if (isDerivation(*i)) {
Derivation drv = derivationFromPath(*i); Derivation drv = derivationFromPath(*i);
for (DerivationOutputs::iterator j = drv.outputs.begin();
j != drv.outputs.end(); ++j) string gcLevelStr = drv.env["__gcLevel"];
if (store->isValidPath(j->second.path)) int gcLevel;
computeFSClosure(j->second.path, livePaths); if (!string2Int(gcLevelStr,gcLevel)) {
gcLevel = defaultGcLevel;
}
if (gcLevel >= gcKeepOutputsThreshold)
for (DerivationOutputs::iterator j = drv.outputs.begin();
j != drv.outputs.end(); ++j)
if (store->isValidPath(j->second.path))
computeFSClosure(j->second.path, livePaths);
} }
} }

6
src/libstore/gc.hh Normal file
View file

@ -0,0 +1,6 @@
#ifndef __GC_H_INCLUDED
#define __GC_H_INCLUDED
const unsigned int defaultGcLevel = 1000;
#endif //__GC_H_INCLUDED