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

H-3413: harpc implement tower-based server #5320

Merged
merged 17 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"libs/@local/harpc/net",
"libs/@local/harpc/tower",
"libs/@local/harpc/service",
"libs/@local/harpc/server",
"libs/@local/hql/*",
"libs/antsi",
"libs/deer",
Expand Down Expand Up @@ -57,6 +58,7 @@ harpc-net.path = "libs/@local/harpc/net"
harpc-types.path = "libs/@local/harpc/types"
harpc-wire-protocol.path = "libs/@local/harpc/wire-protocol"
harpc-tower.path = "libs/@local/harpc/tower"
harpc-service.path = "libs/@local/harpc/service"
hash-graph-store.path = "apps/hash-graph/libs/store"
hash-status.path = "libs/@local/status/rust"
hash-tracing.path = "libs/@local/tracing"
Expand Down
17 changes: 8 additions & 9 deletions libs/@local/harpc/net/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ use alloc::sync::Arc;
use core::error::Error;

use bytes::{Buf, Bytes};
use error_stack::{Context, Report, Result};
use error_stack::Report;
use futures::Stream;
use harpc_wire_protocol::response::kind::ErrorCode;

use crate::session::error::TransactionError;

pub trait ValueEncoder<T>: Sized {
type Error: Context;
type Error;

fn encode_stream(
&self,
items: impl Stream<Item = T> + Send + Sync + 'static,
) -> impl Future<Output = impl Stream<Item = Result<Bytes, Self::Error>> + Send + Sync + 'static>
+ Send;
self,
items: impl Stream<Item = T> + Send + Sync,
) -> impl Future<Output = impl Stream<Item = Result<Bytes, Self::Error>> + Send + Sync> + Send;
}

// TODO: WireError is auto trait, using `request_ref` and `request_value`
Expand Down Expand Up @@ -61,10 +60,10 @@ where
pub trait Encoder<T>: ValueEncoder<T> + ErrorEncoder {}

pub trait ValueDecoder<T> {
type Error: Context;
type Error;

fn decode_stream<B, E>(
&self,
self,
items: impl Stream<Item = core::result::Result<B, E>> + Send + Sync,
) -> impl Future<Output = impl Stream<Item = Result<T, Self::Error>> + Send + Sync> + Send
where
Expand All @@ -73,7 +72,7 @@ pub trait ValueDecoder<T> {

pub trait ErrorDecoder {
type Output;
type Error: Context;
type Error;

/// Decode an error report from a stream of bytes.
fn decode_report(
Expand Down
16 changes: 9 additions & 7 deletions libs/@local/harpc/net/src/session/server/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ pub(crate) struct TransactionParts<P> {
pub permit: P,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TransactionContext {
id: RequestId,

peer: PeerId,
// The PeerId is 80 bytes in size and completely balloons the size of the context, from `32` to
// `104` bytes.
peer: Box<PeerId>,
session: SessionId,

service: ServiceDescriptor,
Expand All @@ -187,8 +189,8 @@ impl TransactionContext {
}

#[must_use]
pub const fn peer(&self) -> PeerId {
self.peer
pub fn peer(&self) -> PeerId {
*self.peer
}

#[must_use]
Expand Down Expand Up @@ -243,7 +245,7 @@ impl Transaction {
let transaction = Self {
context: TransactionContext {
id: permit.id(),
peer,
peer: Box::new(peer),
session,
service: body.service,
procedure: body.procedure,
Expand All @@ -268,8 +270,8 @@ impl Transaction {
}

#[must_use]
pub const fn context(&self) -> TransactionContext {
self.context
pub const fn context(&self) -> &TransactionContext {
&self.context
}

pub fn into_parts(self) -> (TransactionContext, TransactionSink, TransactionStream) {
Expand Down
41 changes: 41 additions & 0 deletions libs/@local/harpc/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cargo-features = ["edition2024"]

[package]
name = "harpc-server"
authors.workspace = true
version.workspace = true
edition.workspace = true
license.workspace = true
publish.workspace = true

[dependencies]
# Public workspace dependencies

# Public third-party dependencies

# Private workspace dependencies
harpc-net.workspace = true
harpc-service = { workspace = true, public = true }
harpc-tower.workspace = true
harpc-types.workspace = true
harpc-wire-protocol.workspace = true

# Private third-party dependencies
derive-where.workspace = true
error-stack.workspace = true
frunk = "0.4.3"
frunk_core = {version = "0.4.3", public = true}
futures.workspace = true
scc.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["macros"] }
tokio-util = { workspace = true, features = ["rt"] }
tower = { workspace = true, public = true }
tracing.workspace = true

[lints]
workspace = true

[dev-dependencies]
graph-types.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Loading
Loading