ci: Fix CI errors (#381)

Signed-off-by: Ping Yu <yuping@pingcap.com>
This commit is contained in:
Ping Yu 2022-12-14 10:21:58 +08:00 committed by GitHub
parent 027a7dffd1
commit d2f78b2768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 57 additions and 35 deletions

View File

@ -17,6 +17,11 @@ jobs:
profile: minimal
toolchain: nightly
override: true
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
- uses: actions-rs/cargo@v1
@ -39,6 +44,7 @@ jobs:
with:
command: fmt
args: --all -- --check
clippy:
name: clippy
runs-on: ubuntu-latest
@ -49,6 +55,11 @@ jobs:
toolchain: nightly
components: clippy
override: true
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
- uses: actions-rs/clippy-check@v1
@ -56,6 +67,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-targets --all-features -- -D clippy::all
name: Clippy Output
unit-test:
name: unit test
env:
@ -68,10 +80,16 @@ jobs:
profile: minimal
toolchain: nightly
override: true
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
- name: unit test
run: make unit-test
integration-test:
name: integration test
env:
@ -84,6 +102,11 @@ jobs:
profile: minimal
toolchain: nightly
override: true
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
- name: install tiup

View File

@ -35,7 +35,7 @@ async fn main() -> Result<()> {
//
// Here we set the key `TiKV` to have the value `Rust` associated with it.
client.put(KEY.to_owned(), VALUE.to_owned()).await.unwrap(); // Returns a `tikv_client::Error` on failure.
println!("Put key {:?}, value {:?}.", KEY, VALUE);
println!("Put key {KEY:?}, value {VALUE:?}.");
// Unlike a standard Rust HashMap all calls take owned values. This is because under the hood
// protobufs must take ownership of the data. If we only took a borrow we'd need to internally
@ -48,7 +48,7 @@ async fn main() -> Result<()> {
// types are supported as well, but it all ends up as `Vec<u8>` in the end.
let value: Option<Value> = client.get(KEY.to_owned()).await?;
assert_eq!(value, Some(Value::from(VALUE.to_owned())));
println!("Get key `{}` returned value {:?}.", KEY, value);
println!("Get key `{KEY}` returned value {value:?}.");
// You can also set the `ColumnFamily` used by the request.
// This is *advanced usage* and should have some special considerations.
@ -56,7 +56,7 @@ async fn main() -> Result<()> {
.delete(KEY.to_owned())
.await
.expect("Could not delete value");
println!("Key: `{}` deleted", KEY);
println!("Key: `{KEY}` deleted");
// Here we check if the key has been deleted from the key-value store.
let value: Option<Value> = client
@ -80,7 +80,7 @@ async fn main() -> Result<()> {
.batch_get(keys.clone())
.await
.expect("Could not get values");
println!("Found values: {:?} for keys: {:?}", values, keys);
println!("Found values: {values:?} for keys: {keys:?}");
// Scanning a range of keys is also possible giving it two bounds
// it will returns all entries between these two.
@ -96,7 +96,7 @@ async fn main() -> Result<()> {
&keys,
&[Key::from("k1".to_owned()), Key::from("k2".to_owned()),]
);
println!("Scaning from {:?} to {:?} gives: {:?}", start, end, keys);
println!("Scanning from {start:?} to {end:?} gives: {keys:?}");
let k1 = "k1";
let k2 = "k2";
@ -126,10 +126,7 @@ async fn main() -> Result<()> {
"v3".to_owned()
]
);
println!(
"Scaning batch scan from {:?} gives: {:?}",
batch_scan_keys, vals
);
println!("Scanning batch scan from {batch_scan_keys:?} gives: {vals:?}");
// Cleanly exit.
Ok(())

View File

@ -52,7 +52,7 @@ async fn scan(client: &Client, range: impl Into<BoundRange>, limit: u32) {
txn.scan(range, limit)
.await
.expect("Could not scan key-value pairs in range")
.for_each(|pair| println!("{:?}", pair));
.for_each(|pair| println!("{pair:?}"));
txn.commit().await.expect("Could not commit transaction");
}

View File

@ -32,7 +32,7 @@ impl MockPd {
fn store() -> tikv_client_proto::metapb::Store {
// TODO: start_timestamp?
tikv_client_proto::metapb::Store {
address: format!("localhost:{}", MOCK_TIKV_PORT),
address: format!("localhost:{MOCK_TIKV_PORT}"),
..Default::default()
}
}
@ -58,7 +58,7 @@ impl Pd for MockPd {
) {
let member = Member {
name: "mock tikv".to_owned(),
client_urls: vec![format!("localhost:{}", MOCK_PD_PORT)],
client_urls: vec![format!("localhost:{MOCK_PD_PORT}")],
..Default::default()
};
let resp = GetMembersResponse {

View File

@ -17,7 +17,7 @@ struct HexRepr<'a>(pub &'a [u8]);
impl<'a> fmt::Display for HexRepr<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for byte in self.0 {
write!(f, "{:02X}", byte)?;
write!(f, "{byte:02X}")?;
}
Ok(())
}

View File

@ -285,7 +285,7 @@ fn thread_name(prefix: &str) -> String {
thread::current()
.name()
.and_then(|name| name.split("::").skip(1).last())
.map(|tag| format!("{}::{}", prefix, tag))
.map(|tag| format!("{prefix}::{tag}"))
.unwrap_or_else(|| prefix.to_owned())
}

View File

@ -111,8 +111,7 @@ impl<C: RetryClientTrait> RegionCache<C> {
}
}
Err(Error::StringError(format!(
"Concurrent PD requests failed for {} times",
MAX_RETRY_WAITING_CONCURRENT_REQUEST
"Concurrent PD requests failed for {MAX_RETRY_WAITING_CONCURRENT_REQUEST} times"
)))
}

View File

@ -155,7 +155,7 @@ where
)
.await
}
None => Err(Error::RegionError(e)),
None => Err(Error::RegionError(Box::new(e))),
}
} else {
Ok(vec![Ok(resp)])
@ -213,7 +213,7 @@ where
|| e.has_raft_entry_too_large()
|| e.has_max_timestamp_not_synced()
{
Err(Error::RegionError(e))
Err(Error::RegionError(Box::new(e)))
} else {
// TODO: pass the logger around
// info!("unknwon region error: {:?}", e);
@ -475,7 +475,10 @@ where
Err(Error::ExtractedErrors(errors))
} else if let Some(errors) = result.region_errors() {
Err(Error::ExtractedErrors(
errors.into_iter().map(Error::RegionError).collect(),
errors
.into_iter()
.map(|e| Error::RegionError(Box::new(e)))
.collect(),
))
} else {
Ok(result)

View File

@ -159,7 +159,7 @@ mod tests {
};
Ok(Box::new(resp) as Box<dyn Any>)
});
Ok(Box::new(kvrpcpb::ResolveLockResponse::default()) as Box<dyn Any>)
Ok(Box::<kvrpcpb::ResolveLockResponse>::default() as Box<dyn Any>)
},
)));

View File

@ -1326,7 +1326,7 @@ impl<PdC: PdClient> Committer<PdC> {
if self.write_size > TXN_COMMIT_BATCH_SIZE {
let size_mb = self.write_size as f64 / 1024.0 / 1024.0;
lock_ttl = (TTL_FACTOR * size_mb.sqrt()) as u64;
lock_ttl = lock_ttl.min(MAX_TTL).max(DEFAULT_LOCK_TTL);
lock_ttl = lock_ttl.clamp(DEFAULT_LOCK_TTL, MAX_TTL);
}
lock_ttl
}
@ -1388,11 +1388,11 @@ mod tests {
move |req: &dyn Any| {
if req.downcast_ref::<kvrpcpb::TxnHeartBeatRequest>().is_some() {
heartbeats_cloned.fetch_add(1, Ordering::SeqCst);
Ok(Box::new(kvrpcpb::TxnHeartBeatResponse::default()) as Box<dyn Any>)
Ok(Box::<kvrpcpb::TxnHeartBeatResponse>::default() as Box<dyn Any>)
} else if req.downcast_ref::<kvrpcpb::PrewriteRequest>().is_some() {
Ok(Box::new(kvrpcpb::PrewriteResponse::default()) as Box<dyn Any>)
Ok(Box::<kvrpcpb::PrewriteResponse>::default() as Box<dyn Any>)
} else {
Ok(Box::new(kvrpcpb::CommitResponse::default()) as Box<dyn Any>)
Ok(Box::<kvrpcpb::CommitResponse>::default() as Box<dyn Any>)
}
},
)));
@ -1432,16 +1432,16 @@ mod tests {
move |req: &dyn Any| {
if req.downcast_ref::<kvrpcpb::TxnHeartBeatRequest>().is_some() {
heartbeats_cloned.fetch_add(1, Ordering::SeqCst);
Ok(Box::new(kvrpcpb::TxnHeartBeatResponse::default()) as Box<dyn Any>)
Ok(Box::<kvrpcpb::TxnHeartBeatResponse>::default() as Box<dyn Any>)
} else if req.downcast_ref::<kvrpcpb::PrewriteRequest>().is_some() {
Ok(Box::new(kvrpcpb::PrewriteResponse::default()) as Box<dyn Any>)
Ok(Box::<kvrpcpb::PrewriteResponse>::default() as Box<dyn Any>)
} else if req
.downcast_ref::<kvrpcpb::PessimisticLockRequest>()
.is_some()
{
Ok(Box::new(kvrpcpb::PessimisticLockResponse::default()) as Box<dyn Any>)
Ok(Box::<kvrpcpb::PessimisticLockResponse>::default() as Box<dyn Any>)
} else {
Ok(Box::new(kvrpcpb::CommitResponse::default()) as Box<dyn Any>)
Ok(Box::<kvrpcpb::CommitResponse>::default() as Box<dyn Any>)
}
},
)));

View File

@ -187,7 +187,7 @@ async fn raw_bank_transfer() -> Result<()> {
let mut sum: u32 = 0;
for person in &people {
let init = rng.gen::<u8>() as u32;
sum += init as u32;
sum += init;
client
.put(person.clone(), init.to_be_bytes().to_vec())
.await?;
@ -335,7 +335,7 @@ async fn txn_bank_transfer() -> Result<()> {
let mut sum: u32 = 0;
for person in &people {
let init = rng.gen::<u8>() as u32;
sum += init as u32;
sum += init;
txn.put(person.clone(), init.to_be_bytes().to_vec()).await?;
}
txn.commit().await?;

View File

@ -15,7 +15,7 @@ mod test {
let mut tikv_server = start_mock_tikv_server();
let _pd_server = start_mock_pd_server();
let client = RawClient::new(vec![format!("localhost:{}", MOCK_PD_PORT)], None)
let client = RawClient::new(vec![format!("localhost:{MOCK_PD_PORT}")], None)
.await
.unwrap();

View File

@ -48,13 +48,13 @@ pub enum Error {
Canceled(#[from] futures::channel::oneshot::Canceled),
/// Errors caused by changes of region information
#[error("Region error: {0:?}")]
RegionError(tikv_client_proto::errorpb::Error),
RegionError(Box<tikv_client_proto::errorpb::Error>),
/// Whether the transaction is committed or not is undetermined
#[error("Whether the transaction is committed or not is undetermined")]
UndeterminedError(Box<Error>),
/// Wraps `tikv_client_proto::kvrpcpb::KeyError`
#[error("{0:?}")]
KeyError(tikv_client_proto::kvrpcpb::KeyError),
KeyError(Box<tikv_client_proto::kvrpcpb::KeyError>),
/// Multiple errors generated from the ExtractError plan.
#[error("Multiple errors: {0:?}")]
ExtractedErrors(Vec<Error>),
@ -97,13 +97,13 @@ pub enum Error {
impl From<tikv_client_proto::errorpb::Error> for Error {
fn from(e: tikv_client_proto::errorpb::Error) -> Error {
Error::RegionError(e)
Error::RegionError(Box::new(e))
}
}
impl From<tikv_client_proto::kvrpcpb::KeyError> for Error {
fn from(e: tikv_client_proto::kvrpcpb::KeyError) -> Error {
Error::KeyError(e)
Error::KeyError(Box::new(e))
}
}