Skip to content

Commit

Permalink
session: cass_session_get_client_id
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Sep 11, 2024
1 parent 356fdcb commit e9e3cd4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scylla-rust-wrapper/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub struct CassCluster {
use_beta_protocol_version: bool,
auth_username: Option<String>,
auth_password: Option<String>,

client_id: Option<uuid::Uuid>,
}

impl CassCluster {
Expand All @@ -111,6 +113,11 @@ impl CassCluster {
pub(crate) fn get_contact_points(&self) -> &[String] {
&self.contact_points
}

#[inline]
pub(crate) fn get_client_id(&self) -> Option<uuid::Uuid> {
self.client_id
}
}

pub struct CassCustomPayload;
Expand Down Expand Up @@ -162,6 +169,7 @@ pub unsafe extern "C" fn cass_cluster_new() -> *mut CassCluster {
default_execution_profile_builder,
execution_profile_map: Default::default(),
load_balancing_config: Default::default(),
client_id: None,
}))
}

Expand Down Expand Up @@ -289,6 +297,7 @@ pub unsafe extern "C" fn cass_cluster_set_client_id(
let client_uuid: uuid::Uuid = client_id.into();
let client_uuid_str = client_uuid.to_string();

cluster.client_id = Some(client_uuid);
cluster
.session_builder
.config
Expand Down
16 changes: 16 additions & 0 deletions scylla-rust-wrapper/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::query_result::{CassResult, CassResultData, CassRow, CassValue, Collec
use crate::statement::CassStatement;
use crate::statement::Statement;
use crate::types::{cass_uint64_t, size_t};
use crate::uuid::CassUuid;
use scylla::frame::response::result::{CqlValue, Row};
use scylla::frame::types::Consistency;
use scylla::query::Query;
Expand All @@ -31,6 +32,7 @@ use tokio::sync::RwLock;
pub struct CassSessionInner {
session: Session,
exec_profile_map: HashMap<ExecProfileName, ExecutionProfileHandle>,
client_id: uuid::Uuid,
}

impl CassSessionInner {
Expand Down Expand Up @@ -82,6 +84,10 @@ impl CassSessionInner {
session_opt,
session_builder,
exec_profile_map,
cluster
.get_client_id()
// If user did not set a client id, generate a random uuid v4.
.unwrap_or_else(uuid::Uuid::new_v4),
keyspace,
))
}
Expand All @@ -90,6 +96,7 @@ impl CassSessionInner {
session_opt: &RwLock<Option<CassSessionInner>>,
session_builder_fut: impl Future<Output = SessionBuilder>,
exec_profile_builder_map: HashMap<ExecProfileName, CassExecProfile>,
client_id: uuid::Uuid,
keyspace: Option<String>,
) -> CassFutureResult {
// This can sleep for a long time, but only if someone connects/closes session
Expand Down Expand Up @@ -119,6 +126,7 @@ impl CassSessionInner {
*session_guard = Some(CassSessionInner {
session,
exec_profile_map,
client_id,
});
Ok(CassResultValue::Empty)
}
Expand Down Expand Up @@ -562,6 +570,14 @@ pub unsafe extern "C" fn cass_session_close(session: *mut CassSession) -> *const
})
}

#[no_mangle]
pub unsafe extern "C" fn cass_session_get_client_id(session: *const CassSession) -> CassUuid {
let cass_session = ptr_to_ref(session);

let client_id: uuid::Uuid = cass_session.blocking_read().as_ref().unwrap().client_id;
client_id.into()
}

#[no_mangle]
pub unsafe extern "C" fn cass_session_get_schema_meta(
session: *const CassSession,
Expand Down

0 comments on commit e9e3cd4

Please sign in to comment.