diff options
author | Florian Klink <flokli@flokli.de> | 2023-06-09T07·28+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-06-12T10·15+0000 |
commit | 6f85dbfc06c4fa96deb968cfeb7e98ba36e95043 (patch) | |
tree | 9dd303d69ae3de19bfe2244d8547c639e4e95995 /tvix/store/src/proto | |
parent | 8d05c0ceaa9bddb7fdaab436730f093eb16374a2 (diff) |
feat(tvix/store/pathinfosvc): add calculate_nar method r/6271
Putting this in the PathInfoService trait makes much more sense, we can have direct control over where/how to cache the results in the implementation. This now requires each PathInfoService to hold pointers to BlobService and DirectoryService. Change-Id: I4faae780d43eae4beeb57bd5e190e6d1a5d3314e Reviewed-on: https://cl.tvl.fyi/c/depot/+/8724 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/store/src/proto')
-rw-r--r-- | tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs | 36 | ||||
-rw-r--r-- | tvix/store/src/proto/tests/grpc_pathinfoservice.rs | 12 |
2 files changed, 17 insertions, 31 deletions
diff --git a/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs b/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs index c070b883fa16..645f4aa60556 100644 --- a/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs +++ b/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs @@ -1,36 +1,24 @@ -use crate::blobservice::BlobService; -use crate::directoryservice::DirectoryService; -use crate::nar::{calculate_size_and_sha256, RenderError}; +use crate::nar::RenderError; use crate::pathinfoservice::PathInfoService; use crate::proto; use tonic::{async_trait, Request, Response, Result, Status}; use tracing::{instrument, warn}; -pub struct GRPCPathInfoServiceWrapper<PS: PathInfoService, DS: DirectoryService> { +pub struct GRPCPathInfoServiceWrapper<PS: PathInfoService> { path_info_service: PS, - blob_service: Box<dyn BlobService>, - directory_service: DS, } -impl<PS: PathInfoService, DS: DirectoryService> GRPCPathInfoServiceWrapper<PS, DS> { - pub fn new( - path_info_service: PS, - blob_service: Box<dyn BlobService>, - directory_service: DS, - ) -> Self { +impl<PS: PathInfoService> From<PS> for GRPCPathInfoServiceWrapper<PS> { + fn from(value: PS) -> Self { Self { - path_info_service, - blob_service, - directory_service, + path_info_service: value, } } } #[async_trait] -impl< - PS: PathInfoService + Send + Sync + 'static, - DS: DirectoryService + Send + Sync + Clone + 'static, - > proto::path_info_service_server::PathInfoService for GRPCPathInfoServiceWrapper<PS, DS> +impl<PS: PathInfoService + Send + Sync + 'static> proto::path_info_service_server::PathInfoService + for GRPCPathInfoServiceWrapper<PS> { #[instrument(skip(self))] async fn get( @@ -78,12 +66,10 @@ impl< match request.into_inner().node { None => Err(Status::invalid_argument("no root node sent")), Some(root_node) => { - let (nar_size, nar_sha256) = calculate_size_and_sha256( - &root_node, - &self.blob_service, - self.directory_service.clone(), - ) - .expect("error during nar calculation"); // TODO: handle error + let (nar_size, nar_sha256) = self + .path_info_service + .calculate_nar(&root_node) + .expect("error during nar calculation"); // TODO: handle error Ok(Response::new(proto::CalculateNarResponse { nar_size, diff --git a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs index dbcdc5ced056..8b7038ccbc35 100644 --- a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs +++ b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs @@ -5,7 +5,9 @@ use crate::proto::GRPCPathInfoServiceWrapper; use crate::proto::PathInfo; use crate::proto::{GetPathInfoRequest, Node, SymlinkNode}; use crate::tests::fixtures::DUMMY_OUTPUT_HASH; -use crate::tests::utils::{gen_blob_service, gen_directory_service, gen_pathinfo_service}; +use crate::tests::utils::gen_blob_service; +use crate::tests::utils::gen_directory_service; +use crate::tests::utils::gen_pathinfo_service; use tonic::Request; /// generates a GRPCPathInfoService out of blob, directory and pathinfo services. @@ -14,11 +16,9 @@ use tonic::Request; /// It uses the NonCachingNARCalculationService NARCalculationService to /// calculate NARs. fn gen_grpc_service() -> impl GRPCPathInfoService { - GRPCPathInfoServiceWrapper::new( - gen_pathinfo_service(), - gen_blob_service(), - gen_directory_service(), - ) + let blob_service = gen_blob_service(); + let directory_service = gen_directory_service(); + GRPCPathInfoServiceWrapper::from(gen_pathinfo_service(blob_service, directory_service)) } /// Trying to get a non-existent PathInfo should return a not found error. |