-
Notifications
You must be signed in to change notification settings - Fork 112
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
Token: add constructor and normalization #948
Conversation
See the following report for details: cargo semver-checks output
|
cargo semver-checks output
|
scylla/src/routing.rs
Outdated
#[inline] | ||
pub fn new_denormalized(value: i64) -> Self { | ||
Self { value } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to expose new_denormalized
?
By default, I'm against exposing functions unless we have a strong reason to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I exposed all methods because before the change the field itself was public. We could restrict this method (maybe new()
too?), but I'd like to know what users need Token
for. Is there any plausible scenario where they need to create a new token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of any such scenario. WDYT @piodul?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code below, it seems there is one case where you call new_denormalize() but only for the MIN value itself. So I think instead of new_denormalized(i64) you should have just a new_invalid() which returns an invalid token - it it64:min.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, we either want to create a valid token (everywhere else) or specifically an invalid token (i64::MIN
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried that a year from now, nobody will remember what a "denormalized" token means. So you'll either need to write a comment explaining what this constructor means and when to use it - or just not have this constructor and have a separate new_invalid() just for the special case of min_token which is easy to understand what it means. If it's enough...
BTW, If I understand correctly, an "invalid token" (min_int) will never be part of any token range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure anything comes to my mind as far as real use cases for users go for
new_denormalized
. For our internal use at least we will have to represent token ranges somehow, specifically their left ends. I don't know whether this concern for users.
What I meant is: are there are scenarios where user needs to create a new token from integer? I'm not talking just about invalid tokens, but any tokens at all. @piodul
I'm asking because I'm wondering if we can make all constructors private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, but I'd err on the more cautious side and allow creating tokens from integers.
Do we have any APIs in the driver that accept Token
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, but I'd err on the more cautious side and allow creating tokens from integers.
Do we have any APIs in the driver that accept
Token
?
There are some:
https://docs.rs/scylla/latest/scylla/routing/struct.Sharder.html#method.shard_of
https://docs.rs/scylla/latest/scylla/transport/locator/struct.TokenRing.html#method.get_elem_for_token
https://docs.rs/scylla/latest/scylla/transport/locator/struct.TokenRing.html#method.ring_range
https://docs.rs/scylla/latest/scylla/transport/locator/struct.TokenRing.html#method.ring_range_full
https://docs.rs/scylla/latest/scylla/transport/locator/struct.ReplicaLocator.html#method.replicas_for_token
https://docs.rs/scylla/latest/scylla/transport/struct.ClusterData.html#method.get_token_endpoints
I found them by search Token
on docs.rs and going to "In Parameters" tab - judging by the results I got I think those should be exhaustive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the constructor needs to remain public I think. Not sure about INVALID constant (previously new_unchecked). We can probably make it private?
ca43793
to
3425851
Compare
cargo semver-checks output
|
cargo semver-checks output
|
cargo semver-checks output
|
813f529
to
9f2c5b6
Compare
|
9f2c5b6
to
049dc35
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
`i64::MIN` turns out to be an invalid value for a token: https://github.com/scylladb/scylladb/blob/4be70bfc2bc7f133cab492b4aac7bab9c790a48c/dht/token.hh#L32 Hashing algorithm should change `i64::MIN` result to `i64::MAX`. In order to have this check in one place and make sure we always perform it I made `value` field of `Token` non-public and created constructor and getter for it.
049dc35
to
7b7592d
Compare
i64::MIN
turns out to be an invalid value for a token: https://github.com/scylladb/scylladb/blob/4be70bfc2bc7f133cab492b4aac7bab9c790a48c/dht/token.hh#L32Hashing algorithm should change
i64::MIN
result toi64::MAX
.In order to have this check in one place and make sure we always perform it I made
value
field ofToken
non-public and created constructor and getter for it.Fixes: #947
Pre-review checklist
./docs/source/
.Fixes:
annotations to PR description.