diff options
author | Florian Klink <flokli@flokli.de> | 2023-06-09T15·22+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-06-12T10·24+0000 |
commit | aa7bdc1199bfbb69091dda942a82812257e30bc4 (patch) | |
tree | 933964562f5746274ef6df59cfa956aca73b0807 /tvix/store/src/pathinfoservice | |
parent | 7725eb53ad67730e92a3839a6c10925c668e5586 (diff) |
refactor(tvix/store): use Arc instead of Box r/6273
This allows us to blob services without closing them before putting them in a box. We currently need to use Arc<_>, not Rc<_>, because the GRPC wrappers require Sync. Change-Id: I679c5f06b62304f5b0456cfefe25a0a881de7c84 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8738 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/store/src/pathinfoservice')
-rw-r--r-- | tvix/store/src/pathinfoservice/memory.rs | 16 | ||||
-rw-r--r-- | tvix/store/src/pathinfoservice/sled.rs | 22 |
2 files changed, 23 insertions, 15 deletions
diff --git a/tvix/store/src/pathinfoservice/memory.rs b/tvix/store/src/pathinfoservice/memory.rs index 1457f3d367f6..35455313cb51 100644 --- a/tvix/store/src/pathinfoservice/memory.rs +++ b/tvix/store/src/pathinfoservice/memory.rs @@ -11,14 +11,14 @@ use std::{ pub struct MemoryPathInfoService { db: Arc<RwLock<HashMap<[u8; 20], proto::PathInfo>>>, - blob_service: Box<dyn BlobService>, - directory_service: Box<dyn DirectoryService>, + blob_service: Arc<dyn BlobService>, + directory_service: Arc<dyn DirectoryService>, } impl MemoryPathInfoService { pub fn new( - blob_service: Box<dyn BlobService>, - directory_service: Box<dyn DirectoryService>, + blob_service: Arc<dyn BlobService>, + directory_service: Arc<dyn DirectoryService>, ) -> Self { Self { db: Default::default(), @@ -58,7 +58,11 @@ impl PathInfoService for MemoryPathInfoService { } fn calculate_nar(&self, root_node: &proto::node::Node) -> Result<(u64, [u8; 32]), Error> { - calculate_size_and_sha256(root_node, &self.blob_service, &self.directory_service) - .map_err(|e| Error::StorageError(e.to_string())) + calculate_size_and_sha256( + root_node, + self.blob_service.clone(), + self.directory_service.clone(), + ) + .map_err(|e| Error::StorageError(e.to_string())) } } diff --git a/tvix/store/src/pathinfoservice/sled.rs b/tvix/store/src/pathinfoservice/sled.rs index a5aa987020b9..f06a905cef8d 100644 --- a/tvix/store/src/pathinfoservice/sled.rs +++ b/tvix/store/src/pathinfoservice/sled.rs @@ -4,7 +4,7 @@ use crate::{ proto, Error, }; use prost::Message; -use std::path::PathBuf; +use std::{path::PathBuf, sync::Arc}; use tracing::warn; /// SledPathInfoService stores PathInfo in a [sled](https://github.com/spacejam/sled). @@ -14,15 +14,15 @@ use tracing::warn; pub struct SledPathInfoService { db: sled::Db, - blob_service: Box<dyn BlobService>, - directory_service: Box<dyn DirectoryService>, + blob_service: Arc<dyn BlobService>, + directory_service: Arc<dyn DirectoryService>, } impl SledPathInfoService { pub fn new( p: PathBuf, - blob_service: Box<dyn BlobService>, - directory_service: Box<dyn DirectoryService>, + blob_service: Arc<dyn BlobService>, + directory_service: Arc<dyn DirectoryService>, ) -> Result<Self, sled::Error> { let config = sled::Config::default().use_compression(true).path(p); let db = config.open()?; @@ -35,8 +35,8 @@ impl SledPathInfoService { } pub fn new_temporary( - blob_service: Box<dyn BlobService>, - directory_service: Box<dyn DirectoryService>, + blob_service: Arc<dyn BlobService>, + directory_service: Arc<dyn DirectoryService>, ) -> Result<Self, sled::Error> { let config = sled::Config::default().temporary(true); let db = config.open()?; @@ -95,7 +95,11 @@ impl PathInfoService for SledPathInfoService { } fn calculate_nar(&self, root_node: &proto::node::Node) -> Result<(u64, [u8; 32]), Error> { - calculate_size_and_sha256(root_node, &self.blob_service, &self.directory_service) - .map_err(|e| Error::StorageError(e.to_string())) + calculate_size_and_sha256( + root_node, + self.blob_service.clone(), + self.directory_service.clone(), + ) + .map_err(|e| Error::StorageError(e.to_string())) } } |