Skip to content

Commit 8c7cb13

Browse files
committed
Introduce binlog feature, proxy mysql_common features
1 parent c40205f commit 8c7cb13

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

Cargo.toml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ default = [
3232
"flate2/zlib",
3333

3434
# set of enabled-by-default mysql_common features
35-
"mysql_common/bigdecimal",
36-
"mysql_common/rust_decimal",
37-
"mysql_common/time",
38-
"mysql_common/frunk",
39-
"mysql_common/binlog",
35+
"bigdecimal",
36+
"rust_decimal",
37+
"time",
38+
"frunk",
39+
"binlog",
4040

4141
"derive",
4242
# use global buffer pool by default
@@ -48,19 +48,31 @@ default-rustls = [
4848
# default-rustls uses rust_backend for flate2.
4949
"flate2/rust_backend",
5050

51-
"mysql_common/bigdecimal",
52-
"mysql_common/rust_decimal",
53-
"mysql_common/time",
54-
"mysql_common/frunk",
51+
"bigdecimal",
52+
"rust_decimal",
53+
"time",
54+
"frunk",
55+
"binlog",
5556

5657
"derive",
5758
"buffer-pool",
5859
]
60+
# minimal feature set with system flate2 impl
5961
minimal = ["flate2/zlib"]
62+
# minimal feature set with rust flate2 impl
63+
minimal-rust = ["flate2/rust_backend"]
6064
rustls-tls = ["rustls", "webpki", "webpki-roots", "rustls-pemfile"]
6165
buffer-pool = []
6266
nightly = []
67+
68+
# mysql_common features
6369
derive = ["mysql_common/derive"]
70+
chrono = ["mysql_common/chrono"]
71+
time = ["mysql_common/time"]
72+
bigdecimal = ["mysql_common/bigdecimal"]
73+
rust_decimal = ["mysql_common/rust_decimal"]
74+
frunk = ["mysql_common/frunk"]
75+
binlog = ["mysql_common/binlog"]
6476

6577
[dev-dependencies]
6678
lazy_static = "1.4.0"

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ doc:
8484

8585
test:
8686
$(run-mysql)
87+
if ! (COMPRESS=0 SSL=0 cargo test --no-default-features --features minimal,time,frunk); \
88+
then \
89+
kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`; \
90+
rm -rf $(MYSQL_DATA_DIR) || true; \
91+
exit 1; \
92+
fi
8793
if ! (COMPRESS=0 SSL=0 cargo test); \
8894
then \
8995
kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`; \

src/conn/binlog_stream.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::Conn;
2121
/// Binlog event stream.
2222
///
2323
/// Stream initialization is lazy, i.e. binlog won't be requested until this stream is polled.
24+
#[cfg_attr(docsrs, doc(cfg(feature = "binlog")))]
2425
pub struct BinlogStream {
2526
conn: Option<Conn>,
2627
esr: EventStreamReader,

src/conn/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
// modified, or distributed except according to those terms.
88

99
use bytes::{Buf, BufMut};
10+
#[cfg(feature = "binlog")]
11+
use mysql_common::packets::binlog_request::BinlogRequest;
1012
use mysql_common::{
1113
constants::UTF8MB4_GENERAL_CI,
1214
crypto,
1315
io::{ParseBuf, ReadMysqlExt},
1416
named_params::ParsedNamedParams,
1517
packets::{
16-
binlog_request::BinlogRequest, AuthPlugin, AuthSwitchRequest, Column, ComChangeUser,
17-
ComChangeUserMoreData, ComStmtClose, ComStmtExecuteRequestBuilder, ComStmtSendLongData,
18-
CommonOkPacket, ErrPacket, HandshakePacket, HandshakeResponse, OkPacket,
19-
OkPacketDeserializer, OkPacketKind, OldAuthSwitchRequest, OldEofPacket,
20-
ResultSetTerminator, SessionStateInfo,
18+
AuthPlugin, AuthSwitchRequest, Column, ComChangeUser, ComChangeUserMoreData, ComStmtClose,
19+
ComStmtExecuteRequestBuilder, ComStmtSendLongData, CommonOkPacket, ErrPacket,
20+
HandshakePacket, HandshakeResponse, OkPacket, OkPacketDeserializer, OkPacketKind,
21+
OldAuthSwitchRequest, OldEofPacket, ResultSetTerminator, SessionStateInfo,
2122
},
2223
proto::{codec::Compression, sync_framed::MySyncFramed, MySerialize},
2324
};
@@ -70,8 +71,10 @@ use crate::{
7071
use crate::DriverError::TlsNotSupported;
7172
use crate::SslOpts;
7273

74+
#[cfg(feature = "binlog")]
7375
use self::binlog_stream::BinlogStream;
7476

77+
#[cfg(feature = "binlog")]
7578
pub mod binlog_stream;
7679
pub mod local_infile;
7780
pub mod opts;
@@ -1215,6 +1218,7 @@ impl Conn {
12151218
.contains(StatusFlags::SERVER_STATUS_NO_BACKSLASH_ESCAPES)
12161219
}
12171220

1221+
#[cfg(feature = "binlog")]
12181222
fn register_as_slave(&mut self, server_id: u32) -> Result<()> {
12191223
use mysql_common::packets::ComRegisterSlave;
12201224

@@ -1227,6 +1231,7 @@ impl Conn {
12271231
Ok(())
12281232
}
12291233

1234+
#[cfg(feature = "binlog")]
12301235
fn request_binlog(&mut self, request: BinlogRequest<'_>) -> Result<()> {
12311236
self.register_as_slave(request.server_id())?;
12321237
self.write_command_raw(&request.as_cmd())?;
@@ -1238,6 +1243,8 @@ impl Conn {
12381243
/// You can use `SHOW BINARY LOGS` to get the current log file and position from the master.
12391244
/// If the request's `filename` is empty, the server will send the binlog-stream
12401245
/// of the first known binlog.
1246+
#[cfg(feature = "binlog")]
1247+
#[cfg_attr(docsrs, doc(cfg(feature = "binlog")))]
12411248
pub fn get_binlog_stream(mut self, request: BinlogRequest<'_>) -> Result<BinlogStream> {
12421249
self.request_binlog(request)?;
12431250
Ok(BinlogStream::new(self))
@@ -1326,8 +1333,10 @@ mod test {
13261333
time::Duration,
13271334
};
13281335

1336+
#[cfg(feature = "binlog")]
13291337
use mysql_common::{binlog::events::EventData, packets::binlog_request::BinlogRequest};
13301338
use rand::Fill;
1339+
#[cfg(feature = "time")]
13311340
use time::PrimitiveDateTime;
13321341

13331342
use crate::{
@@ -2422,6 +2431,7 @@ mod test {
24222431
}
24232432

24242433
#[test]
2434+
#[cfg(feature = "binlog")]
24252435
fn should_read_binlog() -> crate::Result<()> {
24262436
use std::{
24272437
collections::HashMap, sync::mpsc::sync_channel, thread::spawn, time::Duration,

src/conn/pool/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ impl PooledConn {
259259
}
260260

261261
/// Turns this connection into a binlog stream (see [`Conn::get_binlog_stream`]).
262+
#[cfg(feature = "binlog")]
263+
#[cfg_attr(docsrs, doc(cfg(feature = "binlog")))]
262264
pub fn get_binlog_stream(
263265
mut self,
264266
request: crate::BinlogRequest<'_>,

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ pub use crate::myc::constants as consts;
903903
#[doc(inline)]
904904
pub use crate::myc::packets::{binlog_request::BinlogRequest, BinlogDumpFlags};
905905

906+
#[cfg(feature = "binlog")]
907+
#[cfg_attr(docsrs, doc(cfg(feature = "binlog")))]
906908
pub mod binlog {
907909
#[doc(inline)]
908910
pub use crate::myc::binlog::consts::*;
@@ -918,6 +920,9 @@ pub use crate::conn::opts::ClientIdentity;
918920
#[doc(inline)]
919921
pub use crate::myc::packets::{session_state_change, SessionStateInfo};
920922

923+
#[cfg(feature = "binlog")]
924+
#[doc(inline)]
925+
pub use crate::conn::binlog_stream::BinlogStream;
921926
#[doc(inline)]
922927
pub use crate::conn::local_infile::{LocalInfile, LocalInfileHandler};
923928
#[doc(inline)]
@@ -938,7 +943,7 @@ pub use crate::conn::stmt::Statement;
938943
#[doc(inline)]
939944
pub use crate::conn::transaction::{AccessMode, IsolationLevel, Transaction, TxOpts};
940945
#[doc(inline)]
941-
pub use crate::conn::{binlog_stream::BinlogStream, Conn};
946+
pub use crate::conn::Conn;
942947
#[doc(inline)]
943948
pub use crate::error::{DriverError, Error, MySqlError, Result, ServerError, UrlError};
944949
#[doc(inline)]

0 commit comments

Comments
 (0)