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:improvement for point get by unique key or pk #1608

Merged
merged 7 commits into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/storage/mvcc/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use super::{Error, Result};
use super::lock::Lock;
use super::write::{Write, WriteType};
use raftstore::store::engine::{IterOption, SeekMode};
use std::u64;

#[derive(Clone, Default, Debug)]
pub struct ScanMetrics {
Expand Down Expand Up @@ -176,13 +177,20 @@ impl<'a> MvccReader<'a> {
// Check for locks that signal concurrent writes.
if let Some(lock) = try!(self.load_lock(key)) {
if lock.ts <= ts {
// There is a pending lock. Client should wait or clean it.
return Err(Error::KeyIsLocked {
key: try!(key.raw()),
primary: lock.primary,
ts: lock.ts,
ttl: lock.ttl,
});
if ts == u64::MAX && try!(key.raw()) == lock.primary {
// when ts==u64::MAX(which means to get latest committed version for
// primary key),and current key is the primary key, returns the latest
// commit version's value
ts = lock.ts - 1;
} else {
// There is a pending lock. Client should wait or clean it.
return Err(Error::KeyIsLocked {
key: try!(key.raw()),
primary: lock.primary,
ts: lock.ts,
ttl: lock.ttl,
});
}
}
}
loop {
Expand Down
26 changes: 26 additions & 0 deletions tests/storage/test_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use super::util::new_raft_engine;
use super::assert_storage::AssertionStorage;
use storage::util;
use std::collections::HashSet;
use std::u64;

#[test]
fn test_txn_store_get() {
Expand Down Expand Up @@ -83,6 +84,31 @@ fn test_txn_store_cleanup_commit() {
store.rollback_err(vec![b"primary"], 5);
}

#[test]
fn test_txn_store_for_point_get_with_pk() {
let store = AssertionStorage::default();

store.put_ok(b"b", b"v2", 1, 2);
store.put_ok(b"primary", b"v1", 2, 3);
store.put_ok(b"secondary", b"v3", 3, 4);
store.prewrite_ok(vec![Mutation::Put((make_key(b"primary"), b"v3".to_vec())),
Mutation::Put((make_key(b"secondary"), b"s-5".to_vec())),
Mutation::Put((make_key(b"new_key"), b"new_key".to_vec()))],
b"primary",
5);
store.get_ok(b"primary", 4, b"v1");
store.get_ok(b"primary", u64::MAX, b"v1");
store.get_err(b"primary", 6);

store.get_ok(b"secondary", 4, b"v3");
store.get_err(b"secondary", 6);
store.get_err(b"secondary", u64::MAX);

store.get_err(b"new_key", 6);
store.get_ok(b"b", 6, b"v2");

}

#[test]
fn test_txn_store_batch_get() {
let store = AssertionStorage::default();
Expand Down