Skip to content

Commit

Permalink
support fetch server_info without starting Proxy (#330)
Browse files Browse the repository at this point in the history
* support fetch server_info without starting Proxy

Signed-off-by: guo-shaoge <[email protected]>
  • Loading branch information
guo-shaoge authored Jun 1, 2023
1 parent 70da4cc commit 601d803
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
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 @@ -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;
}
}
31 changes: 30 additions & 1 deletion proxy_components/proxy_server/src/util.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
}
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 = 3617226644007633432ull; }
namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 17823293661468169526ull; }
11 changes: 11 additions & 0 deletions raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 601d803

Please sign in to comment.