diff --git a/proxy_components/proxy_ffi/src/interfaces.rs b/proxy_components/proxy_ffi/src/interfaces.rs index b688d62697b..fbdd2fcf173 100644 --- a/proxy_components/proxy_ffi/src/interfaces.rs +++ b/proxy_components/proxy_ffi/src/interfaces.rs @@ -342,6 +342,11 @@ pub mod root { pub apply_state: root::DB::CppStrWithView, pub region: root::DB::CppStrWithView, } + #[repr(u64)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + pub enum ConfigJsonType { + ProxyConfigAddressed = 1, + } #[repr(C)] #[derive(Debug)] pub struct RaftStoreProxyFFIHelper { @@ -462,7 +467,7 @@ pub mod root { pub fn_get_config_json: ::std::option::Option< unsafe extern "C" fn( arg1: root::DB::RaftStoreProxyPtr, - kind: u64, + kind: root::DB::ConfigJsonType, ) -> root::DB::RustStrWithView, >, } @@ -690,7 +695,7 @@ pub mod root { arg3: root::DB::RawVoidPtr, ) -> u32; } - pub const RAFT_STORE_PROXY_VERSION: u64 = 5692329170612304456; + pub const RAFT_STORE_PROXY_VERSION: u64 = 3413295096116791749; pub const RAFT_STORE_PROXY_MAGIC_NUMBER: u32 = 324508639; } } diff --git a/proxy_components/proxy_ffi/src/raftstore_proxy.rs b/proxy_components/proxy_ffi/src/raftstore_proxy.rs index 35989ca4b49..55f2be1a085 100644 --- a/proxy_components/proxy_ffi/src/raftstore_proxy.rs +++ b/proxy_components/proxy_ffi/src/raftstore_proxy.rs @@ -298,7 +298,7 @@ impl RaftStoreProxy { status_server_retry, status_server_retry_limit ); - std::thread::sleep(std::time::Duration::from_millis(1000)); + std::thread::sleep(std::time::Duration::from_millis(3000)); continue; } return false; 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 03df46773a8..3880a4a32ba 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, CppStrVecView, KVGetStatus, RaftProxyStatus, RaftStoreProxyFFIHelper, - RaftStoreProxyPtr, RaftstoreVer, RawCppPtr, RawCppStringPtr, RawRustPtr, RawVoidPtr, - RustStrWithView, SSTReaderInterfaces, + BaseBuffView, ConfigJsonType, CppStrVecView, KVGetStatus, RaftProxyStatus, + RaftStoreProxyFFIHelper, RaftStoreProxyPtr, RaftstoreVer, RawCppPtr, RawCppStringPtr, + RawRustPtr, RawVoidPtr, RustStrWithView, SSTReaderInterfaces, }, read_index_helper, snapshot_reader_impls::*, @@ -302,16 +302,20 @@ pub unsafe extern "C" fn ffi_poll_timer_task(task_ptr: RawVoidPtr, waker: RawVoi pub unsafe extern "C" fn ffi_get_config_json( proxy_ptr: RaftStoreProxyPtr, - _kind: u64, + kind: ConfigJsonType, ) -> RustStrWithView { - let s = proxy_ptr - .as_ref() - .get_proxy_config_str() - .as_bytes() - .to_owned(); - if s.is_empty() { - RustStrWithView::default() - } else { - build_from_string(s) + match kind { + ConfigJsonType::ProxyConfigAddressed => { + let s = proxy_ptr + .as_ref() + .get_proxy_config_str() + .as_bytes() + .to_owned(); + if s.is_empty() { + RustStrWithView::default() + } else { + build_from_string(s) + } + } } } diff --git a/proxy_components/proxy_ffi/src/snapshot_reader_impls/tablet_reader.rs b/proxy_components/proxy_ffi/src/snapshot_reader_impls/tablet_reader.rs index 14af1ba5732..cdbc1a8e77c 100644 --- a/proxy_components/proxy_ffi/src/snapshot_reader_impls/tablet_reader.rs +++ b/proxy_components/proxy_ffi/src/snapshot_reader_impls/tablet_reader.rs @@ -111,7 +111,7 @@ impl TabletReader { let iter = b.as_mut().unwrap(); match et { EngineIteratorSeekType::First => { - let _ = iter.seek_to_first(); + *self.remained.borrow_mut() = iter.seek_to_first().unwrap(); } EngineIteratorSeekType::Last => { let _ = iter.seek_to_last(); diff --git a/proxy_components/proxy_server/src/run.rs b/proxy_components/proxy_server/src/run.rs index 615114c097d..ca2cec2e38e 100644 --- a/proxy_components/proxy_server/src/run.rs +++ b/proxy_components/proxy_server/src/run.rs @@ -123,7 +123,6 @@ pub fn run_impl( engine_store_server_helper: &EngineStoreServerHelper, ) { let (service_event_tx, service_event_rx) = tikv_util::mpsc::unbounded(); // pipe for controling service - let proxy_config_str = serde_json::to_string(&proxy_config).unwrap_or_default(); let engine_store_server_helper_ptr = engine_store_server_helper as *const _ as isize; let mut tikv = TiKvServer::::init( config, @@ -142,6 +141,8 @@ pub fn run_impl( tikv.core.init_yatp(); tikv.core.init_encryption(); + // Use modified `proxy_config` here. + let proxy_config_str = serde_json::to_string(&tikv.proxy_config).unwrap_or_default(); let mut proxy = RaftStoreProxy::new( AtomicU8::new(RaftProxyStatus::Idle as u8), tikv.core.encryption_key_manager.clone(), diff --git a/proxy_tests/proxy/v2_compat/tablet_snapshot.rs b/proxy_tests/proxy/v2_compat/tablet_snapshot.rs index eb9f2c08cbd..5ff84bc2fc1 100644 --- a/proxy_tests/proxy/v2_compat/tablet_snapshot.rs +++ b/proxy_tests/proxy/v2_compat/tablet_snapshot.rs @@ -169,13 +169,33 @@ fn test_get_snapshot_seek() { let cf = ColumnFamilyType::Write; ffi_sst_reader_seek(reader.clone(), cf, EngineIteratorSeekType::Key, bf); let remained = ffi_sst_reader_remained(reader.clone(), cf); - if remained == 1 { - ffi_sst_reader_next(reader.clone(), cf); - let remained = ffi_sst_reader_remained(reader.clone(), cf); - if remained == 1 { - ffi_sst_reader_key(reader.clone(), cf); - } - } + assert_eq!(remained, 0); + } + + unsafe { + let k = format!("k{:06}", 55); + let bf = BaseBuffView { + data: k.as_ptr() as *const _, + len: k.len() as u64, + }; + let cf = ColumnFamilyType::Write; + ffi_sst_reader_seek(reader.clone(), cf, EngineIteratorSeekType::Last, bf); + let remained = ffi_sst_reader_remained(reader.clone(), cf); + assert_eq!(remained, 0); + } + + unsafe { + let k = format!("k{:06}", 55); + let bf = BaseBuffView { + data: k.as_ptr() as *const _, + len: k.len() as u64, + }; + let cf = ColumnFamilyType::Write; + ffi_sst_reader_seek(reader.clone(), cf, EngineIteratorSeekType::First, bf); + let remained = ffi_sst_reader_remained(reader.clone(), cf); + assert_eq!(remained, 1); + let kbf = ffi_sst_reader_key(reader.clone(), cf); + assert_eq!(kbf.to_slice(), format!("k{:06}", 0).as_bytes()); } cluster_v1.shutdown(); diff --git a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version index a4bd39e8ae5..21eddea6cfc 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 = 5692329170612304456ull; } \ No newline at end of file +namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 3413295096116791749ull; } diff --git a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h index 126e187d35e..da9236abc79 100644 --- a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h +++ b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h @@ -233,6 +233,8 @@ struct FastAddPeerRes { CppStrWithView region; }; +enum class ConfigJsonType : uint64_t { ProxyConfigAddressed = 1 }; + struct RaftStoreProxyFFIHelper { RaftStoreProxyPtr proxy_ptr; RaftProxyStatus (*fn_handle_get_proxy_status)(RaftStoreProxyPtr); @@ -268,7 +270,7 @@ struct RaftStoreProxyFFIHelper { void (*fn_notify_compact_log)(RaftStoreProxyPtr, uint64_t region_id, uint64_t compact_index, uint64_t compact_term, uint64_t applied_index); - RustStrWithView (*fn_get_config_json)(RaftStoreProxyPtr, uint64_t kind); + RustStrWithView (*fn_get_config_json)(RaftStoreProxyPtr, ConfigJsonType kind); }; struct PageStorageInterfaces {