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

node: tiny optimizations and code refactors #1108

Merged

Conversation

muzarski
Copy link
Contributor

@muzarski muzarski commented Oct 25, 2024

While reading, and trying to understand the hostname resolution and pool refiller logic, I found some places where things could be slightly adjusted. These changes are mostly tiny optimizations and things that aid code readability.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

We can consume the `to_resolve` vector and move the datacenter string,
instead of cloning.
In previous version, we would needlessly allocate vectors while
having iterators over SocketAddrs.
Notice that using `find_or_last` is equivalent to previous version.
This is just a negation of `is_empty()` method.

For reference:
```
    fn is_empty(&self) -> bool {
        self.conns.iter().all(|conns| conns.is_empty())
    }
```
@muzarski muzarski self-assigned this Oct 25, 2024
Copy link

cargo semver-checks found no API-breaking changes in this PR! 🎉🥳
Checked commit: 81d9576

Copy link
Collaborator

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

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

Thanks for including is_empty body in commit message - it makes review easier.

Copy link
Collaborator

@wprzytula wprzytula left a comment

Choose a reason for hiding this comment

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

I love this! Both allocation optimisations and adjusting to functional paradigm.

Comment on lines +283 to +290
addrs
.find_or_last(|addr| matches!(addr, SocketAddr::V4(_)))
.ok_or_else(|| {
io::Error::new(
io::ErrorKind::Other,
format!("Empty address list returned by DNS for {}", hostname),
)
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any ideas BTW why we're biased for IPv4 addresses???

@wprzytula wprzytula merged commit 7e73e25 into scylladb:main Oct 26, 2024
11 checks passed
@muzarski muzarski deleted the remove-needless-clone-in-host-resolution branch October 29, 2024 14:34
@wprzytula wprzytula mentioned this pull request Nov 14, 2024
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.

3 participants