Skip to content

Commit

Permalink
hotfix(cluster) default 'coordinator_options' in 'check_peer_health'
Browse files Browse the repository at this point in the history
Includes some other last minute fixes and improvements
  • Loading branch information
thibaultcha committed Oct 4, 2016
1 parent 89b8293 commit 5173f4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/resty/cassandra/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local DEBUG = ngx.DEBUG
local NOTICE = ngx.NOTICE
local C = ffi.C

local empty_t = {}
local _log_prefix = '[lua-cassandra] '
local _rec_key = 'host:rec:'
local _prepared_key = 'prepared:id:'
Expand Down Expand Up @@ -131,7 +132,7 @@ local function set_peer_down(self, host)
log(WARN, _log_prefix, 'setting host at ', host, ' DOWN')

local peer = get_peer(self, host, false)
peer = peer or {} -- this can be called from refresh() so no host in shm yet
peer = peer or empty_t -- this can be called from refresh() so no host in shm yet

return set_peer(self, host, false, self.reconn_policy:next_delay(host), get_now(),
peer.data_center, peer.release_version)
Expand All @@ -142,7 +143,7 @@ local function set_peer_up(self, host)
self.reconn_policy:reset(host)

local peer = get_peer(self, host, true)
peer = peer or {} -- this can be called from refresh() so no host in shm yet
peer = peer or empty_t -- this can be called from refresh() so no host in shm yet

return set_peer(self, host, true, 0, 0,
peer.data_center, peer.release_version)
Expand Down Expand Up @@ -173,6 +174,8 @@ local function spawn_peer(host, port, keyspace, opts)
end

local function check_peer_health(self, host, coordinator_options, retry)
coordinator_options = coordinator_options or empty_t

local keyspace
if not coordinator_options.no_keyspace then
keyspace = coordinator_options.keyspace or self.keyspace
Expand Down Expand Up @@ -276,7 +279,7 @@ _Cluster.__index = _Cluster
-- or nil if failure.
-- @treturn string `err`: String describing the error if failure.
function _Cluster.new(opts)
opts = opts or {}
opts = opts or empty_t
if type(opts) ~= 'table' then
return nil, 'opts must be a table'
end
Expand Down Expand Up @@ -705,7 +708,6 @@ do
local query_req = requests.query.new
local batch_req = requests.batch.new
local prep_req = requests.execute_prepared.new
local empty_t = {}

--- Coordinator options.
-- Options to pass to coordinators chosen by the load balancing policy
Expand Down
4 changes: 3 additions & 1 deletion t/06-cluster.t
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,9 @@ GET /t
return
end
local coordinator, err = cluster:next_coordinator('system')
local coordinator, err = cluster:next_coordinator({
keyspace = 'system'
})
if not coordinator then
ngx.log(ngx.ERR, err)
return
Expand Down

0 comments on commit 5173f4f

Please sign in to comment.