about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-12T13·42+0200
committerflokli <flokli@flokli.de>2023-10-14T12·26+0000
commit199e5e0339ee7d58f9e8a6958c8f9aad5b82e26d (patch)
tree9fab43f05adac8dd68420d7b9456a51f3e6d2276
parent0b18be3b57a80e8b02488cf860fdf15981f2f547 (diff)
refactor(tvix/*store): remove some grpc_client let bindings r/6800
We had to have these all while the traits where sync, and there was a
lot of spawning and moving.

Most of this can now be removed in favor of some inline `.clone()`.

Change-Id: Id5466c32a403100bc3347866b3172e06a792e311
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9705
Tested-by: BuildkiteCI
Reviewed-by: Connor Brewster <cbrewster@hey.com>
-rw-r--r--tvix/castore/src/blobservice/grpc.rs7
-rw-r--r--tvix/castore/src/directoryservice/grpc.rs8
-rw-r--r--tvix/store/src/pathinfoservice/grpc.rs37
3 files changed, 25 insertions, 27 deletions
diff --git a/tvix/castore/src/blobservice/grpc.rs b/tvix/castore/src/blobservice/grpc.rs
index 115efa5f09c6..52adf2c6dde5 100644
--- a/tvix/castore/src/blobservice/grpc.rs
+++ b/tvix/castore/src/blobservice/grpc.rs
@@ -112,12 +112,11 @@ impl BlobService for GRPCBlobService {
         &self,
         digest: &B3Digest,
     ) -> Result<Option<Box<dyn BlobReader>>, crate::Error> {
-        // Get a new handle to the gRPC client, and copy the digest.
-        let mut grpc_client = self.grpc_client.clone();
-
         // Get a stream of [proto::BlobChunk], or return an error if the blob
         // doesn't exist.
-        let resp = grpc_client
+        let resp = self
+            .grpc_client
+            .clone()
             .read(proto::ReadBlobRequest {
                 digest: digest.clone().into(),
             })
diff --git a/tvix/castore/src/directoryservice/grpc.rs b/tvix/castore/src/directoryservice/grpc.rs
index 7ef9f84b0a16..4ee2d28e97c0 100644
--- a/tvix/castore/src/directoryservice/grpc.rs
+++ b/tvix/castore/src/directoryservice/grpc.rs
@@ -139,9 +139,11 @@ impl DirectoryService for GRPCDirectoryService {
     }
 
     async fn put(&self, directory: crate::proto::Directory) -> Result<B3Digest, crate::Error> {
-        let mut grpc_client = self.grpc_client.clone();
-
-        let resp = grpc_client.put(tokio_stream::iter(vec![directory])).await;
+        let resp = self
+            .grpc_client
+            .clone()
+            .put(tokio_stream::once(directory))
+            .await;
 
         match resp {
             Ok(put_directory_resp) => Ok(put_directory_resp
diff --git a/tvix/store/src/pathinfoservice/grpc.rs b/tvix/store/src/pathinfoservice/grpc.rs
index a88828083940..3fe1903a14a2 100644
--- a/tvix/store/src/pathinfoservice/grpc.rs
+++ b/tvix/store/src/pathinfoservice/grpc.rs
@@ -54,9 +54,10 @@ impl PathInfoService for GRPCPathInfoService {
                         .connect_with_connector_lazy(tower::service_fn(
                             move |_: tonic::transport::Uri| UnixStream::connect(path.clone()),
                         ));
-                    let grpc_client =
-                        proto::path_info_service_client::PathInfoServiceClient::new(channel);
-                    Ok(Self::from_client(grpc_client))
+
+                    Ok(Self::from_client(
+                        proto::path_info_service_client::PathInfoServiceClient::new(channel),
+                    ))
                 } else {
                     // ensure path is empty, not supported with gRPC.
                     if !url.path().is_empty() {
@@ -78,19 +79,18 @@ impl PathInfoService for GRPCPathInfoService {
                         .unwrap()
                         .connect_lazy();
 
-                    let grpc_client =
-                        proto::path_info_service_client::PathInfoServiceClient::new(channel);
-                    Ok(Self::from_client(grpc_client))
+                    Ok(Self::from_client(
+                        proto::path_info_service_client::PathInfoServiceClient::new(channel),
+                    ))
                 }
             }
         }
     }
 
     async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error> {
-        // Get a new handle to the gRPC client.
-        let mut grpc_client = self.grpc_client.clone();
-
-        let path_info = grpc_client
+        let path_info = self
+            .grpc_client
+            .clone()
             .get(proto::GetPathInfoRequest {
                 by_what: Some(proto::get_path_info_request::ByWhat::ByOutputHash(
                     digest.to_vec().into(),
@@ -106,10 +106,9 @@ impl PathInfoService for GRPCPathInfoService {
     }
 
     async fn put(&self, path_info: PathInfo) -> Result<PathInfo, Error> {
-        // Get a new handle to the gRPC client.
-        let mut grpc_client = self.grpc_client.clone();
-
-        let path_info = grpc_client
+        let path_info = self
+            .grpc_client
+            .clone()
             .put(path_info)
             .await
             .map_err(|e| Error::StorageError(e.to_string()))?
@@ -122,13 +121,11 @@ impl PathInfoService for GRPCPathInfoService {
         &self,
         root_node: &castorepb::node::Node,
     ) -> Result<(u64, [u8; 32]), Error> {
-        // Get a new handle to the gRPC client.
-        let mut grpc_client = self.grpc_client.clone();
-        let root_node = root_node.clone();
-
-        let path_info = grpc_client
+        let path_info = self
+            .grpc_client
+            .clone()
             .calculate_nar(castorepb::Node {
-                node: Some(root_node),
+                node: Some(root_node.clone()),
             })
             .await
             .map_err(|e| Error::StorageError(e.to_string()))?