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

ft-reaper-improvements-final small npe fix #111

Conversation

michaelsembwever
Copy link
Member

Avoid NPE when jmx is unreachable, when getting metrics for host

try{
hostProxy = context.jmxConnectionFactory.connect(hostName);
connected = true;
hostMetrics = getMetricsForHost(hostName, hostProxy);
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving this here won't work because if we cannot connect to one host through JMX (which will happen in multi region clusters) then Reaper won't look if metrics are already there in storage, which it does here : https://github.com/thelastpickle/cassandra-reaper/blob/ft-reaper-improvements-final/src/main/java/com/spotify/reaper/service/SegmentRunner.java#L417-L436

The error are only displayed in DEBUG so it shouldn't clutter the logs.
In which conditions did you get a NPE ?

Copy link
Member Author

@michaelsembwever michaelsembwever Jun 2, 2017

Choose a reason for hiding this comment

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

hostProxy can be null (either context.jmxConnectionFactory.connect(hostName) throws an exception or returns null.

before getMetricsForHost(..) would throw a NPE that wasn't caught.
now it's caught, and subsequently gotMetricsForAllHosts is correctly set to false.

@adejanovski adejanovski force-pushed the mck/ft-reaper-improvements-final-smallfix-0 branch from 2d8c98d to ea3b853 Compare June 22, 2017 05:46
@adejanovski
Copy link
Contributor

@michaelsembwever : I've reworked the patch a bit, using Optional<> to avoid the NPE.
Could you give me your feedback ?

Thanks

@michaelsembwever
Copy link
Member Author

LGTM.

Personally, I would have avoided changing so many lines of code on a living feature-branch. But that's me.

Presuming you'll rebase the commits to one before merging.

@adejanovski adejanovski force-pushed the mck/ft-reaper-improvements-final-smallfix-0 branch from ea3b853 to 8bf0b8c Compare June 22, 2017 08:11
try{
Optional<HostMetrics> hostMetrics;
Optional<HostMetrics> hostMetrics = Optional.absent();
Copy link
Collaborator

Choose a reason for hiding this comment

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

MAJOR Remove this useless assignment to local variable "hostMetrics". rule

@tlpsonarqube
Copy link
Collaborator

SonarQube analysis reported 3 issues

  • MAJOR 3 major

Watch the comments in this conversation to review them.

1 extra issue

Note: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:

  1. MAJOR SegmentRunner.java#L148: Either re-interrupt this method or rethrow the "InterruptedException". rule

try{
Optional<HostMetrics> hostMetrics;
Optional<HostMetrics> hostMetrics = Optional.absent();
try{
Copy link
Collaborator

Choose a reason for hiding this comment

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

MAJOR Extract this nested try block into a separate method. rule

@adejanovski adejanovski merged commit dde34c5 into ft-reaper-improvements-final Jun 22, 2017
@adejanovski adejanovski deleted the mck/ft-reaper-improvements-final-smallfix-0 branch June 22, 2017 12:34
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