Skip to content

Commit 0e84bd1

Browse files
committed
Bump mysql_common
1 parent 829774f commit 0e84bd1

File tree

5 files changed

+70
-25
lines changed

5 files changed

+70
-25
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ keyed_priority_queue = "0.4"
2323
lazy_static = "1"
2424
lru = "0.11.0"
2525
mio = { version = "0.8.0", features = ["os-poll", "net"] }
26-
mysql_common = { version = "0.30", default-features = false }
26+
mysql_common = { version = "0.31", default-features = false }
2727
once_cell = "1.7.2"
2828
pem = "3.0"
2929
percent-encoding = "2.1.0"
@@ -109,7 +109,7 @@ rustls-tls = [
109109
tracing = ["dep:tracing"]
110110
derive = ["mysql_common/derive"]
111111
nightly = []
112-
binlog = []
112+
binlog = ["mysql_common/binlog"]
113113

114114
[lib]
115115
name = "mysql_async"

src/conn/binlog_stream/mod.rs

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use futures_core::ready;
1010
use mysql_common::{
1111
binlog::{
12-
consts::BinlogVersion::Version4,
13-
events::{Event, TableMapEvent},
12+
consts::{BinlogVersion::Version4, EventType},
13+
events::{Event, TableMapEvent, TransactionPayloadEvent},
1414
EventStreamReader,
1515
},
1616
io::ParseBuf,
@@ -19,7 +19,7 @@ use mysql_common::{
1919

2020
use std::{
2121
future::Future,
22-
io::ErrorKind,
22+
io::{Cursor, ErrorKind},
2323
pin::Pin,
2424
task::{Context, Poll},
2525
};
@@ -71,6 +71,9 @@ impl super::Conn {
7171
pub struct BinlogStream {
7272
read_packet: ReadPacket<'static, 'static>,
7373
esr: EventStreamReader,
74+
// TODO: Use 'static reader here (requires impl on the mysql_common side).
75+
/// Uncompressed Transaction_payload_event we are iterating over (if any).
76+
tpe: Option<Cursor<Vec<u8>>>,
7477
}
7578

7679
impl BinlogStream {
@@ -79,6 +82,7 @@ impl BinlogStream {
7982
BinlogStream {
8083
read_packet: ReadPacket::new(conn),
8184
esr: EventStreamReader::new(Version4),
85+
tpe: None,
8286
}
8387
}
8488

@@ -114,6 +118,22 @@ impl futures_core::stream::Stream for BinlogStream {
114118
type Item = Result<Event>;
115119

116120
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
121+
{
122+
let Self {
123+
ref mut tpe,
124+
ref mut esr,
125+
..
126+
} = *self;
127+
128+
if let Some(tpe) = tpe.as_mut() {
129+
match esr.read_decompressed(tpe) {
130+
Ok(Some(event)) => return Poll::Ready(Some(Ok(event))),
131+
Ok(None) => self.tpe = None,
132+
Err(err) => return Poll::Ready(Some(Err(err.into()))),
133+
}
134+
}
135+
}
136+
117137
let packet = match ready!(Pin::new(&mut self.read_packet).poll(cx)) {
118138
Ok(packet) => packet,
119139
Err(err) => return Poll::Ready(Some(Err(err.into()))),
@@ -143,9 +163,17 @@ impl futures_core::stream::Stream for BinlogStream {
143163
if first_byte == Some(0) {
144164
let event_data = &packet[1..];
145165
match self.esr.read(event_data) {
146-
Ok(event) => {
166+
Ok(Some(event)) => {
167+
if event.header().event_type_raw() == EventType::TRANSACTION_PAYLOAD_EVENT as u8
168+
{
169+
match event.read_event::<TransactionPayloadEvent<'_>>() {
170+
Ok(e) => self.tpe = Some(Cursor::new(e.danger_decompress())),
171+
Err(_) => (/* TODO: Log the error */),
172+
}
173+
}
147174
return Poll::Ready(Some(Ok(event)));
148175
}
176+
Ok(None) => return Poll::Ready(None),
149177
Err(err) => return Poll::Ready(Some(Err(err.into()))),
150178
}
151179
} else {
@@ -168,21 +196,21 @@ mod tests {
168196
use crate::prelude::*;
169197
use crate::{test_misc::get_opts, *};
170198

171-
async fn gen_dummy_data() -> super::Result<()> {
172-
let mut conn = Conn::new(get_opts()).await?;
173-
199+
async fn gen_dummy_data(conn: &mut Conn) -> super::Result<()> {
174200
"CREATE TABLE IF NOT EXISTS customers (customer_id int not null)"
175-
.ignore(&mut conn)
201+
.ignore(&mut *conn)
176202
.await?;
177203

204+
let mut tx = conn.start_transaction(Default::default()).await?;
178205
for i in 0_u8..100 {
179206
"INSERT INTO customers(customer_id) VALUES (?)"
180207
.with((i,))
181-
.ignore(&mut conn)
208+
.ignore(&mut tx)
182209
.await?;
183210
}
211+
tx.commit().await?;
184212

185-
"DROP TABLE customers".ignore(&mut conn).await?;
213+
"DROP TABLE customers".ignore(conn).await?;
186214

187215
Ok(())
188216
}
@@ -193,6 +221,12 @@ mod tests {
193221
Some(pool) => pool.get_conn().await.unwrap(),
194222
};
195223

224+
if conn.server_version() >= (8, 0, 31) && conn.server_version() < (9, 0, 0) {
225+
let _ = "SET binlog_transaction_compression=ON"
226+
.ignore(&mut conn)
227+
.await;
228+
}
229+
196230
if let Ok(Some(gtid_mode)) = "SELECT @@GLOBAL.GTID_MODE"
197231
.first::<String, _>(&mut conn)
198232
.await
@@ -209,7 +243,7 @@ mod tests {
209243
let filename = row.get(0).unwrap();
210244
let position = row.get(1).unwrap();
211245

212-
gen_dummy_data().await.unwrap();
246+
gen_dummy_data(&mut conn).await.unwrap();
213247
Ok((conn, filename, position))
214248
}
215249

src/conn/routines/exec.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ impl Routine<()> for ExecRoutine<'_> {
7171
break;
7272
}
7373
Params::Named(_) => {
74-
if self.stmt.named_params.is_none() {
74+
if self.stmt.named_params.is_empty() {
7575
let error = DriverError::NamedParamsForPositionalQuery.into();
7676
return Err(error);
7777
}
7878

7979
let named = mem::replace(&mut self.params, Params::Empty);
80-
self.params =
81-
named.into_positional(self.stmt.named_params.as_ref().unwrap())?;
80+
self.params = named.into_positional(&self.stmt.named_params)?;
8281

8382
continue;
8483
}

src/io/read_packet.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515
task::{Context, Poll},
1616
};
1717

18-
use crate::{buffer_pool::PooledBuf, connection_like::Connection, error::IoError, Conn};
18+
use crate::{buffer_pool::PooledBuf, connection_like::Connection, error::IoError};
1919

2020
/// Reads a packet.
2121
#[derive(Debug)]
@@ -27,7 +27,8 @@ impl<'a, 't> ReadPacket<'a, 't> {
2727
Self(conn.into())
2828
}
2929

30-
pub(crate) fn conn_ref(&self) -> &Conn {
30+
#[cfg(feature = "binlog")]
31+
pub(crate) fn conn_ref(&self) -> &crate::Conn {
3132
&*self.0
3233
}
3334
}

src/queryable/stmt.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use futures_util::FutureExt;
1010
use mysql_common::{
1111
io::ParseBuf,
12-
named_params::parse_named_params,
12+
named_params::ParsedNamedParams,
1313
packets::{ComStmtClose, StmtPacket},
1414
};
1515

@@ -45,12 +45,22 @@ fn to_statement_move<'a, T: AsQuery + 'a>(
4545
) -> ToStatementResult<'a> {
4646
let fut = async move {
4747
let query = stmt.as_query();
48-
let (named_params, raw_query) = parse_named_params(query.as_ref())?;
49-
let inner_stmt = match conn.get_cached_stmt(&*raw_query) {
48+
let parsed = ParsedNamedParams::parse(query.as_ref())?;
49+
let inner_stmt = match conn.get_cached_stmt(parsed.query()) {
5050
Some(inner_stmt) => inner_stmt,
51-
None => conn.prepare_statement(raw_query).await?,
51+
None => {
52+
conn.prepare_statement(Cow::Borrowed(parsed.query()))
53+
.await?
54+
}
5255
};
53-
Ok(Statement::new(inner_stmt, named_params))
56+
Ok(Statement::new(
57+
inner_stmt,
58+
parsed
59+
.params()
60+
.iter()
61+
.map(|x| x.as_ref().to_vec())
62+
.collect::<Vec<_>>(),
63+
))
5464
}
5565
.boxed();
5666
ToStatementResult::Mediate(fut)
@@ -240,11 +250,12 @@ impl StmtInner {
240250
#[derive(Debug, Clone, Eq, PartialEq)]
241251
pub struct Statement {
242252
pub(crate) inner: Arc<StmtInner>,
243-
pub(crate) named_params: Option<Vec<Vec<u8>>>,
253+
/// An empty vector in case of no named params.
254+
pub(crate) named_params: Vec<Vec<u8>>,
244255
}
245256

246257
impl Statement {
247-
pub(crate) fn new(inner: Arc<StmtInner>, named_params: Option<Vec<Vec<u8>>>) -> Self {
258+
pub(crate) fn new(inner: Arc<StmtInner>, named_params: Vec<Vec<u8>>) -> Self {
248259
Self {
249260
inner,
250261
named_params,

0 commit comments

Comments
 (0)