Skip to content

Add range_versions field to Request used by tici#1356

Merged
ti-chi-bot[bot] merged 8 commits intopingcap:masterfrom
wshwsh12:add_versioned_lookup
Feb 4, 2026
Merged

Add range_versions field to Request used by tici#1356
ti-chi-bot[bot] merged 8 commits intopingcap:masterfrom
wshwsh12:add_versioned_lookup

Conversation

@wshwsh12
Copy link
Contributor

No description provided.

@ti-chi-bot ti-chi-bot bot added the size/XL label Sep 29, 2025
@ti-chi-bot ti-chi-bot bot requested a review from pingyu September 29, 2025 08:44
string connection_alias = 13; // This is the session alias between a client and tidb

repeated TableShardInfos table_shard_infos= 14; // Shard infos for FTS index, used by TiFlash reading TiCI.
// versions of each reange, used in TiCI lookup, if range_versions is set, then len(range_versions) should equal to len(ranges), and all the range in ranges should be point range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// versions of each reange, used in TiCI lookup, if range_versions is set, then len(range_versions) should equal to len(ranges), and all the range in ranges should be point range
// versions of each range, used in TiCI lookup, if range_versions is set, then len(range_versions) should equal to len(ranges), and all the range in ranges should be point range

@wshwsh12 wshwsh12 requested a review from windtalker October 11, 2025 07:28
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@wshwsh12 wshwsh12 force-pushed the add_versioned_lookup branch from 113cbfc to 5d3f2c4 Compare January 7, 2026 06:45
@ti-chi-bot ti-chi-bot bot added size/XXL and removed size/XL labels Jan 27, 2026

repeated TableShardInfos table_shard_infos= 14; // Shard infos for FTS index, used by TiFlash reading TiCI.
// versions of each range, used in TiCI lookup, if range_versions is set, then len(range_versions) should equal to len(ranges), and all the range in ranges should be point range
repeated uint64 range_versions = 15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range_versions is a parallel array to ranges, which is easy to desync when ranges are reordered/filtered/deduped; a safer modeling is
“version attached to range” (e.g. extend KeyRange, or introduce VersionedKeyRange { KeyRange range = 1; fixed64 read_ts = 2; }) to prevent subtle mismatches.

string connection_alias = 13; // This is the session alias between a client and tidb

repeated TableShardInfos table_shard_infos= 14; // Shard infos for FTS index, used by TiFlash reading TiCI.
// versions of each range, used in TiCI lookup, if range_versions is set, then len(range_versions) should equal to len(ranges), and all the range in ranges should be point range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For repeated in proto3 a clearer invariant is “when range_versions is non-empty” instead of range_versions is set.

}

service VersionedKv {
rpc VersionedCoprocessor(coprocessor.Request) returns (coprocessor.Response) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better comment about the invariants and usage scenarios here to avoid mis-usages for the new interface.

@wshwsh12 wshwsh12 requested a review from cfzjywxk January 30, 2026 06:42
repeated TableShardInfos table_shard_infos= 14; // Shard infos for FTS index, used by TiFlash reading TiCI.
// Versioned point ranges for TiCI lookup.
// When `versioned_ranges` is non-empty, all `versioned_ranges[i].range` must be point range.
repeated VersionedKeyRange versioned_ranges = 15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed if versioned_ranges is included in repeated StoreBatchTask tasks = 11;?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When tidb variable StoreBatchSize = 0, StoreBatchTask will not be used. In this case, this field will be used.

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot ti-chi-bot bot added the lgtm label Feb 4, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 4, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, windtalker

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 4, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-30 12:25:09.077149251 +0000 UTC m=+1360736.691106107: ☑️ agreed by cfzjywxk.
  • 2026-02-04 08:30:43.813728451 +0000 UTC m=+255714.915127165: ☑️ agreed by windtalker.

@ti-chi-bot ti-chi-bot bot merged commit f3cc977 into pingcap:master Feb 4, 2026
5 checks passed
ti-chi-bot bot pushed a commit to tikv/tikv that referenced this pull request Feb 13, 2026
…19302)

close #19357

coprocessor: support versioned lookup via per-key read ts (range_versions)

  This introduces a special "versioned lookup" read path for coprocessor DAG requests:

  - When `coppb::Request.range_versions` is empty, behavior is unchanged.
  - When `range_versions` is provided:
    - `ranges.len()` must equal `range_versions.len()`
    - all `ranges` must be point ranges
    - only DAG + TableScan is allowed
    - each `ranges[i]` is read at `range_versions[i]` (per-key read ts), while bypassing txn-related checks:
      - endpoint memory lock checking / max_ts update
      - lock-cf checking in PointGetter
      - RcCheckTs newer-ts conflicts

  Implementation overview:
  - Plumb `range_versions` through Endpoint -> DagHandlerBuilder -> TableScan -> RangesScanner.
  - Add Store/SnapshotStore `get_entry_at_ts` backed by PointGetter with `bypass_txn_check`.
  - Disable coprocessor cache for versioned lookup to avoid unintended cache hits.

  Tests:
  - Add unit tests for validation/guard rails and bypass behaviors.
  - Add executor tests to verify per-range ts usage (including backward scan alignment).
  - Extend coprocessor integration tests for reading older versions.

  Dependencies:
  - Requires kvproto change adding `coppb::Request.range_versions` (kvproto PR: pingcap/kvproto#1356).
    The temporary `[patch]` in `Cargo.toml` can be removed after kvproto is merged.

Signed-off-by: wshwsh12 <793703860@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants