about summary refs log tree commit diff
path: root/tvix/store/src/nar/grpc_nar_calculation_service.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-06-08T20·00+0300
committerclbot <clbot@tvl.fyi>2023-06-12T10·15+0000
commit8d05c0ceaa9bddb7fdaab436730f093eb16374a2 (patch)
tree33e034ae01b219d413247f1f93ea383133bd8062 /tvix/store/src/nar/grpc_nar_calculation_service.rs
parent27ff98000b0cdf0ed30eb8837c7d44cd3e79d32f (diff)
refactor(tvix/src/nar): drop NARCalculationService r/6270
There's only one way to calculate NAR files, by walking through them.

Things like caching such replies should be done closer to where we use
these, composing NARCalculationService doesn't actually give us much.

Instead, expose two functions, `nar::calculate_size_and_sha256` and
`nar::writer_nar`, the latter writing NAR to a writer, the former using
write_nar to only keeping the NAR size and digest.

Change-Id: Ie5d2cfea35470fdbb5cbf9da1136b0cdf0250266
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8723
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/store/src/nar/grpc_nar_calculation_service.rs')
-rw-r--r--tvix/store/src/nar/grpc_nar_calculation_service.rs69
1 files changed, 0 insertions, 69 deletions
diff --git a/tvix/store/src/nar/grpc_nar_calculation_service.rs b/tvix/store/src/nar/grpc_nar_calculation_service.rs
deleted file mode 100644
index 429593743914..000000000000
--- a/tvix/store/src/nar/grpc_nar_calculation_service.rs
+++ /dev/null
@@ -1,69 +0,0 @@
-use super::NARCalculationService;
-use crate::proto;
-use tonic::transport::Channel;
-use tonic::Status;
-
-/// A NAR calculation service which asks a remote tvix-store for NAR calculation
-/// (via the gRPC PathInfoService).
-#[derive(Clone)]
-pub struct GRPCNARCalculationService {
-    /// A handle into the active tokio runtime. Necessary to spawn tasks.
-    tokio_handle: tokio::runtime::Handle,
-
-    /// The internal reference to a gRPC client.
-    /// Cloning it is cheap, and it internally handles concurrent requests.
-    grpc_client: proto::path_info_service_client::PathInfoServiceClient<Channel>,
-}
-
-impl GRPCNARCalculationService {
-    /// construct a new [GRPCNARCalculationService], by passing a handle to the
-    /// tokio runtime, and a gRPC client.
-    pub fn new(
-        tokio_handle: tokio::runtime::Handle,
-        grpc_client: proto::path_info_service_client::PathInfoServiceClient<Channel>,
-    ) -> Self {
-        Self {
-            tokio_handle,
-            grpc_client,
-        }
-    }
-
-    /// construct a [GRPCNARCalculationService], from a [proto::path_info_service_client::PathInfoServiceClient<Channel>].
-    /// panics if called outside the context of a tokio runtime.
-    pub fn from_client(
-        grpc_client: proto::path_info_service_client::PathInfoServiceClient<Channel>,
-    ) -> Self {
-        Self {
-            tokio_handle: tokio::runtime::Handle::current(),
-            grpc_client,
-        }
-    }
-}
-
-impl NARCalculationService for GRPCNARCalculationService {
-    fn calculate_nar(
-        &self,
-        root_node: &proto::node::Node,
-    ) -> Result<(u64, [u8; 32]), super::RenderError> {
-        // Get a new handle to the gRPC client, and copy the root node.
-        let mut grpc_client = self.grpc_client.clone();
-        let root_node = root_node.clone();
-
-        let task: tokio::task::JoinHandle<Result<_, Status>> =
-            self.tokio_handle.spawn(async move {
-                Ok(grpc_client
-                    .calculate_nar(proto::Node {
-                        node: Some(root_node),
-                    })
-                    .await?
-                    .into_inner())
-            });
-
-        match self.tokio_handle.block_on(task).unwrap() {
-            Ok(resp) => Ok((resp.nar_size, resp.nar_sha256.to_vec().try_into().unwrap())),
-            Err(e) => Err(super::RenderError::StoreError(crate::Error::StorageError(
-                e.to_string(),
-            ))),
-        }
-    }
-}