Skip to content

Conversation

@arthurschreiber
Copy link
Member

@arthurschreiber arthurschreiber commented Sep 9, 2025

Description

This adds a new --hex-width cli flag to vtctldclient GenerateShardRanges. This flag allows specifying how many characters to use for start and end parts of the shard range labels. This can be used to reduce the shard size differences when using a shard count that is not a power of 2.

I'm not super happy with the naming of the CLI flag, suggestions for alternative naming are welcome.

Related Issue(s)

Fixes: #15744
References: #17688

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Sep 9, 2025

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Sep 9, 2025
@github-actions github-actions bot added this to the v23.0.0 milestone Sep 9, 2025
@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.48%. Comparing base (7398277) to head (a43a090).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
go/cmd/vtctldclient/command/shards.go 66.66% 1 Missing ⚠️
go/vt/vtctl/vtctl.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #18633   +/-   ##
=======================================
  Coverage   67.48%   67.48%           
=======================================
  Files        1613     1613           
  Lines      263962   263948   -14     
=======================================
- Hits       178146   178137    -9     
+ Misses      85816    85811    -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arthurschreiber arthurschreiber changed the title Allow specifying the number of characters to use when generating shard ranges. feat: Allow specifying the number of characters to use when generating shard ranges. Sep 12, 2025
@arthurschreiber arthurschreiber added Type: Feature Component: CLI and removed NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsWebsiteDocsUpdate What it says labels Sep 16, 2025
@arthurschreiber arthurschreiber force-pushed the arthur/generate-shard-ranges branch from 0018ddf to 92afd27 Compare September 16, 2025 06:03
This allows specifying how many characters should be used in the generated shard labels. Using a higher number if characters reduces unevenness of shard sizes when using shard counts that are not a power of two.

Signed-off-by: Arthur Schreiber <[email protected]>
@arthurschreiber arthurschreiber removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request labels Sep 16, 2025
@arthurschreiber arthurschreiber marked this pull request as ready for review September 16, 2025 12:58
Copy link
Collaborator

@nickvanw nickvanw left a comment

Choose a reason for hiding this comment

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

This looks good to me, will wait for feedback from others on the command line flag.

It would be good to add some more exhaustive tests for common scenarios, I think - passing 0 in for various values, and overriding to 3 or 4 at smaller shard values.

// equal distribution of N shards.
GenerateShardRanges = &cobra.Command{
Use: "GenerateShardRanges <num_shards>",
Use: "GenerateShardRanges <num_shards> [--chars]",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think --chars makes sense. Other things I thought about:

  • --num-digits
  • --digits
  • --hex-char-count
  • --char-count
  • --range-digits

Let me know if you or anyone thinks any of those are better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Claude likes --digits. It also suggests --width.

Copy link
Member

Choose a reason for hiding this comment

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

what about --hex-format-length or --format-length

@arthurschreiber
Copy link
Member Author

It would be good to add some more exhaustive tests for common scenarios, I think - passing 0 in for various values, and overriding to 3 or 4 at smaller shard values.

I added another test case for 512 shards (to verify that using a shard number > 256 uses 4 characters).

@arthurschreiber arthurschreiber force-pushed the arthur/generate-shard-ranges branch from a6e7216 to 7874274 Compare September 16, 2025 18:24
Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

LGTM
Like @nickvanw said, need some test with different hex length passed to the function and finalizing on the flag name

@harshit-gangal
Copy link
Member

It would be good to add some more exhaustive tests for common scenarios, I think - passing 0 in for various values, and overriding to 3 or 4 at smaller shard values.

I added another test case for 512 shards (to verify that using a shard number > 256 uses 4 characters).

A test like 8 shards with 4 length

@arthurschreiber
Copy link
Member Author

Signed-off-by: Arthur Schreiber <[email protected]>
@arthurschreiber arthurschreiber force-pushed the arthur/generate-shard-ranges branch from 472910a to b683f2f Compare September 17, 2025 10:18
@arthurschreiber arthurschreiber changed the title feat: Allow specifying the number of characters to use when generating shard ranges. feat: Allow specifying the hex width to use when generating shard ranges. Sep 22, 2025
@arthurschreiber
Copy link
Member Author

I renamed the option to --hex-width.

@arthurschreiber arthurschreiber enabled auto-merge (squash) September 22, 2025 14:28
Copy link
Collaborator

@nickvanw nickvanw left a comment

Choose a reason for hiding this comment

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

:shipit:

@arthurschreiber arthurschreiber merged commit d3c3003 into vitessio:main Sep 22, 2025
103 of 104 checks passed
@arthurschreiber arthurschreiber deleted the arthur/generate-shard-ranges branch September 23, 2025 00:05
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.

Feature Request: configurable number of digits in generated shard ranges

5 participants