Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txn: Support check for_update_ts when prewriting #14492

Merged
merged 24 commits into from Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
243c131
update kvproto
MyonKeminta Mar 30, 2023
036916f
txn: Support check for_update_ts when prewriting
MyonKeminta Mar 30, 2023
c1b3367
Fix build
MyonKeminta Mar 30, 2023
6925586
Add unit test to action/prewrite
MyonKeminta Mar 31, 2023
53ab086
Merge branch 'm/prewrite-check-for-update-ts' of https://github.com/M…
MyonKeminta Mar 31, 2023
a273936
Add more tests
MyonKeminta Apr 4, 2023
1e03cfc
Exclude the case that lock.for_update_ts == min_commit_ts
MyonKeminta Apr 4, 2023
c301221
fix tests and typos
MyonKeminta Apr 4, 2023
97fdd06
Fix build
MyonKeminta Apr 4, 2023
e8f140f
Fix build
MyonKeminta Apr 4, 2023
8dea574
Fix tests
MyonKeminta Apr 4, 2023
95c4ab0
Fix lint
MyonKeminta Apr 6, 2023
63df17d
Remove the code about async commit safety check as it will be in anot…
MyonKeminta Apr 6, 2023
ce549c3
Update kvproto
MyonKeminta Apr 6, 2023
19ab2e5
Disallow lock.for_update_ts < expected
MyonKeminta Apr 6, 2023
da7d3d1
Fix build
MyonKeminta Apr 6, 2023
ea37a82
Fix build
MyonKeminta Apr 6, 2023
9809fb6
fix lint
MyonKeminta Apr 6, 2023
75ac09f
Address comments
MyonKeminta Apr 10, 2023
b4a714c
Remove the change about updating max_ts
MyonKeminta Apr 10, 2023
e85a9ad
Add reason to PessimisticLockNotFound
MyonKeminta Apr 11, 2023
b1a098f
Merge branch 'master' into m/prewrite-check-for-update-ts
ti-chi-bot Apr 11, 2023
20c1739
Merge branch 'master' into m/prewrite-check-for-update-ts
ti-chi-bot Apr 12, 2023
01ee044
Merge branch 'master' into m/prewrite-check-for-update-ts
ti-chi-bot Apr 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/resolved_ts/src/cmd.rs
Expand Up @@ -424,6 +424,7 @@ mod tests {
Mutation::make_put(k1.clone(), b"v4".to_vec()),
&None,
SkipPessimisticCheck,
None,
)
.unwrap();
one_pc_commit(true, &mut txn, 10.into());
Expand Down
6 changes: 6 additions & 0 deletions src/storage/mod.rs
Expand Up @@ -8254,6 +8254,7 @@ mod tests {
None,
false,
AssertionLevel::Off,
vec![],
Context::default(),
),
expect_ok_callback(tx.clone(), 0),
Expand Down Expand Up @@ -9620,6 +9621,7 @@ mod tests {
Some(vec![b"e".to_vec()]),
false,
AssertionLevel::Off,
vec![],
Context::default(),
),
Box::new(move |res| {
Expand Down Expand Up @@ -9718,6 +9720,7 @@ mod tests {
None,
false,
AssertionLevel::Off,
vec![],
Default::default(),
),
expect_ok_callback(tx.clone(), 0),
Expand Down Expand Up @@ -9768,6 +9771,7 @@ mod tests {
Some(vec![k2.to_vec()]),
false,
AssertionLevel::Off,
vec![],
Default::default(),
),
expect_ok_callback(tx.clone(), 0),
Expand Down Expand Up @@ -10604,6 +10608,7 @@ mod tests {
None,
false,
AssertionLevel::Off,
vec![],
Context::default(),
),
Box::new(move |res| {
Expand Down Expand Up @@ -10662,6 +10667,7 @@ mod tests {
None,
false,
AssertionLevel::Off,
vec![],
Context::default(),
),
Box::new(move |res| {
Expand Down
34 changes: 25 additions & 9 deletions src/storage/mvcc/mod.rs
Expand Up @@ -132,10 +132,14 @@ pub enum ErrorInner {
KeyVersion,

#[error(
"pessimistic lock not found, start_ts:{}, key:{}",
.start_ts, log_wrappers::Value::key(.key)
"pessimistic lock not found, start_ts:{}, key:{}, reason: {:?}",
.start_ts, log_wrappers::Value::key(.key), .reason
)]
PessimisticLockNotFound { start_ts: TimeStamp, key: Vec<u8> },
PessimisticLockNotFound {
start_ts: TimeStamp,
key: Vec<u8>,
reason: PessimisticLockNotFoundReason,
},

#[error(
"min_commit_ts {} is larger than max_commit_ts {}, start_ts: {}",
Expand Down Expand Up @@ -257,12 +261,15 @@ impl ErrorInner {
key: key.to_owned(),
})
}
ErrorInner::PessimisticLockNotFound { start_ts, key } => {
Some(ErrorInner::PessimisticLockNotFound {
start_ts: *start_ts,
key: key.to_owned(),
})
}
ErrorInner::PessimisticLockNotFound {
start_ts,
key,
reason,
} => Some(ErrorInner::PessimisticLockNotFound {
start_ts: *start_ts,
key: key.to_owned(),
reason: *reason,
}),
ErrorInner::CommitTsTooLarge {
start_ts,
min_commit_ts,
Expand Down Expand Up @@ -421,6 +428,15 @@ pub fn default_not_found_error(key: Vec<u8>, hint: &str) -> Error {
}
}

#[derive(Debug, Clone, Copy)]
pub enum PessimisticLockNotFoundReason {
LockTsMismatch,
LockMissingAmendFail,
LockForUpdateTsMismatch,
NonLockKeyConflict,
FailpointInjected,
}

pub mod tests {
use std::borrow::Cow;

Expand Down
2 changes: 2 additions & 0 deletions src/storage/mvcc/reader/reader.rs
Expand Up @@ -886,6 +886,7 @@ pub mod tests {
m,
&None,
SkipPessimisticCheck,
None,
)
.unwrap();
self.write(txn.into_modifies());
Expand All @@ -910,6 +911,7 @@ pub mod tests {
m,
&None,
DoPessimisticCheck,
None,
)
.unwrap();
self.write(txn.into_modifies());
Expand Down
9 changes: 8 additions & 1 deletion src/storage/mvcc/txn.rs
Expand Up @@ -9,7 +9,7 @@ use kvproto::kvrpcpb::LockInfo;
use txn_types::{Key, Lock, PessimisticLock, TimeStamp, Value};

use super::metrics::{GC_DELETE_VERSIONS_HISTOGRAM, MVCC_VERSIONS_HISTOGRAM};
use crate::storage::kv::Modify;
use crate::storage::{kv::Modify, mvcc::PessimisticLockNotFoundReason};

pub const MAX_TXN_WRITE_SIZE: usize = 32 * 1024;

Expand Down Expand Up @@ -306,6 +306,7 @@ pub(crate) fn make_txn_error(
"pessimisticlocknotfound" => ErrorInner::PessimisticLockNotFound {
start_ts,
key: key.to_raw().unwrap(),
reason: PessimisticLockNotFoundReason::FailpointInjected,
},
_ => ErrorInner::Other(box_err!("unexpected error string")),
}
Expand Down Expand Up @@ -815,6 +816,7 @@ pub(crate) mod tests {
Mutation::make_put(key.clone(), v.to_vec()),
&None,
SkipPessimisticCheck,
None,
)
.unwrap();
assert!(txn.write_size() > 0);
Expand Down Expand Up @@ -859,6 +861,7 @@ pub(crate) mod tests {
Mutation::make_put(Key::from_raw(key), value.to_vec()),
&None,
SkipPessimisticCheck,
None,
)
.unwrap_err();

Expand All @@ -872,6 +875,7 @@ pub(crate) mod tests {
Mutation::make_put(Key::from_raw(key), value.to_vec()),
&None,
SkipPessimisticCheck,
None,
)
.unwrap();
}
Expand Down Expand Up @@ -1312,6 +1316,7 @@ pub(crate) mod tests {
mutation,
&Some(vec![b"key1".to_vec(), b"key2".to_vec(), b"key3".to_vec()]),
SkipPessimisticCheck,
None,
)
.unwrap();
let modifies = txn.into_modifies();
Expand Down Expand Up @@ -1370,6 +1375,7 @@ pub(crate) mod tests {
mutation,
&Some(vec![b"key1".to_vec(), b"key2".to_vec(), b"key3".to_vec()]),
DoPessimisticCheck,
None,
)
.unwrap();
let modifies = txn.into_modifies();
Expand Down Expand Up @@ -1439,6 +1445,7 @@ pub(crate) mod tests {
mutation,
&Some(vec![b"key1".to_vec(), b"key2".to_vec(), b"key3".to_vec()]),
DoPessimisticCheck,
None,
)
.unwrap();
assert_eq!(min_commit_ts.into_inner(), 100);
Expand Down
2 changes: 0 additions & 2 deletions src/storage/txn/actions/acquire_pessimistic_lock.rs
Expand Up @@ -452,7 +452,6 @@ pub mod tests {
TestEngineBuilder,
};

#[cfg(test)]
pub fn acquire_pessimistic_lock_allow_lock_with_conflict<E: Engine>(
engine: &mut E,
key: &[u8],
Expand Down Expand Up @@ -496,7 +495,6 @@ pub mod tests {
res.map(|r| r.0)
}

#[cfg(test)]
pub fn must_succeed_allow_lock_with_conflict<E: Engine>(
engine: &mut E,
key: &[u8],
Expand Down