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

Move port and cport range check just before clusterStartHandshake function #1686

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from

Conversation

hwware
Copy link
Member

@hwware hwware commented Feb 7, 2025

Now for the cluster meet command, we first check the port and cport number, and then the function clusterStartHandshake() is called.
In the function clusterStartHandshake(), ip address is checked first and then port and cport range are checked.
Even port or cport range is out of bound, only error message "Invalid node address specified" is reported.
This is not correct.

In this PR, I just make the port and cport check together before clusterStartHandshake() function. Thus the port number and range can be checked together.

@hwware hwware force-pushed the cluster-meet-port-check branch from 470e164 to 007f9c6 Compare February 7, 2025 18:39
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 71.17%. Comparing base (79d5047) to head (e634138).
Report is 2 commits behind head on unstable.

Files with missing lines Patch % Lines
src/cluster_legacy.c 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           unstable    #1686   +/-   ##
=========================================
  Coverage     71.17%   71.17%           
=========================================
  Files           123      123           
  Lines         65641    65644    +3     
=========================================
+ Hits          46720    46724    +4     
+ Misses        18921    18920    -1     
Files with missing lines Coverage Δ
src/cluster_legacy.c 86.12% <33.33%> (+0.22%) ⬆️

... and 13 files with indirect coverage changes

src/cluster.h Outdated
@@ -134,4 +134,5 @@ int isNodeAvailable(clusterNode *node);
long long getNodeReplicationOffset(clusterNode *node);
sds aggregateClientOutputBuffer(client *c);
void resetClusterStats(void);
int verifyPortNumber(client *c, long long *port, long long *cport);
Copy link
Member

Choose a reason for hiding this comment

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

This function does more than just verification, it also parses and assigns port values. Consider renaming it to something like parseAndValidatePorts for better clarity.

Copy link
Member Author

Choose a reason for hiding this comment

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

It makes sense to me. Will update.

@hwware hwware force-pushed the cluster-meet-port-check branch from 56b0034 to 1ab8b98 Compare February 10, 2025 21:16
@zuiderkwast
Copy link
Contributor

The behavior change is that CLUSTER MEET can return an error instead of OK when the ports are invalid. This means the user can see the error early and understand what's wrong.

This is the user-visible change, so it should be the title of the PR I think. The rest is just refactoring which is not important for users and release notes.

Copy link
Member

@enjoy-binbin enjoy-binbin left a comment

Choose a reason for hiding this comment

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

why we need this? The old code also seems to be very easy to understand and maintain

@hwware
Copy link
Member Author

hwware commented Feb 26, 2025

why we need this? The old code also seems to be very easy to understand and maintain

Current old cause developers hard to identify the problem. Existing logic is to check port,, and then in function clusterStartHandshake check the ip first and check the port again.

The easier way to put all port checking logic together, and then check the ip.

@zuiderkwast
Copy link
Contributor

@enjoy-binbin @hwware The first commit is smaller. It just moves the check from clusterStartHandshake to CLUSTER MEET so it can return an error, without extra refactoring.

ce4c0d4

@hwware hwware force-pushed the cluster-meet-port-check branch from 1ab8b98 to 656abde Compare February 26, 2025 16:37
@hwware
Copy link
Member Author

hwware commented Feb 26, 2025

@enjoy-binbin @hwware The first commit is smaller. It just moves the check from clusterStartHandshake to CLUSTER MEET so it can return an error, without extra refactoring.

ce4c0d4

Yes, I just make thing easier. It looks like i update codes to the fist commit, and check the port and cport in the Cluster Meet part.
Sometimes simple is good enough

@hwware hwware force-pushed the cluster-meet-port-check branch from ea8755d to b5e4e19 Compare February 26, 2025 16:44
@hwware hwware changed the title Create a function to check the connection port Make the port and cport check together for Cluster Meet command Feb 26, 2025
@hwware hwware changed the title Make the port and cport check together for Cluster Meet command Make the port and cport check together and before clusterStartHandshake() function call for Cluster Meet command Feb 26, 2025
@hwware hwware changed the title Make the port and cport check together and before clusterStartHandshake() function call for Cluster Meet command Move port and cport range check just before clusterStartHandshake function Feb 26, 2025
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

Yes, this is simpler. I like it more. @enjoy-binbin WDYT?

I have just a minor comment about the error message.

Co-authored-by: Viktor Söderqvist <[email protected]>
Signed-off-by: Wen Hui <[email protected]>
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

LGTM.

Before merge, please update the PR title to clarify the user-visible behavior, that CLUSTER MEET validates the ports and returns error for invalid ports.

That is what we should mention in the release notes.

@zuiderkwast zuiderkwast added the release-notes This issue should get a line item in the release notes label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes This issue should get a line item in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants