From 23baffcd12a4b98ebdc4b23f3e7b57f509914e85 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger <60744015+Lloyd-Pottiger@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:06:36 +0800 Subject: [PATCH] FFI: add two empty implement FFI for compatibility (#361) * FFI: add two empty implement FFI Signed-off-by: Lloyd-Pottiger * add description Signed-off-by: Lloyd-Pottiger * move into a struct Signed-off-by: Lloyd-Pottiger * move to CloudStorageEngineInterfaces Signed-off-by: Lloyd-Pottiger * fmt Signed-off-by: Lloyd-Pottiger * update version Signed-off-by: Lloyd-Pottiger * f Signed-off-by: Lloyd-Pottiger * f Signed-off-by: Lloyd-Pottiger * update version Signed-off-by: Lloyd-Pottiger --------- Signed-off-by: Lloyd-Pottiger --- .../proxy_ffi/src/encryption_impls.rs | 19 +++++++++++++++++++ proxy_components/proxy_ffi/src/interfaces.rs | 15 ++++++++++++++- .../src/raftstore_proxy_helper_impls.rs | 12 +++++++++--- .../ffi/src/RaftStoreProxyFFI/@version | 2 +- .../ffi/src/RaftStoreProxyFFI/ProxyFFI.h | 6 ++++++ 5 files changed, 49 insertions(+), 5 deletions(-) diff --git a/proxy_components/proxy_ffi/src/encryption_impls.rs b/proxy_components/proxy_ffi/src/encryption_impls.rs index d45f4e453ad..42974856336 100644 --- a/proxy_components/proxy_ffi/src/encryption_impls.rs +++ b/proxy_components/proxy_ffi/src/encryption_impls.rs @@ -166,3 +166,22 @@ pub extern "C" fn ffi_handle_link_file( ) } } + +// The CloudStorageEngineFFI contains dummy implementation of +// CloudStorageEngine-specific FFI, not used, just for tiflash compilation. +pub struct CloudStorageEngineFFI {} + +impl CloudStorageEngineFFI { + // always return false + pub extern "C" fn ffi_get_keyspace_encryption( + _proxy_ptr: RaftStoreProxyPtr, + _keyspace_id: u32, + ) -> bool { + false + } + + // always return empty string + pub extern "C" fn ffi_get_master_key(_proxy_ptr: RaftStoreProxyPtr) -> RawCppStringPtr { + get_engine_store_server_helper().gen_cpp_string(b"") + } +} diff --git a/proxy_components/proxy_ffi/src/interfaces.rs b/proxy_components/proxy_ffi/src/interfaces.rs index eeab1c45644..781fd4a7c81 100644 --- a/proxy_components/proxy_ffi/src/interfaces.rs +++ b/proxy_components/proxy_ffi/src/interfaces.rs @@ -311,6 +311,18 @@ pub mod root { ) -> root::DB::RustStrWithViewVec, >, } + #[repr(C)] + #[derive(Debug)] + pub struct CloudStorageEngineInterfaces { + pub fn_get_keyspace_encryption: ::std::option::Option< + unsafe extern "C" fn(arg1: root::DB::RaftStoreProxyPtr, arg2: u32) -> bool, + >, + pub fn_get_master_key: ::std::option::Option< + unsafe extern "C" fn( + arg1: root::DB::RaftStoreProxyPtr, + ) -> root::DB::RawCppStringPtr, + >, + } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MsgPBType { @@ -420,6 +432,7 @@ pub mod root { ), >, pub sst_reader_interfaces: root::DB::SSTReaderInterfaces, + pub cloud_storage_engine_interfaces: root::DB::CloudStorageEngineInterfaces, pub fn_server_info: ::std::option::Option< unsafe extern "C" fn( arg1: root::DB::RaftStoreProxyPtr, @@ -741,7 +754,7 @@ pub mod root { arg3: root::DB::RawVoidPtr, ) -> u32; } - pub const RAFT_STORE_PROXY_VERSION: u64 = 5455550920944837743; + pub const RAFT_STORE_PROXY_VERSION: u64 = 3560036848329077111; pub const RAFT_STORE_PROXY_MAGIC_NUMBER: u32 = 324508639; } } diff --git a/proxy_components/proxy_ffi/src/raftstore_proxy_helper_impls.rs b/proxy_components/proxy_ffi/src/raftstore_proxy_helper_impls.rs index 3880a4a32ba..1ae277abe95 100644 --- a/proxy_components/proxy_ffi/src/raftstore_proxy_helper_impls.rs +++ b/proxy_components/proxy_ffi/src/raftstore_proxy_helper_impls.rs @@ -20,9 +20,9 @@ use super::{ encryption_impls::*, engine_store_helper_impls::*, interfaces_ffi::{ - BaseBuffView, ConfigJsonType, CppStrVecView, KVGetStatus, RaftProxyStatus, - RaftStoreProxyFFIHelper, RaftStoreProxyPtr, RaftstoreVer, RawCppPtr, RawCppStringPtr, - RawRustPtr, RawVoidPtr, RustStrWithView, SSTReaderInterfaces, + BaseBuffView, CloudStorageEngineInterfaces, ConfigJsonType, CppStrVecView, KVGetStatus, + RaftProxyStatus, RaftStoreProxyFFIHelper, RaftStoreProxyPtr, RaftstoreVer, RawCppPtr, + RawCppStringPtr, RawRustPtr, RawVoidPtr, RustStrWithView, SSTReaderInterfaces, }, read_index_helper, snapshot_reader_impls::*, @@ -78,6 +78,12 @@ impl RaftStoreProxyFFIHelper { fn_approx_size: Some(ffi_approx_size), fn_get_split_keys: Some(ffi_get_split_keys), }, + cloud_storage_engine_interfaces: CloudStorageEngineInterfaces { + fn_get_keyspace_encryption: Some( + CloudStorageEngineFFI::ffi_get_keyspace_encryption, + ), + fn_get_master_key: Some(CloudStorageEngineFFI::ffi_get_master_key), + }, fn_server_info: None, fn_make_read_index_task: Some(ffi_make_read_index_task), fn_make_async_waker: Some(ffi_make_async_waker), diff --git a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version index c8dce432c72..b79f8a14aab 100644 --- a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version +++ b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version @@ -1,3 +1,3 @@ #pragma once #include -namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 5455550920944837743ull; } \ No newline at end of file +namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 3560036848329077111ull; } \ No newline at end of file diff --git a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h index 5e30dfec8c0..f0a095dfdae 100644 --- a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h +++ b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h @@ -206,6 +206,11 @@ struct SSTReaderInterfaces { RustStrWithViewVec (*fn_get_split_keys)(SSTReaderPtr, uint64_t splits_count); }; +struct CloudStorageEngineInterfaces { + bool (*fn_get_keyspace_encryption)(RaftStoreProxyPtr, uint32_t); + RawCppStringPtr (*fn_get_master_key)(RaftStoreProxyPtr); +}; + enum class MsgPBType : uint32_t { ReadIndexResponse = 0, ServerInfoResponse, @@ -264,6 +269,7 @@ struct RaftStoreProxyFFIHelper { void (*fn_insert_batch_read_index_resp)(RawVoidPtr, BaseBuffView, uint64_t)); // To remove SSTReaderInterfaces sst_reader_interfaces; + CloudStorageEngineInterfaces cloud_storage_engine_interfaces; uint32_t (*fn_server_info)(RaftStoreProxyPtr, BaseBuffView, RawVoidPtr); RawRustPtr (*fn_make_read_index_task)(RaftStoreProxyPtr, BaseBuffView);