libstore: asyncify Store::optimiseStore
Change-Id: I443fe4bddb0bec519ee36d55060e082ae66802cc
This commit is contained in:
@@ -811,7 +811,7 @@ static void opOptimise(AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
|
||||
if (!opArgs.empty() || !opFlags.empty())
|
||||
throw UsageError("no arguments expected");
|
||||
|
||||
store->optimiseStore();
|
||||
aio.blockOn(store->optimiseStore());
|
||||
}
|
||||
|
||||
/* Serve the nix store in a way usable by a restricted ssh user. */
|
||||
|
||||
@@ -843,7 +843,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref<Store> store
|
||||
|
||||
case WorkerProto::Op::OptimiseStore:
|
||||
logger->startWork();
|
||||
store->optimiseStore();
|
||||
aio.blockOn(store->optimiseStore());
|
||||
logger->stopWork();
|
||||
to << 1;
|
||||
break;
|
||||
|
||||
@@ -263,9 +263,9 @@ public:
|
||||
* Optimise the disk space usage of the Nix store by hard-linking
|
||||
* files with the same contents.
|
||||
*/
|
||||
void optimiseStore(OptimiseStats & stats);
|
||||
kj::Promise<Result<void>> optimiseStore(OptimiseStats & stats);
|
||||
|
||||
void optimiseStore() override;
|
||||
kj::Promise<Result<void>> optimiseStore() override;
|
||||
|
||||
/**
|
||||
* Optimise a single store path. Optionally, test the encountered
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "lix/libstore/local-store.hh"
|
||||
#include "lix/libstore/globals.hh"
|
||||
#include "lix/libutil/result.hh"
|
||||
#include "lix/libutil/signals.hh"
|
||||
#include "lix/libutil/strings.hh"
|
||||
|
||||
@@ -256,8 +257,8 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
|
||||
}
|
||||
|
||||
|
||||
void LocalStore::optimiseStore(OptimiseStats & stats)
|
||||
{
|
||||
kj::Promise<Result<void>> LocalStore::optimiseStore(OptimiseStats & stats)
|
||||
try {
|
||||
Activity act(*logger, actOptimiseStore);
|
||||
|
||||
auto paths = queryAllValidPaths();
|
||||
@@ -283,17 +284,23 @@ void LocalStore::optimiseStore(OptimiseStats & stats)
|
||||
done++;
|
||||
act.progress(done, paths.size());
|
||||
}
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
void LocalStore::optimiseStore()
|
||||
{
|
||||
kj::Promise<Result<void>> LocalStore::optimiseStore()
|
||||
try {
|
||||
OptimiseStats stats;
|
||||
|
||||
optimiseStore(stats);
|
||||
TRY_AWAIT(optimiseStore(stats));
|
||||
|
||||
printInfo("%s freed by hard-linking %d files",
|
||||
showBytes(stats.bytesFreed),
|
||||
stats.filesLinked);
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
void LocalStore::optimisePath(const Path & path, RepairFlag repair)
|
||||
|
||||
@@ -808,12 +808,15 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::optimiseStore()
|
||||
{
|
||||
kj::Promise<Result<void>> RemoteStore::optimiseStore()
|
||||
try {
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::OptimiseStore;
|
||||
conn.processStderr();
|
||||
readInt(conn->from);
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
|
||||
void collectGarbage(const GCOptions & options, GCResults & results) override;
|
||||
|
||||
void optimiseStore() override;
|
||||
kj::Promise<Result<void>> optimiseStore() override;
|
||||
|
||||
kj::Promise<Result<bool>> verifyStore(bool checkContents, RepairFlag repair) override;
|
||||
|
||||
|
||||
@@ -703,7 +703,7 @@ public:
|
||||
* Optimise the disk space usage of the Nix store by hard-linking files
|
||||
* with the same contents.
|
||||
*/
|
||||
virtual void optimiseStore() { };
|
||||
virtual kj::Promise<Result<void>> optimiseStore() { return {result::success()}; }
|
||||
|
||||
/**
|
||||
* Check the integrity of the Nix store.
|
||||
|
||||
@@ -23,7 +23,7 @@ struct CmdOptimiseStore : StoreCommand
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
store->optimiseStore();
|
||||
aio().blockOn(store->optimiseStore());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user