Skip to content

Commit 446ce2a

Browse files
committed
lust and gs tablet fix release 0215
1 parent 7839ca4 commit 446ce2a

File tree

13 files changed

+337
-104
lines changed

13 files changed

+337
-104
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

volo-thrift/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ tokio = { workspace = true, features = [
4848
"parking_lot",
4949
] }
5050
tracing.workspace = true
51+
tokio-condvar = "0.1.0"
5152

5253
[features]
5354
default = []

volo-thrift/src/client/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,10 @@ impl<IL, OL, C, Req, Resp, MkT, MkC, LB> ClientBuilder<IL, OL, C, Req, Resp, MkT
463463
}
464464

465465
#[derive(Clone)]
466-
pub struct MessageService<Resp, MkT, MkC>
466+
pub struct MessageService<Req, Resp, MkT, MkC>
467467
where
468-
Resp: EntryMessage + Send + 'static,
468+
Req: EntryMessage + Send + 'static + Sync,
469+
Resp: EntryMessage + Send + 'static + Sync,
469470
MkT: MakeTransport,
470471
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf> + Sync,
471472
{
@@ -474,14 +475,14 @@ where
474475
#[cfg(feature = "multiplex")]
475476
inner: motore::utils::Either<
476477
pingpong::Client<Resp, MkT, MkC>,
477-
crate::transport::multiplex::Client<Resp, MkT, MkC>,
478+
crate::transport::multiplex::Client<Req, Resp, MkT, MkC>,
478479
>,
479480
read_biz_error: bool,
480481
}
481482

482-
impl<Req, Resp, MkT, MkC> Service<ClientContext, Req> for MessageService<Resp, MkT, MkC>
483+
impl<Req, Resp, MkT, MkC> Service<ClientContext, Req> for MessageService<Req, Resp, MkT, MkC>
483484
where
484-
Req: EntryMessage + 'static + Send,
485+
Req: Send + 'static + EntryMessage + Sync,
485486
Resp: Send + 'static + EntryMessage + Sync,
486487
MkT: MakeTransport,
487488
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf> + Sync,
@@ -531,8 +532,8 @@ where
531532
+ Clone
532533
+ Sync,
533534
Req: EntryMessage + Send + 'static + Sync + Clone,
534-
Resp: EntryMessage + Send + 'static,
535-
IL: Layer<MessageService<Resp, MkT, MkC>>,
535+
Resp: EntryMessage + Send + 'static + Sync,
536+
IL: Layer<MessageService<Req, Resp, MkT, MkC>>,
536537
IL::Service:
537538
Service<ClientContext, Req, Response = Option<Resp>> + Sync + Clone + Send + 'static,
538539
<IL::Service as Service<ClientContext, Req>>::Error: Send + Into<ClientError>,

volo-thrift/src/codec/default/mod.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ pub struct DefaultEncoder<E, W> {
116116
impl<E: ZeroCopyEncoder, W: AsyncWrite + Unpin + Send + Sync + 'static> Encoder
117117
for DefaultEncoder<E, W>
118118
{
119-
#[inline]
120-
async fn encode<Req: Send + EntryMessage, Cx: ThriftContext>(
119+
async fn send<Req: Send + EntryMessage, Cx: ThriftContext>(
121120
&mut self,
122121
cx: &mut Cx,
123122
msg: ThriftMessage<Req>,
@@ -179,6 +178,52 @@ impl<E: ZeroCopyEncoder, W: AsyncWrite + Unpin + Send + Sync + 'static> Encoder
179178
}
180179
// write_result
181180
}
181+
182+
#[inline]
183+
async fn encode<Req: Send + EntryMessage, Cx: ThriftContext>(
184+
&mut self,
185+
cx: &mut Cx,
186+
msg: ThriftMessage<Req>,
187+
) -> Result<(), ThriftException> {
188+
cx.stats_mut().record_encode_start_at();
189+
190+
// first, we need to get the size of the message
191+
let (real_size, malloc_size) = self.encoder.size(cx, &msg)?;
192+
trace!(
193+
"[VOLO] codec encode message real size: {}, malloc size: {}",
194+
real_size,
195+
malloc_size
196+
);
197+
cx.stats_mut().set_write_size(real_size);
198+
199+
// then we reserve the size of the message in the linked bytes
200+
self.linked_bytes.reserve(malloc_size);
201+
// after that, we encode the message into the linked bytes
202+
self.encoder
203+
.encode(cx, &mut self.linked_bytes, msg)
204+
.map_err(|e| {
205+
// record the error time
206+
cx.stats_mut().record_encode_end_at();
207+
e
208+
})?;
209+
210+
cx.stats_mut().record_encode_end_at();
211+
Ok(())
212+
}
213+
214+
async fn flush(&mut self) -> Result<(), ThriftException> {
215+
let write_result: Result<(), ThriftException> = self
216+
.linked_bytes
217+
.write_all_vectored(&mut self.writer)
218+
.await
219+
.map_err(|e| e.into());
220+
write_result?;
221+
self.writer.flush().await.map_err(Into::into)
222+
}
223+
224+
async fn reset(&mut self) {
225+
self.linked_bytes.reset();
226+
}
182227
}
183228

184229
pub struct DefaultDecoder<D, R> {

volo-thrift/src/codec/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ pub trait Decoder: Send + 'static {
2626
///
2727
/// Note: [`Encoder`] should be designed to be ready for reuse.
2828
pub trait Encoder: Send + 'static {
29+
fn reset(&mut self) -> impl Future<Output = ()> + Send;
30+
fn send<Req: Send + EntryMessage, Cx: ThriftContext>(
31+
&mut self,
32+
cx: &mut Cx,
33+
msg: ThriftMessage<Req>,
34+
) -> impl Future<Output = Result<(), ThriftException>> + Send;
2935
fn encode<Req: Send + EntryMessage, Cx: ThriftContext>(
3036
&mut self,
3137
cx: &mut Cx,
3238
msg: ThriftMessage<Req>,
3339
) -> impl Future<Output = Result<(), ThriftException>> + Send;
40+
41+
fn flush(&mut self) -> impl Future<Output = Result<(), ThriftException>> + Send;
3442
}
3543

3644
/// [`MakeCodec`] receives an [`AsyncRead`] and an [`AsyncWrite`] and returns a

volo-thrift/src/transport/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub(crate) mod incoming;
2-
#[cfg(feature = "multiplex")]
32
pub mod multiplex;
43
pub mod pingpong;
54
pub mod pool;

volo-thrift/src/transport/multiplex/client.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ use crate::{
1414
ClientError, EntryMessage, ThriftMessage,
1515
};
1616

17-
pub struct MakeClientTransport<MkT, MkC, Resp>
17+
pub struct MakeClientTransport<MkT, MkC, Req, Resp>
1818
where
1919
MkT: MakeTransport,
2020
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf>,
2121
{
2222
make_transport: MkT,
2323
make_codec: MkC,
24-
_phantom: PhantomData<fn() -> Resp>,
24+
_phantom: PhantomData<(fn() -> Resp, fn() -> Req)>,
2525
}
2626

27-
impl<MkT: MakeTransport, MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf>, Resp> Clone
28-
for MakeClientTransport<MkT, MkC, Resp>
27+
impl<MkT: MakeTransport, MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf>, Req, Resp> Clone
28+
for MakeClientTransport<MkT, MkC, Req, Resp>
2929
{
3030
fn clone(&self) -> Self {
3131
Self {
@@ -36,7 +36,7 @@ impl<MkT: MakeTransport, MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf>, Resp> Cl
3636
}
3737
}
3838

39-
impl<MkT, MkC, Resp> MakeClientTransport<MkT, MkC, Resp>
39+
impl<MkT, MkC, Req, Resp> MakeClientTransport<MkT, MkC, Req, Resp>
4040
where
4141
MkT: MakeTransport,
4242
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf>,
@@ -51,13 +51,14 @@ where
5151
}
5252
}
5353

54-
impl<MkT, MkC, Resp> UnaryService<Address> for MakeClientTransport<MkT, MkC, Resp>
54+
impl<MkT, MkC, Req, Resp> UnaryService<Address> for MakeClientTransport<MkT, MkC, Req, Resp>
5555
where
5656
MkT: MakeTransport,
5757
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf> + Sync,
58-
Resp: EntryMessage + Send + 'static,
58+
Resp: EntryMessage + Send + 'static + Sync,
59+
Req: EntryMessage + Send + 'static + Sync,
5960
{
60-
type Response = ThriftTransport<MkC::Encoder, Resp>;
61+
type Response = ThriftTransport<MkC::Encoder, Req, Resp>;
6162
type Error = io::Error;
6263

6364
async fn call(&self, target: Address) -> Result<Self::Response, Self::Error> {
@@ -72,22 +73,24 @@ where
7273
}
7374
}
7475

75-
pub struct Client<Resp, MkT, MkC>
76+
pub struct Client<Req, Resp, MkT, MkC>
7677
where
7778
MkT: MakeTransport,
7879
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf> + Sync,
79-
Resp: EntryMessage + Send + 'static,
80+
Resp: EntryMessage + Send + 'static + Sync,
81+
Req: EntryMessage + Send + 'static + Sync,
8082
{
8183
#[allow(clippy::type_complexity)]
82-
make_transport: PooledMakeTransport<MakeClientTransport<MkT, MkC, Resp>, Address>,
84+
make_transport: PooledMakeTransport<MakeClientTransport<MkT, MkC, Req, Resp>, Address>,
8385
_marker: PhantomData<Resp>,
8486
}
8587

86-
impl<Resp, MkT, MkC> Clone for Client<Resp, MkT, MkC>
88+
impl<Req, Resp, MkT, MkC> Clone for Client<Req, Resp, MkT, MkC>
8789
where
8890
MkT: MakeTransport,
8991
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf> + Sync,
90-
Resp: EntryMessage + Send + 'static,
92+
Resp: EntryMessage + Send + 'static + Sync,
93+
Req: EntryMessage + Send + 'static + Sync,
9194
{
9295
fn clone(&self) -> Self {
9396
Self {
@@ -97,11 +100,12 @@ where
97100
}
98101
}
99102

100-
impl<Resp, MkT, MkC> Client<Resp, MkT, MkC>
103+
impl<Req, Resp, MkT, MkC> Client<Req, Resp, MkT, MkC>
101104
where
102105
MkT: MakeTransport,
103106
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf> + Sync,
104-
Resp: EntryMessage + Send + 'static,
107+
Resp: EntryMessage + Send + 'static + Sync,
108+
Req: EntryMessage + Send + 'static + Sync,
105109
{
106110
pub fn new(make_transport: MkT, pool_cfg: Option<Config>, make_codec: MkC) -> Self {
107111
let make_transport = MakeClientTransport::new(make_transport, make_codec);
@@ -113,9 +117,9 @@ where
113117
}
114118
}
115119

116-
impl<Req, Resp, MkT, MkC> Service<ClientContext, ThriftMessage<Req>> for Client<Resp, MkT, MkC>
120+
impl<Req, Resp, MkT, MkC> Service<ClientContext, ThriftMessage<Req>> for Client<Req, Resp, MkT, MkC>
117121
where
118-
Req: Send + 'static + EntryMessage,
122+
Req: Send + 'static + EntryMessage + Sync,
119123
Resp: EntryMessage + Send + 'static + Sync,
120124
MkT: MakeTransport,
121125
MkC: MakeCodec<MkT::ReadHalf, MkT::WriteHalf> + Sync,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod client;
22
mod server;
33
mod thrift_transport;
4+
pub mod utils;
45

56
pub use client::Client;
67
pub use server::serve;

volo-thrift/src/transport/multiplex/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub async fn serve<Svc, Req, Resp, E, D>(
5656
if let Err(e) = metainfo::METAINFO
5757
.scope(
5858
RefCell::new(mi),
59-
encoder.encode::<Resp, ServerContext>(&mut cx, msg),
59+
encoder.send::<Resp, ServerContext>(&mut cx, msg),
6060
)
6161
.await
6262
{

0 commit comments

Comments
 (0)