Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- cse
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
Expand Down Expand Up @@ -52,8 +53,13 @@ jobs:

integration-test:
name: integration test
strategy:
fail-fast: false
matrix:
case: ["integration-test-txn", "integration-test-raw"]
env:
CARGO_INCREMENTAL: 0
TIKV_VERSION: v7.5.5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -69,14 +75,22 @@ jobs:
- name: start tiup playground
run: |
# use latest stable version
~/.tiup/bin/tiup install tikv pd
~/.tiup/bin/tiup playground --mode tikv-slim --kv 3 --without-monitor --kv.config config/tikv.toml --pd.config config/pd.toml &
~/.tiup/bin/tiup install tikv:${{ env.TIKV_VERSION }} pd:${{ env.TIKV_VERSION }}
~/.tiup/bin/tiup playground ${{ env.TIKV_VERSION }} --mode tikv-slim --kv 3 --tag cluster --without-monitor --kv.config config/tikv.toml --pd.config config/pd.toml &
while :; do
echo "waiting cluster to be ready"
[[ "$(curl -I http://127.0.0.1:2379/pd/api/v1/regions 2>/dev/null | head -n 1 | cut -d$' ' -f2)" -ne "405" ]] || break
sleep 1
done
- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: integration test
run: MULTI_REGION=1 make integration-test
- name: Integration test
run: MULTI_REGION=1 make ${{ matrix.case }}
- name: Upload logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: cluster-logs
path: |
~/.tiup/data/cluster/tikv*/*.log
~/.tiup/data/cluster/pd*/*.log
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ clap = "2"
env_logger = "0.10"
fail = { version = "0.4", features = ["failpoints"] }
proptest = "1"
proptest-derive = "0.3"
proptest-derive = "0.5.1"
reqwest = { version = "0.11", default-features = false, features = [
"native-tls-vendored",
] }
Expand Down
21 changes: 14 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
export RUSTFLAGS=-Dwarnings

.PHONY: default check unit-test integration-tests test doc docker-pd docker-kv docker all
.PHONY: default check unit-test generate integration-tests integration-tests-txn integration-tests-raw test doc docker-pd docker-kv docker all

export PD_ADDRS ?= 127.0.0.1:2379
export MULTI_REGION ?= 1

ALL_FEATURES := integration-tests

INTEGRATION_TEST_ARGS := --features "integration-tests"
NEXTEST_ARGS := --config-file $(shell pwd)/config/nextest.toml -P ci

INTEGRATION_TEST_ARGS := --features "integration-tests" --test-threads 1

RUN_INTEGRATION_TEST := cargo nextest run ${NEXTEST_ARGS} --all ${INTEGRATION_TEST_ARGS}

default: check

Expand All @@ -20,12 +24,15 @@ check: generate
cargo clippy --all-targets --features "${ALL_FEATURES}" -- -D clippy::all

unit-test: generate
cargo nextest run --all --no-default-features
cargo nextest run ${NEXTEST_ARGS} --all --no-default-features

integration-test: integration-test-txn integration-test-raw

integration-test-txn: generate
$(RUN_INTEGRATION_TEST) txn_

integration-test: generate
cargo test txn_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
cargo test raw_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
cargo test misc_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
integration-test-raw: generate
$(RUN_INTEGRATION_TEST) raw_

test: unit-test integration-test

Expand Down
8 changes: 8 additions & 0 deletions config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[profile.ci]
retries = 0
fail-fast = false
slow-timeout = { period = "60s", terminate-after = 3 } # Timeout 3m.
failure-output = "final"

[profile.ci.junit]
path = "junit.xml"
8 changes: 5 additions & 3 deletions config/tikv.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
[coprocessor]
region-max-keys = 10
region-split-keys = 7
region-split-keys = 150
batch-split-limit = 100

[raftstore]
region-split-check-diff = "1B"
pd-heartbeat-tick-interval = "2s"
pd-store-heartbeat-tick-interval = "5s"
split-region-check-tick-interval = "1s"
raft-entry-max-size = "1MB"
raft-entry-max-size = "256KiB"

[rocksdb]
max-open-files = 10000

[raftdb]
max-open-files = 10000

[storage]
reserve-space = "0MiB"
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "clippy"]
channel = "1.84.1"
components = ["rustfmt", "clippy", "rust-analyzer"]
5 changes: 3 additions & 2 deletions src/common/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::result;
use thiserror::Error;

use crate::proto::kvrpcpb;
use crate::region::RegionVerId;
use crate::BoundRange;

/// An error originating from the TiKV client or dependencies.
Expand Down Expand Up @@ -89,8 +90,8 @@ pub enum Error {
#[error("Region {} is not found in the response", region_id)]
RegionNotFoundInResponse { region_id: u64 },
/// No leader is found for the given id.
#[error("Leader of region {} is not found", region_id)]
LeaderNotFound { region_id: u64 },
#[error("Leader of region {} is not found", region.id)]
LeaderNotFound { region: RegionVerId },
/// Scan limit exceeds the maximum
#[error("Limit {} exceeds max scan limit {}", limit, max_limit)]
MaxScanLimitExceeded { limit: u32, max_limit: u32 },
Expand Down
1 change: 1 addition & 0 deletions src/generated/backup.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// The message save the metadata of a backup.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions src/generated/cdcpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Header {
Expand Down
1 change: 1 addition & 0 deletions src/generated/configpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Status {
Expand Down
1 change: 1 addition & 0 deletions src/generated/coprocessor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// \[start, end)
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions src/generated/deadlock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct WaitForEntriesRequest {}
Expand Down
1 change: 1 addition & 0 deletions src/generated/debugpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetRequest {
Expand Down
1 change: 1 addition & 0 deletions src/generated/diagnosticspb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SearchLogRequest {
Expand Down
1 change: 1 addition & 0 deletions src/generated/disk_usage.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum DiskUsage {
Expand Down
1 change: 1 addition & 0 deletions src/generated/encryptionpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// General encryption metadata for any data type.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions src/generated/enginepb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CommandRequestHeader {
Expand Down
1 change: 1 addition & 0 deletions src/generated/eraftpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// The entry is a type of change that needs to be applied. It contains two data fields.
/// While the fields are built into the model; their usage is determined by the entry_type.
///
Expand Down
1 change: 1 addition & 0 deletions src/generated/errorpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// NotLeader is the error variant that tells a request be handle by raft leader
/// is sent to raft follower or learner.
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
1 change: 1 addition & 0 deletions src/generated/google.api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// Defines the HTTP configuration for an API service. It contains a list of
/// \[HttpRule\]\[google.api.HttpRule\], each specifying the mapping of an RPC method
/// to one or more HTTP REST API methods.
Expand Down
1 change: 1 addition & 0 deletions src/generated/import_kvpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SwitchModeRequest {
Expand Down
1 change: 1 addition & 0 deletions src/generated/import_sstpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SwitchModeRequest {
Expand Down
1 change: 1 addition & 0 deletions src/generated/kvrpcpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// A transactional get command. Lookup a value for `key` in the transaction with
/// starting timestamp = `version`.
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
1 change: 1 addition & 0 deletions src/generated/metapb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Cluster {
Expand Down
1 change: 1 addition & 0 deletions src/generated/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
pub mod backup {
include!("backup.rs");
}
Expand Down
1 change: 1 addition & 0 deletions src/generated/mpp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// TaskMeta contains meta of a mpp plan, including query's ts and task address.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions src/generated/pdpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RequestHeader {
Expand Down
1 change: 1 addition & 0 deletions src/generated/raft_cmdpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetRequest {
Expand Down
1 change: 1 addition & 0 deletions src/generated/raft_serverpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RaftMessage {
Expand Down
1 change: 1 addition & 0 deletions src/generated/replication_modepb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// The replication status sync from PD to TiKV.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions src/generated/resource_usage_agent.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CpuTimeRecord {
Expand Down
1 change: 1 addition & 0 deletions src/generated/span.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SpanSet {
Expand Down
1 change: 1 addition & 0 deletions src/generated/tikvpb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BatchCommandsRequest {
Expand Down
1 change: 0 additions & 1 deletion src/kv/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::fmt;
use std::ops::Bound;
use std::u8;

#[allow(unused_imports)]
#[cfg(test)]
Expand Down
3 changes: 1 addition & 2 deletions src/kv/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
use std::fmt;
use std::u8;

mod bound_range;
pub mod codec;
Expand All @@ -16,7 +15,7 @@ pub use value::Value;

struct HexRepr<'a>(pub &'a [u8]);

impl<'a> fmt::Display for HexRepr<'a> {
impl fmt::Display for HexRepr<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for byte in self.0 {
write!(f, "{byte:02X}")?;
Expand Down
1 change: 0 additions & 1 deletion src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ const _PROPTEST_VALUE_MAX: usize = 1024 * 16; // 16 KB
/// Since `Value` is just an alias for `Vec<u8>`, conversions to and from it are easy.
///
/// Many functions which accept a `Value` accept an `Into<Value>`.

pub type Value = Vec<u8>;
2 changes: 2 additions & 0 deletions src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ impl PdClient for MockPdClient {

async fn invalidate_region_cache(&self, _ver_id: crate::region::RegionVerId) {}

async fn invalidate_store_cache(&self, _store_id: crate::region::StoreId) {}

fn get_codec(&self) -> &Self::Codec {
&self.codec
}
Expand Down
7 changes: 7 additions & 0 deletions src/pd/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::proto::metapb;
use crate::region::RegionId;
use crate::region::RegionVerId;
use crate::region::RegionWithLeader;
use crate::region::StoreId;
use crate::region_cache::RegionCache;
use crate::request::codec::{ApiV1TxnCodec, Codec};
use crate::store::KvConnect;
Expand Down Expand Up @@ -208,6 +209,8 @@ pub trait PdClient: Send + Sync + 'static {

async fn invalidate_region_cache(&self, ver_id: RegionVerId);

async fn invalidate_store_cache(&self, store_id: StoreId);

/// Get the codec carried by `PdClient`.
/// The purpose of carrying the codec is to avoid passing it on so many calling paths.
fn get_codec(&self) -> &Self::Codec;
Expand Down Expand Up @@ -283,6 +286,10 @@ impl<Cod: Codec, KvC: KvConnect + Send + Sync + 'static> PdClient for PdRpcClien
self.region_cache.invalidate_region_cache(ver_id).await
}

async fn invalidate_store_cache(&self, store_id: StoreId) {
self.region_cache.invalidate_store_cache(store_id).await
}

fn get_codec(&self) -> &Self::Codec {
self.codec
.as_ref()
Expand Down
1 change: 1 addition & 0 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#![allow(clippy::large_enum_variant)]
#![allow(clippy::enum_variant_names)]
#![allow(clippy::doc_lazy_continuation)]

pub use protos::*;

Expand Down
1 change: 0 additions & 1 deletion src/raw/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use core::ops::Range;
use std::str::FromStr;
use std::sync::Arc;
use std::u32;

use futures::StreamExt;
use log::debug;
Expand Down
4 changes: 2 additions & 2 deletions src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl RegionWithLeader {
self.leader
.as_ref()
.ok_or(Error::LeaderNotFound {
region_id: self.region.id,
region: self.ver_id(),
})
.map(|l| {
let mut ctx = kvrpcpb::Context::default();
Expand Down Expand Up @@ -89,7 +89,7 @@ impl RegionWithLeader {
.as_ref()
.cloned()
.ok_or_else(|| Error::LeaderNotFound {
region_id: self.id(),
region: self.ver_id(),
})
.map(|s| s.store_id)
}
Expand Down
5 changes: 5 additions & 0 deletions src/region_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ impl<C: RetryClientTrait> RegionCache<C> {
}
}

pub async fn invalidate_store_cache(&self, store_id: StoreId) {
let mut cache = self.store_cache.write().await;
cache.remove(&store_id);
}

pub async fn read_through_all_stores(&self) -> Result<Vec<Store>> {
let stores = self
.inner_client
Expand Down
Loading