Skip to content

proto: add paging_size_bytes to coprocessor.Request#1448

Merged
ti-chi-bot[bot] merged 1 commit into
pingcap:masterfrom
JmPotato:demo/ru-paging-size
Jun 11, 2026
Merged

proto: add paging_size_bytes to coprocessor.Request#1448
ti-chi-bot[bot] merged 1 commit into
pingcap:masterfrom
JmPotato:demo/ru-paging-size

Conversation

@JmPotato

@JmPotato JmPotato commented Apr 2, 2026

Copy link
Copy Markdown
Member

What is changed and how it works?

Add a new paging_size_bytes field (field 17, uint64) to the coprocessor.Request message.

  • When paging_size_bytes is 0, the feature is disabled (backward compatible).
  • When set to a positive value, TiKV will stop scanning the current page once accumulated scanned bytes reach this limit and return the page boundary so the next page can resume from there.

Note: paging_size_bytes is intentionally distinct from the existing max_keys_read (field 16). max_keys_read is a per-task hard ceiling on storage-engine keys scanned, applied uniformly to any coprocessor request. paging_size_bytes is a paging-only, byte-granularity dimension intended for Resource Control: it bounds the byte volume of a single page so RU pre-charging in PD's resource controller can be performed at byte granularity, complementing the existing row-count-based paging (paging_size). The two fields target different scenarios and may be set independently.

Why is this needed?

In concurrent coprocessor workloads under Resource Control, row-count-based paging alone cannot prevent "token cliff" effects where multiple workers exhaust RU budgets simultaneously. A byte-based budget provides finer-grained control for RU pre-charging in PD's resource controller.

Related PRs

@ti-chi-bot

ti-chi-bot Bot commented Apr 28, 2026

Copy link
Copy Markdown

@YuhaoZhang00: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Add a new uint64 field `paging_size_bytes` (field 17) to the
coprocessor Request message. When set, TiKV will stop scanning
when accumulated scanned bytes reach this limit, enabling
byte-budget paging for finer-grained Resource Control.

Note: rebased onto upstream master where field 16 is now taken
by max_keys_read (pingcap#1450), so paging_size_bytes was bumped from
field 16 to field 17.

Signed-off-by: JmPotato <github@ipotato.me>
@JmPotato JmPotato force-pushed the demo/ru-paging-size branch from a6a24f9 to c2edc88 Compare June 11, 2026 08:14
@ti-chi-bot

ti-chi-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

@lhy1024: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added the lgtm label Jun 11, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, lhy1024, rleungx, YuhaoZhang00

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

ti-chi-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-05-18 03:22:10.355002663 +0000 UTC m=+148059.859133339: ☑️ agreed by rleungx.
  • 2026-06-11 08:22:28.159639647 +0000 UTC m=+1034649.229957037: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot Bot merged commit a15c348 into pingcap:master Jun 11, 2026
5 checks passed
@JmPotato JmPotato deleted the demo/ru-paging-size branch June 11, 2026 08:46
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jun 26, 2026
Add a TiDB-side knob `tidb_paging_size_bytes` (global+session sysvar,
default 0) and plumb the value end-to-end so it lands as the new
`paging_size_bytes` field on `coprocessor.Request`.

- `tidb_paging_size_bytes` is allowed in `SET_VAR` hints; default 0
  disables byte-budget paging.
- The value flows through `DistSQLContext` into
  `kv.Request.Paging.PagingSizeBytes` via `RequestBuilder`.
- In the cop client, `pagingBytesEligible` gates the feature to
  TiKV + DAG requests. When the byte budget is positive on an
  eligible request whose row-count paging is disabled, paging is
  force-enabled with minimum row parameters so the byte budget
  becomes the dominant page-break signal. This must happen before
  `checkStoreBatchCopr` because batch copr is incompatible with
  paging.
- The byte budget is carried on each generated `copTask`,
  populates `coprocessor.Request.PagingSizeBytes` on outgoing
  RPCs, propagates onto retried tasks (region/lock errors), and
  is cleared together with `pagingSize` when the small-limit
  downgrade fires.

Dependency:

- Pin `pingcap/kvproto` to JmPotato/kvproto demo/ru-paging-size
  which adds `paging_size_bytes` (tag 17) to `coprocessor.Request`
  via pingcap/kvproto#1448; revert this replace once that PR is
  merged and tagged.

Tests:

- `TestPagingBytesEligible` covers eligibility for TiKV/DAG vs
  TiFlash and non-DAG requests.
- `TestBuildCopTasksWithPagingSizeBytes` covers task construction
  with and without small-limit downgrade.
- `tests/integrationtest/sessionctx/setvar` is extended to cover
  the new sysvar (default, set, set via SET_VAR hint).

Signed-off-by: JmPotato <github@ipotato.me>
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jun 29, 2026
Add a TiDB-side knob `tidb_paging_size_bytes` (global+session sysvar,
default 0) and plumb the value end-to-end so it lands as the new
`paging_size_bytes` field on `coprocessor.Request`.

- `tidb_paging_size_bytes` is allowed in `SET_VAR` hints; default 0
  disables byte-budget paging.
- The value flows through `DistSQLContext` into
  `kv.Request.Paging.PagingSizeBytes` via `RequestBuilder`.
- In the cop client, `pagingBytesEligible` gates the feature to
  TiKV + DAG requests. When the byte budget is positive on an
  eligible request whose row-count paging is disabled, paging is
  force-enabled with minimum row parameters so the byte budget
  becomes the dominant page-break signal. This must happen before
  `checkStoreBatchCopr` because batch copr is incompatible with
  paging.
- The byte budget is carried on each generated `copTask`,
  populates `coprocessor.Request.PagingSizeBytes` on outgoing
  RPCs, propagates onto retried tasks (region/lock errors), and
  is cleared together with `pagingSize` when the small-limit
  downgrade fires.

Dependency:

- Pin `pingcap/kvproto` to JmPotato/kvproto demo/ru-paging-size
  which adds `paging_size_bytes` (tag 17) to `coprocessor.Request`
  via pingcap/kvproto#1448; revert this replace once that PR is
  merged and tagged.

Tests:

- `TestPagingBytesEligible` covers eligibility for TiKV/DAG vs
  TiFlash and non-DAG requests.
- `TestBuildCopTasksWithPagingSizeBytes` covers task construction
  with and without small-limit downgrade.
- `tests/integrationtest/sessionctx/setvar` is extended to cover
  the new sysvar (default, set, set via SET_VAR hint).

Signed-off-by: JmPotato <github@ipotato.me>
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jun 29, 2026
Add a TiDB-side knob `tidb_paging_size_bytes` (global+session sysvar,
default 0) and plumb the value end-to-end so it lands as the new
`paging_size_bytes` field on `coprocessor.Request`.

- `tidb_paging_size_bytes` is allowed in `SET_VAR` hints; default 0
  disables byte-budget paging.
- The value flows through `DistSQLContext` into
  `kv.Request.Paging.PagingSizeBytes` via `RequestBuilder`.
- In the cop client, `pagingBytesEligible` gates the feature to
  TiKV + DAG requests. When the byte budget is positive on an
  eligible request whose row-count paging is disabled, paging is
  force-enabled with minimum row parameters so the byte budget
  becomes the dominant page-break signal. This must happen before
  `checkStoreBatchCopr` because batch copr is incompatible with
  paging.
- The byte budget is carried on each generated `copTask`,
  populates `coprocessor.Request.PagingSizeBytes` on outgoing
  RPCs, propagates onto retried tasks (region/lock errors), and
  is cleared together with `pagingSize` when the small-limit
  downgrade fires.

Dependency:

- Pin `pingcap/kvproto` to JmPotato/kvproto demo/ru-paging-size
  which adds `paging_size_bytes` (tag 17) to `coprocessor.Request`
  via pingcap/kvproto#1448; revert this replace once that PR is
  merged and tagged.

Tests:

- `TestPagingBytesEligible` covers eligibility for TiKV/DAG vs
  TiFlash and non-DAG requests.
- `TestBuildCopTasksWithPagingSizeBytes` covers task construction
  with and without small-limit downgrade.
- `tests/integrationtest/sessionctx/setvar` is extended to cover
  the new sysvar (default, set, set via SET_VAR hint).

Signed-off-by: JmPotato <github@ipotato.me>
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jun 29, 2026
Add a TiDB-side knob `tidb_paging_size_bytes` (global+session sysvar,
default 0) and plumb the value end-to-end so it lands as the new
`paging_size_bytes` field on `coprocessor.Request`.

- `tidb_paging_size_bytes` is allowed in `SET_VAR` hints; default 0
  disables byte-budget paging.
- The value flows through `DistSQLContext` into
  `kv.Request.Paging.PagingSizeBytes` via `RequestBuilder`.
- In the cop client, `pagingBytesEligible` gates the feature to
  TiKV + DAG requests. When the byte budget is positive on an
  eligible request whose row-count paging is disabled, paging is
  force-enabled with minimum row parameters so the byte budget
  becomes the dominant page-break signal. This must happen before
  `checkStoreBatchCopr` because batch copr is incompatible with
  paging.
- The byte budget is carried on each generated `copTask`,
  populates `coprocessor.Request.PagingSizeBytes` on outgoing
  RPCs, propagates onto retried tasks (region/lock errors), and
  is cleared together with `pagingSize` when the small-limit
  downgrade fires.

Dependency:

- Pin `pingcap/kvproto` to JmPotato/kvproto demo/ru-paging-size
  which adds `paging_size_bytes` (tag 17) to `coprocessor.Request`
  via pingcap/kvproto#1448; revert this replace once that PR is
  merged and tagged.

Tests:

- `TestPagingBytesEligible` covers eligibility for TiKV/DAG vs
  TiFlash and non-DAG requests.
- `TestBuildCopTasksWithPagingSizeBytes` covers task construction
  with and without small-limit downgrade.
- `tests/integrationtest/sessionctx/setvar` is extended to cover
  the new sysvar (default, set, set via SET_VAR hint).

Signed-off-by: JmPotato <github@ipotato.me>
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jul 1, 2026
Add a TiDB-side knob `tidb_paging_size_bytes` (global+session sysvar,
default 0) and plumb the value end-to-end so it lands as the new
`paging_size_bytes` field on `coprocessor.Request`.

- `tidb_paging_size_bytes` is allowed in `SET_VAR` hints; default 0
  disables byte-budget paging.
- The value flows through `DistSQLContext` into
  `kv.Request.Paging.PagingSizeBytes` via `RequestBuilder`.
- In the cop client, `pagingBytesEligible` gates the feature to
  TiKV + DAG requests. When the byte budget is positive on an
  eligible request whose row-count paging is disabled, paging is
  force-enabled with minimum row parameters so the byte budget
  becomes the dominant page-break signal. This must happen before
  `checkStoreBatchCopr` because batch copr is incompatible with
  paging.
- The byte budget is carried on each generated `copTask`,
  populates `coprocessor.Request.PagingSizeBytes` on outgoing
  RPCs, propagates onto retried tasks (region/lock errors), and
  is cleared together with `pagingSize` when the small-limit
  downgrade fires.

Dependency:

- Pin `pingcap/kvproto` to JmPotato/kvproto demo/ru-paging-size
  which adds `paging_size_bytes` (tag 17) to `coprocessor.Request`
  via pingcap/kvproto#1448; revert this replace once that PR is
  merged and tagged.

Tests:

- `TestPagingBytesEligible` covers eligibility for TiKV/DAG vs
  TiFlash and non-DAG requests.
- `TestBuildCopTasksWithPagingSizeBytes` covers task construction
  with and without small-limit downgrade.
- `tests/integrationtest/sessionctx/setvar` is extended to cover
  the new sysvar (default, set, set via SET_VAR hint).

Signed-off-by: JmPotato <github@ipotato.me>
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.

5 participants