Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
Signed-off-by: Calvin Neo <[email protected]>
  • Loading branch information
CalvinNeo committed Sep 14, 2024
1 parent 32ce500 commit e99cb8f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
10 changes: 6 additions & 4 deletions proxy_components/engine_store_ffi/src/core/fast_add_peer.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down Expand Up @@ -439,7 +439,8 @@ impl<T: Transport + 'static, ER: RaftEngine> ProxyForwarder<T, ER> {
"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 => {
Expand Down Expand Up @@ -517,6 +518,7 @@ impl<T: Transport + 'static, ER: RaftEngine> ProxyForwarder<T, ER> {
msg: &RaftMessage,
apply_state: RaftApplyState,
new_region: kvproto::metapb::Region,
serverless_extra: ServerlessExtra,
) -> RaftStoreResult<FastAddPeerStatus> {
let cached_manager = self.get_cached_manager();
let inner_msg = msg.get_message();
Expand Down Expand Up @@ -623,8 +625,8 @@ impl<T: Transport + 'static, ER: RaftEngine> ProxyForwarder<T, ER> {
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
);

Expand Down
1 change: 1 addition & 0 deletions proxy_components/engine_store_ffi/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
60 changes: 60 additions & 0 deletions proxy_components/engine_store_ffi/src/core/serverless_extra.rs
Original file line number Diff line number Diff line change
@@ -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<u8>,
enc_key: Vec<u8>,
txn_file_ref: Vec<u8>,
}

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
}
}
6 changes: 5 additions & 1 deletion proxy_components/proxy_ffi/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
}
}
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 = 9679186549381427051ull; }
namespace DB { constexpr uint64_t RAFT_STORE_PROXY_VERSION = 2149052863435660119ull; }
4 changes: 4 additions & 0 deletions raftstore-proxy/ffi/src/RaftStoreProxyFFI/ProxyFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e99cb8f

Please sign in to comment.