Skip to content

Fix driver defaults - cluster & exec profiles #332

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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ CASSANDRA_NO_VALGRIND_TEST_FILTER := $(subst ${SPACE},${EMPTY},AsyncTests.Integr
endif

ifndef CCM_COMMIT_ID
# TODO: change it back to master/next when https://github.com/scylladb/scylla-ccm/issues/646 is fixed.
export CCM_COMMIT_ID := 5392dd68
export CCM_COMMIT_ID := master
endif

ifndef SCYLLA_VERSION
Expand All @@ -136,6 +135,7 @@ endif
CURRENT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BUILD_DIR := "${CURRENT_DIR}build"
INTEGRATION_TEST_BIN := ${BUILD_DIR}/cassandra-integration-tests
EXAMPLES_DIR := ${BUILD_DIR}/examples

clean:
rm -rf "${BUILD_DIR}"
Expand Down
6 changes: 3 additions & 3 deletions scylla-rust-wrapper/src/argconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ impl<'a, T: Sized, P: Properties> CassPtr<'a, T, P> {

/// Pointer constructors.
impl<T: Sized, P: Properties> CassPtr<'_, T, P> {
fn null() -> Self {
pub fn null() -> Self {
CassPtr {
ptr: None,
_phantom: PhantomData,
}
}

pub(crate) fn is_null(&self) -> bool {
pub fn is_null(&self) -> bool {
self.ptr.is_none()
}

Expand All @@ -271,7 +271,7 @@ impl<T: Sized, P: Properties> CassPtr<'_, T, P> {

/// Constructors for to exclusive pointers.
impl<T: Sized> CassPtr<'_, T, (Exclusive, CMut)> {
fn null_mut() -> Self {
pub(crate) fn null_mut() -> Self {
CassPtr {
ptr: None,
_phantom: PhantomData,
Expand Down
70 changes: 58 additions & 12 deletions scylla-rust-wrapper/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use crate::cass_types::CassConsistency;
use crate::cass_types::{CassBatchType, make_batch_type};
use crate::exec_profile::PerStatementExecProfile;
use crate::retry_policy::CassRetryPolicy;
use crate::statement::{BoundStatement, CassStatement};
use crate::statement::{
BoundStatement, CassStatement, get_consistency_from_cass_consistency,
get_serial_consistency_from_cass_consistency,
};
use crate::types::*;
use crate::value::CassCqlValue;
use scylla::statement::batch::Batch;
use scylla::value::MaybeUnset;
use std::convert::TryInto;
use std::sync::Arc;

pub struct CassBatch {
Expand Down Expand Up @@ -65,13 +67,30 @@ pub unsafe extern "C" fn cass_batch_set_consistency(
return CassError::CASS_ERROR_LIB_BAD_PARAMS;
};

let consistency = match consistency.try_into().ok() {
Some(c) => c,
None => return CassError::CASS_ERROR_LIB_BAD_PARAMS,
let Ok(maybe_set_consistency) = get_consistency_from_cass_consistency(consistency) else {
return CassError::CASS_ERROR_LIB_BAD_PARAMS;
};
match maybe_set_consistency {
MaybeUnset::Unset => {
// The correct semantics for `CASS_CONSISTENCY_UNKNOWN` is to
// make statement not have any opinion at all about consistency.
// Then, the default from the cluster/execution profile should be used.
// Unfortunately, the Rust Driver does not support
// "unsetting" consistency from a statement at the moment.
//
// FIXME: Implement unsetting consistency in the Rust Driver.
// Then, fix this code.
//
// For now, we will throw an error in order to warn the user
// about this limitation.
return CassError::CASS_ERROR_LIB_BAD_PARAMS;
}
MaybeUnset::Set(consistency) => {
Arc::make_mut(&mut batch.state)
.batch
.set_consistency(consistency);
}
};
Arc::make_mut(&mut batch.state)
.batch
.set_consistency(consistency);

CassError::CASS_OK
}
Expand All @@ -86,13 +105,40 @@ pub unsafe extern "C" fn cass_batch_set_serial_consistency(
return CassError::CASS_ERROR_LIB_BAD_PARAMS;
};

let serial_consistency = match serial_consistency.try_into().ok() {
Some(c) => c,
None => return CassError::CASS_ERROR_LIB_BAD_PARAMS,
// cpp-driver doesn't validate passed value in any way.
// If it is an incorrect serial-consistency value then it will be set
// and sent as-is.
// Before adapting the driver to Rust Driver 0.12 this code
// set serial consistency if a user passed correct value and set it to
// None otherwise.
// I think that failing explicitly is a better idea, so I decided to return
// an error.
let Ok(maybe_set_serial_consistency) =
get_serial_consistency_from_cass_consistency(serial_consistency)
else {
return CassError::CASS_ERROR_LIB_BAD_PARAMS;
};
let serial_consistency = match maybe_set_serial_consistency {
MaybeUnset::Unset => {
// The correct semantics for `CASS_CONSISTENCY_UNKNOWN` is to
// make batch not have any opinion at all about serial consistency.
// Then, the default from the cluster/execution profile should be used.
// Unfortunately, the Rust Driver does not support
// "unsetting" serial consistency from a batch at the moment.
//
// FIXME: Implement unsetting serial consistency in the Rust Driver.
// Then, fix this code.
//
// For now, we will throw an error in order to warn the user
// about this limitation.
return CassError::CASS_ERROR_LIB_BAD_PARAMS;
}
MaybeUnset::Set(sc) => sc,
};

Arc::make_mut(&mut batch.state)
.batch
.set_serial_consistency(Some(serial_consistency));
.set_serial_consistency(serial_consistency);

CassError::CASS_OK
}
Expand Down
14 changes: 1 addition & 13 deletions scylla-rust-wrapper/src/cass_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::cass_error::CassError;
use crate::types::*;
use scylla::cluster::metadata::{CollectionType, NativeType};
use scylla::frame::response::result::ColumnType;
use scylla::frame::types::{Consistency, SerialConsistency};
use scylla::frame::types::Consistency;
use scylla::statement::batch::BatchType;
use std::cell::UnsafeCell;
use std::convert::TryFrom;
Expand Down Expand Up @@ -915,18 +915,6 @@ impl TryFrom<CassConsistency> for Consistency {
}
}

impl TryFrom<CassConsistency> for SerialConsistency {
type Error = ();

fn try_from(serial: CassConsistency) -> Result<SerialConsistency, Self::Error> {
match serial {
CassConsistency::CASS_CONSISTENCY_SERIAL => Ok(SerialConsistency::Serial),
CassConsistency::CASS_CONSISTENCY_LOCAL_SERIAL => Ok(SerialConsistency::LocalSerial),
_ => Err(()),
}
}
}

pub(crate) fn make_batch_type(type_: CassBatchType) -> Option<BatchType> {
match type_ {
CassBatchType::CASS_BATCH_TYPE_LOGGED => Some(BatchType::Logged),
Expand Down
Loading
Loading