@@ -116,27 +116,30 @@ impl<PdC: PdClient> Transaction<PdC> {
116
116
}
117
117
118
118
/// 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.
120
123
///
121
124
/// # 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.
126
125
///
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.
128
130
///
129
131
/// # Pessimistic transaction
130
- /// Once resolved this request will pessimistically lock and fetch the latest
131
- /// value associated with the given key at **current timestamp**.
132
132
///
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.
134
137
///
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.
139
140
///
141
+ /// Note: The behavior of the request under pessimistic transaction does not
142
+ /// follow snapshot isolation.
140
143
///
141
144
/// # Examples
142
145
/// ```rust,no_run
@@ -238,27 +241,12 @@ impl<PdC: PdClient> Transaction<PdC> {
238
241
}
239
242
240
243
/// 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.
250
244
///
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.
261
247
///
248
+ /// Non-existent entries will not appear in the result. The order of the
249
+ /// keys is not retained in the result.
262
250
///
263
251
/// # Examples
264
252
/// ```rust,no_run
0 commit comments