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

extract_server_update #2065

Merged
merged 1 commit into from
Apr 8, 2021
Merged

Conversation

alexpantyukhin
Copy link
Contributor

  • Link to issue, e.g. Resolves #NNN
  • Documentation added (if applicable)
  • Tests added
  • Branch rebased on top of current master (git pull --rebase origin master)
  • Changes squashed to a single commit (described here)
  • Build is green in Travis CI
  • You have certified that the contribution is your original work and that you license the work to the project under the Apache 2 license

Resolves #

Changes proposed in this pull request:

  • Extract server updates functionality into function

/cc @nats-io/core

@derekcollison derekcollison requested a review from kozlovic April 5, 2021 22:12
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

*Client does not exist. Anyway, had some more comments.

server/client.go Outdated
@@ -3125,6 +3117,16 @@ func (c *client) deliverMsg(sub *subscription, subject, reply, mh, msg []byte, g
return true
}

func (c *client) serveUpdate(client *Client, sub *subscription) {
Copy link
Member

Choose a reason for hiding this comment

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

I would rename this to make it a server receiver since when we call above, you already have srv. Also, maybe a rename to func (s *Server) updateRemoteSubscription(c *client, sub *subscription)?

server/client.go Outdated
func (c *client) serveUpdate(client *Client, sub *subscription) {
srv := client.srv

if srv.gateway.enabled {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think ordering matters much, but trying to be consistent with most of the rest of the code (mainly in (*client).processUnsub(), I would change the order to do update route, then update gateway, then update leafnodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried user the following sequence:
https://github.com/nats-io/nats-server/blob/master/server/client.go#L2972
It says that we need that sequence of execution. There we update gateway, route, and leafs.
By the way, if we have to have different sequences in different places, then the PR is not needed.

Should we have the order route, then update gateway, then update leafnodes. on both places?

Copy link
Member

Choose a reason for hiding this comment

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

Like I said, the order may not matter much, but the comment was saying something but then doing something else. See, in non defer cases, we would call update route, gateway then leafnodes. But in the defer (which reverse the order), we have leafnodes, route and gateway. I am guessing that the "defer srv.updateLeafNodes(client.acc, sub, -1)" was added later, and not at the right position.

Like I said, I think ordering is not mandatory, but I like to try to be consistent. So in your new function, you should have the "route, gateway and leafnodes" in that that order please. Order in that function will always be the same, and the good thing is that the whole function is called as a defer, so we don't have to think about reordering list of defers..

@alexpantyukhin alexpantyukhin force-pushed the extract_server_update branch 2 times, most recently from 93e45b6 to c0f50a3 Compare April 7, 2021 07:48
@alexpantyukhin
Copy link
Contributor Author

@kozlovic All mentions are fixed. Ready for review.

server/server.go Outdated
@@ -3356,3 +3356,12 @@ func (s *Server) setFirstPingTimer(c *client) {
d += time.Duration(addDelay)
c.ping.tmr = time.AfterFunc(d, c.processPingTimer)
}

func (s *Server) updateRemoteSubscription(c *client, sub *subscription) {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for mentioning that now, but since we are just removing here, the name of the function should reflect that, or, maybe better, keep this name but add a delta int as the last parameter of this function (and pass delta in updateRouteSubscriptionMap(), gatewayUpdateSubInterest() and updateLeafNodes().

In the places you called updateRemoteSubscription() in this PR you would pass -1. There are only 1 or 2 places in the rest of the server code where we could possibly call this function with a positive delta, because in some cases we do some of the things based on the client's kind (CLIENT, etc..).
We internally need to have a deeper look at that, but I think having this function with a delta could make it be reusable later when we cleanup the rest of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good input! I will fix asap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kozlovic fixed.

@alexpantyukhin alexpantyukhin force-pushed the extract_server_update branch from c0f50a3 to e16bebb Compare April 8, 2021 12:37
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your contribution!

@kozlovic kozlovic merged commit c7f8296 into nats-io:master Apr 8, 2021
@alexpantyukhin alexpantyukhin deleted the extract_server_update branch April 8, 2021 17:53
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.

2 participants