Skip to content

Commit

Permalink
pick fn_get_lock_key (#364)
Browse files Browse the repository at this point in the history
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
  • Loading branch information
CalvinNeo authored Jan 17, 2024
1 parent fabe2d6 commit 04e2be4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ pub fn gen_engine_store_server_helper(
fn_set_pb_msg_by_bytes: Some(ffi_set_pb_msg_by_bytes),
fn_handle_safe_ts_update: Some(ffi_handle_safe_ts_update),
fn_fast_add_peer: Some(ffi_fast_add_peer),
fn_get_lock_by_key: Some(ffi_get_lock_by_key),
fn_apply_fap_snapshot: Some(ffi_apply_fap_snapshot),
fn_query_fap_snapshot_state: Some(ffi_query_fap_snapshot_state),
fn_kvstore_region_exists: Some(ffi_kvstore_region_exists),
Expand Down Expand Up @@ -586,3 +587,25 @@ unsafe extern "C" fn ffi_handle_compute_store_stats(
engine_keys_read: 0,
}
}

unsafe extern "C" fn ffi_get_lock_by_key(
arg1: *const interfaces_ffi::EngineStoreServerWrap,
region_id: u64,
key: interfaces_ffi::BaseBuffView,
) -> interfaces_ffi::BaseBuffView {
let store = into_engine_store_server_wrap(arg1);
match (*store.engine_store_server).kvstore.get(&region_id) {
Some(e) => {
let cf_index = interfaces_ffi::ColumnFamilyType::Lock as usize;
let value = e.data[cf_index].get(key.to_slice()).unwrap().as_ptr();
interfaces_ffi::BaseBuffView {
data: value as *const i8,
len: 0,
}
}
None => interfaces_ffi::BaseBuffView {
data: std::ptr::null(),
len: 0,
},
}
}
6 changes: 6 additions & 0 deletions proxy_components/proxy_ffi/src/engine_store_helper_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ impl EngineStoreServerHelper {
debug_assert!(self.fn_fast_add_peer.is_some());
unsafe { (self.fn_fast_add_peer.into_inner())(self.inner, region_id, new_peer_id) }
}

pub fn get_lock_by_key(&self, region_id: u64, key: &[u8]) -> Vec<u8> {
unsafe { (self.fn_get_lock_by_key.into_inner())(self.inner, region_id, key.into()) }
.to_slice()
.to_vec()
}
}

// PageStorage specific
Expand Down
9 changes: 8 additions & 1 deletion proxy_components/proxy_ffi/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,13 @@ pub mod root {
new_peer_id: u64,
) -> root::DB::FastAddPeerRes,
>,
pub fn_get_lock_by_key: ::std::option::Option<
unsafe extern "C" fn(
arg1: *const root::DB::EngineStoreServerWrap,
arg2: u64,
arg3: root::DB::BaseBuffView,
) -> root::DB::BaseBuffView,
>,
pub fn_query_fap_snapshot_state: ::std::option::Option<
unsafe extern "C" fn(
arg1: *mut root::DB::EngineStoreServerWrap,
Expand All @@ -734,7 +741,7 @@ pub mod root {
arg3: root::DB::RawVoidPtr,
) -> u32;
}
pub const RAFT_STORE_PROXY_VERSION: u64 = 14498963167462351742;
pub const RAFT_STORE_PROXY_VERSION: u64 = 5455550920944837743;
pub const RAFT_STORE_PROXY_MAGIC_NUMBER: u32 = 324508639;
}
}
2 changes: 1 addition & 1 deletion raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once
#include <cstdint>
namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 14498963167462351742ull; }
namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 5455550920944837743ull; }
2 changes: 2 additions & 0 deletions raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ struct EngineStoreServerHelper {
uint64_t leader_safe_ts);
FastAddPeerRes (*fn_fast_add_peer)(EngineStoreServerWrap *,
uint64_t region_id, uint64_t new_peer_id);
BaseBuffView (*fn_get_lock_by_key)(const EngineStoreServerWrap *, uint64_t,
BaseBuffView);
FapSnapshotState (*fn_query_fap_snapshot_state)(EngineStoreServerWrap *,
uint64_t region_id,
uint64_t new_peer_id);
Expand Down

0 comments on commit 04e2be4

Please sign in to comment.