Skip to content

Support limiting prefixes probed for MySQL to constrain runtime - #38164

Merged
peterdukelarsen merged 1 commit into
mainfrom
pl/mysql-partition-request-budget
Aug 17, 2026
Merged

Support limiting prefixes probed for MySQL to constrain runtime#38164
peterdukelarsen merged 1 commit into
mainfrom
pl/mysql-partition-request-budget

Conversation

@peterdukelarsen

@peterdukelarsen peterdukelarsen commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Motivation

Part of SS-97.

In degenerate cases with high cardinality of first characters, many short prefixes (i.e. "a", "aa", "aaa", "aaaa"...), or unexpected bugs, we want to ensure partitioning terminates in a reasonable amount of time.

Description

Bounds the partitioner's probe traffic with a request budget derived from the table's estimated row count, via the new mysql_source_snapshot_partition_requests_per_billion_rows dyncfg (floored at 256 requests). When the budget runs out the walk stops splitting and emits coarser partitions, so cost is capped without losing correctness. The budget also serves as the hard bound on the walk for degenerate key spaces.

Adds mock tests for budget-bounded probing and for termination on non-advancing prefixes.

🤖 Generated with Claude Code

@peterdukelarsen
peterdukelarsen deleted the pl/mysql-partition-request-budget branch August 11, 2026 17:01
@peterdukelarsen
peterdukelarsen restored the pl/mysql-partition-request-budget branch August 11, 2026 17:03
@peterdukelarsen peterdukelarsen changed the title pl/mysql partition request budget storage: budget MySQL snapshot partition probing by table size Aug 11, 2026
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from f3a2461 to 90dc1b3 Compare August 11, 2026 17:26
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from 90dc1b3 to f3a000c Compare August 11, 2026 17:38
@linear-code

linear-code Bot commented Aug 11, 2026

Copy link
Copy Markdown

SS-97

@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch 8 times, most recently from 48cfbb4 to f071ccd Compare August 11, 2026 19:40
@peterdukelarsen
peterdukelarsen requested a review from a team August 11, 2026 19:40
@peterdukelarsen peterdukelarsen changed the title storage: budget MySQL snapshot partition probing by table size Support limiting prefixes probed for MySQL to constrain runtime Aug 11, 2026
@peterdukelarsen
peterdukelarsen marked this pull request as ready for review August 11, 2026 19:48
@peterdukelarsen
peterdukelarsen requested a review from a team as a code owner August 11, 2026 19:48
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from f071ccd to 1d68e03 Compare August 11, 2026 20:15
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from 1d68e03 to ecefb45 Compare August 11, 2026 22:41
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from ecefb45 to f5d757b Compare August 11, 2026 23:02
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from f5d757b to 9304f11 Compare August 11, 2026 23:35
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from 9304f11 to bcc67c6 Compare August 11, 2026 23:42
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from bcc67c6 to 1b0861e Compare August 12, 2026 00:12
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch 2 times, most recently from a097f1c to c33afc9 Compare August 12, 2026 01:23

@ublubu ublubu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like it bounds the probing and tests some of the cases it guards against. 👍

/// cover them.
struct MockDb {
keys: Vec<String>,
requests: usize,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What sort of requests is this counting? Asking because some operations cost 1, while others cost 2.

@peterdukelarsen peterdukelarsen Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The 1 and 2 here map to the number of underlying requests made to mysql. In the actual implementation one method makes two calls while the other makes one so I wanted to make sure the number of individual requests was bounded in about the way I expected (less than 4 requests per prefix).

Comment thread src/mysql-util/src/partition.rs Outdated
let budget = 20;
let boundaries = partition(&mut db, 16, count, 10, budget).await?;
assert!(
db.requests <= 80, // 4x budget

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Limiting the probes to 20 prefixes makes sense. Where does the 4x upper bound come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We make up to 4 requests per prefix -- one to get the first key matching the current prefix (only once per parent amortized across children) , two to get the next, and then one to estimate the size.

@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from c33afc9 to e54c103 Compare August 17, 2026 18:13
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from e54c103 to aff95e4 Compare August 17, 2026 18:48
Base automatically changed from pl/mysql-pk-partitioner-tests to main August 17, 2026 19:02
Bound the prefix partitioner to a per-table probe query budget scaled
to the estimated row count, 2500 requests per billion rows by default
via the mysql_source_snapshot_partition_requests_per_billion_rows
dyncfg, with a floor of 256 so small tables can afford their handful
of splits. Probes run sequentially, so this caps the wall-clock that
partitioning can add to snapshot start in proportion to the snapshot
work it optimizes. An exhausted budget stops splitting early and
leaves coarser buckets, never incorrect ones.

Adds a mock test asserting the partitioner never exceeds its budget
and still returns a valid ordered boundary list when truncated.
@peterdukelarsen
peterdukelarsen force-pushed the pl/mysql-partition-request-budget branch from aff95e4 to 4384c69 Compare August 17, 2026 19:02
@peterdukelarsen
peterdukelarsen merged commit 9d524e8 into main Aug 17, 2026
82 checks passed
@peterdukelarsen
peterdukelarsen deleted the pl/mysql-partition-request-budget branch August 17, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants