Skip to content

Commit

Permalink
fix(cluster) store and use protocol_version from first coordinator
Browse files Browse the repository at this point in the history
Not doing so would be harmful when a connection would be kept alive, but
when being reused, `connect()` is called but doesn't check if the
procotol is supported (only does so when `getreusedtimes() == 0`). We
now store the protocol version in the cluster's `peers_opts` table.

All nodes from the cluster must currently use the same protocol version.
  • Loading branch information
thibaultcha committed Aug 17, 2016
1 parent ec5172a commit a4e4d9b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/resty/cassandra/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ end
-- @treturn boolean `ok`: `true` if success, `nil` if failure.
-- @treturn string `err`: String describing the error if failure.
function _Cluster:refresh()
local protocol_version
local old_peers, err = get_peers(self)
if err then return nil, err
elseif old_peers then
Expand Down Expand Up @@ -415,6 +416,8 @@ function _Cluster:refresh()

coordinator:setkeepalive()

protocol_version = coordinator.protocol_version

rows[#rows+1] = {rpc_address = coordinator.host} -- local host

for i = 1, #rows do
Expand All @@ -439,6 +442,7 @@ function _Cluster:refresh()
local ok, err = lock:unlock()
if not ok then return nil, 'failed to unlock: '..err end

self.peers_opts.protocol_version = protocol_version
self.lb_policy:init(peers)
self.init = true
return true
Expand Down

0 comments on commit a4e4d9b

Please sign in to comment.