Eliminate reserveSpace flag

This commit is contained in:
Eelco Dolstra 2016-02-24 17:33:53 +01:00
parent 5a64e66268
commit 28e7e29abd
10 changed files with 33 additions and 37 deletions

View file

@ -608,6 +608,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
state.shouldDelete = options.action == GCOptions::gcDeleteDead || options.action == GCOptions::gcDeleteSpecific;
if (state.shouldDelete && pathExists(reservedPath))
deletePath(reservedPath);
/* Acquire the global GC root. This prevents
a) New roots from being added.
b) Processes from creating new temporary root files. */

View file

@ -216,8 +216,9 @@ void checkStoreNotSymlink()
}
LocalStore::LocalStore(bool reserveSpace)
: didSetSubstituterEnv(false)
LocalStore::LocalStore()
: reservedPath(settings.nixDBPath + "/reserved")
, didSetSubstituterEnv(false)
{
schemaPath = settings.nixDBPath + "/schema";
@ -276,8 +277,6 @@ LocalStore::LocalStore(bool reserveSpace)
needed, we reserve some dummy space that we can free just
before doing a garbage collection. */
try {
Path reservedPath = settings.nixDBPath + "/reserved";
if (reserveSpace) {
struct stat st;
if (stat(reservedPath.c_str(), &st) == -1 ||
st.st_size != settings.reservedSize)
@ -292,9 +291,6 @@ LocalStore::LocalStore(bool reserveSpace)
ftruncate(fd, settings.reservedSize);
}
}
}
else
deletePath(reservedPath);
} catch (SysError & e) { /* don't care about errors */
}

View file

@ -88,11 +88,13 @@ private:
Path linksDir;
Path reservedPath;
public:
/* Initialise the local store, upgrading the schema if
necessary. */
LocalStore(bool reserveSpace = true);
LocalStore();
~LocalStore();

View file

@ -49,7 +49,7 @@ RemoteStore::RemoteStore(size_t maxConnections)
}
ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace)
ref<RemoteStore::Connection> RemoteStore::openConnection()
{
auto conn = make_ref<Connection>();
@ -106,7 +106,7 @@ ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace)
}
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 11)
conn->to << reserveSpace;
conn->to << false;
conn->processStderr();
}

View file

@ -106,7 +106,7 @@ private:
ref<Pool<Connection>> connections;
ref<Connection> openConnection(bool reserveSpace = true);
ref<Connection> openConnection();
void setOptions(ref<Connection> conn);
};

View file

@ -320,7 +320,7 @@ void Store::exportPaths(const Paths & paths,
namespace nix {
ref<Store> openStoreAt(const std::string & uri, bool reserveSpace)
ref<Store> openStoreAt(const std::string & uri)
{
if (std::string(uri, 0, 7) == "file://") {
auto store = make_ref<LocalBinaryCacheStore>(std::shared_ptr<Store>(0),
@ -345,13 +345,13 @@ ref<Store> openStoreAt(const std::string & uri, bool reserveSpace)
return mode == mDaemon
? (ref<Store>) make_ref<RemoteStore>()
: (ref<Store>) make_ref<LocalStore>(reserveSpace);
: (ref<Store>) make_ref<LocalStore>();
}
ref<Store> openStore(bool reserveSpace)
ref<Store> openStore()
{
return openStoreAt(getEnv("NIX_REMOTE"), reserveSpace);
return openStoreAt(getEnv("NIX_REMOTE"));
}

View file

@ -432,16 +432,12 @@ void removeTempRoots();
If uri is empty, it defaults to direct or daemon depending on
whether the user has write access to the local Nix store/database.
The Boolean reserveSpace denotes whether some disk space should
be reserved to enable future garbage collector runs. It should be
set to true *unless* you're going to collect garbage.
*/
ref<Store> openStoreAt(const std::string & uri, bool reserveSpace = true);
set to true *unless* you're going to collect garbage. */
ref<Store> openStoreAt(const std::string & uri);
/* Open the store indicated by the NIX_REMOTE environment variable. */
ref<Store> openStore(bool reserveSpace = true);
ref<Store> openStore();
/* Display a set of paths in human-readable form (i.e., between quotes

View file

@ -82,7 +82,7 @@ int main(int argc, char * * argv)
// Run the actual garbage collector.
if (!dryRun) {
auto store = openStore(false);
auto store = openStore();
options.action = GCOptions::gcDeleteDead;
GCResults results;
PrintFreed freed(true, results);

View file

@ -562,9 +562,8 @@ static void processConnection(bool trusted)
if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from))
setAffinityTo(readInt(from));
bool reserveSpace = true;
if (GET_PROTOCOL_MINOR(clientVersion) >= 11)
reserveSpace = readInt(from) != 0;
readInt(from); // obsolete reserveSpace
/* Send startup error messages to the client. */
startWork();
@ -582,7 +581,7 @@ static void processConnection(bool trusted)
#endif
/* Open the store. */
auto store = make_ref<LocalStore>(reserveSpace);
auto store = make_ref<LocalStore>();
stopWork();
to.flush();

View file

@ -1131,7 +1131,7 @@ int main(int argc, char * * argv)
if (!op) throw UsageError("no operation specified");
if (op != opDump && op != opRestore) /* !!! hack */
store = openStore(op != opGC);
store = openStore();
op(opFlags, opArgs);
});