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

fix(*) cassandra contact points initialization #4378

Closed
wants to merge 1 commit into from

Conversation

bungle
Copy link
Member

@bungle bungle commented Mar 9, 2019

Summary

C* doesn't initialize contact points correctly when the contact points need to be resolved with DNS. DNS on the other hand uses Nginx cosockets that cannot be used with init phase. Nginx cosockets are not fully compatible with lua sockets. This PR is a quick fix for the issue.

This is based on next to prevent some merge conflicts. I can rebase on master if that is needed.

@Tieske
Copy link
Member

Tieske commented Mar 10, 2019

Wondering whether the cassandra code is the right place to fix this. Wouldn't the dns client be the right place to fix it?

Also wondering, doesn't this same issue exist for Postgres? Why do we connect to Cassandra in this phase, but not to Postgres?

@hutchic
Copy link
Contributor

hutchic commented Mar 10, 2019

@Tieske Based on my tests of rc1 postgres does not suffer the same issue

@bungle
Copy link
Member Author

bungle commented Mar 10, 2019

@Tieske the question is that do we want to have this hack available anywhere or just here. I guess you could perhaps inject such hack at some point to your dns client if we need it work anywhere. Postgres does not run anything on init, not sure if it should test connection there(?).

Because we are about to release the rc2 soon, I wanted to isolate this hack so that it has a smaller surface area (and no need to update dependencies at this point of release cycle).

@bungle bungle added this to the 1.1.0 milestone Mar 10, 2019
@thibaultcha
Copy link
Member

Also wondering, doesn't this same issue exist for Postgres? Why do we connect to Cassandra in this phase, but not to Postgres?

Both Postgres and Cassandra strategies will connect to their respective instances during init_by_lua. The former to retrieve the Postgres version, the latter to refresh the cluster topology and retrieve the peers' versions as well. However, both have mechanisms to fallback to LuaSocket for their queries in this phase. Both Postgres instances and Cassandra peers could be specified as hostname thanks to our globalpatches.lua or the LuaSocket fallback in the case of init_by_lua (this is, as far as I remember, not tested and involuntarily supported). However, since we updated the C* strategy to use our DNS client in init_by_lua, but the tests rely on /etc/hosts values (which do not yield), this slipped away.

@thibaultcha
Copy link
Member

(And the tests run in ngx.timer anyway because of rbusted (resty-cli) which supports yielding. Hence why the integration tests starting Kong itself in this PR).

C* doesn't initialize contact points correctly when the contact points
need to be resolved with DNS. DNS on the other hand uses Nginx cosockets
that cannot be used with init phase. Nginx cosockets are not fully
compatible with lua sockets. This PR is a quick fix for the issue.
@bungle bungle force-pushed the fix/cassandra-contact-points branch from 9a8b3d2 to 1159fcc Compare March 11, 2019 19:09
@@ -14,7 +14,77 @@ function CassandraConnector.new(kong_config)
do
-- Resolve contact points before instantiating cluster, since the
-- driver does not support hostnames in the contact points list.

-- TODO: this is an ugly hack to force lua sockets on a third party library
Copy link
Member

Choose a reason for hiding this comment

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

May be worth being more explicit here:

  • we force sync option for resty.dns.client to not spawn a timer
  • we force LuaSocket for resty.dns.resolver to not spawn a cosocket in init_by_lua

Can add at merge time, in fact let me take care of it, no worries 👍

})
end

ngx.socket.udp = function(...)
Copy link
Member

Choose a reason for hiding this comment

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

Note for posterity:

ideally we should add support for ngx.socket.udp to lua-resty-socket and avoid duplicating the fallback logic there and here (lua-resty-socket has its own test suite and benefits other projects).

Copy link
Member Author

@bungle bungle Mar 11, 2019

Choose a reason for hiding this comment

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

Oh yes, looks like it already has all things covered. Lets add dependency to it with 1.1+.

thibaultcha pushed a commit that referenced this pull request Mar 11, 2019
C* doesn't initialize contact points correctly when the contact points
need to be resolved with DNS. DNS on the other hand uses Nginx cosockets
that cannot be used with init phase. Nginx cosockets are not fully
compatible with lua sockets. This PR is a quick fix for the issue.

From #4378

Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

merging locally.

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.

4 participants