Skip to content

Commit

Permalink
Merge pull request #351 from blackbeam/release-v24.0.0
Browse files Browse the repository at this point in the history
Release v24.0.0
  • Loading branch information
blackbeam authored May 17, 2023
2 parents 817bbfc + 71a67d9 commit 0a40252
Show file tree
Hide file tree
Showing 20 changed files with 1,249 additions and 500 deletions.
34 changes: 20 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mysql"
version = "23.0.1"
version = "24.0.0"
authors = ["blackbeam"]
description = "Mysql client library implemented in rust"
license = "MIT/Apache-2.0"
Expand Down Expand Up @@ -32,29 +32,34 @@ default = [
"flate2/zlib",

# set of enabled-by-default mysql_common features
"mysql_common/bigdecimal03",
"mysql_common/bigdecimal",
"mysql_common/rust_decimal",
"mysql_common/time03",
"mysql_common/uuid",
"mysql_common/time",
"mysql_common/frunk",

"derive",
# use global buffer pool by default
"buffer-pool",
]
default-rustls = [
"rustls-tls",
"flate2/zlib",
"mysql_common/bigdecimal03",

# default-rustls uses rust_backend for flate2.
"flate2/rust_backend",

"mysql_common/bigdecimal",
"mysql_common/rust_decimal",
"mysql_common/time03",
"mysql_common/uuid",
"mysql_common/time",
"mysql_common/frunk",

"derive",
"buffer-pool",
]
minimal = ["flate2/zlib"]
rustls-tls = ["rustls", "webpki", "webpki-roots", "rustls-pemfile"]
buffer-pool = []
nightly = []
derive = ["mysql_common/derive"]

[dev-dependencies]
lazy_static = "1.4.0"
Expand All @@ -69,11 +74,11 @@ bytes = "1.0.1"
crossbeam = "0.8.1"
io-enum = "1.0.0"
flate2 = { version = "1.0", default-features = false }
lru = "0.8.1"
mysql_common = { version = "0.29.2", default-features = false }
socket2 = "0.4"
lru = "0.10"
mysql_common = { version = "0.30", default-features = false }
socket2 = "0.5.2"
once_cell = "1.7.2"
pem = "1.0.1"
pem = "2.0.1"
percent-encoding = "2.1.0"
serde = "1"
serde_json = "1"
Expand All @@ -85,7 +90,7 @@ version = "0.2.3"
optional = true

[dependencies.rustls]
version = "0.20.0"
version = "0.21.0"
features = ["dangerous_configuration"]
optional = true

Expand All @@ -95,10 +100,11 @@ optional = true

[dependencies.webpki]
version = "0.22.0"
features = ["std"]
optional = true

[dependencies.webpki-roots]
version = "0.22.1"
version = "0.23.0"
optional = true

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ Features:
* MySql binary protocol support, i.e. support of prepared statements and binary result sets;
* support of multi-result sets;
* support of named parameters for prepared statements (see the [Named Parameters](#named-parameters) section);
* optional per-connection cache of prepared statements (see the [Statement Cache](#statement-cache) section);
* per-connection cache of prepared statements (see the [Statement Cache](#statement-cache) section);
* buffer pool (see the [Buffer Pool](#buffer-pool) section);
* support of MySql packets larger than 2^24;
* support of Unix sockets and Windows named pipes;
* support of custom LOCAL INFILE handlers;
* support of MySql protocol compression;
* support of auth plugins:
* **mysql_native_password** - for MySql prior to v8;
* **caching_sha2_password** - for MySql v8 and higher.
* **caching_sha2_password** - for MySql v8 and higher;
* **mysql_clear_password** - opt-in (see [`Opts::get_enable_cleartext_plugin`].

### Installation

Expand Down Expand Up @@ -109,9 +110,10 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {

* feature sets:

* **default** – includes default `mysql_common` features, `native-tls`, `buffer-pool`
and `flate2/zlib`
* **default** – includes default `mysql_common` features, `native-tls`, `buffer-pool`,
`flate2/zlib` and `derive`
* **default-rustls** - same as `default` but with `rustls-tls` instead of `native-tls`
and `flate2/rust_backend` instead of `flate2/zlib`
* **minimal** - includes `flate2/zlib`

* crate's features:
Expand All @@ -122,6 +124,7 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
(see the [SSL Support](#ssl-support) section)
* **buffer-pool** (enabled by default) – enables buffer pooling
(see the [Buffer Pool](#buffer-pool) section)
* **derive** (enabled by default) – reexports derive macros under `prelude`

* external features enabled by default:

Expand Down Expand Up @@ -176,7 +179,14 @@ let _ = Opts::from_url("mysql://user:pass%[email protected]:3307/some_db?")?;
Supported URL parameters (for the meaning of each field please refer to the docs on `Opts`
structure in the create API docs):

* `prefer_socket: true | false` - defines the value of the same field in the `Opts` structure;
* `user: string` – MySql client user name
* `password: string` – MySql client password;
* `db_name: string` – MySql database name;
* `host: Host` – MySql server hostname/ip;
* `port: u16` – MySql server port;
* `pool_min: usize` – see [`PoolConstraints::min`];
* `pool_max: usize` – see [`PoolConstraints::max`];
* `prefer_socket: true | false` - see [`Opts::get_prefer_socket`];
* `tcp_keepalive_time_ms: u32` - defines the value (in milliseconds)
of the `tcp_keepalive_time` field in the `Opts` structure;
* `tcp_keepalive_probe_interval_secs: u32` - defines the value
Expand All @@ -188,6 +198,10 @@ structure in the create API docs):
* `tcp_user_timeout_ms` - defines the value (in milliseconds)
of the `tcp_user_timeout` field in the `Opts` structure;
* `stmt_cache_size: u32` - defines the value of the same field in the `Opts` structure;
* `enable_cleartext_plugin` – see [`Opts::get_enable_cleartext_plugin`];
* `secure_auth` – see [`Opts::get_secure_auth`];
* `reset_connection` – see [`PoolOpts::reset_connection`];
* `check_health` – see [`PoolOpts::check_health`];
* `compress` - defines the value of the same field in the `Opts` structure.
Supported value are:
* `true` - enables compression with the default compression level;
Expand Down Expand Up @@ -646,6 +660,16 @@ assert!(conn_2.exec_drop(&stmt_1, ("foo",)).is_err());

#### Statement cache

##### Note

Statemet cache only works for:
1. for raw [`Conn`]
2. for [`PooledConn`]:
* within it's lifetime if [`PoolOpts::reset_connection`] is `true`
* within the lifetime of a wrapped [`Conn`] if [`PoolOpts::reset_connection`] is `false`

##### Description

`Conn` will manage the cache of prepared statements on the client side, so subsequent calls
to prepare with the same statement won't lead to a client-server roundtrip. Cache size
for each connection is determined by the `stmt_cache_size` field of the `Opts` structure.
Expand Down
48 changes: 26 additions & 22 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ jobs:
SSL=false COMPRESS=true cargo test
SSL=true COMPRESS=true cargo test
SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk
env:
RUST_BACKTRACE: 1
DATABASE_URL: mysql://root:root@localhost:3306/mysql
displayName: Run tests
- job: "TestBasicMacOs"
pool:
vmImage: "macOS-10.15"
vmImage: "macOS-11"
strategy:
maxParallel: 10
matrix:
Expand Down Expand Up @@ -91,11 +91,11 @@ jobs:
SSL=false COMPRESS=true cargo test
SSL=true COMPRESS=true cargo test
SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk
env:
RUST_BACKTRACE: 1
DATABASE_URL: mysql://root@localhost/mysql
Expand Down Expand Up @@ -142,11 +142,11 @@ jobs:
SSL=false COMPRESS=true cargo test
SSL=true COMPRESS=true cargo test
SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk
SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk
SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk
env:
RUST_BACKTRACE: 1
DATABASE_URL: mysql://root:password@localhost/mysql
Expand Down Expand Up @@ -201,9 +201,13 @@ jobs:
displayName: Run MySql in Docker
- bash: |
docker exec container bash -l -c "mysql -uroot -ppassword -e \"SET old_passwords = 1; GRANT ALL PRIVILEGES ON *.* TO 'root2'@'%' IDENTIFIED WITH mysql_old_password AS 'password'; SET PASSWORD FOR 'root2'@'%' = OLD_PASSWORD('password')\"";
docker exec container bash -l -c "echo 'deb [trusted=yes] http://archive.debian.org/debian/ stretch main non-free contrib' > /etc/apt/sources.list"
docker exec container bash -l -c "echo 'deb-src [trusted=yes] http://archive.debian.org/debian/ stretch main non-free contrib ' >> /etc/apt/sources.list"
docker exec container bash -l -c "echo 'deb [trusted=yes] http://archive.debian.org/debian-security/ stretch/updates main non-free contrib' >> /etc/apt/sources.list"
docker exec container bash -l -c "echo 'deb [trusted=yes] http://repo.mysql.com/apt/debian/ stretch mysql-5.6' > /etc/apt/sources.list.d/mysql.list"
condition: eq(variables['DB_VERSION'], '5.6')
- bash: |
docker exec container bash -l -c "apt-get update"
docker exec container bash -l -c "apt-get --allow-unauthenticated -y update"
docker exec container bash -l -c "apt-get install -y curl clang libssl-dev pkg-config build-essential"
docker exec container bash -l -c "curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable"
displayName: Install Rust in docker
Expand All @@ -214,11 +218,11 @@ jobs:
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=$SSL cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=$SSL COMPRESS=true cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk"
env:
RUST_BACKTRACE: 1
DATABASE_URL: mysql://root:password@localhost/mysql
Expand Down Expand Up @@ -286,11 +290,11 @@ jobs:
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time03,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,flate2/zlib,mysql_common/time,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time03,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=true cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=false cargo test --no-default-features --features flate2/zlib,mysql_common/time,mysql_common/frunk"
env:
RUST_BACKTRACE: 1
DATABASE_URL: mysql://root:password@localhost/mysql
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::env;
fn main() {
let names = ["CARGO_CFG_TARGET_OS", "CARGO_CFG_TARGET_ARCH"];
for name in &names {
let value =
env::var(name).expect(&format!("Could not get the environment variable {}", name));
let value = env::var(name)
.unwrap_or_else(|_| panic!("Could not get the environment variable {}", name));
println!("cargo:rustc-env={}={}", name, value);
}
}
6 changes: 3 additions & 3 deletions src/buffer_pool/enabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use crossbeam::queue::ArrayQueue;
use once_cell::sync::Lazy;

use std::{mem::replace, ops::Deref, sync::Arc};
use std::{mem::take, ops::Deref, sync::Arc};

const DEFAULT_MYSQL_BUFFER_POOL_CAP: usize = 128;
const DEFAULT_MYSQL_BUFFER_SIZE_CAP: usize = 4 * 1024 * 1024;

static BUFFER_POOL: Lazy<Arc<BufferPool>> = Lazy::new(|| Default::default());
static BUFFER_POOL: Lazy<Arc<BufferPool>> = Lazy::new(Default::default);

#[inline(always)]
pub fn get_buffer() -> Buffer {
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Deref for Buffer {
impl Drop for Buffer {
fn drop(&mut self) {
if let Some(ref inner) = self.1 {
inner.put(replace(&mut self.0, vec![]));
inner.put(take(&mut self.0));
}
}
}
24 changes: 11 additions & 13 deletions src/conn/binlog_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,34 @@ impl Iterator for BinlogStream {
}
};

let first_byte = packet.get(0).copied();
let first_byte = packet.first().copied();

if first_byte == Some(255) {
if let Ok(ErrPacket::Error(err)) = ParseBuf(&*packet).parse(conn.0.capability_flags) {
if let Ok(ErrPacket::Error(err)) = ParseBuf(&packet).parse(conn.0.capability_flags) {
self.conn = None;
return Some(Err(crate::Error::MySqlError(From::from(err))));
}
}

if first_byte == Some(254) && packet.len() < 8 {
if ParseBuf(&*packet)
if first_byte == Some(254)
&& packet.len() < 8
&& ParseBuf(&packet)
.parse::<OkPacketDeserializer<NetworkStreamTerminator>>(conn.0.capability_flags)
.is_ok()
{
self.conn = None;
return None;
}
{
self.conn = None;
return None;
}

if first_byte == Some(0) {
let event_data = &packet[1..];
match self.esr.read(event_data) {
Ok(event) => {
return Some(Ok(event));
}
Err(err) => return Some(Err(err.into())),
Ok(event) => Some(Ok(event)),
Err(err) => Some(Err(err.into())),
}
} else {
self.conn = None;
return Some(Err(crate::error::DriverError::UnexpectedPacket.into()));
Some(Err(crate::error::DriverError::UnexpectedPacket.into()))
}
}
}
Loading

0 comments on commit 0a40252

Please sign in to comment.