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

cargo: update rust driver's version to 0.13.1 #138

Merged
merged 10 commits into from
Jul 18, 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
409 changes: 247 additions & 162 deletions scylla-rust-wrapper/Cargo.lock

Large diffs are not rendered by default.

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

[dependencies]
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "40aaee6", features = [
"ssl",
] }
scylla = { version = "0.13.1", features = ["ssl"] }
tokio = { version = "1.27.0", features = ["full"] }
lazy_static = "1.4.0"
uuid = "1.1.2"
Expand All @@ -34,7 +32,7 @@ chrono = "0.4.20"
assert_matches = "1.5.0"
ntest = "0.9.3"
rusty-fork = "0.3.0"
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "40aaee6" }
scylla-proxy = { version = "0.0.4" }

[lib]
name = "scylla_cpp_driver"
Expand Down
4 changes: 2 additions & 2 deletions scylla-rust-wrapper/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::exec_profile::PerStatementExecProfile;
use crate::retry_policy::CassRetryPolicy;
use crate::statement::{CassStatement, Statement};
use crate::types::*;
use crate::value::CassCqlValue;
use scylla::batch::Batch;
use scylla::frame::response::result::CqlValue;
use scylla::frame::value::MaybeUnset;
use std::convert::TryInto;
use std::sync::Arc;
Expand All @@ -22,7 +22,7 @@ pub struct CassBatch {
#[derive(Clone)]
pub struct CassBatchState {
pub batch: Batch,
pub bound_values: Vec<Vec<MaybeUnset<Option<CqlValue>>>>,
pub bound_values: Vec<Vec<MaybeUnset<Option<CassCqlValue>>>>,
}

#[no_mangle]
Expand Down
20 changes: 11 additions & 9 deletions scylla-rust-wrapper/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@
//! It can be used for binding named parameter in CassStatement or field by name in CassUserType.
//! * Functions from make_appender don't take any extra argument, as they are for use by CassCollection
//! functions - values are appended to collection.
use crate::cass_types::CassDataType;
use scylla::frame::response::result::CqlValue;
use crate::{cass_types::CassDataType, value::CassCqlValue};

pub fn is_compatible_type(_data_type: &CassDataType, _value: &Option<CqlValue>) -> bool {
pub fn is_compatible_type(_data_type: &CassDataType, _value: &Option<CassCqlValue>) -> bool {
// TODO: cppdriver actually checks types.
true
}
Expand All @@ -66,7 +65,7 @@ macro_rules! make_index_binder {
) -> CassError {
// For some reason detected as unused, which is not true
#[allow(unused_imports)]
use scylla::frame::response::result::CqlValue::*;
use crate::value::CassCqlValue::*;
match ($e)($($arg), *) {
Ok(v) => $consume_v(ptr_to_ref_mut(this), index as usize, v),
Err(e) => e,
Expand All @@ -86,7 +85,7 @@ macro_rules! make_name_binder {
) -> CassError {
// For some reason detected as unused, which is not true
#[allow(unused_imports)]
use scylla::frame::response::result::CqlValue::*;
use crate::value::CassCqlValue::*;
let name = ptr_to_cstr(name).unwrap();
match ($e)($($arg), *) {
Ok(v) => $consume_v(ptr_to_ref_mut(this), name, v),
Expand All @@ -108,7 +107,7 @@ macro_rules! make_name_n_binder {
) -> CassError {
// For some reason detected as unused, which is not true
#[allow(unused_imports)]
use scylla::frame::response::result::CqlValue::*;
use crate::value::CassCqlValue::*;
let name = ptr_to_cstr_n(name, name_length).unwrap();
match ($e)($($arg), *) {
Ok(v) => $consume_v(ptr_to_ref_mut(this), name, v),
Expand All @@ -128,7 +127,7 @@ macro_rules! make_appender {
) -> CassError {
// For some reason detected as unused, which is not true
#[allow(unused_imports)]
use scylla::frame::response::result::CqlValue::*;
use crate::value::CassCqlValue::*;
match ($e)($($arg), *) {
Ok(v) => $consume_v(ptr_to_ref_mut(this), v),
Err(e) => e,
Expand Down Expand Up @@ -178,7 +177,10 @@ macro_rules! invoke_binder_maker_macro_with_type {
$this,
$consume_v,
$fn,
|v| Ok(Some(Date(v))),
|v| {
use scylla::frame::value::CqlDate;
Ok(Some(Date(CqlDate(v))))
},
[v @ cass_uint32_t]
);
};
Expand Down Expand Up @@ -295,7 +297,7 @@ macro_rules! invoke_binder_maker_macro_with_type {
$consume_v,
$fn,
|p: *const crate::tuple::CassTuple| {
std::convert::TryInto::try_into(ptr_to_ref(p)).map(Some)
Ok(Some(ptr_to_ref(p).into()))
},
[p @ *const crate::tuple::CassTuple]
);
Expand Down
2 changes: 2 additions & 0 deletions scylla-rust-wrapper/src/cass_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl From<&BadQuery> for CassError {
BadQuery::ValuesTooLongForKey(_usize, _usize2) => CassError::CASS_ERROR_LAST_ENTRY,
BadQuery::BadKeyspaceName(_bad_keyspace_name) => CassError::CASS_ERROR_LAST_ENTRY,
BadQuery::Other(_other_query) => CassError::CASS_ERROR_LAST_ENTRY,
BadQuery::SerializationError(_) => CassError::CASS_ERROR_LAST_ENTRY,
BadQuery::TooManyQueriesInBatchStatement(_) => CassError::CASS_ERROR_LAST_ENTRY,
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions scylla-rust-wrapper/src/collection.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::argconv::*;
use crate::cass_error::CassError;
use crate::types::*;
use scylla::frame::response::result::CqlValue;
use scylla::frame::response::result::CqlValue::*;
use crate::value::CassCqlValue;
use std::convert::TryFrom;

include!(concat!(env!("OUT_DIR"), "/cppdriver_data_collection.rs"));
Expand All @@ -11,24 +10,26 @@ include!(concat!(env!("OUT_DIR"), "/cppdriver_data_collection.rs"));
pub struct CassCollection {
pub collection_type: CassCollectionType,
pub capacity: usize,
pub items: Vec<CqlValue>,
pub items: Vec<CassCqlValue>,
}

impl CassCollection {
pub fn append_cql_value(&mut self, value: Option<CqlValue>) -> CassError {
pub fn append_cql_value(&mut self, value: Option<CassCqlValue>) -> CassError {
// FIXME: Bounds check, type check
// There is no API to append null, so unwrap is safe
self.items.push(value.unwrap());
CassError::CASS_OK
}
}

impl TryFrom<&CassCollection> for CqlValue {
impl TryFrom<&CassCollection> for CassCqlValue {
type Error = ();
fn try_from(collection: &CassCollection) -> Result<Self, Self::Error> {
// FIXME: validate that collection items are correct
match collection.collection_type {
CassCollectionType::CASS_COLLECTION_TYPE_LIST => Ok(List(collection.items.clone())),
CassCollectionType::CASS_COLLECTION_TYPE_LIST => {
Ok(CassCqlValue::List(collection.items.clone()))
}
CassCollectionType::CASS_COLLECTION_TYPE_MAP => {
let mut grouped_items = Vec::new();
// FIXME: validate even number of items
Expand All @@ -39,10 +40,10 @@ impl TryFrom<&CassCollection> for CqlValue {
grouped_items.push((key, value));
}

Ok(Map(grouped_items))
Ok(CassCqlValue::Map(grouped_items))
}
CassCollectionType::CASS_COLLECTION_TYPE_SET => {
Ok(CqlValue::Set(collection.items.clone()))
Ok(CassCqlValue::Set(collection.items.clone()))
}
_ => Err(()),
}
Expand Down
1 change: 1 addition & 0 deletions scylla-rust-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub mod tuple;
pub mod types;
pub mod user_type;
pub mod uuid;
pub mod value;

lazy_static! {
pub static ref RUNTIME: Runtime = Runtime::new().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion scylla-rust-wrapper/src/prepared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub unsafe extern "C" fn cass_prepared_bind(
prepared_raw: *const CassPrepared,
) -> *mut CassStatement {
let prepared: Arc<_> = clone_arced(prepared_raw);
let bound_values_size = prepared.get_prepared_metadata().col_count;
let bound_values_size = prepared.get_variable_col_specs().len();

// cloning prepared statement's arc, because creating CassStatement should not invalidate
// the CassPrepared argument
Expand Down
23 changes: 7 additions & 16 deletions scylla-rust-wrapper/src/query_error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::argconv::*;
use crate::cass_error::*;
use crate::types::*;
use scylla::frame::types::{LegacyConsistency, SerialConsistency};
use scylla::statement::Consistency;
use scylla::transport::errors::*;

Expand All @@ -21,6 +20,8 @@ impl From<Consistency> for CassConsistency {
Consistency::LocalQuorum => CassConsistency::CASS_CONSISTENCY_LOCAL_QUORUM,
Consistency::EachQuorum => CassConsistency::CASS_CONSISTENCY_EACH_QUORUM,
Consistency::LocalOne => CassConsistency::CASS_CONSISTENCY_LOCAL_ONE,
Consistency::Serial => CassConsistency::CASS_CONSISTENCY_SERIAL,
Consistency::LocalSerial => CassConsistency::CASS_CONSISTENCY_LOCAL_SERIAL,
}
}
}
Expand Down Expand Up @@ -59,34 +60,24 @@ pub unsafe extern "C" fn cass_error_result_consistency(
let error_result: &CassErrorResult = ptr_to_ref(error_result);
match error_result {
QueryError::DbError(DbError::Unavailable { consistency, .. }, _) => {
get_cass_consistency_from_legacy(consistency)
CassConsistency::from(*consistency)
}
QueryError::DbError(DbError::ReadTimeout { consistency, .. }, _) => {
get_cass_consistency_from_legacy(consistency)
CassConsistency::from(*consistency)
}
QueryError::DbError(DbError::WriteTimeout { consistency, .. }, _) => {
get_cass_consistency_from_legacy(consistency)
CassConsistency::from(*consistency)
}
QueryError::DbError(DbError::ReadFailure { consistency, .. }, _) => {
get_cass_consistency_from_legacy(consistency)
CassConsistency::from(*consistency)
}
QueryError::DbError(DbError::WriteFailure { consistency, .. }, _) => {
get_cass_consistency_from_legacy(consistency)
CassConsistency::from(*consistency)
}
_ => CassConsistency::CASS_CONSISTENCY_UNKNOWN,
}
}

fn get_cass_consistency_from_legacy(consistency: &LegacyConsistency) -> CassConsistency {
match consistency {
LegacyConsistency::Regular(regular) => CassConsistency::from(*regular),
LegacyConsistency::Serial(serial) => match serial {
SerialConsistency::Serial => CassConsistency::CASS_CONSISTENCY_SERIAL,
SerialConsistency::LocalSerial => CassConsistency::CASS_CONSISTENCY_LOCAL_SERIAL,
},
}
}

#[no_mangle]
pub unsafe extern "C" fn cass_error_result_responses_received(
error_result: *const CassErrorResult,
Expand Down
13 changes: 6 additions & 7 deletions scylla-rust-wrapper/src/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ pub unsafe extern "C" fn cass_value_get_uint32(
) -> CassError {
let val: &CassValue = ptr_to_ref(value);
match val.value {
Some(Value::RegularValue(CqlValue::Date(u))) => std::ptr::write(output, u), // FIXME: hack
Some(Value::RegularValue(CqlValue::Date(u))) => std::ptr::write(output, u.0), // FIXME: hack
Some(_) => return CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE,
None => return CassError::CASS_ERROR_LIB_NULL_VALUE,
};
Expand Down Expand Up @@ -1033,12 +1033,9 @@ pub unsafe extern "C" fn cass_value_get_int64(
Some(Value::RegularValue(CqlValue::Counter(i))) => {
std::ptr::write(output, i.0 as cass_int64_t)
}
Some(Value::RegularValue(CqlValue::Time(d))) => match d.num_nanoseconds() {
Some(nanos) => std::ptr::write(output, nanos as cass_int64_t),
None => return CassError::CASS_ERROR_LIB_NULL_VALUE,
},
Some(Value::RegularValue(CqlValue::Time(d))) => std::ptr::write(output, d.0),
Some(Value::RegularValue(CqlValue::Timestamp(d))) => {
std::ptr::write(output, d.num_milliseconds() as cass_int64_t)
std::ptr::write(output, d.0 as cass_int64_t)
}
Some(_) => return CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE,
None => return CassError::CASS_ERROR_LIB_NULL_VALUE,
Expand All @@ -1055,7 +1052,9 @@ pub unsafe extern "C" fn cass_value_get_uuid(
let val: &CassValue = ptr_to_ref(value);
match val.value {
Some(Value::RegularValue(CqlValue::Uuid(uuid))) => std::ptr::write(output, uuid.into()),
Some(Value::RegularValue(CqlValue::Timeuuid(uuid))) => std::ptr::write(output, uuid.into()),
Some(Value::RegularValue(CqlValue::Timeuuid(uuid))) => {
std::ptr::write(output, Into::<Uuid>::into(uuid).into())
}
Some(_) => return CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE,
None => return CassError::CASS_ERROR_LIB_NULL_VALUE,
};
Expand Down
6 changes: 3 additions & 3 deletions scylla-rust-wrapper/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ pub unsafe extern "C" fn cass_session_get_schema_meta(
#[cfg(test)]
mod tests {
use rusty_fork::rusty_fork_test;
use scylla::{frame::types::LegacyConsistency, transport::errors::DbError};
use scylla::transport::errors::DbError;
use scylla_proxy::{
Condition, Node, Proxy, Reaction, RequestFrame, RequestOpcode, RequestReaction,
RequestRule, ResponseFrame, RunningProxy,
Expand Down Expand Up @@ -703,7 +703,7 @@ mod tests {
Condition::RequestOpcode(RequestOpcode::Query),
// We won't respond to any queries (including metadata fetch),
// but the driver will manage to continue with dummy metadata.
RequestReaction::drop_connection(),
RequestReaction::forge().server_error(),
)]
}

Expand Down Expand Up @@ -1070,7 +1070,7 @@ mod tests {
// We don't use the example ReadTimeout error that is included in proxy,
// because in order to trigger a retry we need data_present=false.
RequestReaction::forge_with_error(DbError::ReadTimeout {
consistency: LegacyConsistency::Regular(Consistency::All),
consistency: Consistency::All,
received: 1,
required: 1,
data_present: false,
Expand Down
Loading
Loading