diff --git a/proxy_components/engine_store_ffi/src/core/fast_add_peer.rs b/proxy_components/engine_store_ffi/src/core/fast_add_peer.rs index 49d201ba7cd..76989fcb9c7 100644 --- a/proxy_components/engine_store_ffi/src/core/fast_add_peer.rs +++ b/proxy_components/engine_store_ffi/src/core/fast_add_peer.rs @@ -1,6 +1,6 @@ // Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. use crate::{ - core::{common::*, ProxyForwarder}, + core::{common::*, serverless_extra::*, ProxyForwarder}, ffi::interfaces_ffi::FastAddPeerStatus, }; @@ -439,7 +439,8 @@ impl ProxyForwarder { "new_region" => ?new_region, "apply_state" => ?apply_state, ); - match self.build_and_send_snapshot(region_id, new_peer_id, msg, apply_state, new_region) { + let serverless_extra = ServerlessExtra::new(&res); + match self.build_and_send_snapshot(region_id, new_peer_id, msg, apply_state, new_region, serverless_extra) { Ok(s) => { match s { FastAddPeerStatus::Ok => { @@ -517,6 +518,7 @@ impl ProxyForwarder { msg: &RaftMessage, apply_state: RaftApplyState, new_region: kvproto::metapb::Region, + serverless_extra: ServerlessExtra, ) -> RaftStoreResult { let cached_manager = self.get_cached_manager(); let inner_msg = msg.get_message(); @@ -623,8 +625,8 @@ impl ProxyForwarder { pb_snapshot_metadata.set_term(key.term); } - debug!( - "pb_snapshot_data {:?} pb_snapshot_metadata {:?}", + info!( + "fast path: pb_snapshot_data {:?} pb_snapshot_metadata {:?}", pb_snapshot_data, pb_snapshot_metadata ); diff --git a/proxy_components/engine_store_ffi/src/core/mod.rs b/proxy_components/engine_store_ffi/src/core/mod.rs index b60e037304a..81e0b0ddf23 100644 --- a/proxy_components/engine_store_ffi/src/core/mod.rs +++ b/proxy_components/engine_store_ffi/src/core/mod.rs @@ -4,6 +4,7 @@ pub(crate) mod common; pub mod fast_add_peer; pub mod forward_raft; pub mod forwarder; +pub mod serverless_extra; pub use fast_add_peer::*; pub use forward_raft::*; diff --git a/proxy_components/engine_store_ffi/src/core/serverless_extra.rs b/proxy_components/engine_store_ffi/src/core/serverless_extra.rs new file mode 100644 index 00000000000..5a3875e2003 --- /dev/null +++ b/proxy_components/engine_store_ffi/src/core/serverless_extra.rs @@ -0,0 +1,60 @@ +// Copyright 2024 TiKV Project Authors. Licensed under Apache-2.0. + +use std::convert::TryInto; + +use crate::{ + core::common::*, + ffi::interfaces_ffi::{FastAddPeerRes, FastAddPeerStatus}, +}; + +pub struct ServerlessExtra { + shard_ver: u64, + inner_key: Vec, + enc_key: Vec, + txn_file_ref: Vec, +} + +impl ServerlessExtra { + // TODO TXN_FILE_REF + pub fn new(res: &FastAddPeerRes) -> Self { + Self { + shard_ver: res.shard_ver, + inner_key: res.inner_key.view.to_slice().to_vec(), + enc_key: res.enc_key.view.to_slice().to_vec(), + txn_file_ref: res.txn_file_ref.view.to_slice().to_vec(), + } + } + + pub fn mutate_snap(&self, shard_id: u64, changeset: &mut kvenginepb::ChangeSet) { + let snap = changeset.mut_snapshot(); + { + let props = kvengine::Properties::default(); + props.set(kvengine::ENCRYPTION_KEY, self.get_enc_key()); + props.set(kvengine::TXN_FILE_REF, self.get_txn_file_ref()); + snap.set_properties(props.to_pb(shard_id)); + snap.set_inner_key_off(self.get_inner_key_off()); + } + changeset.set_shard_ver(self.get_shard_ver()); + } + + fn get_shard_ver(&self) -> u64 { + self.shard_ver + } + + fn get_inner_key_off(&self) -> u32 { + if self.inner_key.len() < 4 { + info!("fast path: get error inner key {:?}", self.inner_key); + return 0; + } + u32::from_be_bytes(self.inner_key[0..4].try_into().unwrap()) + } + + fn get_enc_key(&self) -> &[u8] { + &self.enc_key + } + + fn get_txn_file_ref(&self) -> &[u8] { + // load_peer_txn_file_locks + &self.txn_file_ref + } +} \ No newline at end of file diff --git a/proxy_components/proxy_ffi/src/interfaces.rs b/proxy_components/proxy_ffi/src/interfaces.rs index ca2e9337c6f..4b87b425fd8 100644 --- a/proxy_components/proxy_ffi/src/interfaces.rs +++ b/proxy_components/proxy_ffi/src/interfaces.rs @@ -361,6 +361,10 @@ pub mod root { pub status: root::DB::FastAddPeerStatus, pub apply_state: root::DB::CppStrWithView, pub region: root::DB::CppStrWithView, + pub shard_ver: u64, + pub inner_key: root::DB::CppStrWithView, + pub enc_key: root::DB::CppStrWithView, + pub txn_file_ref: root::DB::CppStrWithView, } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -789,7 +793,7 @@ pub mod root { arg3: root::DB::RawVoidPtr, ) -> u32; } - pub const RAFT_STORE_PROXY_VERSION: u64 = 9679186549381427051; + pub const RAFT_STORE_PROXY_VERSION: u64 = 2149052863435660119; pub const RAFT_STORE_PROXY_MAGIC_NUMBER: u32 = 324508639; } } diff --git a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/@version index 59c3d0bca37..10aed53e70b 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 = 9679186549381427051ull; } \ No newline at end of file +namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 2149052863435660119ull; } \ 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 3dd1feba12a..5a3cbaf4817 100644 --- a/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h +++ b/raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h @@ -243,6 +243,10 @@ struct FastAddPeerRes { FastAddPeerStatus status; CppStrWithView apply_state; CppStrWithView region; + uint64_t shard_ver; + CppStrWithView inner_key; + CppStrWithView enc_key; + CppStrWithView txn_file_ref; }; enum class FapSnapshotState : uint32_t {