tikv / client-rust

Rust Client for TiKV.
Apache License 2.0
389 stars 131 forks source link

Fix reverse scan for scene of multiple regions #438

Closed pingyu closed 1 year ago

pingyu commented 1 year ago

Close #436

Fix the issue by swap start_key & end_key before requesting regions from PD, and swap back before apply shards to request. As the start_key & end_key in reverse range request are in the meaning of [end_key, start_key).

The issue can be reproduced before the shardable_range was fixed. See 435cf0a36dbb1026c32f757f94bf86f7e713fbb1:

MULTI_REGION=1 cargo test txn_scan_reverse --all --features "integration-tests" -- --nocapture
    Finished test [unoptimized + debuginfo] target(s) in 0.11s
     Running unittests src/lib.rs (target/debug/deps/tikv_client-ebeddab360b427a7)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 39 filtered out; finished in 0.00s

     Running tests/failpoint_tests.rs (target/debug/deps/failpoint_tests-f2d522e63dab2b69)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 5 filtered out; finished in 0.00s

     Running tests/integration_tests.rs (target/debug/deps/integration_tests-aae509a3e2e0836d)

running 1 test
init finish with 290 regions
Error: MultipleKeyErrors([KeyError(KeyError { locked: None, retryable: "", abort: "Error(Txn(Error(InvalidReqRange { start: Some([0, 0, 0, 0, 0, 0, 0, 0, 251]), end: Some([192, 0, 0, 0, 0, 0, 0, 0, 252]), lower_bound: Some([191, 191, 253, 1, 0, 0, 0, 0, 251]), upper_bound: Some([193, 63, 252, 251, 0, 0, 0, 0, 251]) })))", conflict: None, already_exist: None, deadlock: None, commit_ts_expired: None, txn_not_found: None, commit_ts_too_large: None, assertion_failed: None })])
test txn_scan_reverse ... FAILED

failures:

failures:
    txn_scan_reverse

See also https://github.com/tikv/client-rust/actions/runs/6989951811/job/19018973704?pr=438.

pingyu commented 1 year ago

CC @jmhrpr. Thank you for providing the clue! I will fix it this weekend.