Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add "auto-split" arg to auto-gen UID prefixes #1035

Merged
merged 2 commits into from
Apr 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tools/spanner/purge_ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def spanner_purge(args):
instance = client.instance(args.instance_id)
database = instance.database(args.database_id)
expiry_condition = get_expiry_condition(args)
if args.auto_split:
args.uid_prefixes = [
hex(i).lstrip("0x").zfill(args.auto_split) for i in range(
0, 16 ** args.auto_split)]
prefixes = args.uid_prefixes if args.uid_prefixes else [None]

for prefix in prefixes:
Expand Down Expand Up @@ -190,6 +194,14 @@ def get_args():
help="Array of strings used to limit purges based on UID. "
"Each entry is a separate purge run."
)
parser.add_argument(
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth adding a guard to error out if both auto_split and uid_prefixes are specified?

Copy link
Member Author

Choose a reason for hiding this comment

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

If this was a general use tool, absolutely. Since it's in-house, I'm willing to let it slide and just answer any questions SRE might come up with.

If they hit it as a problem, I'll add the guards.

"--auto_split",
type=int,
default=os.environ.get("PURGE_AUTO_SPLIT"),
help="""Automatically generate `uid_prefixes` for this many digits, """
"""(e.g. `3` would produce """
"""`uid_prefixes=["000","001","002",...,"fff"])"""
)
parser.add_argument(
"--mode",
type=str,
Expand Down