Skip to content

Commit 71dd80e

Browse files
committed
Be a little more consistent with the types in request ctor functions
Signed-off-by: Nick Cameron <[email protected]>
1 parent 304d8d1 commit 71dd80e

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/transaction/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl Client {
185185
let mut start_key = vec![];
186186
loop {
187187
let req = new_scan_lock_request(
188-
mem::take(&mut start_key),
188+
mem::take(&mut start_key).into(),
189189
safepoint.clone(),
190190
SCAN_LOCK_BATCH_SIZE,
191191
);

src/transaction/requests.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl KvRequest for kvrpcpb::GetRequest {
1818
type Result = Option<Value>;
1919
type RpcResponse = kvrpcpb::GetResponse;
2020
type KeyData = Key;
21+
2122
fn store_stream<PdC: PdClient>(
2223
&mut self,
2324
pd_client: Arc<PdC>,
@@ -60,9 +61,9 @@ impl HasLocks for kvrpcpb::GetResponse {
6061
}
6162
}
6263

63-
pub fn new_mvcc_get_request(key: impl Into<Key>, timestamp: Timestamp) -> kvrpcpb::GetRequest {
64+
pub fn new_mvcc_get_request(key: Key, timestamp: Timestamp) -> kvrpcpb::GetRequest {
6465
let mut req = kvrpcpb::GetRequest::default();
65-
req.set_key(key.into().into());
66+
req.set_key(key.into());
6667
req.set_version(timestamp.version());
6768
req
6869
}
@@ -72,6 +73,7 @@ impl KvRequest for kvrpcpb::BatchGetRequest {
7273
type Result = Vec<KvPair>;
7374
type RpcResponse = kvrpcpb::BatchGetResponse;
7475
type KeyData = Vec<Key>;
76+
7577
fn make_rpc_request(&self, keys: Self::KeyData, store: &Store) -> Result<Self> {
7678
let mut req = self.request_from_store(store)?;
7779
req.set_keys(keys.into_iter().map(Into::into).collect());
@@ -153,12 +155,12 @@ impl KvRequest for kvrpcpb::ScanRequest {
153155
}
154156

155157
pub fn new_mvcc_scan_request(
156-
range: impl Into<BoundRange>,
158+
range: BoundRange,
157159
timestamp: Timestamp,
158160
limit: u32,
159161
key_only: bool,
160162
) -> kvrpcpb::ScanRequest {
161-
let (start_key, end_key) = range.into().into_keys();
163+
let (start_key, end_key) = range.into_keys();
162164
let mut req = kvrpcpb::ScanRequest::default();
163165
req.set_start_key(start_key.into());
164166
req.set_end_key(end_key.unwrap_or_default().into());
@@ -574,7 +576,7 @@ impl KvRequest for kvrpcpb::PessimisticLockRequest {
574576
}
575577

576578
pub fn new_pessimistic_lock_request(
577-
keys: Vec<impl Into<Key>>,
579+
keys: Vec<Key>,
578580
primary_lock: Key,
579581
start_version: u64,
580582
lock_ttl: u64,
@@ -587,7 +589,7 @@ pub fn new_pessimistic_lock_request(
587589
.map(|key| {
588590
let mut mutation = kvrpcpb::Mutation::default();
589591
mutation.set_op(kvrpcpb::Op::PessimisticLock);
590-
mutation.set_key(key.into().into());
592+
mutation.set_key(key.into());
591593
mutation
592594
})
593595
.collect();
@@ -640,12 +642,12 @@ impl KvRequest for kvrpcpb::ScanLockRequest {
640642
}
641643

642644
pub fn new_scan_lock_request(
643-
start_key: impl Into<Key>,
645+
start_key: Key,
644646
safepoint: Timestamp,
645647
limit: u32,
646648
) -> kvrpcpb::ScanLockRequest {
647649
let mut req = kvrpcpb::ScanLockRequest::default();
648-
req.set_start_key(start_key.into().into());
650+
req.set_start_key(start_key.into());
649651
req.set_max_version(safepoint.version());
650652
req.set_limit(limit);
651653
req

src/transaction/transaction.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ impl Transaction {
455455
}
456456
}
457457
TransactionKind::Pessimistic(_) => {
458-
self.pessimistic_lock(keys, false).await?;
458+
self.pessimistic_lock(keys.into_iter().map(|k| k.into()), false)
459+
.await?;
459460
}
460461
}
461462
Ok(())
@@ -574,19 +575,15 @@ impl Transaction {
574575
/// Only valid for pessimistic transactions, panics if called on an optimistic transaction.
575576
async fn pessimistic_lock(
576577
&mut self,
577-
keys: impl IntoIterator<Item = impl Into<Key>>,
578+
keys: impl IntoIterator<Item = Key>,
578579
need_value: bool,
579580
) -> Result<Vec<Option<Vec<u8>>>> {
580581
assert!(
581582
matches!(self.options.kind, TransactionKind::Pessimistic(_)),
582583
"`pessimistic_lock` is only valid to use with pessimistic transactions"
583584
);
584585

585-
let keys: Vec<Vec<u8>> = keys
586-
.into_iter()
587-
.map(|it| it.into())
588-
.map(|it: Key| it.into())
589-
.collect();
586+
let keys: Vec<Key> = keys.into_iter().collect();
590587
let first_key = keys[0].clone();
591588
let primary_lock = self.buffer.get_primary_key_or(&first_key.into()).await;
592589
let lock_ttl = DEFAULT_LOCK_TTL;

0 commit comments

Comments
 (0)