Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/kubernetes-service-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ publish = false
# This pulls version from main branch so that docker build works (docker was confused by paths)
#groupcache = { git = "https://github.com/Petroniuss/groupcache.git" }
groupcache = { path = "../../groupcache" }
tonic = "0.12.3"
axum = "0.7.7"
tonic = "0.14.2"
axum = "0.8.0"

tower = { version = "0.5.1", features = ["steer"] }
tower-http = { version = "0.6.1", features = ["trace"] }
Expand All @@ -20,10 +20,10 @@ serde_json = "1"

tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
axum-prometheus = "0.7.0"
axum-prometheus = "0.9.0"

anyhow = "1"
async-trait = "0.1"

kube = { version = "0.96.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.23.0", features = ["latest"] }
kube = { version = "2.0.1", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.26.0", features = ["latest"] }
2 changes: 1 addition & 1 deletion examples/simple-multiple-instances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false
[dependencies]
groupcache = { path = "../../groupcache" }

tonic = "0.12.3"
tonic = "0.14.2"
tokio = { version = "1.34", features = ["full"] }
tower-http = { version = "0.6.1", features = ["trace"] }

Expand Down
13 changes: 8 additions & 5 deletions groupcache-pb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "groupcache-pb"
version = "0.1.0"
version = "0.3.0"
edition = "2021"
authors = ["Patryk Wojtyczek"]
categories = ["caching", "web-programming", "concurrency", "asynchronous"]
Expand All @@ -12,7 +12,10 @@ readme = "../readme.md"
repository = "https://github.com/Petroniuss/groupcache"

[dependencies]
prost = "0.13.3"
tonic = "0.12.3"
anyhow = "1"
tonic-build = { version= "0.12.3", features = ["prost"] }
prost = "0.14.1"
tonic = "0.14.2"
tonic-prost = "0.14.2"
tonic-prost-build = { version = "0.14.2" }

[build-dependencies]
tonic-prost-build = "*"
11 changes: 7 additions & 4 deletions groupcache-pb/src/main.rs → groupcache-pb/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use anyhow::anyhow;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// skip codegen if there hasn't been any updates.
if true {
return Ok(());
}

let current_dir = std::env::current_dir()?;
if !current_dir.ends_with("groupcache-pb") {
return Err(anyhow!(
return Err(format!(
"must be run from the root of the crate, instead was {:#?}",
current_dir
)
.into());
}

tonic_build::configure()
tonic_prost_build::configure()
.out_dir("src/")
.compile_protos(&["protos/groupcache.proto"], &["protos/"])?;
Ok(())
Expand Down
127 changes: 81 additions & 46 deletions groupcache-pb/src/groupcache_pb.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetRequest {
#[prost(string, tag = "1")]
pub key: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetResponse {
#[prost(bytes = "vec", optional, tag = "1")]
pub value: ::core::option::Option<::prost::alloc::vec::Vec<u8>>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RemoveRequest {
#[prost(string, tag = "1")]
pub key: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RemoveResponse {}
/// Generated client implementations.
pub mod groupcache_client {
Expand All @@ -23,10 +23,10 @@ pub mod groupcache_client {
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value
clippy::let_unit_value,
)]
use tonic::codegen::http::Uri;
use tonic::codegen::*;
use tonic::codegen::http::Uri;
#[derive(Debug, Clone)]
pub struct GroupcacheClient<T> {
inner: tonic::client::Grpc<T>,
Expand All @@ -44,7 +44,7 @@ pub mod groupcache_client {
}
impl<T> GroupcacheClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T: tonic::client::GrpcService<tonic::body::Body>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
Expand All @@ -65,13 +65,14 @@ pub mod groupcache_client {
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
http::Request<tonic::body::Body>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<http::Request<tonic::body::BoxBody>>>::Error:
Into<StdError> + std::marker::Send + std::marker::Sync,
<T as tonic::codegen::Service<
http::Request<tonic::body::Body>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
GroupcacheClient::new(InterceptedService::new(inner, interceptor))
}
Expand Down Expand Up @@ -110,11 +111,18 @@ pub mod groupcache_client {
&mut self,
request: impl tonic::IntoRequest<super::GetRequest>,
) -> std::result::Result<tonic::Response<super::GetResponse>, tonic::Status> {
self.inner.ready().await.map_err(|e| {
tonic::Status::unknown(format!("Service was not ready: {}", e.into()))
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/groupcache_pb.Groupcache/Get");
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/groupcache_pb.Groupcache/Get",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("groupcache_pb.Groupcache", "Get"));
Expand All @@ -124,11 +132,18 @@ pub mod groupcache_client {
&mut self,
request: impl tonic::IntoRequest<super::RemoveRequest>,
) -> std::result::Result<tonic::Response<super::RemoveResponse>, tonic::Status> {
self.inner.ready().await.map_err(|e| {
tonic::Status::unknown(format!("Service was not ready: {}", e.into()))
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/groupcache_pb.Groupcache/Remove");
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/groupcache_pb.Groupcache/Remove",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("groupcache_pb.Groupcache", "Remove"));
Expand All @@ -143,7 +158,7 @@ pub mod groupcache_server {
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value
clippy::let_unit_value,
)]
use tonic::codegen::*;
/// Generated trait containing gRPC methods that should be implemented for use with GroupcacheServer.
Expand Down Expand Up @@ -179,7 +194,10 @@ pub mod groupcache_server {
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(inner: T, interceptor: F) -> InterceptedService<Self, F>
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> InterceptedService<Self, F>
where
F: tonic::service::Interceptor,
{
Expand Down Expand Up @@ -220,7 +238,7 @@ pub mod groupcache_server {
B: Body + std::marker::Send + 'static,
B::Error: Into<StdError> + std::marker::Send + 'static,
{
type Response = http::Response<tonic::body::BoxBody>;
type Response = http::Response<tonic::body::Body>;
type Error = std::convert::Infallible;
type Future = BoxFuture<Self::Response, Self::Error>;
fn poll_ready(
Expand All @@ -234,15 +252,21 @@ pub mod groupcache_server {
"/groupcache_pb.Groupcache/Get" => {
#[allow(non_camel_case_types)]
struct GetSvc<T: Groupcache>(pub Arc<T>);
impl<T: Groupcache> tonic::server::UnaryService<super::GetRequest> for GetSvc<T> {
impl<T: Groupcache> tonic::server::UnaryService<super::GetRequest>
for GetSvc<T> {
type Response = super::GetResponse;
type Future = BoxFuture<tonic::Response<Self::Response>, tonic::Status>;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::GetRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { <T as Groupcache>::get(&inner, request).await };
let fut = async move {
<T as Groupcache>::get(&inner, request).await
};
Box::pin(fut)
}
}
Expand All @@ -253,7 +277,7 @@ pub mod groupcache_server {
let inner = self.inner.clone();
let fut = async move {
let method = GetSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
Expand All @@ -271,16 +295,21 @@ pub mod groupcache_server {
"/groupcache_pb.Groupcache/Remove" => {
#[allow(non_camel_case_types)]
struct RemoveSvc<T: Groupcache>(pub Arc<T>);
impl<T: Groupcache> tonic::server::UnaryService<super::RemoveRequest> for RemoveSvc<T> {
impl<T: Groupcache> tonic::server::UnaryService<super::RemoveRequest>
for RemoveSvc<T> {
type Response = super::RemoveResponse;
type Future = BoxFuture<tonic::Response<Self::Response>, tonic::Status>;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::RemoveRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut =
async move { <T as Groupcache>::remove(&inner, request).await };
let fut = async move {
<T as Groupcache>::remove(&inner, request).await
};
Box::pin(fut)
}
}
Expand All @@ -291,7 +320,7 @@ pub mod groupcache_server {
let inner = self.inner.clone();
let fut = async move {
let method = RemoveSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
Expand All @@ -306,19 +335,25 @@ pub mod groupcache_server {
};
Box::pin(fut)
}
_ => Box::pin(async move {
let mut response = http::Response::new(empty_body());
let headers = response.headers_mut();
headers.insert(
tonic::Status::GRPC_STATUS,
(tonic::Code::Unimplemented as i32).into(),
);
headers.insert(
http::header::CONTENT_TYPE,
tonic::metadata::GRPC_CONTENT_TYPE,
);
Ok(response)
}),
_ => {
Box::pin(async move {
let mut response = http::Response::new(
tonic::body::Body::default(),
);
let headers = response.headers_mut();
headers
.insert(
tonic::Status::GRPC_STATUS,
(tonic::Code::Unimplemented as i32).into(),
);
headers
.insert(
http::header::CONTENT_TYPE,
tonic::metadata::GRPC_CONTENT_TYPE,
);
Ok(response)
})
}
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions groupcache-pb/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Contains generated tonic code for peer to peer communication.
//!
//! Run main.rs to regenerate the code when updating .proto or bumping tonic/prost version.
#[rustfmt::skip]
mod groupcache_pb;

pub use groupcache_pb::groupcache_client::GroupcacheClient;
pub use groupcache_pb::groupcache_server::Groupcache;
use groupcache_pb::groupcache_server::GroupcacheServer as GroupcacheGRPCServer;
pub use groupcache_pb::{GetRequest, GetResponse, RemoveRequest, RemoveResponse};
pub use crate::groupcache_pb::groupcache_client::GroupcacheClient;
pub use crate::groupcache_pb::groupcache_server::Groupcache;
use crate::groupcache_pb::groupcache_server::GroupcacheServer as GroupcacheGRPCServer;
pub use crate::groupcache_pb::{GetRequest, GetResponse, RemoveRequest, RemoveResponse};

/// gRPC server implementing groupcache GET to retrieve values.
pub type GroupcacheServer<T> = GroupcacheGRPCServer<T>;
14 changes: 7 additions & 7 deletions groupcache/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "groupcache"
version = "0.2.1"
version = "0.3.0"
authors = ["Patryk Wojtyczek"]
edition = "2021"
categories = ["caching", "web-programming", "concurrency", "asynchronous"]
Expand All @@ -16,24 +16,24 @@ readme = "readme.md"
repository = "https://github.com/Petroniuss/groupcache"

[dependencies]
groupcache-pb = { path = "../groupcache-pb", version = "0.1.0" }
tonic = "0.12.3"
groupcache-pb = { path = "../groupcache-pb", version = "0.3.0" }
tonic = "0.14.2"
hashring = "0.3.3"
anyhow = "1.0"
thiserror = "2.0"
axum = "0.7.7"
axum = "0.8.0"
tokio = { version = "1.34" , features = ["rt"]}
serde = { version = "1.0", features = ["derive"] }
rmp-serde = "1.1"
async-trait = "0.1.74"
singleflight-async = "0.1.1"
singleflight-async = "0.2.0"
moka = { version = "0.12.1", features = ["future"] }
log = "0.4.20"
metrics = "0.22.0"
metrics = "0.24.0"

[dev-dependencies]
cargo-husky = { workspace = true }
pretty_assertions = "1.4.0"
tokio-stream = { version = "0.1.14", features = ["net"] }
tokio = { version = "1.34", features = ["time", "test-util", "rt", "macros"] }
rstest = "0.18.2"
rstest = "0.26.1"
Loading