-
Notifications
You must be signed in to change notification settings - Fork 111
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 unnamable types #1094
Fix unnamable types #1094
Conversation
See the following report for details: cargo semver-checks output
|
f42b184
to
0275ef4
Compare
Fixed compilation errors when building without |
impl ClusterData { | ||
// Updates information about rack count in each datacenter | ||
fn update_rack_count(datacenters: &mut HashMap<String, Datacenter>) { | ||
for datacenter in datacenters.values_mut() { | ||
datacenter.rack_count = datacenter | ||
.nodes | ||
.iter() | ||
.filter_map(|node| node.rack.as_ref()) | ||
.unique() | ||
.count(); | ||
} | ||
} | ||
|
||
pub(crate) async fn wait_until_all_pools_are_initialized(&self) { |
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.
wow.
|
||
if let Some(dc) = &node.datacenter { | ||
match datacenters.get_mut(dc) { | ||
Some(v) => v.nodes.push(node.clone()), | ||
None => { | ||
let v = Datacenter { | ||
nodes: vec![node.clone()], | ||
rack_count: 0, | ||
}; | ||
datacenters.insert(dc.clone(), v); | ||
} | ||
} | ||
} | ||
|
||
for token in peer_tokens { |
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.
but...
|
||
Self::update_rack_count(&mut datacenters); | ||
|
||
let keyspaces = metadata.keyspaces; |
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.
...was that really pointless?! I can't believe it has always been... Could you please locate the commit that made datacenters
unused?
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.
This code was introduced in this commit: 8d82b04#diff-fc8ab4fd7742b17e4767ade6844fd697e5a7b0050bbadb414f52d19f6245bbac (PR: #172 )
You can see that the result is saved in ClusterData.
Then the field in ClusterData was removed by the same author 2 years later: 0db57c1 - but the calculation in ClusterData::new remained, introducing uselessness. PR: #612
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 pretty sure that even thought there was no useless calculation before #612 this API was still useless because Datacenter
struct was never truly public (= pub and exported)
0275ef4
to
e22f437
Compare
It was public but not exported, despite being returned from methods that are part of public API.
e22f437
to
0d871db
Compare
`ResolvedContactPoint` was unnameable. It was part of public API, because it was in a variant of `UntranslatedEndpoint`, which itself was public. `UntranslatedEndpoint` is not used in any public API, so can be made `pub(crate)`. Thanks to that `ResolvedContactPoint` can also be made `pub(crate)` as it no longer appears in any public API.
It was not possible for user to create / retrieve `KnownNode::CloudEndpoint` variant: - `CloudEndpoint` was unnameable type, which means user can't create an instance of it. - No public API allowed user to create this variant or CloudEndpoint struct: they are only used internally. This commit splits `KnownNode` struct into two: - `KnownNode`, without `CloudEndpoint`, which is part of public API - `InternalKnownNode` which is only used internally and thus `pub(crate)`. Thanks to that, `CloudEndpoint` is no longer part of any public API and can be made `pub(crate)`.
This struct is a part of public API: it is present in a field of `SessionConfig`. It was not exported - so it was an unnameable type. It has a pub method that allows its construction by parsing a yaml file, so user could (if this struct was public) create it and put it in several `SessionConfigs`. This commit exports this struct so it is a proper part of public API.
`ClusterData::new()` was creating a datacenter hashmap, populating it with all the nodes, updating rack counts in it, and then dropping it. This whole work is useless and can be just removed.
e25419d
to
a56b55b
Compare
This method does some things that are unnecessary here: - For each DC it allocates a vector with it's nodes - It calculates rack count (which requires .unique() call which allocates) For the purpose of this test - and I'm pretty sure most of possible usages of get_datacenters_info - it is enough to get DC names from replica locator.
This method seems to have very limited usability: - For iterating through datacenter names user can call `ReplicaLocator::datacenter_names, which is constant time. - Nothing else was available to the user because `Datacenter` struct is not exported (so is unnameable). This also means all the work done by this method was a waste. - For more advanced tasks there are `ReplicaLocator::unique_nodes_in_datacenter_ring` and `ClusterData::get_nodes_info`. I don't think it is worth it to have this method which allocates a lot on each call and calculates rack counts. It could make sense to have rack counts precalculated when creating `ClusterData` - I'll think about it during metadata refactor. I'm pretty sure that the original intention was to calculate this whole hash map in `ClusterData::new`, but for some reason the calculation there was thrown out and redone here. I don't think its worth it repair this API now considering it was basically unavailable to users.`
It is no longer used anywhere.
Such types should not appear anywhere - except for sealed traits. Previous commits removed all occurrences of such types, so now we can enable the lint. The one legit occurrence - a sealed trait - is marked with `#[allow]`.
a56b55b
to
8a3e60d
Compare
@@ -29,6 +29,10 @@ use openssl::ssl::SslContext; | |||
use tracing::warn; | |||
|
|||
mod sealed { | |||
// This is a sealed trait - its whole purpose is to be unnameable. | |||
// This means we need to disable the check. | |||
#[allow(unknown_lints)] // Rust 1.66 doesn't know this lint |
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.
We no longer support Rust 1.66. Does 1.70 know this lint?
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.
Unfortunately not - it was introduced in 1.79, so we would need to bump MSRV much higher for that.
This PR enables the
unnameable_types
lint. This lint catches types that arepub
The only situation when this is desired that I know of is creating a sealed trait.
This PR fixes all occurrences of unnameable types and enables the lint so that
we don't introduce more in the future.
Pre-review checklist
I added relevant tests for new features and bug fixes.I have provided docstrings for the public items that I want to introduce.I have adjusted the documentation in./docs/source/
.Fixes:
annotations to PR description.