Skip to content

Commit 9e22769

Browse files
Files for Claude to work with, for the duration of the flags migrationproject
Signed-off-by: Rohit Nayak <[email protected]>
1 parent fe1db90 commit 9e22769

File tree

10 files changed

+1084
-11
lines changed

10 files changed

+1084
-11
lines changed

go/cmd/vtbackup/cli/vtbackup.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,25 @@ func init() {
201201

202202
servenv.MoveFlagsToCobraCommand(Main)
203203

204-
Main.Flags().DurationVar(&minBackupInterval, "min_backup_interval", minBackupInterval, "Only take a new backup if it's been at least this long since the most recent backup.")
205-
Main.Flags().DurationVar(&minRetentionTime, "min_retention_time", minRetentionTime, "Keep each old backup for at least this long before removing it. Set to 0 to disable pruning of old backups.")
206-
Main.Flags().IntVar(&minRetentionCount, "min_retention_count", minRetentionCount, "Always keep at least this many of the most recent backups in this backup storage location, even if some are older than the min_retention_time. This must be at least 1 since a backup must always exist to allow new backups to be made")
207-
Main.Flags().BoolVar(&initialBackup, "initial_backup", initialBackup, "Instead of restoring from backup, initialize an empty database with the provided init-db-sql-file and upload a backup of that for the shard, if the shard has no backups yet. This can be used to seed a brand new shard with an initial, empty backup. If any backups already exist for the shard, this will be considered a successful no-op. This can only be done before the shard exists in topology (i.e. before any tablets are deployed).")
208-
Main.Flags().BoolVar(&allowFirstBackup, "allow_first_backup", allowFirstBackup, "Allow this job to take the first backup of an existing shard.")
209-
Main.Flags().BoolVar(&restartBeforeBackup, "restart_before_backup", restartBeforeBackup, "Perform a mysqld clean/full restart after applying binlogs, but before taking the backup. Only makes sense to work around xtrabackup bugs.")
204+
utils.SetFlagDurationVar(Main.Flags(), &minBackupInterval, "min-backup-interval", minBackupInterval, "Only take a new backup if it's been at least this long since the most recent backup.")
205+
utils.SetFlagDurationVar(Main.Flags(), &minRetentionTime, "min-retention-time", minRetentionTime, "Keep each old backup for at least this long before removing it. Set to 0 to disable pruning of old backups.")
206+
utils.SetFlagIntVar(Main.Flags(), &minRetentionCount, "min-retention-count", minRetentionCount, "Always keep at least this many of the most recent backups in this backup storage location, even if some are older than the min_retention_time. This must be at least 1 since a backup must always exist to allow new backups to be made")
207+
utils.SetFlagBoolVar(Main.Flags(), &initialBackup, "initial-backup", initialBackup, "Instead of restoring from backup, initialize an empty database with the provided init-db-sql-file and upload a backup of that for the shard, if the shard has no backups yet. This can be used to seed a brand new shard with an initial, empty backup. If any backups already exist for the shard, this will be considered a successful no-op. This can only be done before the shard exists in topology (i.e. before any tablets are deployed).")
208+
utils.SetFlagBoolVar(Main.Flags(), &allowFirstBackup, "allow-first-backup", allowFirstBackup, "Allow this job to take the first backup of an existing shard.")
209+
utils.SetFlagBoolVar(Main.Flags(), &restartBeforeBackup, "restart-before-backup", restartBeforeBackup, "Perform a mysqld clean/full restart after applying binlogs, but before taking the backup. Only makes sense to work around xtrabackup bugs.")
210210
Main.Flags().BoolVar(&upgradeSafe, "upgrade-safe", upgradeSafe, "Whether to use innodb_fast_shutdown=0 for the backup so it is safe to use for MySQL upgrades.")
211211

212212
// vttablet-like flags
213213
utils.SetFlagStringVar(Main.Flags(), &initDbNameOverride, "init-db-name-override", initDbNameOverride, "(init parameter) override the name of the db used by vttablet")
214214
utils.SetFlagStringVar(Main.Flags(), &initKeyspace, "init-keyspace", initKeyspace, "(init parameter) keyspace to use for this tablet")
215215
utils.SetFlagStringVar(Main.Flags(), &initShard, "init-shard", initShard, "(init parameter) shard to use for this tablet")
216216
Main.Flags().IntVar(&concurrency, "concurrency", concurrency, "(init restore parameter) how many concurrent files to restore at once")
217-
Main.Flags().StringVar(&incrementalFromPos, "incremental_from_pos", incrementalFromPos, "Position, or name of backup from which to create an incremental backup. Default: empty. If given, then this backup becomes an incremental backup from given position or given backup. If value is 'auto', this backup will be taken from the last successful backup position.")
217+
utils.SetFlagStringVar(Main.Flags(), &incrementalFromPos, "incremental-from-pos", incrementalFromPos, "Position, or name of backup from which to create an incremental backup. Default: empty. If given, then this backup becomes an incremental backup from given position or given backup. If value is 'auto', this backup will be taken from the last successful backup position.")
218218

219219
// mysqlctld-like flags
220220
utils.SetFlagIntVar(Main.Flags(), &mysqlPort, "mysql-port", mysqlPort, "MySQL port")
221221
utils.SetFlagStringVar(Main.Flags(), &mysqlSocket, "mysql-socket", mysqlSocket, "Path to the mysqld socket file")
222-
Main.Flags().DurationVar(&mysqlTimeout, "mysql_timeout", mysqlTimeout, "how long to wait for mysqld startup")
222+
utils.SetFlagDurationVar(Main.Flags(), &mysqlTimeout, "mysql-timeout", mysqlTimeout, "how long to wait for mysqld startup")
223223
Main.Flags().DurationVar(&mysqlShutdownTimeout, "mysql-shutdown-timeout", mysqlShutdownTimeout, "how long to wait for mysqld shutdown")
224224
utils.SetFlagStringVar(Main.Flags(), &initDBSQLFile, "init-db-sql-file", initDBSQLFile, "path to .sql file to run after mysql_install_db")
225225
Main.Flags().BoolVar(&detachedMode, "detach", detachedMode, "detached mode - run backups detached from the terminal")

go/cmd/vtctlclient/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import (
2828

2929
"vitess.io/vitess/go/acl"
3030
"vitess.io/vitess/go/exit"
31-
"vitess.io/vitess/go/vt/utils"
3231
"vitess.io/vitess/go/trace"
3332
"vitess.io/vitess/go/vt/log"
3433
"vitess.io/vitess/go/vt/logutil"
3534
"vitess.io/vitess/go/vt/servenv"
35+
"vitess.io/vitess/go/vt/utils"
3636
"vitess.io/vitess/go/vt/vtctl/vtctlclient"
3737

3838
logutilpb "vitess.io/vitess/go/vt/proto/logutil"

go/flags/endtoend/FLAGS_PROJECT_README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,33 @@ You can find some PRs that have done this in the list
1616
from: https://github.com/vitessio/vitess/pulls?q=is%3Apr+flags+author%3Amounicasruthi+is%3Amerged
1717
For example: https://github.com/vitessio/vitess/pull/17975, https://github.com/vitessio/vitess/pull/18296
1818

19+
20+
## Pending Tasks
21+
22+
1. Find all the flags per binary by writing a similar script like count_flags.sh that
23+
* per binary, lists all flags for tha binary
24+
* per flag, lists all binaries for that flag
25+
* count of all binaries pending with number of flags pending for each
26+
2. Group flags by function
27+
3. Replace the flags across the code base using the flags utility functions from go/vt/utils/flags.go as done in
28+
previous PRs
29+
4. Ensure unit tests run in the folders where the files are being modified
30+
5. Pause after each group for manual validation and check-in and potentially separate PR creation
31+
6. Repeat Steps 3 to 5 until all flags are replaced
32+
7. Finally, go through the code base looking for any flags with underscores still being used and see how we can
33+
replace that with the dashed version. For this, since there are several identifiers using underscores, we should
34+
do a grep for the underscore versions of the all the flags either one by one or with a giant regexp, which ever
35+
works best. Or we could also create a golang program that goes through every go file in the repository. Whichever
36+
is the best approach, we are ok running these programs for long durations, say overnight, if required on our
37+
local machines.
38+
1939
## Miscellaneous notes
2040

2141
* We don't want to extend the usage of DualFormatVar for flags, because technically that supports a mix of
2242
dashes and underscores, and that is not what we want to do.
43+
* Sometimes tests fail due to upgrade/downgrade and we need to use the `GetFlagVariantForTestsByVersion` function
44+
but that needs to be manually determined from the failures in the CI upgrade/downgrade tests. If you see this
45+
function being used DO NOT replace it.
2346

2447
* The binaries we are interested in:
2548
* vtctld
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Vitess Flags Migration Verification Checklist
2+
3+
## Pre-Migration Checklist
4+
- [x] Analyze current flag usage with help text files
5+
- [x] Group flags by function/component
6+
- [x] Identify high-impact flags (used by multiple binaries)
7+
- [x] Plan migration order
8+
9+
## Per-Group Migration Checklist
10+
11+
### For Each Flag Group:
12+
1. **Code Changes**
13+
- [ ] Add `vitess.io/vitess/go/vt/utils` import where needed
14+
- [ ] Replace flag definition with appropriate `utils.SetFlag*Var` function
15+
- [ ] Ensure flag name uses dashes, not underscores
16+
- [ ] DO NOT manually add deprecation/hiding - utils functions handle this automatically
17+
- [ ] For cobra-based commands, use utils functions with Root.PersistentFlags() or cmd.Flags()
18+
19+
2. **Testing**
20+
- [ ] Run unit tests for modified packages
21+
- [ ] Verify both flag formats work (--flag-name and --flag_name)
22+
- [ ] Check that underscore version shows deprecation warning
23+
- [ ] Ensure help text shows dashed version as primary
24+
25+
3. **Documentation**
26+
- [ ] Update CLAUDE.md with completed migrations
27+
- [ ] Note any special cases or exceptions found
28+
- [ ] Record test results
29+
30+
## Completed Migrations
31+
32+
### ✅ Timeout Flags Group (2 flags)
33+
**Date:** 2025-09-05
34+
**Files Modified:**
35+
- `/go/vt/vtctld/action_repository.go`
36+
- `/go/cmd/vtctlclient/main.go`
37+
- `/go/cmd/vtctldclient/command/root.go`
38+
- `/go/vt/vtgate/tabletgateway.go`
39+
40+
**Flags Migrated:**
41+
- `action_timeout``action-timeout`
42+
- `gateway_initial_tablet_timeout``gateway-initial-tablet-timeout`
43+
44+
**Tests Run:**
45+
-`go test ./go/vt/vtctld` - PASS
46+
-`go test ./go/vt/vtgate` - PASS
47+
- ✅ Help text verification - Shows dashed version
48+
49+
## Pending Migrations
50+
51+
### Backup/Restore Flags (5 flags)
52+
- `allow_first_backup`
53+
- `file_backup_storage_root`
54+
- `initial_backup`
55+
- `min_backup_interval`
56+
- `restart_before_backup`
57+
58+
### Database Flags (20 flags)
59+
- Various mysql_auth_* flags
60+
- mysql_bind_host
61+
- mysql_timeout
62+
- etc.
63+
64+
### Stats/Monitoring Flags (2 flags)
65+
- `statsd_address`
66+
- `statsd_sample_rate`
67+
68+
## Final Verification
69+
- [ ] All underscore flags replaced with dash versions
70+
- [ ] Backward compatibility maintained
71+
- [ ] All tests passing
72+
- [ ] Documentation updated
73+
- [ ] PR created and reviewed
74+
75+
## Notes
76+
- Glog flags (log_dir, log_backtrace_at) come from Go standard library - may not need migration
77+
- Some tests use `GetFlagVariantForTestsByVersion` - DO NOT modify these
78+
- Utils functions automatically handle deprecation and hiding - no manual work needed
79+
- Utils functions work with both pflag.FlagSet and cobra's Flags()/PersistentFlags()
80+
81+
## Key Pattern to Follow:
82+
```go
83+
// Before:
84+
fs.StringVar(&variable, "flag_with_underscore", defaultValue, "description")
85+
86+
// After:
87+
utils.SetFlagStringVar(fs, &variable, "flag-with-dashes", defaultValue, "description")
88+
```

go/flags/endtoend/analyze_flags.py

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Comprehensive flag analysis tool for Vitess flags migration project.
4+
Analyzes help text files to identify flags with underscores that need migration.
5+
"""
6+
7+
import os
8+
import re
9+
from collections import defaultdict
10+
import json
11+
12+
def parse_help_file(filepath):
13+
"""Parse a help text file and extract flag information."""
14+
flags = []
15+
binary_name = os.path.basename(filepath).replace('.txt', '')
16+
17+
with open(filepath, 'r') as f:
18+
lines = f.readlines()
19+
20+
reading_flags = False
21+
for line in lines:
22+
# Check if we're entering the flags section
23+
if line.strip() in ["Flags:", "Usage of vtctlclient:"]:
24+
reading_flags = True
25+
continue
26+
27+
if reading_flags:
28+
# Extract flag if line starts with --
29+
match = re.match(r'\s*(--[a-zA-Z0-9_-]+)', line)
30+
if match:
31+
flag_name = match.group(1)[2:] # Remove --
32+
has_underscore = '_' in flag_name
33+
has_dash = '-' in flag_name
34+
35+
flags.append({
36+
'name': flag_name,
37+
'has_underscore': has_underscore,
38+
'has_dash': has_dash,
39+
'binary': binary_name
40+
})
41+
42+
return flags
43+
44+
def analyze_all_binaries():
45+
"""Analyze all binary help files and generate comprehensive report."""
46+
flags_dir = '/Users/rohit/vitess/go/flags/endtoend'
47+
48+
# Target binaries we care about
49+
target_binaries = [
50+
'vtctld', 'vtctldclient', 'vttablet', 'vtgate', 'vtorc',
51+
'mysqlctl', 'mysqlctld', 'vtcombo', 'vttestserver',
52+
'vtbackup', 'vtclient', 'vtbench'
53+
]
54+
55+
all_flags = []
56+
binary_stats = {}
57+
flag_to_binaries = defaultdict(set)
58+
59+
# Process each help file
60+
for filename in os.listdir(flags_dir):
61+
if filename.endswith('.txt'):
62+
binary_name = filename.replace('.txt', '')
63+
if binary_name not in target_binaries:
64+
continue
65+
66+
filepath = os.path.join(flags_dir, filename)
67+
flags = parse_help_file(filepath)
68+
all_flags.extend(flags)
69+
70+
# Calculate stats for this binary
71+
underscore_count = sum(1 for f in flags if f['has_underscore'])
72+
dash_count = sum(1 for f in flags if f['has_dash'] and not f['has_underscore'])
73+
74+
binary_stats[binary_name] = {
75+
'total_flags': len(flags),
76+
'underscore_flags': underscore_count,
77+
'dash_flags': dash_count,
78+
'completion_percentage': round((dash_count / len(flags) * 100) if flags else 100, 1)
79+
}
80+
81+
# Map flags to binaries
82+
for flag in flags:
83+
flag_to_binaries[flag['name']].add(binary_name)
84+
85+
return all_flags, binary_stats, flag_to_binaries
86+
87+
def generate_report():
88+
"""Generate comprehensive migration report."""
89+
all_flags, binary_stats, flag_to_binaries = analyze_all_binaries()
90+
91+
print("=" * 80)
92+
print("VITESS FLAGS MIGRATION STATUS REPORT")
93+
print("=" * 80)
94+
print()
95+
96+
# Overall statistics
97+
total_underscore = sum(s['underscore_flags'] for s in binary_stats.values())
98+
total_dash = sum(s['dash_flags'] for s in binary_stats.values())
99+
total_flags = sum(s['total_flags'] for s in binary_stats.values())
100+
101+
print("OVERALL PROGRESS:")
102+
print(f" Total flags: {total_flags}")
103+
print(f" Flags with underscores (need migration): {total_underscore}")
104+
print(f" Flags with dashes (completed): {total_dash}")
105+
print(f" Overall completion: {round((total_dash / total_flags * 100) if total_flags else 100, 1)}%")
106+
print()
107+
108+
# Per-binary statistics
109+
print("PER-BINARY STATUS:")
110+
print("-" * 80)
111+
print(f"{'Binary':<15} {'Total':<10} {'Underscore':<12} {'Dash':<10} {'Completion':<12}")
112+
print("-" * 80)
113+
114+
# Sort by number of underscore flags (most work needed first)
115+
sorted_binaries = sorted(binary_stats.items(),
116+
key=lambda x: x[1]['underscore_flags'],
117+
reverse=True)
118+
119+
for binary, stats in sorted_binaries:
120+
status = "✓ DONE" if stats['underscore_flags'] == 0 else ""
121+
print(f"{binary:<15} {stats['total_flags']:<10} {stats['underscore_flags']:<12} "
122+
f"{stats['dash_flags']:<10} {stats['completion_percentage']:<10.1f}% {status}")
123+
124+
print()
125+
126+
# Find unique underscore flags across all binaries
127+
unique_underscore_flags = set()
128+
for flag in all_flags:
129+
if flag['has_underscore']:
130+
unique_underscore_flags.add(flag['name'])
131+
132+
print(f"UNIQUE FLAGS WITH UNDERSCORES: {len(unique_underscore_flags)}")
133+
print("-" * 80)
134+
135+
# Group flags by how many binaries use them
136+
flag_usage = defaultdict(list)
137+
for flag_name in unique_underscore_flags:
138+
binaries = flag_to_binaries[flag_name]
139+
flag_usage[len(binaries)].append((flag_name, binaries))
140+
141+
# Show flags used by multiple binaries first (higher impact)
142+
for count in sorted(flag_usage.keys(), reverse=True):
143+
if count > 1:
144+
print(f"\nFlags used by {count} binaries:")
145+
for flag_name, binaries in sorted(flag_usage[count]):
146+
print(f" {flag_name:<40} -> {', '.join(sorted(binaries))}")
147+
148+
# Save detailed data to JSON for further processing
149+
detailed_data = {
150+
'binary_stats': binary_stats,
151+
'unique_underscore_flags': list(unique_underscore_flags),
152+
'flag_to_binaries': {k: list(v) for k, v in flag_to_binaries.items() if '_' in k}
153+
}
154+
155+
with open('/Users/rohit/vitess/go/flags/endtoend/flags_analysis.json', 'w') as f:
156+
json.dump(detailed_data, f, indent=2)
157+
158+
print()
159+
print("Detailed analysis saved to: flags_analysis.json")
160+
print()
161+
162+
# Suggest migration priority
163+
print("SUGGESTED MIGRATION PRIORITY:")
164+
print("-" * 80)
165+
print("1. High-impact flags (used by multiple binaries)")
166+
print("2. Binaries with most underscore flags remaining:")
167+
for i, (binary, stats) in enumerate(sorted_binaries[:5], 1):
168+
if stats['underscore_flags'] > 0:
169+
print(f" {i}. {binary} ({stats['underscore_flags']} flags)")
170+
171+
if __name__ == "__main__":
172+
generate_report()

0 commit comments

Comments
 (0)