Skip to content

Commit ef5f170

Browse files
committed
doc: rephrase doc
Signed-off-by: ekexium <[email protected]>
1 parent b317ab7 commit ef5f170

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

src/transaction/transaction.rs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,30 @@ impl<PdC: PdClient> Transaction<PdC> {
116116
}
117117

118118
/// Create a `get for udpate` request.
119-
/// It has different behaviors in optimistic and pessimistic transactions.
119+
///
120+
/// The request reads and "locks" a key. It is similar to `SELECT ... FOR
121+
/// UPDATE` in TiDB, and has different behavior in optimistic and
122+
/// pessimistic transactions.
120123
///
121124
/// # Optimistic transaction
122-
/// Once resolved this request will retrieve the value just like a normal `get` request,
123-
/// and "locks" the key. This lock will not affect other (concurrent) transactions, but will
124-
/// prevent the current transaction from successfully committing if there is another write
125-
/// containing the "locked" key which is committed between the start and commit of the current transaction.
126125
///
127-
/// The value is read from the `start timestamp`, thus it is cached in the local buffer.
126+
/// It reads at the "start timestamp" and caches the value, just like normal
127+
/// get requests. The lock is written in prewrite and commit, so it cannot
128+
/// prevent concurrent transactions from writing the same key, but can only
129+
/// prevent itself from committing.
128130
///
129131
/// # Pessimistic transaction
130-
/// Once resolved this request will pessimistically lock and fetch the latest
131-
/// value associated with the given key at **current timestamp**.
132132
///
133-
/// The "current timestamp" (also called `for_update_ts` of the request) is fetched immediately from PD.
133+
/// It reads at the "current timestamp" and thus does not cache the value.
134+
/// So following read requests won't be affected by the `get_for_udpate`.
135+
/// A lock will be acquired immediately with this request, which prevents
136+
/// concurrent transactions from mutating the keys.
134137
///
135-
/// Note: The behavior of this command does not follow snapshot isolation. It is similar to `select for update` in TiDB,
136-
/// which is similar to that in MySQL. It reads the latest value (using current timestamp),
137-
/// and the value is not cached in the local buffer.
138-
/// So normal `get`-like commands after `get_for_update` will not be influenced, they still read values at `start_ts`.
138+
/// The "current timestamp" (also called `for_update_ts` of the request) is
139+
/// fetched immediately from the timestamp oracle.
139140
///
141+
/// Note: The behavior of the request under pessimistic transaction does not
142+
/// follow snapshot isolation.
140143
///
141144
/// # Examples
142145
/// ```rust,no_run
@@ -238,27 +241,12 @@ impl<PdC: PdClient> Transaction<PdC> {
238241
}
239242

240243
/// Create a new 'batch get for update' request.
241-
/// It has different behaviors in optimistic and pessimistic transactions.
242-
///
243-
/// # Optimistic transaction
244-
/// Once resolved this request will retrieve the values just like a normal `batch_get` request,
245-
/// and "locks" the keys. The locks will not affect other (concurrent) transactions, but will
246-
/// prevent the current transaction from successfully committing if there is any other write
247-
/// containing a "locked" key which is committed between the start and commit of the current transaction.
248-
///
249-
/// The values are read from the `start timestamp`, thus they are cached in the local buffer.
250244
///
251-
/// # Pessimistic transaction
252-
/// Once resolved this request will pessimistically lock the keys and
253-
/// fetch the values associated with the given keys.
254-
///
255-
/// Note: The behavior of this command does not follow snapshot isolation. It is similar to `select for update` in TiDB,
256-
/// which is similar to that in MySQL. It reads the latest value (using current timestamp),
257-
/// and the value is not cached in the local buffer.
258-
/// So normal `get`-like commands after `batch_get_for_update` will not be influenced, they still read values at `start_ts`.
259-
///
260-
/// Non-existent entries will not appear in the result. The order of the keys is not retained in the result.
245+
/// Similar [`get_for_update`](Transaction::get_for_update), but it works
246+
/// for a batch of keys.
261247
///
248+
/// Non-existent entries will not appear in the result. The order of the
249+
/// keys is not retained in the result.
262250
///
263251
/// # Examples
264252
/// ```rust,no_run

0 commit comments

Comments
 (0)