From 58f5ff2c173b6c64e3ffb1d2cd4d840e0dcf38c3 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 28 Dec 2022 16:40:28 +0100 Subject: feat(tvix/store): initial dummy implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This replaces the hello world example from tvix-store with an actual gRPC endpoint, implementing all of BlobService, DirectoryService and PathInfoService. All RPC methods currently respond with the unimplemented gRPC status. Co-Authored-By: Márton Boros Change-Id: Ieba333cca44dc1e3f2ffbe676ba7a99e672b9bfb Reviewed-on: https://cl.tvl.fyi/c/depot/+/7664 Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/Cargo.lock | 20 ++++++++------ tvix/Cargo.nix | 44 ++++++++++++++++++++++--------- tvix/store/Cargo.toml | 3 +++ tvix/store/src/dummy_blob_service.rs | 34 ++++++++++++++++++++++++ tvix/store/src/dummy_directory_service.rs | 28 ++++++++++++++++++++ tvix/store/src/dummy_path_info_service.rs | 26 ++++++++++++++++++ tvix/store/src/main.rs | 42 +++++++++++++++++++++++++++-- 7 files changed, 175 insertions(+), 22 deletions(-) create mode 100644 tvix/store/src/dummy_blob_service.rs create mode 100644 tvix/store/src/dummy_directory_service.rs create mode 100644 tvix/store/src/dummy_path_info_service.rs (limited to 'tvix') diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock index a79c6d613517..35aeb3aa4f4c 100644 --- a/tvix/Cargo.lock +++ b/tvix/Cargo.lock @@ -290,9 +290,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.27" +version = "4.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0acbd8d28a0a60d7108d7ae850af6ba34cf2d1257fc646980e5f97ce14275966" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" dependencies = [ "bitflags", "clap_derive", @@ -884,9 +884,9 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae5bc6e2eb41c9def29a3e0f1306382807764b9b53112030eff57435667352d" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ "hermit-abi 0.2.6", "io-lifetimes", @@ -1045,7 +1045,7 @@ dependencies = [ name = "nix-cli" version = "0.1.0" dependencies = [ - "clap 4.0.27", + "clap 4.0.32", "tempfile", ] @@ -1553,9 +1553,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.36.3" +version = "0.36.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" dependencies = [ "bitflags", "errno", @@ -1889,6 +1889,7 @@ dependencies = [ "libc", "memchr", "mio", + "num_cpus", "pin-project-lite", "socket2", "tokio-macros", @@ -2090,7 +2091,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" name = "tvix-cli" version = "0.1.0" dependencies = [ - "clap 4.0.27", + "clap 4.0.32", "dirs", "rustyline", "smol_str", @@ -2145,11 +2146,14 @@ dependencies = [ "anyhow", "blake3", "data-encoding", + "clap 4.0.32", "lazy_static", "prost", "prost-build", "test-case", "thiserror", + "tokio", + "tokio-stream", "tonic", "tonic-build", ] diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix index 89185708f89b..2487f8abff6c 100644 --- a/tvix/Cargo.nix +++ b/tvix/Cargo.nix @@ -932,12 +932,12 @@ rec { }; resolvedDefaultFeatures = [ "std" ]; }; - "clap 4.0.27" = rec { + "clap 4.0.32" = rec { crateName = "clap"; - version = "4.0.27"; + version = "4.0.32"; edition = "2021"; crateBin = [ ]; - sha256 = "0rjr4wacx5sz1sc4dikz4p8z4k53dfpm1s3sil8dfq0aib9dijqa"; + sha256 = "0fcsz3zggk0g0y76vv7v7ivn72p1v980h2yhi0zf9y9mr45p1nx7"; dependencies = [ { name = "bitflags"; @@ -2580,9 +2580,9 @@ rec { }; "is-terminal" = rec { crateName = "is-terminal"; - version = "0.4.0"; + version = "0.4.2"; edition = "2018"; - sha256 = "0b9mcxb46mzz1q1i4cdmp5j7g042ccqg3q5357prs75l5rpbrrda"; + sha256 = "12c11c8iv2wwyadzajzffmy1fy9nphdpvdj54d367k0c234bdpr8"; authors = [ "softprops " "Dan Gohman " @@ -2600,14 +2600,14 @@ rec { { name = "rustix"; packageId = "rustix"; - target = { target, features }: (!((target."windows" or false) || ("hermit" == target."os"))); + target = { target, features }: (!((target."windows" or false) || ("hermit" == target."os") || ("unknown" == target."os"))); features = [ "termios" ]; } { name = "windows-sys"; packageId = "windows-sys"; target = { target, features }: (target."windows" or false); - features = [ "Win32_Foundation" "Win32_System_Console" ]; + features = [ "Win32_Foundation" "Win32_Storage_FileSystem" "Win32_System_Console" ]; } ]; @@ -3003,7 +3003,7 @@ rec { dependencies = [ { name = "clap"; - packageId = "clap 4.0.27"; + packageId = "clap 4.0.32"; } { name = "tempfile"; @@ -4370,9 +4370,9 @@ rec { }; "rustix" = rec { crateName = "rustix"; - version = "0.36.3"; + version = "0.36.6"; edition = "2018"; - sha256 = "0gi2v2a66h5mgaacq7ih1fw4pa0rpdh7gx1dq28d7cafzi6vn7qb"; + sha256 = "0ja5vcjlfc10d97dgdz57c7spv1nrm4jdqgdqhlw7il2nrywzsjg"; authors = [ "Dan Gohman " "Jakub Konka " @@ -4472,6 +4472,7 @@ rec { "libc_errno" = [ "dep:libc_errno" ]; "once_cell" = [ "dep:once_cell" ]; "os_pipe" = [ "io-lifetimes/os_pipe" ]; + "param" = [ "fs" ]; "procfs" = [ "once_cell" "itoa" "fs" ]; "rustc-dep-of-std" = [ "core" "alloc" "compiler_builtins" "linux-raw-sys/rustc-dep-of-std" "bitflags/rustc-dep-of-std" ]; "std" = [ "io-lifetimes" ]; @@ -5331,6 +5332,11 @@ rec { packageId = "mio"; optional = true; } + { + name = "num_cpus"; + packageId = "num_cpus"; + optional = true; + } { name = "pin-project-lite"; packageId = "pin-project-lite"; @@ -5399,7 +5405,7 @@ rec { "tracing" = [ "dep:tracing" ]; "windows-sys" = [ "dep:windows-sys" ]; }; - resolvedDefaultFeatures = [ "bytes" "default" "io-std" "io-util" "libc" "macros" "memchr" "mio" "net" "rt" "socket2" "sync" "time" "tokio-macros" "windows-sys" ]; + resolvedDefaultFeatures = [ "bytes" "default" "io-std" "io-util" "libc" "macros" "memchr" "mio" "net" "num_cpus" "rt" "rt-multi-thread" "socket2" "sync" "time" "tokio-macros" "windows-sys" ]; }; "tokio-io-timeout" = rec { crateName = "tokio-io-timeout"; @@ -6176,7 +6182,7 @@ rec { dependencies = [ { name = "clap"; - packageId = "clap 4.0.27"; + packageId = "clap 4.0.32"; features = [ "derive" "env" ]; } { @@ -6389,6 +6395,11 @@ rec { packageId = "blake3"; features = [ "rayon" "std" ]; } + { + name = "clap"; + packageId = "clap 4.0.32"; + features = [ "derive" "env" ]; + } { name = "data-encoding"; packageId = "data-encoding"; @@ -6405,6 +6416,15 @@ rec { name = "thiserror"; packageId = "thiserror"; } + { + name = "tokio"; + packageId = "tokio"; + features = [ "rt-multi-thread" ]; + } + { + name = "tokio-stream"; + packageId = "tokio-stream"; + } { name = "tonic"; packageId = "tonic"; diff --git a/tvix/store/Cargo.toml b/tvix/store/Cargo.toml index ee8c1191ee5d..5cae4e0dfcd7 100644 --- a/tvix/store/Cargo.toml +++ b/tvix/store/Cargo.toml @@ -8,8 +8,11 @@ anyhow = "1.0.68" blake3 = { version = "1.3.1", features = ["rayon", "std"] } data-encoding = "2.3.3" lazy_static = "1.4.0" +clap = { version = "4.0", features = ["derive", "env"] } prost = "0.11.2" thiserror = "1.0.38" +tokio = { version = "1.23.0", features = ["rt-multi-thread"] } +tokio-stream = "0.1.11" tonic = "0.8.2" [build-dependencies] diff --git a/tvix/store/src/dummy_blob_service.rs b/tvix/store/src/dummy_blob_service.rs new file mode 100644 index 000000000000..7731ea3344e3 --- /dev/null +++ b/tvix/store/src/dummy_blob_service.rs @@ -0,0 +1,34 @@ +use tokio_stream::wrappers::ReceiverStream; + +use crate::proto::blob_service_server::BlobService; +use crate::proto::BlobChunk; +use crate::proto::BlobMeta; +use crate::proto::PutBlobResponse; +use crate::proto::ReadBlobRequest; +use crate::proto::StatBlobRequest; +use tonic::{Request, Response, Result, Status, Streaming}; + +pub struct DummyBlobService {} + +#[tonic::async_trait] +impl BlobService for DummyBlobService { + type ReadStream = ReceiverStream>; + + async fn stat(&self, _request: Request) -> Result> { + Err(Status::unimplemented("not implemented")) + } + + async fn read( + &self, + _request: Request, + ) -> Result, Status> { + Err(Status::unimplemented("not implemented")) + } + + async fn put( + &self, + _request: Request>, + ) -> Result> { + Err(Status::unimplemented("not implemented")) + } +} diff --git a/tvix/store/src/dummy_directory_service.rs b/tvix/store/src/dummy_directory_service.rs new file mode 100644 index 000000000000..e9b54d85afd4 --- /dev/null +++ b/tvix/store/src/dummy_directory_service.rs @@ -0,0 +1,28 @@ +use tokio_stream::wrappers::ReceiverStream; + +use crate::proto::directory_service_server::DirectoryService; +use crate::proto::Directory; +use crate::proto::GetDirectoryRequest; +use crate::proto::PutDirectoryResponse; +use tonic::{Request, Response, Result, Status, Streaming}; + +pub struct DummyDirectoryService {} + +#[tonic::async_trait] +impl DirectoryService for DummyDirectoryService { + type GetStream = ReceiverStream>; + + async fn get( + &self, + _request: Request, + ) -> Result, Status> { + Err(Status::unimplemented("not implemented")) + } + + async fn put( + &self, + _request: Request>, + ) -> Result> { + Err(Status::unimplemented("not implemented")) + } +} diff --git a/tvix/store/src/dummy_path_info_service.rs b/tvix/store/src/dummy_path_info_service.rs new file mode 100644 index 000000000000..3bc99ad334d9 --- /dev/null +++ b/tvix/store/src/dummy_path_info_service.rs @@ -0,0 +1,26 @@ +use crate::proto::path_info_service_server::PathInfoService; +use crate::proto::CalculateNarResponse; +use crate::proto::GetPathInfoRequest; +use crate::proto::Node; +use crate::proto::PathInfo; +use tonic::{Request, Response, Result, Status}; + +pub struct DummyPathInfoService {} + +#[tonic::async_trait] +impl PathInfoService for DummyPathInfoService { + async fn get(&self, _request: Request) -> Result> { + Err(Status::unimplemented("not implemented")) + } + + async fn put(&self, _request: Request) -> Result> { + Err(Status::unimplemented("not implemented")) + } + + async fn calculate_nar( + &self, + _request: Request, + ) -> Result> { + Err(Status::unimplemented("not implemented")) + } +} diff --git a/tvix/store/src/main.rs b/tvix/store/src/main.rs index c7823b87e468..cc9002438bce 100644 --- a/tvix/store/src/main.rs +++ b/tvix/store/src/main.rs @@ -1,3 +1,13 @@ +use crate::proto::blob_service_server::BlobServiceServer; +use crate::proto::directory_service_server::DirectoryServiceServer; +use crate::proto::path_info_service_server::PathInfoServiceServer; + +use clap::Parser; +use tonic::{transport::Server, Result}; + +mod dummy_blob_service; +mod dummy_directory_service; +mod dummy_path_info_service; mod nixbase32; mod nixpath; mod proto; @@ -5,6 +15,34 @@ mod proto; #[cfg(test)] mod tests; -fn main() { - println!("Hello, world!"); +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Cli { + #[clap(long, short = 'l')] + listen_address: Option, +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let cli = Cli::parse(); + let listen_address = cli + .listen_address + .unwrap_or("[::]:8000".to_string()) + .parse() + .unwrap(); + + let blob_service = dummy_blob_service::DummyBlobService {}; + let directory_service = dummy_directory_service::DummyDirectoryService {}; + let path_info_service = dummy_path_info_service::DummyPathInfoService {}; + + println!("tvix-store listening on {}", listen_address); + + Server::builder() + .add_service(BlobServiceServer::new(blob_service)) + .add_service(DirectoryServiceServer::new(directory_service)) + .add_service(PathInfoServiceServer::new(path_info_service)) + .serve(listen_address) + .await?; + + Ok(()) } -- cgit 1.4.1