diff options
author | Florian Klink <flokli@flokli.de> | 2023-06-12T12·13+0300 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-06-12T12·43+0000 |
commit | 64a4f6185c5dcd96ee57978963324ea50f4dd6f7 (patch) | |
tree | 2bf4136908835b3b766c736e5f7713f05f664b69 /tvix/store/src | |
parent | b49f7cfec6a11816971d7d7c7cdcee3088bae7d2 (diff) |
refactor(tvix/store/blobsvc): drop Result<_,_> around open_write r/6278
We never returned Err here anyways, and we can still return an error during the first (or subsequent) write(s). Change-Id: I4b4cd3d35f6ea008e9ffe2f7b71bfc9187309e2f Reviewed-on: https://cl.tvl.fyi/c/depot/+/8750 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/store/src')
-rw-r--r-- | tvix/store/src/blobservice/grpc.rs | 10 | ||||
-rw-r--r-- | tvix/store/src/blobservice/memory.rs | 4 | ||||
-rw-r--r-- | tvix/store/src/blobservice/mod.rs | 3 | ||||
-rw-r--r-- | tvix/store/src/blobservice/sled.rs | 4 | ||||
-rw-r--r-- | tvix/store/src/import.rs | 2 | ||||
-rw-r--r-- | tvix/store/src/proto/grpc_blobservice_wrapper.rs | 5 | ||||
-rw-r--r-- | tvix/store/src/tests/nar_renderer.rs | 6 |
7 files changed, 15 insertions, 19 deletions
diff --git a/tvix/store/src/blobservice/grpc.rs b/tvix/store/src/blobservice/grpc.rs index 46ec64bce785..6f04c6a3d4b6 100644 --- a/tvix/store/src/blobservice/grpc.rs +++ b/tvix/store/src/blobservice/grpc.rs @@ -121,9 +121,9 @@ impl BlobService for GRPCBlobService { } } - /// Returns a [Self::BlobWriter], that'll internally wrap each write in a - // [proto::BlobChunk] and which is passed to the - fn open_write(&self) -> Result<Box<dyn BlobWriter>, crate::Error> { + /// Returns a BlobWriter, that'll internally wrap each write in a + // [proto::BlobChunk], which is send to the gRPC server. + fn open_write(&self) -> Box<dyn BlobWriter> { let mut grpc_client = self.grpc_client.clone(); // set up an mpsc channel passing around Bytes. @@ -155,11 +155,11 @@ impl BlobService for GRPCBlobService { // … which is then turned into a [io::Write]. let writer = SyncIoBridge::new(async_writer); - Ok(Box::new(GRPCBlobWriter { + Box::new(GRPCBlobWriter { tokio_handle: self.tokio_handle.clone(), // TODO: is the clone() ok here? task_and_writer: Some((task, writer)), digest: None, - })) + }) } } diff --git a/tvix/store/src/blobservice/memory.rs b/tvix/store/src/blobservice/memory.rs index 166eeabdb6a2..0ea8479f87e5 100644 --- a/tvix/store/src/blobservice/memory.rs +++ b/tvix/store/src/blobservice/memory.rs @@ -30,8 +30,8 @@ impl BlobService for MemoryBlobService { } #[instrument(skip(self))] - fn open_write(&self) -> Result<Box<dyn BlobWriter>, Error> { - Ok(Box::new(MemoryBlobWriter::new(self.db.clone()))) + fn open_write(&self) -> Box<dyn BlobWriter> { + Box::new(MemoryBlobWriter::new(self.db.clone())) } } diff --git a/tvix/store/src/blobservice/mod.rs b/tvix/store/src/blobservice/mod.rs index d9aa15bf2a46..c1bca927d7d0 100644 --- a/tvix/store/src/blobservice/mod.rs +++ b/tvix/store/src/blobservice/mod.rs @@ -24,8 +24,7 @@ pub trait BlobService: Send + Sync { /// Insert a new blob into the store. Returns a [BlobWriter], which /// implements [io::Write] and a [BlobWriter::close]. - /// TODO: is there any reason we want this to be a Result<>, and not just T? - fn open_write(&self) -> Result<Box<dyn BlobWriter>, Error>; + fn open_write(&self) -> Box<dyn BlobWriter>; } /// A [io::Write] that you need to close() afterwards, and get back the digest diff --git a/tvix/store/src/blobservice/sled.rs b/tvix/store/src/blobservice/sled.rs index 3f212142b9d1..1ae71170e1e4 100644 --- a/tvix/store/src/blobservice/sled.rs +++ b/tvix/store/src/blobservice/sled.rs @@ -46,8 +46,8 @@ impl BlobService for SledBlobService { } #[instrument(skip(self))] - fn open_write(&self) -> Result<Box<dyn BlobWriter>, Error> { - Ok(Box::new(SledBlobWriter::new(self.db.clone()))) + fn open_write(&self) -> Box<dyn BlobWriter> { + Box::new(SledBlobWriter::new(self.db.clone())) } } diff --git a/tvix/store/src/import.rs b/tvix/store/src/import.rs index 1e639e1d7cd0..dd366aef9576 100644 --- a/tvix/store/src/import.rs +++ b/tvix/store/src/import.rs @@ -114,7 +114,7 @@ fn process_entry( let mut file = File::open(entry_path.clone()) .map_err(|e| Error::UnableToOpen(entry_path.clone(), e))?; - let mut writer = blob_service.open_write()?; + let mut writer = blob_service.open_write(); if let Err(e) = io::copy(&mut file, &mut writer) { return Err(Error::UnableToRead(entry_path, e)); diff --git a/tvix/store/src/proto/grpc_blobservice_wrapper.rs b/tvix/store/src/proto/grpc_blobservice_wrapper.rs index 04097997c2e4..fee97c7d2d0e 100644 --- a/tvix/store/src/proto/grpc_blobservice_wrapper.rs +++ b/tvix/store/src/proto/grpc_blobservice_wrapper.rs @@ -161,10 +161,7 @@ impl super::blob_service_server::BlobService for GRPCBlobServiceWrapper { let data_reader = tokio_util::io::StreamReader::new(data_stream); // prepare a writer, which we'll use in the blocking task below. - let mut writer = self - .blob_service - .open_write() - .map_err(|e| Status::internal(format!("unable to open for write: {}", e)))?; + let mut writer = self.blob_service.open_write(); let result = task::spawn_blocking(move || -> Result<super::PutBlobResponse, Status> { // construct a sync reader to the data diff --git a/tvix/store/src/tests/nar_renderer.rs b/tvix/store/src/tests/nar_renderer.rs index 37a01c2e1826..b92fdc087b28 100644 --- a/tvix/store/src/tests/nar_renderer.rs +++ b/tvix/store/src/tests/nar_renderer.rs @@ -61,7 +61,7 @@ fn single_file_wrong_blob_size() { let blob_service = gen_blob_service(); // insert blob into the store - let mut writer = blob_service.open_write().unwrap(); + let mut writer = blob_service.open_write(); io::copy( &mut io::Cursor::new(HELLOWORLD_BLOB_CONTENTS.to_vec()), &mut writer, @@ -125,7 +125,7 @@ fn single_file() { let blob_service = gen_blob_service(); // insert blob into the store - let mut writer = blob_service.open_write().unwrap(); + let mut writer = blob_service.open_write(); io::copy( &mut io::Cursor::new(HELLOWORLD_BLOB_CONTENTS.to_vec()), &mut writer, @@ -158,7 +158,7 @@ fn test_complicated() { // put all data into the stores. // insert blob into the store - let mut writer = blob_service.open_write().unwrap(); + let mut writer = blob_service.open_write(); io::copy( &mut io::Cursor::new(EMPTY_BLOB_CONTENTS.to_vec()), &mut writer, |