Skip to content

Commit

Permalink
Merge pull request #262 from CalvinNeo/merge-tikv-release-6.6-2
Browse files Browse the repository at this point in the history
Merge master about 6.6(7ec73fd)
  • Loading branch information
CalvinNeo authored Jan 31, 2023
2 parents 453b9df + fc18cfa commit 6444536
Show file tree
Hide file tree
Showing 220 changed files with 9,945 additions and 3,556 deletions.
136 changes: 88 additions & 48 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ raftstore = { workspace = true, features = ["engine_rocks"] }
raftstore-v2 = { workspace = true }
rand = "0.7.3"
regex = "1.3"
resource_control = { workspace = true }
resource_metering = { workspace = true }
rev_lines = "0.2.1"
seahash = "4.1.0"
Expand Down Expand Up @@ -266,6 +267,7 @@ members = [
"components/raftstore",
"components/raftstore-v2",
"components/resolved_ts",
"components/resource_control",
"components/resource_metering",
"components/security",
"components/server",
Expand Down Expand Up @@ -344,6 +346,7 @@ raft_log_engine = { path = "components/raft_log_engine" }
raftstore = { path = "components/raftstore", default-features = false }
raftstore-v2 = { path = "components/raftstore-v2", default-features = false }
resolved_ts = { path = "components/resolved_ts" }
resource_control = { path = "components/resource_control" }
resource_metering = { path = "components/resource_metering" }
security = { path = "components/security" }
server = { path = "components/server" }
Expand Down
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ RUN ln -s /usr/bin/cmake3 /usr/bin/cmake
ENV LIBRARY_PATH /usr/local/lib:$LIBRARY_PATH
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH

# Install protoc
RUN curl -LO "https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip"
RUN unzip protoc-3.15.8-linux-x86_64.zip -d /usr/local/
ENV PATH /usr/local/bin/:$PATH

# Install Rustup
RUN curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path --default-toolchain none -y
ENV PATH /root/.cargo/bin/:$PATH
Expand All @@ -72,8 +77,7 @@ RUN mkdir -p ./cmd/tikv-ctl/src ./cmd/tikv-server/src && \
echo 'fn main() {}' > ./cmd/tikv-ctl/src/main.rs && \
echo 'fn main() {}' > ./cmd/tikv-server/src/main.rs && \
for cargotoml in $(find . -type f -name "Cargo.toml"); do \
sed -i '/fuzz/d' ${cargotoml} && \
sed -i '/profiler/d' ${cargotoml} ; \
sed -i '/fuzz/d' ${cargotoml} ; \
done

COPY Makefile ./
Expand Down Expand Up @@ -105,8 +109,9 @@ FROM pingcap/alpine-glibc
COPY --from=builder /tikv/target/release/tikv-server /tikv-server
COPY --from=builder /tikv/target/release/tikv-ctl /tikv-ctl

# FIXME: Figure out why libstdc++ is not staticly linked.
RUN apk add --no-cache \
curl
curl libstdc++

EXPOSE 20160 20180

Expand Down
4 changes: 3 additions & 1 deletion cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ fn link_sys_lib(lib: &str, tool: &cc::Tool) {
}
// remove lib prefix and .a postfix.
let libname = &lib[3..lib.len() - 2];
println!("cargo:rustc-link-lib=static:+whole-archive={}", &libname);
// Get around the issue "the linking modifiers `+bundle` and `+whole-archive`
// are not compatible with each other when generating rlibs"
println!("cargo:rustc-link-lib=static:-bundle,+whole-archive={}", &libname);
println!(
"cargo:rustc-link-search=native={}",
path.parent().unwrap().display()
Expand Down
1 change: 1 addition & 0 deletions components/api_version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bitflags = "1.0.1"
codec = { workspace = true }
engine_traits = { workspace = true }
kvproto = { workspace = true }
log_wrappers = { workspace = true }
match-template = "0.0.1"
thiserror = "1.0"
tikv_alloc = { workspace = true }
Expand Down
163 changes: 163 additions & 0 deletions components/api_version/src/keyspace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
use std::fmt::Debug;

use engine_traits::{Error, Result};
use tikv_util::box_err;

use super::*;

const KEYSPACE_PREFIX_LEN: usize = 4;

pub trait KvPair {
fn key(&self) -> &[u8];
fn value(&self) -> &[u8];
fn kv(&self) -> (&[u8], &[u8]) {
(self.key(), self.value())
}
}

impl KvPair for (Vec<u8>, Vec<u8>) {
fn key(&self) -> &[u8] {
&self.0
}
fn value(&self) -> &[u8] {
&self.1
}
}

pub trait Keyspace {
type KvPair: KvPair = (Vec<u8>, Vec<u8>);
fn make_kv_pair(p: (Vec<u8>, Vec<u8>)) -> Result<Self::KvPair>;
fn parse_keyspace(key: &[u8]) -> Result<(Option<KeyspaceId>, &[u8])> {
Ok((None, key))
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub struct KeyspaceId(u32);

impl From<u32> for KeyspaceId {
fn from(id: u32) -> Self {
Self(id)
}
}

impl Keyspace for ApiV1 {
fn make_kv_pair(p: (Vec<u8>, Vec<u8>)) -> Result<Self::KvPair> {
Ok(p)
}
}

impl Keyspace for ApiV1Ttl {
fn make_kv_pair(p: (Vec<u8>, Vec<u8>)) -> Result<Self::KvPair> {
Ok(p)
}
}

impl Keyspace for ApiV2 {
type KvPair = KeyspaceKv;

fn make_kv_pair(p: (Vec<u8>, Vec<u8>)) -> Result<Self::KvPair> {
let (k, v) = p;
let (keyspace, _) = Self::parse_keyspace(&k)?;
Ok(KeyspaceKv {
k,
v,
keyspace: keyspace.unwrap(),
})
}

fn parse_keyspace(key: &[u8]) -> Result<(Option<KeyspaceId>, &[u8])> {
let mode = ApiV2::parse_key_mode(key);
if key.len() < KEYSPACE_PREFIX_LEN || (mode != KeyMode::Raw && mode != KeyMode::Txn) {
return Err(Error::Other(box_err!(
"invalid API V2 key: {}",
log_wrappers::Value(key)
)));
}
let id = u32::from_be_bytes([0, key[1], key[2], key[3]]);
Ok((Some(KeyspaceId::from(id)), &key[KEYSPACE_PREFIX_LEN..]))
}
}

pub struct KeyspaceKv {
k: Vec<u8>,
v: Vec<u8>,
keyspace: KeyspaceId,
}

impl KvPair for KeyspaceKv {
fn key(&self) -> &[u8] {
&self.k[KEYSPACE_PREFIX_LEN..]
}

fn value(&self) -> &[u8] {
&self.v
}
}

impl KeyspaceKv {
pub fn keyspace(&self) -> KeyspaceId {
self.keyspace
}
}

impl PartialEq<(Vec<u8>, Vec<u8>)> for KeyspaceKv {
fn eq(&self, other: &(Vec<u8>, Vec<u8>)) -> bool {
self.kv() == (&other.0, &other.1)
}
}

impl PartialEq for KeyspaceKv {
fn eq(&self, other: &Self) -> bool {
self.k == other.k && self.v == other.v
}
}

impl Debug for KeyspaceKv {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("KeyspaceKv")
.field("key", &log_wrappers::Value(self.key()))
.field("value", &log_wrappers::Value(self.value()))
.field("keyspace", &self.keyspace())
.finish()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_v1_parse_keyspace() {
let k = b"t123_111";
let (keyspace, key) = ApiV1::parse_keyspace(k).unwrap();
assert_eq!(None, keyspace);
assert_eq!(k, key);

let (keyspace, key) = ApiV1Ttl::parse_keyspace(k).unwrap();
assert_eq!(None, keyspace);
assert_eq!(k, key);
}

#[test]
fn test_v2_parse_keyspace() {
let ok = vec![
(b"x\x00\x00\x01t123_114", 1, b"t123_114"),
(b"r\x00\x00\x01t123_112", 1, b"t123_112"),
(b"x\x01\x00\x00t213_112", 0x010000, b"t213_112"),
(b"r\x01\x00\x00t123_113", 0x010000, b"t123_113"),
];

for (key, id, user_key) in ok {
let (keyspace, key) = ApiV2::parse_keyspace(key).unwrap();
assert_eq!(Some(KeyspaceId::from(id)), keyspace);
assert_eq!(user_key, key);
}

let err: Vec<&[u8]> = vec![b"t123_111", b"s\x00\x00", b"r\x00\x00"];

for key in err {
ApiV2::parse_keyspace(key).unwrap_err();
}
}
}
6 changes: 5 additions & 1 deletion components/api_version/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.

#![feature(min_specialization)]
#![feature(associated_type_defaults)]

mod api_v1;
mod api_v1ttl;
pub mod api_v2;
pub mod keyspace;

use engine_traits::Result;
use kvproto::kvrpcpb::ApiVersion;
pub use match_template::match_template;
use txn_types::{Key, TimeStamp};

pub trait KvFormat: Clone + Copy + 'static + Send + Sync {
use crate::keyspace::Keyspace;

pub trait KvFormat: Keyspace + Clone + Copy + 'static + Send + Sync {
const TAG: ApiVersion;
/// Corresponding TAG of client requests. For test only.
#[cfg(any(test, feature = "testexport"))]
Expand Down
Loading

0 comments on commit 6444536

Please sign in to comment.