#![allow(unsafe_code)]
use crate::hton::result::result_to_error;
use crate::panic_guard::FfiBoundary;
use crate::runtime;
use crate::runtime::FfiPtr;
use crate::sys;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__rotate_encryption_master_key() -> bool {
FfiBoundary::run_default(true, || match runtime::handlerton() {
Some(h) => result_to_error(h.rotate_encryption_master_key()),
None => false,
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__redo_log_set_state(
thd: *const sys::THD,
enable: bool,
) -> bool {
FfiBoundary::run_default(true, || {
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => result_to_error(h.redo_log_set_state(thd_ref, enable)),
None => false,
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__get_table_statistics(
db_name: *const u8,
db_name_len: usize,
table_name: *const u8,
table_name_len: usize,
se_private_id: u64,
flags: u32,
) -> bool {
FfiBoundary::run_default(true, || {
let db = match unsafe { FfiPtr::bytes_to_str(db_name, db_name_len) } {
Ok(s) => s,
Err(_) => return true,
};
let tab = match unsafe { FfiPtr::bytes_to_str(table_name, table_name_len) } {
Ok(s) => s,
Err(_) => return true,
};
match runtime::handlerton() {
Some(h) => result_to_error(h.get_table_statistics(db, tab, se_private_id, flags)),
None => false,
}
})
}
#[unsafe(no_mangle)]
#[allow(clippy::too_many_arguments)]
pub unsafe extern "C" fn rust__hton__get_index_column_cardinality(
db_name: *const u8,
db_name_len: usize,
table_name: *const u8,
table_name_len: usize,
index_name: *const u8,
index_name_len: usize,
index_ordinal_position: u32,
column_ordinal_position: u32,
se_private_id: u64,
out_cardinality: *mut u64,
) -> bool {
FfiBoundary::run_default(true, || {
let (db, tab, idx) = unsafe {
match (
FfiPtr::bytes_to_str(db_name, db_name_len),
FfiPtr::bytes_to_str(table_name, table_name_len),
FfiPtr::bytes_to_str(index_name, index_name_len),
) {
(Ok(a), Ok(b), Ok(c)) => (a, b, c),
_ => return true,
}
};
let result = match runtime::handlerton() {
Some(h) => h.get_index_column_cardinality(
db,
tab,
idx,
index_ordinal_position,
column_ordinal_position,
se_private_id,
),
None => Ok(None),
};
match result {
Ok(Some(card)) => {
if out_cardinality.is_null() {
return true;
}
unsafe { out_cardinality.write(card) };
false
}
Ok(None) | Err(_) => true,
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__get_tablespace_statistics(
tablespace_name: *const u8,
tablespace_name_len: usize,
file_name: *const u8,
file_name_len: usize,
) -> bool {
FfiBoundary::run_default(true, || {
let ts = match unsafe { FfiPtr::bytes_to_str(tablespace_name, tablespace_name_len) } {
Ok(s) => s,
Err(_) => return true,
};
let file = match unsafe { FfiPtr::bytes_to_str(file_name, file_name_len) } {
Ok(s) => s,
Err(_) => return true,
};
match runtime::handlerton() {
Some(h) => result_to_error(h.get_tablespace_statistics(ts, file)),
None => false,
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__post_ddl(thd: *const sys::THD) {
FfiBoundary::run_void(|| {
let thd_ref = unsafe { thd.as_ref() };
if let Some(h) = runtime::handlerton() {
h.post_ddl(thd_ref);
}
});
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__post_recover() {
FfiBoundary::run_void(|| {
if let Some(h) = runtime::handlerton() {
h.post_recover();
}
});
}