From 0a9a0037e91210e720f4ad88ad988a3a5139a9ee Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Mon, 11 Apr 2016 11:20:16 -0700 Subject: [PATCH] fix(cassandra) add a 'port' option for clusters Clusters with nodes not running on the default `9042` port couldn't be properly reached by Kong. This bumps the driver (including the fix), and adds a `port` options to the configuration. Thanks @allisthere2love for the investigation. This issue was never encountered before and my guess is because such clusters added their contact_points including the port (`x.x.x.x:9043`), and the driver could connect to it, but not to the other nodes, since it was trying `9042` on those. So it simply considered the other nodes as DOWN, and thus still works (if one doesn't check the logs and those lags are not displaying warnings, it seems like nothing is going wrong). However @allisthere2love had nodes from another C* cluster listening on `9042`, leading to inconsistencies and thus, actual errors that allowed us to track it down. As per other datastax drivers, all nodes of a cluster must listen on the same port. Fix Mashape/kong#1139 See thibaultCha/lua-cassandra#47 --- kong-0.7.0-0.rockspec | 2 +- kong.yml | 2 ++ kong/dao/cassandra/factory.lua | 3 +++ kong/tools/config_defaults.lua | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/kong-0.7.0-0.rockspec b/kong-0.7.0-0.rockspec index 89d08864525..98749125ca5 100644 --- a/kong-0.7.0-0.rockspec +++ b/kong-0.7.0-0.rockspec @@ -19,7 +19,7 @@ dependencies = { "yaml ~> 1.1.2-1", "lapis ~> 1.3.1-1", "stringy ~> 0.4-1", - "lua-cassandra ~> 0.5.0", + "lua-cassandra ~> 0.5.1", "multipart ~> 0.2-1", "lua-path ~> 0.2.3-1", "lua-cjson ~> 2.1.0-1", diff --git a/kong.yml b/kong.yml index 7c5e6ddf7d6..2ff3fe6d010 100644 --- a/kong.yml +++ b/kong.yml @@ -99,6 +99,8 @@ # contact_points: # - "127.0.0.1:9042" + # port: 9042 + ###### ## Name of the keyspace used by Kong. Will be created if it does not exist. # keyspace: kong diff --git a/kong/dao/cassandra/factory.lua b/kong/dao/cassandra/factory.lua index 4fb81708830..e8c7f976fed 100644 --- a/kong/dao/cassandra/factory.lua +++ b/kong/dao/cassandra/factory.lua @@ -114,6 +114,9 @@ function CassandraFactory:get_session_options() prepared_shm = "cassandra_prepared", contact_points = self.properties.contact_points, keyspace = self.properties.keyspace, + protocol_options = { + default_port = self.properties.port + }, query_options = { prepare = true }, diff --git a/kong/tools/config_defaults.lua b/kong/tools/config_defaults.lua index 168fd9f72c3..37780c1a03b 100644 --- a/kong/tools/config_defaults.lua +++ b/kong/tools/config_defaults.lua @@ -38,6 +38,7 @@ return { type = "table", content = { ["contact_points"] = {type = "array", default = {"127.0.0.1:9042"}}, + ["port"] = {type = "number", default = 9042}, ["keyspace"] = {type = "string", default = "kong"}, ["timeout"] = {type = "number", default = 5000}, ["replication_strategy"] = {type = "string", default = "SimpleStrategy", enum = {"SimpleStrategy", "NetworkTopologyStrategy"}},