-
Notifications
You must be signed in to change notification settings - Fork 109
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 Client scan with endKey not working #660
Comments
Could you offer a minimal step to reproduce this issue? |
We don't know what that error means, so we haven't been able to reproduce that issue with a small amount of data. The details of the problem we encountered here are as follows
So we want to know what this error really means, and see if we can find what the wrong prefix and data have in common with it. |
We did not encounter this problem with small amounts of data. |
The cause of error To address this issue, I think you can assign the What's the usage of the new |
Thanks! The reason why this new scan function is defined is that the “limit” of most of our scan request will be relatively large, but the results of many queries may not be very large. However, the original scan function that supports “version” does not support sinking the endkey to the TIKV server. It only pulls the limit (or scanBatchSize) amount of data to the client and then filters it in the iterator, which is too inefficient for us. . The new code is public List<KvPair> scan(
BackOffer backOffer, ByteString startKey,ByteString endKey, int limit, long version, boolean keyOnly) {
boolean forWrite = false;
while (true) {
// we should refresh region
region = regionManager.getRegionByKey(startKey, backOffer);
ByteString finalEndKey = compare(region.getEndKey().toByteArray(),endKey.toByteArray())<0 ?region.getEndKey():endKey;
Supplier<ScanRequest> request =
() ->
ScanRequest.newBuilder()
.setContext(
makeContext(
getResolvedLocks(version), this.storeType, backOffer.getSlowLog()))
.setStartKey(codec.encodeKey(startKey))
.setVersion(version)
.setKeyOnly(keyOnly)
.setEndKey(codec.encodeKey(finalEndKey))
.setLimit(Math.min(limit, conf.getScanBatchSize()))
.build(); |
Got it. I think this change is great, and it's very welcome to raise a pull request. |
@AIFun feel free to open a pull request, we could use this scan to implement all variant versions of the scan. |
There are still some bug in my code. I'm trying to fix them.I'll open a PR after it work. |
This issue is stale because it has been open 30 days with no activity. |
Bug Report
1. Describe the bug
We use txn client to scan data, with a certain start key and end key, but it does not woking with a KV:Storage:InvalidReqRange error, here is the log output by Tikv
[2022/10/18 14:07:42.333 +00:00] [ERROR] [errors.rs:407] ["txn aborts"] [err_code=KV:Storage:InvalidReqRange] [err="Error(Txn(Error(InvalidReqRange { start: Some([2, 0, 0, 0, 0, 0, 0, 1, 255, 1, 0, 0, 0, 51, 220, 2, 0, 255, 0, 26, 0, 0, 1, 19, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]), end: Some([2, 0, 0, 0, 0, 0, 0, 1, 255, 1, 0, 0, 0, 51, 220, 2, 0, 255, 0, 26, 0, 0, 1, 19, 0, 1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]), lower_bound: Some([2, 0, 0, 0, 0, 0, 0, 1, 255, 1, 0, 0, 0, 46, 66, 1, 0, 255, 0, 4, 0, 0, 1, 19, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 1, 0, 0, 0, 247, 139, 7, 0, 255, 0, 10, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]), upper_bound: Some([2, 0, 0, 0, 0, 0, 0, 1, 255, 1, 0, 0, 0, 51, 220, 2, 0, 255, 0, 26, 0, 0, 1, 19, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 1, 0, 0, 0, 67, 139, 1, 0, 255, 0, 30, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]) })))"]
Howerver, we remove the end Key, it works!
2. Minimal reproduce step (Required)
Just use Txn scan api
3. What did you see instead (Required)
None
4. What did you expect to see? (Required)
We really want it works to scan with start and end key!
5. What are your Java Client and TiKV versions? (Required)
3.3.0
The text was updated successfully, but these errors were encountered: