Skip to content

Commit

Permalink
Fix fn_get_config_json (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinNeo authored Oct 12, 2023
1 parent 28583d7 commit 521fd9d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 27 deletions.
9 changes: 7 additions & 2 deletions proxy_components/proxy_ffi/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
>,
}
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion proxy_components/proxy_ffi/src/raftstore_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 17 additions & 13 deletions proxy_components/proxy_ffi/src/raftstore_proxy_helper_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion proxy_components/proxy_server/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ pub fn run_impl<CER: ConfiguredRaftEngine, F: KvFormat>(
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::<CER, F>::init(
config,
Expand All @@ -142,6 +141,8 @@ pub fn run_impl<CER: ConfiguredRaftEngine, F: KvFormat>(
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(),
Expand Down
34 changes: 27 additions & 7 deletions proxy_tests/proxy/v2_compat/tablet_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
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 = 5692329170612304456ull; }
namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 3413295096116791749ull; }
4 changes: 3 additions & 1 deletion raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 521fd9d

Please sign in to comment.