feat: add leave host to dfdaemon (#263)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2024-02-08 12:34:33 +08:00 committed by GitHub
parent 3e7e029137
commit 223a70ca9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 7 deletions

8
Cargo.lock generated
View File

@ -587,9 +587,9 @@ dependencies = [
[[package]]
name = "dragonfly-api"
version = "2.0.92"
version = "2.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b54213518c67b593aefd69dfc045f707de736728514304961472ef47bf26b46"
checksum = "c0b576aa7bb14e56ae381a4c09ec1c4c65c013bac39069d52fa24aa500916614"
dependencies = [
"prost 0.11.9",
"prost-types 0.12.3",
@ -2928,9 +2928,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.35.1"
version = "1.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104"
checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931"
dependencies = [
"backtrace",
"bytes",

View File

@ -55,7 +55,7 @@ hostname = "^0.3"
local-ip-address = "0.5.3"
rocksdb = "0.21.0"
num_cpus = "1.0"
dragonfly-api = "2.0.92"
dragonfly-api = "2.0.93"
chrono = { version = "0.4.33", features = ["serde"] }
sysinfo = "0.29.6"
sha2 = "0.10"

View File

@ -27,7 +27,9 @@ use dragonfly_api::dfdaemon::v2::{
DeleteTaskRequest, DownloadTaskRequest, DownloadTaskResponse,
StatTaskRequest as DfdaemonStatTaskRequest, UploadTaskRequest,
};
use dragonfly_api::scheduler::v2::StatTaskRequest as SchedulerStatTaskRequest;
use dragonfly_api::scheduler::v2::{
LeaveHostRequest as SchedulerLeaveHostRequest, StatTaskRequest as SchedulerStatTaskRequest,
};
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
@ -336,7 +338,7 @@ impl DfdaemonDownload for DfdaemonDownloadServerHandler {
Ok(Response::new(task))
}
// delete_task tells the dfdaemon to delete the task.
// delete_task calls the dfdaemon to delete the task.
#[instrument(skip_all)]
async fn delete_task(
&self,
@ -345,6 +347,23 @@ impl DfdaemonDownload for DfdaemonDownloadServerHandler {
println!("delete_task: {:?}", request);
Err(Status::unimplemented("not implemented"))
}
// leave_host calls the scheduler to leave the host.
#[instrument(skip_all)]
async fn leave_host(&self, _: Request<()>) -> Result<Response<()>, Status> {
self.task
.scheduler_client
.leave_host(SchedulerLeaveHostRequest {
id: self.task.id_generator.host_id(),
})
.await
.map_err(|e| {
error!("leave host: {}", e);
Status::internal(e.to_string())
})?;
Ok(Response::new(()))
}
}
// DfdaemonDownloadClient is a wrapper of DfdaemonDownloadGRPCClient.