txn: fix scan missing endKey in V2 API#794
Conversation
- Add scan(backOffer, startKey, endKey, version, keyOnly) overload - Use codec.encodeRange() to set both startKey and endKey - Decode response KvPairs via codec.decodeKvPairs() - Pass rangeEndKey through ScanIterator Signed-off-by: lilei <lilei592@jd.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughRegionStoreClient.scan now supports scanning with both start and end keys, encoding the range and decoding returned kv pairs. ScanIterator stores a rangeEndKey field and adjusts end-of-scan branching in cacheLoadFails. ConcreteScanIterator passes rangeEndKey/keyOnly to scan and updates its hasNext end-key check. ChangesScan end key propagation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ConcreteScanIterator
participant ScanIterator
participant RegionStoreClient
participant Codec
ConcreteScanIterator->>RegionStoreClient: scan(backOffer, startKey, rangeEndKey, version, keyOnly)
RegionStoreClient->>Codec: encodeRange(startKey, endKey)
Codec-->>RegionStoreClient: encoded key range
RegionStoreClient->>RegionStoreClient: build ScanRequest with startKey/endKey
RegionStoreClient->>Codec: decodeKvPairs(resp.getPairsList())
Codec-->>RegionStoreClient: decoded kv pairs
RegionStoreClient-->>ConcreteScanIterator: decoded kv pairs
ConcreteScanIterator->>ScanIterator: cacheLoadFails(lastKey)
ScanIterator->>ScanIterator: check lastKey against endKey, update processingLastBatch/startKey
ConcreteScanIterator->>ConcreteScanIterator: hasNext() checks !hasEndKey or key < endKey
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Welcome @lilei-jd! It looks like this is your first PR to tikv/client-java 🎉 |
What problem does this PR solve?
Issue Number: close #660
Problem Description: In V2 API mode, RegionStoreClient.scan() only sets startKey in the Scan request without encoding or passing endKey, causing TiKV to receive an incomplete scan range and return InvalidReqRange errors. Additionally, the response KvPairs are not decoded (V2 key prefix not stripped), and the ScanIterator/ConcreteScanIterator have incorrect logic when endKey is empty or startKey reaches +∞, causing premature iteration termination.
What is changed and how does it work?
Code changes
Check List for Tests
This PR has been tested by at least one of the following methods:
Side effects
Related changes
Summary by CodeRabbit