From 223a70ca9d19c585264a568bbd72d633ea06822c Mon Sep 17 00:00:00 2001 From: Gaius Date: Thu, 8 Feb 2024 12:34:33 +0800 Subject: [PATCH] feat: add leave host to dfdaemon (#263) Signed-off-by: Gaius --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- src/grpc/dfdaemon_download.rs | 23 +++++++++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77b380ca..9b064f13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index b719f135..76bbf11d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/grpc/dfdaemon_download.rs b/src/grpc/dfdaemon_download.rs index b5a7503f..4d0fa18b 100644 --- a/src/grpc/dfdaemon_download.rs +++ b/src/grpc/dfdaemon_download.rs @@ -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, 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.