feat(3p/nix): Implement FindRoots, CollectGarbage
Implement the RPC client and server handlers for the FindRoots and CollectGarbage RPC calls Change-Id: Ifa5d582c6a33bd1e7661ac2fc860505ef404dad0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1656 Tested-by: BuildkiteCI Reviewed-by: kanepyork <rikingcoding@gmail.com>
This commit is contained in:
parent
f9df9b4733
commit
ea488b5705
5 changed files with 117 additions and 3 deletions
|
|
@ -252,6 +252,61 @@ class WorkerServiceImpl final : public WorkerService::Service {
|
|||
__FUNCTION__);
|
||||
}
|
||||
|
||||
Status FindRoots(grpc::ServerContext*, const google::protobuf::Empty*,
|
||||
nix::proto::FindRootsResponse* response) override {
|
||||
return HandleExceptions(
|
||||
[&]() -> Status {
|
||||
auto roots = store_->findRoots(false);
|
||||
for (const auto& [target, links] : roots) {
|
||||
StorePaths link_paths;
|
||||
for (const auto& link : links) {
|
||||
link_paths.add_paths(link);
|
||||
}
|
||||
response->mutable_roots()->insert({target, link_paths});
|
||||
}
|
||||
|
||||
return Status::OK;
|
||||
},
|
||||
__FUNCTION__);
|
||||
}
|
||||
|
||||
Status CollectGarbage(grpc::ServerContext*,
|
||||
const proto::CollectGarbageRequest* request,
|
||||
proto::CollectGarbageResponse* response) override {
|
||||
return HandleExceptions(
|
||||
[&]() -> Status {
|
||||
GCOptions options;
|
||||
auto action = GCActionFromProto(request->action());
|
||||
if (!action.has_value()) {
|
||||
return Status(grpc::StatusCode::INVALID_ARGUMENT,
|
||||
"Invalid GC action");
|
||||
}
|
||||
|
||||
options.action = action.value();
|
||||
for (const auto& path : request->paths_to_delete()) {
|
||||
options.pathsToDelete.insert(path);
|
||||
}
|
||||
options.ignoreLiveness = request->ignore_liveness();
|
||||
options.maxFreed = request->max_freed();
|
||||
|
||||
if (options.ignoreLiveness) {
|
||||
return Status(grpc::StatusCode::INVALID_ARGUMENT,
|
||||
"you are not allowed to ignore liveness");
|
||||
}
|
||||
|
||||
GCResults results;
|
||||
store_->collectGarbage(options, results);
|
||||
|
||||
for (const auto& path : results.paths) {
|
||||
response->add_deleted_paths(path);
|
||||
}
|
||||
response->set_bytes_freed(results.bytesFreed);
|
||||
|
||||
return Status::OK;
|
||||
},
|
||||
__FUNCTION__);
|
||||
}
|
||||
|
||||
Status QuerySubstitutablePathInfos(
|
||||
grpc::ServerContext*, const StorePaths* request,
|
||||
nix::proto::SubstitutablePathInfos* response) override {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue