Skip to content

Commit

Permalink
Delay iterator panic to data access (tikv#9915)
Browse files Browse the repository at this point in the history
* disable nortcheck in release and dist_release

Signed-off-by: tabokie <[email protected]>

* fix build

Signed-off-by: tabokie <[email protected]>

* disable nortcheck and delay panic till data access

Signed-off-by: tabokie <[email protected]>

* minor

Signed-off-by: tabokie <[email protected]>

* fix tests

Signed-off-by: tabokie <[email protected]>
  • Loading branch information
tabokie authored Apr 2, 2021
1 parent b2fad97 commit 0bbe646
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ test-engines-panic = [
"tikv/test-engines-panic",
]

nortcheck = []

[lib]
name = "cmd"

Expand Down
14 changes: 12 additions & 2 deletions components/engine_rocks/src/engine_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,30 @@ impl engine_traits::Iterator for RocksEngineIterator {
}

fn prev(&mut self) -> Result<bool> {
assert!(cfg!(feature = "nortcheck") || self.valid()?);
#[cfg(not(feature = "nortcheck"))]
if !self.valid()? {
return Err(Error::Engine("Iterator invalid".to_string()));
}
self.0.prev().map_err(Error::Engine)
}

fn next(&mut self) -> Result<bool> {
assert!(cfg!(feature = "nortcheck") || self.valid()?);
#[cfg(not(feature = "nortcheck"))]
if !self.valid()? {
return Err(Error::Engine("Iterator invalid".to_string()));
}
self.0.next().map_err(Error::Engine)
}

fn key(&self) -> &[u8] {
#[cfg(not(feature = "nortcheck"))]
assert!(self.valid().unwrap());
self.0.key()
}

fn value(&self) -> &[u8] {
#[cfg(not(feature = "nortcheck"))]
assert!(self.valid().unwrap());
self.0.value()
}

Expand Down
10 changes: 2 additions & 8 deletions components/engine_traits_tests/src/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ where

assert_eq!(iter.valid().unwrap(), false);

assert!(panic::catch_unwind(AssertUnwindSafe(|| {
let _ = iter.prev();
}))
.is_err());
assert!(panic::catch_unwind(AssertUnwindSafe(|| {
let _ = iter.next();
}))
.is_err());
assert!(iter.prev().is_err());
assert!(iter.next().is_err());
assert!(panic::catch_unwind(AssertUnwindSafe(|| {
iter.key();
}))
Expand Down

0 comments on commit 0bbe646

Please sign in to comment.