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

Use fetch_update when generating new IDs #25542

Open
hiltontj opened this issue Nov 13, 2024 · 0 comments
Open

Use fetch_update when generating new IDs #25542

hiltontj opened this issue Nov 13, 2024 · 0 comments
Labels

Comments

@hiltontj
Copy link
Contributor

Given the limits we impose on database, table, column, etc., this may not be likely, but fetch_add silently wraps around to 0 on overflow. That would be pretty bad if it were to happen. This can be seen in the DbId::new method.

We could instead use fetch_update with a u32::checked_add, e.g.,

NEXT_ID.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |n| n.checked_add(1)).expect("too many IDs!")
@hiltontj hiltontj added the v3 label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant