about summary refs log tree commit diff
path: root/tvix/store/src/bin/tvix-store.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-02-27T16·47+0100
committerflokli <flokli@flokli.de>2023-03-10T10·58+0000
commit6f6ddccc92e539c800c705987f7e628e66eed0a3 (patch)
tree45cc3259d33c1bddc95f3cfc98f238a3279e5add /tvix/store/src/bin/tvix-store.rs
parentb4a89461f574647b7b0656c7b37107c767ad5a0c (diff)
refactor(tvix/store): move entrypoint to src/bin/tvix-store.rs r/5936
Change-Id: Ibb83be75a2be27debd9e85b43c1b824f59e54dab
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8165
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/store/src/bin/tvix-store.rs')
-rw-r--r--tvix/store/src/bin/tvix-store.rs106
1 files changed, 106 insertions, 0 deletions
diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs
new file mode 100644
index 000000000000..d2095a079f28
--- /dev/null
+++ b/tvix/store/src/bin/tvix-store.rs
@@ -0,0 +1,106 @@
+use tracing_subscriber::prelude::*;
+use tvix_store::blobservice::SledBlobService;
+use tvix_store::chunkservice::SledChunkService;
+use tvix_store::directoryservice::SledDirectoryService;
+use tvix_store::nar::NonCachingNARCalculationService;
+use tvix_store::pathinfoservice::SledPathInfoService;
+use tvix_store::proto::blob_service_server::BlobServiceServer;
+use tvix_store::proto::directory_service_server::DirectoryServiceServer;
+use tvix_store::proto::path_info_service_server::PathInfoServiceServer;
+use tvix_store::proto::GRPCBlobServiceWrapper;
+use tvix_store::proto::GRPCDirectoryServiceWrapper;
+use tvix_store::proto::GRPCPathInfoServiceWrapper;
+
+#[cfg(feature = "reflection")]
+use tvix_store::proto::FILE_DESCRIPTOR_SET;
+
+use clap::Parser;
+use tonic::{transport::Server, Result};
+use tracing::{info, Level};
+
+#[derive(Parser)]
+#[command(author, version, about, long_about = None)]
+struct Cli {
+    #[clap(long, short = 'l')]
+    listen_address: Option<String>,
+    /// Whether to log in JSON
+    #[clap(long)]
+    json: bool,
+
+    #[clap(long)]
+    log_level: Option<Level>,
+}
+
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+    let cli = Cli::parse();
+    let listen_address = cli
+        .listen_address
+        .unwrap_or_else(|| "[::]:8000".to_string())
+        .parse()
+        .unwrap();
+
+    let level = cli.log_level.unwrap_or(Level::INFO);
+
+    let subscriber = tracing_subscriber::registry()
+        .with(if cli.json {
+            Some(
+                tracing_subscriber::fmt::Layer::new()
+                    .with_writer(std::io::stdout.with_max_level(level))
+                    .json(),
+            )
+        } else {
+            None
+        })
+        .with(if !cli.json {
+            Some(
+                tracing_subscriber::fmt::Layer::new()
+                    .with_writer(std::io::stdout.with_max_level(level))
+                    .pretty(),
+            )
+        } else {
+            None
+        });
+
+    tracing::subscriber::set_global_default(subscriber).expect("Unable to set global subscriber");
+
+    let mut server = Server::builder();
+
+    let blob_service = SledBlobService::new("blobs.sled".into())?;
+    let chunk_service = SledChunkService::new("chunks.sled".into())?;
+    let directory_service = SledDirectoryService::new("directories.sled".into())?;
+    let path_info_service = SledPathInfoService::new("pathinfo.sled".into())?;
+
+    let nar_calculation_service = NonCachingNARCalculationService::new(
+        blob_service.clone(),
+        chunk_service.clone(),
+        directory_service.clone(),
+    );
+
+    let mut router = server
+        .add_service(BlobServiceServer::new(GRPCBlobServiceWrapper::new(
+            blob_service,
+            chunk_service,
+        )))
+        .add_service(DirectoryServiceServer::new(
+            GRPCDirectoryServiceWrapper::from(directory_service),
+        ))
+        .add_service(PathInfoServiceServer::new(GRPCPathInfoServiceWrapper::new(
+            path_info_service,
+            nar_calculation_service,
+        )));
+
+    #[cfg(feature = "reflection")]
+    {
+        let reflection_svc = tonic_reflection::server::Builder::configure()
+            .register_encoded_file_descriptor_set(FILE_DESCRIPTOR_SET)
+            .build()?;
+        router = router.add_service(reflection_svc);
+    }
+
+    info!("tvix-store listening on {}", listen_address);
+
+    router.serve(listen_address).await?;
+
+    Ok(())
+}