Skip to content

Commit 555981e

Browse files
committed
doc: update
Signed-off-by: ekexium <ekexium@gmail.com>
1 parent a3f814a commit 555981e

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/request/plan.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ impl<In: Clone + Send + Sync + 'static, P: Plan<Result = Vec<Result<In>>>, M: Me
132132
#[derive(Clone, Copy)]
133133
pub struct Collect;
134134

135+
/// A merge strategy to be used with
136+
/// [`preserve_keys`](super::plan_builder::PlanBuilder::preserve_keys).
137+
/// It matches the keys preserved before and the values returned in the response.
135138
#[derive(Clone, Debug)]
136139
pub struct CollectAndMatchKey;
137140

@@ -274,6 +277,11 @@ impl<P: Plan + HasKeys, PdC: PdClient> HasKeys for ResolveLock<P, PdC> {
274277
}
275278
}
276279

280+
/// When executed, the plan extracts errors from its inner plan, and
281+
/// returns an `Err` wrapping the error.
282+
///
283+
/// The errors come from two places: `Err` from inner plans, and `Ok(response)`
284+
/// where `response` contains unresolved errors (`error` and `region_error`).
277285
pub struct ExtractError<P: Plan> {
278286
pub inner: P,
279287
}
@@ -286,11 +294,6 @@ impl<P: Plan> Clone for ExtractError<P> {
286294
}
287295
}
288296

289-
/// When executed, the plan extracts errors from its inner plan, and
290-
/// returns an `Err` wrapping the error.
291-
///
292-
/// The errors come from two places: `Err` from inner plans, and `Ok(response)`
293-
/// where `response` contains unresolved errors (`error` and `region_error`).
294297
#[async_trait]
295298
impl<P: Plan> Plan for ExtractError<P>
296299
where
@@ -310,7 +313,11 @@ where
310313
}
311314
}
312315

313-
// Requires: len(inner.keys) == len(inner.result)
316+
/// When executed, the plan clones the keys and execute its inner plan, then
317+
/// returns `(keys, response)`.
318+
///
319+
/// It's useful when the information of keys are lost in the response but needed
320+
/// for processing.
314321
pub struct PreserveKey<P: Plan + HasKeys> {
315322
pub inner: P,
316323
}

src/transaction/transaction.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use tikv_client_proto::{kvrpcpb, pdpb::Timestamp};
2525
/// and its mutations are readable for transactions with `start_ts` >= its `commit_ts`.
2626
///
2727
/// Mutations, or write operations made in a transaction are buffered locally and sent at the time of commit,
28-
/// except for pessimisitc locking.
28+
/// except for pessimistic locking.
2929
/// In pessimistic mode, all write operations or `xxx_for_update` operations will first acquire pessimistic locks in TiKV.
3030
/// A lock exists until the transaction is committed (in the first phase of 2PC) or rolled back, or it exceeds its Time To Live (TTL).
3131
///
@@ -126,8 +126,6 @@ impl Transaction {
126126
/// and the value is not cached in the local buffer.
127127
/// So normal `get`-like commands after `get_for_update` will not be influenced, they still read values at `start_ts`.
128128
///
129-
/// Different from `get`, this request does not distinguish between empty values and non-existent keys
130-
/// , i.e. querying non-existent keys will result in empty values.
131129
///
132130
/// It can only be used in pessimistic mode.
133131
///
@@ -238,8 +236,7 @@ impl Transaction {
238236
/// and the value is not cached in the local buffer.
239237
/// So normal `get`-like commands after `batch_get_for_update` will not be influenced, they still read values at `start_ts`.
240238
///
241-
/// Different from `batch_get`, this request does not distinguish between empty values and non-existent keys
242-
/// , i.e. querying non-existent keys will result in empty values.
239+
/// Non-existent entries will not appear in the result. The order of the keys is not retained in the result.
243240
///
244241
/// It can only be used in pessimistic mode.
245242
///
@@ -263,8 +260,6 @@ impl Transaction {
263260
/// txn.commit().await.unwrap();
264261
/// # });
265262
/// ```
266-
// This is temporarily disabled because we cannot correctly match the keys and values.
267-
// See `impl KvRequest for kvrpcpb::PessimisticLockRequest` for details.
268263
pub async fn batch_get_for_update(
269264
&mut self,
270265
keys: impl IntoIterator<Item = impl Into<Key>>,
@@ -607,10 +602,13 @@ impl Transaction {
607602
.await
608603
}
609604

610-
/// Pessimistically lock the keys.
605+
/// Pessimistically lock the keys, and optionally retrieve corresponding values.
606+
/// If a key does not exist, the corresponding pair will not appear in the result.
607+
///
608+
/// Once resolved it acquires locks on the keys in TiKV.
609+
/// A lock prevents other transactions from mutating the entry until it is released.
611610
///
612-
/// Once resolved it acquires a lock on the key in TiKV.
613-
/// The lock prevents other transactions from mutating the entry until it is released.
611+
/// # Panics
614612
///
615613
/// Only valid for pessimistic transactions, panics if called on an optimistic transaction.
616614
async fn pessimistic_lock(

0 commit comments

Comments
 (0)