Skip to content
Snippets Groups Projects
Commit 4aba51fc authored by Fedor Telnov's avatar Fedor Telnov Committed by Denis Smirnov
Browse files

refactor: better interfaces, open cartridge API

parent f2fbedc5
No related branches found
No related tags found
1 merge request!403refactor: better interfaces, open cartridge API
Pipeline #36536 passed
......@@ -8,9 +8,9 @@ pub struct AsyncCommands {
pub invalidate_segment_cache: bool,
}
thread_local!(static COORDINATOR_ENGINE: RefCell<RouterRuntime> = RefCell::new(RouterRuntime::new().unwrap()));
thread_local!(static SEGMENT_ENGINE: RefCell<StorageRuntime> = RefCell::new(StorageRuntime::new().unwrap()));
thread_local!(static ASYNC_COMMANDS: RefCell<AsyncCommands> = RefCell::new(AsyncCommands::default()));
thread_local!(pub static COORDINATOR_ENGINE: RefCell<RouterRuntime> = RefCell::new(RouterRuntime::new().unwrap()));
thread_local!(pub static SEGMENT_ENGINE: RefCell<StorageRuntime> = RefCell::new(StorageRuntime::new().unwrap()));
thread_local!(pub static ASYNC_COMMANDS: RefCell<AsyncCommands> = RefCell::new(AsyncCommands::default()));
pub mod calculate_bucket_id;
pub mod exec_query;
......
......@@ -113,7 +113,7 @@ impl TryFrom<FunctionArgs> for Args {
}
#[no_mangle]
pub extern "C" fn calculate_bucket_id(ctx: FunctionCtx, args: FunctionArgs) -> c_int {
extern "C" fn calculate_bucket_id(ctx: FunctionCtx, args: FunctionArgs) -> c_int {
let ret_code = load_config(&COORDINATOR_ENGINE);
if ret_code != 0 {
return ret_code;
......
......@@ -13,7 +13,7 @@ use sbroad::{debug, error};
/// Dispatch parameterized SQL query from coordinator to the segments.
#[no_mangle]
pub extern "C" fn dispatch_query(f_ctx: FunctionCtx, args: FunctionArgs) -> c_int {
extern "C" fn dispatch_query(f_ctx: FunctionCtx, args: FunctionArgs) -> c_int {
let lua_params = match PatternWithParams::try_from(args) {
Ok(params) => params,
Err(e) => {
......@@ -78,7 +78,7 @@ pub extern "C" fn dispatch_query(f_ctx: FunctionCtx, args: FunctionArgs) -> c_in
}
#[no_mangle]
pub extern "C" fn execute(f_ctx: FunctionCtx, args: FunctionArgs) -> c_int {
extern "C" fn execute(f_ctx: FunctionCtx, args: FunctionArgs) -> c_int {
debug!(Option::from("decode_msgpack"), &format!("args: {args:?}"));
let tuple_buf: Vec<u8> = TupleBuffer::from(Tuple::from(args)).into();
let (raw_required, mut raw_optional) = match decode_msgpack(tuple_buf.as_slice()) {
......
......@@ -10,7 +10,7 @@ use sbroad::{executor::engine::QueryCache, log::tarantool_error};
/// Flush cached configuration in the Rust memory of the coordinator runtime.
/// This function should be invoked in the Lua cartridge application with `apply_config()`.
#[no_mangle]
pub extern "C" fn invalidate_coordinator_cache(ctx: FunctionCtx, _: FunctionArgs) -> c_int {
extern "C" fn invalidate_coordinator_cache(ctx: FunctionCtx, _: FunctionArgs) -> c_int {
COORDINATOR_ENGINE.with(|runtime| match runtime.try_borrow() {
Ok(runtime) => {
if let Err(e) = runtime.clear_config() {
......@@ -35,7 +35,7 @@ pub extern "C" fn invalidate_coordinator_cache(ctx: FunctionCtx, _: FunctionArgs
/// Flush cached configuration in the Rust memory of the segment runtime.
/// This function should be invoked in the Lua cartridge application with `apply_config()`.
#[no_mangle]
pub extern "C" fn invalidate_segment_cache(ctx: FunctionCtx, _: FunctionArgs) -> c_int {
extern "C" fn invalidate_segment_cache(ctx: FunctionCtx, _: FunctionArgs) -> c_int {
SEGMENT_ENGINE.with(|runtime| match runtime.try_borrow() {
Ok(runtime) => {
if let Err(e) = runtime.clear_config() {
......
......@@ -226,7 +226,11 @@ impl StorageRuntime {
Ok(result)
}
#[allow(unused_variables)]
/// Executes provided plan.
///
/// # Errors
///
/// Will return `Err` if underlying DML/DQL implementation returns `Err`.
pub fn execute_plan(
&self,
required: &mut RequiredData,
......
mod api;
mod cartridge;
pub mod api;
pub mod cartridge;
......@@ -4,6 +4,12 @@ pub trait ToHashString {
fn to_hash_string(&self) -> String;
}
impl<T: ToHashString> ToHashString for &T {
fn to_hash_string(&self) -> String {
T::to_hash_string(self)
}
}
#[must_use]
/// A simple function to calculate the bucket id from a string slice.
/// `(MurMur3 hash at str) % bucket_count + 1`
......@@ -14,11 +20,14 @@ pub fn str_to_bucket_id(s: &str, bucket_count: u64) -> u64 {
}
#[must_use]
pub fn bucket_id_by_tuple<T>(tuple: &[&T], bucket_count: u64) -> u64
pub fn bucket_id_by_tuple<T>(sharding_val: impl IntoIterator<Item = T>, bucket_count: u64) -> u64
where
T: ToHashString,
{
let hash_str = tuple.iter().map(|v| v.to_hash_string()).collect::<String>();
let hash_str = sharding_val
.into_iter()
.map(|v| v.to_hash_string())
.collect::<String>();
str_to_bucket_id(&hash_str, bucket_count)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment