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

fix: randomID returns shorter IDs with same amount of entropy #17

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

peterldowns
Copy link
Owner

@peterldowns peterldowns commented Sep 25, 2024

As reported in #16, the previous implementation of randomID used a hashing construction (a) inappropriately, (b) incorrectly. As a result, the IDs that were being generated had a random prefix and then a consistent suffix, like this:

3aa05350d41d8cd98f00b204e9800998ecf8427e
f1c841c1d41d8cd98f00b204e9800998ecf8427e
e5dde3f7d41d8cd98f00b204e9800998ecf8427e

This PR fixes the function to essentially just return the randomly generated prefixes, and omit the suffix entirely. The fixed-suffix was always a mistake and never intended, I just wasn't paying close attention beyond "are the instance database names colliding".

I tested this change by running some tests that used pgtestdb and intentionally failed, then checking the connection strings that were printed as part of the failing test's logs. Here's an example:

testdbconf: postgres://pgtdbuser:pgtdbpass@localhost:5433/testdb_tpl_c2b33a22a68750f84b5af76e9774be0e_inst_a4a3ce6c?sslmode=disabl

The key part is inst_a4a3ce6c, which is now (a) shorter than before, (b) just as random.

@peterldowns peterldowns linked an issue Sep 25, 2024 that may be closed by this pull request
@peterldowns peterldowns merged commit 79612d4 into main Sep 25, 2024
3 checks passed
@peterldowns peterldowns deleted the pd/randomid-fix branch September 25, 2024 18:12
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.

database instance names contain redundant data
1 participant