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

bump rust-driver to 0.15 (with eager deserialization) #206

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
79 changes: 72 additions & 7 deletions scylla-rust-wrapper/Cargo.lock

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

5 changes: 3 additions & 2 deletions scylla-rust-wrapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ categories = ["database"]
license = "MIT OR Apache-2.0"

[dependencies]
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "64b4afcd", features = [
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "v0.15.0", features = [
"ssl",
] }
Comment on lines 12 to 15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more idiomatic to use the pinned 0.15 version from crates.io? I.e., =0.15 selector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it would. The problem is that it does not work...

scylla and scylla-proxy need to point to the same commit id. Otherwise, we get following error thrown by cargo check --tests:

cargo check --tests
    Checking scylla-cpp-driver-rust v0.2.0 (/home/mikolajuzarski/proj/cpp-rust-driver/scylla-rust-wrapper)
error[E0308]: mismatched types
    --> src/session.rs:1026:51
     |
1026 |                   RequestReaction::forge_with_error(DbError:...
     |  _________________---------------------------------_^
     | |                 |
     | |                 arguments to this function are incorrect
1027 | |                     consistency: Consistency::All,
1028 | |                     received: 1,
1029 | |                     required: 1,
1030 | |                     data_present: false,
1031 | |                 }),
     | |_________________^ expected `DbError`, found a different `DbError`
     |
     = note: `DbError` and `DbError` have similar names, but are actually distinct types
note: `DbError` is defined in crate `scylla_cql`
    --> /home/mikolajuzarski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scylla-cql-0.4.0/src/frame/response/error.rs:154:1
     |
154  | pub enum DbError {
     | ^^^^^^^^^^^^^^^^
note: `DbError` is defined in crate `scylla_cql`
    --> /home/mikolajuzarski/.cargo/git/checkouts/scylla-rust-driver-8578d68f45edd77e/f59908c/scylla-cql/src/frame/response/error.rs:154:1
     |
154  | pub enum DbError {
     | ^^^^^^^^^^^^^^^^
     = note: perhaps two different versions of crate `scylla_cql` are being used?
note: associated function defined here
    --> /home/mikolajuzarski/.cargo/git/checkouts/scylla-rust-driver-8578d68f45edd77e/f59908c/scylla-proxy/src/actions.rs:369:12
     |
369  |     pub fn forge_with_error(error: DbError) -> Self {
     |            ^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `scylla-cpp-driver-rust` (lib test) due to 1 previous error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's enough to convince me. Let's leave this as-is.

tokio = { version = "1.27.0", features = ["full"] }
Expand All @@ -26,13 +26,14 @@ openssl = "0.10.32"
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
tracing = "0.1.37"
futures = "0.3"
thiserror = "1.0"

[build-dependencies]
bindgen = "0.65"
chrono = "0.4.20"

[dev-dependencies]
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "64b4afcd" }
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "v0.15.0" }

assert_matches = "1.5.0"
ntest = "0.9.3"
Expand Down
63 changes: 46 additions & 17 deletions scylla-rust-wrapper/src/cass_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,35 @@ use scylla::transport::errors::*;

// Re-export error types.
pub(crate) use crate::cass_error_types::{CassError, CassErrorSource};
use crate::query_error::CassErrorResult;

impl From<&QueryError> for CassError {
fn from(error: &QueryError) -> Self {
match error {
QueryError::DbError(db_error, _string) => CassError::from(db_error),
QueryError::BadQuery(bad_query) => CassError::from(bad_query),
pub trait ToCassError {
fn to_cass_error(&self) -> CassError;
}

impl ToCassError for CassErrorResult {
fn to_cass_error(&self) -> CassError {
match self {
CassErrorResult::Query(query_error) => query_error.to_cass_error(),

// TODO:
// For now let's leave these as LIB_INVALID_DATA.
// I don't see any variants that would make more sense.
// TBH, I'm almost sure that we should introduce additional enum variants
// of CassError in the future ~ muzarski.
CassErrorResult::ResultMetadataLazyDeserialization(_) => {
CassError::CASS_ERROR_LIB_INVALID_DATA
}
muzarski marked this conversation as resolved.
Show resolved Hide resolved
CassErrorResult::Deserialization(_) => CassError::CASS_ERROR_LIB_INVALID_DATA,
}
}
}

impl ToCassError for QueryError {
fn to_cass_error(&self) -> CassError {
match self {
QueryError::DbError(db_error, _string) => db_error.to_cass_error(),
QueryError::BadQuery(bad_query) => bad_query.to_cass_error(),
QueryError::ProtocolError(_str) => CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR,
QueryError::TimeoutError => CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT, // This may be either read or write timeout error
QueryError::UnableToAllocStreamId => CassError::CASS_ERROR_LIB_NO_STREAMS,
Expand All @@ -32,9 +55,9 @@ impl From<&QueryError> for CassError {
}
}

impl From<&DbError> for CassError {
fn from(error: &DbError) -> Self {
match error {
impl ToCassError for DbError {
fn to_cass_error(&self) -> CassError {
match self {
DbError::ServerError => CassError::CASS_ERROR_SERVER_SERVER_ERROR,
DbError::ProtocolError => CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR,
DbError::AuthenticationError => CassError::CASS_ERROR_SERVER_BAD_CREDENTIALS,
Expand Down Expand Up @@ -62,9 +85,9 @@ impl From<&DbError> for CassError {
}
}

impl From<&BadQuery> for CassError {
fn from(error: &BadQuery) -> Self {
match error {
impl ToCassError for BadQuery {
fn to_cass_error(&self) -> CassError {
match self {
BadQuery::SerializeValuesError(_serialize_values_error) => {
CassError::CASS_ERROR_LAST_ENTRY
}
Expand All @@ -81,9 +104,9 @@ impl From<&BadQuery> for CassError {
}
}

impl From<&NewSessionError> for CassError {
fn from(error: &NewSessionError) -> Self {
match error {
impl ToCassError for NewSessionError {
fn to_cass_error(&self) -> CassError {
match self {
NewSessionError::FailedToResolveAnyHostname(_hostnames) => {
CassError::CASS_ERROR_LIB_NO_HOSTS_AVAILABLE
}
Expand Down Expand Up @@ -117,9 +140,9 @@ impl From<&NewSessionError> for CassError {
}
}

impl From<&BadKeyspaceName> for CassError {
fn from(error: &BadKeyspaceName) -> Self {
match error {
impl ToCassError for BadKeyspaceName {
fn to_cass_error(&self) -> CassError {
match self {
BadKeyspaceName::Empty => CassError::CASS_ERROR_LAST_ENTRY,
BadKeyspaceName::TooLong(_string, _usize) => CassError::CASS_ERROR_LAST_ENTRY,
BadKeyspaceName::IllegalCharacter(_string, _char) => CassError::CASS_ERROR_LAST_ENTRY,
Expand All @@ -133,6 +156,12 @@ pub trait CassErrorMessage {
fn msg(&self) -> String;
}

impl CassErrorMessage for CassErrorResult {
fn msg(&self) -> String {
self.to_string()
}
}

impl CassErrorMessage for QueryError {
fn msg(&self) -> String {
self.to_string()
Expand Down
3 changes: 2 additions & 1 deletion scylla-rust-wrapper/src/future.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::argconv::*;
use crate::cass_error::CassError;
use crate::cass_error::CassErrorMessage;
use crate::cass_error::ToCassError;
use crate::prepared::CassPrepared;
use crate::query_error::CassErrorResult;
use crate::query_result::CassResult;
Expand Down Expand Up @@ -320,7 +321,7 @@ pub unsafe extern "C" fn cass_future_ready(future_raw: *const CassFuture) -> cas
#[no_mangle]
pub unsafe extern "C" fn cass_future_error_code(future_raw: *const CassFuture) -> CassError {
ptr_to_ref(future_raw).with_waited_result(|r: &mut CassFutureResult| match r {
Ok(CassResultValue::QueryError(err)) => CassError::from(err.as_ref()),
Ok(CassResultValue::QueryError(err)) => err.to_cass_error(),
Err((err, _)) => *err,
_ => CassError::CASS_OK,
})
Expand Down
Loading