about summary refs log tree commit diff
path: root/tvix/store/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-06-12T13·04+0300
committerflokli <flokli@flokli.de>2023-06-12T13·27+0000
commitb5e37869e6ddddf0575bdc98e0f4cc05753f0fc0 (patch)
tree92aeb382accb472ab935ec1f097c0dd6a547e27c /tvix/store/src
parent64a4f6185c5dcd96ee57978963324ea50f4dd6f7 (diff)
refactor(tvix/store/pathinfosvc): use Arc<dyn …> r/6279
This removes the use of generics, like previously done with Blob and
Directory services.

Change-Id: I7cc8bd1439b026c88e80c11e38aafc63c74e5e84
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8751
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/store/src')
-rw-r--r--tvix/store/src/bin/tvix-store.rs9
-rw-r--r--tvix/store/src/fuse/mod.rs10
-rw-r--r--tvix/store/src/pathinfoservice/mod.rs2
-rw-r--r--tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs13
-rw-r--r--tvix/store/src/proto/tests/grpc_pathinfoservice.rs8
-rw-r--r--tvix/store/src/store_io.rs10
-rw-r--r--tvix/store/src/tests/utils.rs4
7 files changed, 30 insertions, 26 deletions
diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs
index ae72559d3943..b95f408a55b6 100644
--- a/tvix/store/src/bin/tvix-store.rs
+++ b/tvix/store/src/bin/tvix-store.rs
@@ -13,6 +13,7 @@ use tvix_store::directoryservice::DirectoryService;
 use tvix_store::directoryservice::GRPCDirectoryService;
 use tvix_store::directoryservice::SledDirectoryService;
 use tvix_store::pathinfoservice::GRPCPathInfoService;
+use tvix_store::pathinfoservice::PathInfoService;
 use tvix_store::pathinfoservice::SledPathInfoService;
 use tvix_store::proto::blob_service_client::BlobServiceClient;
 use tvix_store::proto::blob_service_server::BlobServiceServer;
@@ -104,11 +105,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
                 Arc::new(SledBlobService::new("blobs.sled".into())?);
             let directory_service: Arc<dyn DirectoryService> =
                 Arc::new(SledDirectoryService::new("directories.sled".into())?);
-            let path_info_service = SledPathInfoService::new(
+            let path_info_service: Arc<dyn PathInfoService> = Arc::new(SledPathInfoService::new(
                 "pathinfo.sled".into(),
                 blob_service.clone(),
                 directory_service.clone(),
-            )?;
+            )?);
 
             let listen_address = listen_address
                 .unwrap_or_else(|| "[::]:8000".to_string())
@@ -156,7 +157,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
             let io = Arc::new(TvixStoreIO::new(
                 Arc::new(blob_service),
                 Arc::new(directory_service),
-                path_info_service,
+                Arc::new(path_info_service),
             ));
 
             let tasks = paths
@@ -193,7 +194,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
                 let f = FUSE::new(
                     Arc::new(blob_service),
                     Arc::new(directory_service),
-                    path_info_service,
+                    Arc::new(path_info_service),
                 );
                 fuser::mount2(f, &dest, &[])
             })
diff --git a/tvix/store/src/fuse/mod.rs b/tvix/store/src/fuse/mod.rs
index d28e2b309c43..7206cf3076d0 100644
--- a/tvix/store/src/fuse/mod.rs
+++ b/tvix/store/src/fuse/mod.rs
@@ -3,17 +3,17 @@ use crate::{
 };
 use std::sync::Arc;
 
-pub struct FUSE<PS: PathInfoService> {
+pub struct FUSE {
     blob_service: Arc<dyn BlobService>,
     directory_service: Arc<dyn DirectoryService>,
-    path_info_service: PS,
+    path_info_service: Arc<dyn PathInfoService>,
 }
 
-impl<PS: PathInfoService> FUSE<PS> {
+impl FUSE {
     pub fn new(
         blob_service: Arc<dyn BlobService>,
         directory_service: Arc<dyn DirectoryService>,
-        path_info_service: PS,
+        path_info_service: Arc<dyn PathInfoService>,
     ) -> Self {
         Self {
             blob_service,
@@ -23,4 +23,4 @@ impl<PS: PathInfoService> FUSE<PS> {
     }
 }
 
-impl<PS: PathInfoService> fuser::Filesystem for FUSE<PS> {}
+impl fuser::Filesystem for FUSE {}
diff --git a/tvix/store/src/pathinfoservice/mod.rs b/tvix/store/src/pathinfoservice/mod.rs
index 2483909a1190..937d8f2a1119 100644
--- a/tvix/store/src/pathinfoservice/mod.rs
+++ b/tvix/store/src/pathinfoservice/mod.rs
@@ -10,7 +10,7 @@ pub use self::sled::SledPathInfoService;
 
 /// The base trait all PathInfo services need to implement.
 /// This is a simple get and put of [proto::Directory], returning their digest.
-pub trait PathInfoService {
+pub trait PathInfoService: Send + Sync {
     /// Retrieve a PathInfo message by the output digest.
     fn get(&self, digest: [u8; 20]) -> Result<Option<proto::PathInfo>, Error>;
 
diff --git a/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs b/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs
index 645f4aa60556..9f26da213bd5 100644
--- a/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs
+++ b/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs
@@ -1,15 +1,16 @@
 use crate::nar::RenderError;
 use crate::pathinfoservice::PathInfoService;
 use crate::proto;
+use std::sync::Arc;
 use tonic::{async_trait, Request, Response, Result, Status};
 use tracing::{instrument, warn};
 
-pub struct GRPCPathInfoServiceWrapper<PS: PathInfoService> {
-    path_info_service: PS,
+pub struct GRPCPathInfoServiceWrapper {
+    path_info_service: Arc<dyn PathInfoService>,
 }
 
-impl<PS: PathInfoService> From<PS> for GRPCPathInfoServiceWrapper<PS> {
-    fn from(value: PS) -> Self {
+impl From<Arc<dyn PathInfoService>> for GRPCPathInfoServiceWrapper {
+    fn from(value: Arc<dyn PathInfoService>) -> Self {
         Self {
             path_info_service: value,
         }
@@ -17,9 +18,7 @@ impl<PS: PathInfoService> From<PS> for GRPCPathInfoServiceWrapper<PS> {
 }
 
 #[async_trait]
-impl<PS: PathInfoService + Send + Sync + 'static> proto::path_info_service_server::PathInfoService
-    for GRPCPathInfoServiceWrapper<PS>
-{
+impl proto::path_info_service_server::PathInfoService for GRPCPathInfoServiceWrapper {
     #[instrument(skip(self))]
     async fn get(
         &self,
diff --git a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs
index 8b7038ccbc35..186461d16528 100644
--- a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs
+++ b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs
@@ -8,6 +8,7 @@ use crate::tests::fixtures::DUMMY_OUTPUT_HASH;
 use crate::tests::utils::gen_blob_service;
 use crate::tests::utils::gen_directory_service;
 use crate::tests::utils::gen_pathinfo_service;
+use std::sync::Arc;
 use tonic::Request;
 
 /// generates a GRPCPathInfoService out of blob, directory and pathinfo services.
@@ -15,10 +16,13 @@ use tonic::Request;
 /// We only interact with it via the PathInfo GRPC interface.
 /// It uses the NonCachingNARCalculationService NARCalculationService to
 /// calculate NARs.
-fn gen_grpc_service() -> impl GRPCPathInfoService {
+fn gen_grpc_service() -> Arc<dyn GRPCPathInfoService> {
     let blob_service = gen_blob_service();
     let directory_service = gen_directory_service();
-    GRPCPathInfoServiceWrapper::from(gen_pathinfo_service(blob_service, directory_service))
+    Arc::new(GRPCPathInfoServiceWrapper::from(gen_pathinfo_service(
+        blob_service,
+        directory_service,
+    )))
 }
 
 /// Trying to get a non-existent PathInfo should return a not found error.
diff --git a/tvix/store/src/store_io.rs b/tvix/store/src/store_io.rs
index c35da49da998..fcbc5842a3e2 100644
--- a/tvix/store/src/store_io.rs
+++ b/tvix/store/src/store_io.rs
@@ -29,18 +29,18 @@ use crate::{
 /// This is to both cover cases of syntactically valid store paths, that exist
 /// on the filesystem (still managed by Nix), as well as being able to read
 /// files outside store paths.
-pub struct TvixStoreIO<PS: PathInfoService> {
+pub struct TvixStoreIO {
     blob_service: Arc<dyn BlobService>,
     directory_service: Arc<dyn DirectoryService>,
-    path_info_service: PS,
+    path_info_service: Arc<dyn PathInfoService>,
     std_io: StdIO,
 }
 
-impl<PS: PathInfoService> TvixStoreIO<PS> {
+impl TvixStoreIO {
     pub fn new(
         blob_service: Arc<dyn BlobService>,
         directory_service: Arc<dyn DirectoryService>,
-        path_info_service: PS,
+        path_info_service: Arc<dyn PathInfoService>,
     ) -> Self {
         Self {
             blob_service,
@@ -179,7 +179,7 @@ fn calculate_nar_based_store_path(nar_sha256_digest: &[u8; 32], name: &str) -> S
     build_regular_ca_path(name, &nar_hash_with_mode, Vec::<String>::new(), false).unwrap()
 }
 
-impl<PS: PathInfoService> EvalIO for TvixStoreIO<PS> {
+impl EvalIO for TvixStoreIO {
     #[instrument(skip(self), ret, err)]
     fn path_exists(&self, path: &Path) -> Result<bool, io::Error> {
         if let Ok((store_path, sub_path)) =
diff --git a/tvix/store/src/tests/utils.rs b/tvix/store/src/tests/utils.rs
index 171919e4e777..9ccd3dcc65b7 100644
--- a/tvix/store/src/tests/utils.rs
+++ b/tvix/store/src/tests/utils.rs
@@ -17,6 +17,6 @@ pub fn gen_directory_service() -> Arc<dyn DirectoryService> {
 pub fn gen_pathinfo_service(
     blob_service: Arc<dyn BlobService>,
     directory_service: Arc<dyn DirectoryService>,
-) -> impl PathInfoService {
-    MemoryPathInfoService::new(blob_service, directory_service)
+) -> Arc<dyn PathInfoService> {
+    Arc::new(MemoryPathInfoService::new(blob_service, directory_service))
 }