Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement the Lock middleware with tokio::sync #427

Merged
merged 5 commits into from
Feb 17, 2020
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
4 changes: 4 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -874,9 +874,13 @@ version = "0.1.0"
dependencies = [
"futures",
"linkerd2-error",
"rand 0.7.2",
"tokio",
"tower",
"tracing",
"tracing-futures",
"tracing-log",
"tracing-subscriber",
]

[[package]]
Expand Down
6 changes: 6 additions & 0 deletions linkerd/lock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ linkerd2-error = { path = "../error" }
tokio = "0.1"
tower = "0.1"
tracing = "0.1"

[dev-dependencies]
rand = "0.7"
tracing-futures = "0.1"
tracing-log = "0.1"
tracing-subscriber = "0.2"
44 changes: 44 additions & 0 deletions linkerd/lock/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pub use linkerd2_error::Error;
use std::sync::Arc;

#[derive(Debug)]
pub struct Poisoned(());

#[derive(Debug)]
pub struct ServiceError(Arc<Error>);

// === impl Poisoned ===

impl Poisoned {
pub fn new() -> Self {
Poisoned(())
}
}

impl std::fmt::Display for Poisoned {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "poisoned")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor nit: i believe the write! macro can have a small amount of overhead vs Formatter::write_str when there's no string interpolation to perform. this probably doesn't matter in practice...

}
}

impl std::error::Error for Poisoned {}

// === impl ServiceError ===

impl ServiceError {
pub(crate) fn new(e: Arc<Error>) -> Self {
ServiceError(e)
}

pub fn inner(&self) -> &Error {
self.0.as_ref()
}
}

impl std::fmt::Display for ServiceError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}

impl std::error::Error for ServiceError {}
20 changes: 20 additions & 0 deletions linkerd/lock/src/layer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use super::Lock;

#[derive(Clone, Debug, Default)]
pub struct LockLayer(());

// === impl Layer ===

impl LockLayer {
pub fn new() -> Self {
LockLayer(())
}
}

impl<S> tower::layer::Layer<S> for LockLayer {
type Service = Lock<S>;

fn layer(&self, inner: S) -> Self::Service {
Self::Service::new(inner)
}
}
Loading