From 601d803562cde9a7fe8d17120d073aea55ae1012 Mon Sep 17 00:00:00 2001 From: guo-shaoge Date: Thu, 1 Jun 2023 12:58:11 +0800 Subject: [PATCH] support fetch server_info without starting Proxy (#330) * support fetch server_info without starting Proxy Signed-off-by: guo-shaoge --- proxy_components/proxy_ffi/src/interfaces.rs | 9 +++++- proxy_components/proxy_server/src/util.rs | 31 ++++++++++++++++++- .../ffi/src/RaftStoreProxyFFI/@version | 2 +- .../ffi/src/RaftStoreProxyFFI/ProxyFFI.h | 11 +++++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/proxy_components/proxy_ffi/src/interfaces.rs b/proxy_components/proxy_ffi/src/interfaces.rs index 3f0e965e7c5..f457f3c79ac 100644 --- a/proxy_components/proxy_ffi/src/interfaces.rs +++ b/proxy_components/proxy_ffi/src/interfaces.rs @@ -613,7 +613,14 @@ pub mod root { ) -> root::DB::FastAddPeerRes, >, } - pub const RAFT_STORE_PROXY_VERSION: u64 = 3617226644007633432; + extern "C" { + pub fn ffi_get_server_info_from_proxy( + arg1: isize, + arg2: root::DB::BaseBuffView, + arg3: root::DB::RawVoidPtr, + ) -> u32; + } + pub const RAFT_STORE_PROXY_VERSION: u64 = 17823293661468169526; pub const RAFT_STORE_PROXY_MAGIC_NUMBER: u32 = 324508639; } } diff --git a/proxy_components/proxy_server/src/util.rs b/proxy_components/proxy_server/src/util.rs index c00d196696a..1a5158ae335 100644 --- a/proxy_components/proxy_server/src/util.rs +++ b/proxy_components/proxy_server/src/util.rs @@ -1,6 +1,9 @@ // Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. -use std::time::{Duration, Instant}; +use std::{ + pin::Pin, + time::{Duration, Instant}, +}; use engine_store_ffi::ffi::interfaces_ffi::{BaseBuffView, RaftStoreProxyPtr, RawVoidPtr}; use futures::{compat::Future01CompatExt, executor::block_on}; @@ -74,3 +77,29 @@ pub extern "C" fn ffi_server_info( engine_store_ffi::ffi::set_server_info_resp(&resp, res); 0 } + +#[no_mangle] +pub extern "C" fn ffi_get_server_info_from_proxy( + server_helper_ptr: isize, + view: BaseBuffView, + res: RawVoidPtr, +) -> u32 { + assert_ne!(server_helper_ptr, 0); + let mut req = ServerInfoRequest::default(); + assert_ne!(view.data, std::ptr::null()); + assert_ne!(view.len, 0); + req.merge_from_bytes(view.to_slice()).unwrap(); + + let resp = server_info_for_ffi(req); + let buff = engine_store_ffi::ffi::ProtoMsgBaseBuff::new(&resp); + unsafe { + let server_helper = &(*(server_helper_ptr + as *const engine_store_ffi::ffi::interfaces_ffi::EngineStoreServerHelper)); + server_helper.set_pb_msg_by_bytes( + engine_store_ffi::ffi::interfaces_ffi::MsgPBType::ServerInfoResponse, + res, + Pin::new(&buff).into(), + ); + } + 0 +} diff --git a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version index 98d5effe612..87cb8441a06 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 = 3617226644007633432ull; } \ No newline at end of file +namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 17823293661468169526ull; } \ 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 22558455e47..dd2b9498d51 100644 --- a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h +++ b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h @@ -304,4 +304,15 @@ struct EngineStoreServerHelper { FastAddPeerRes (*fn_fast_add_peer)(EngineStoreServerWrap *, uint64_t region_id, uint64_t new_peer_id); }; + +#ifdef __cplusplus +extern "C" { +#endif +// Basically same as ffi_server_info, but no need to setup ProxyHelper, only +// need to setup ServerHelper. Used when proxy not start. +uint32_t ffi_get_server_info_from_proxy(intptr_t, BaseBuffView, RawVoidPtr); +#ifdef __cplusplus +} +#endif + } // namespace DB