Skip to content

Commit

Permalink
feat(cluster) implement a 'no_keysapce' option
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Oct 4, 2016
1 parent 2c51568 commit cdc6607
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/resty/cassandra/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@ local function spawn_peer(host, port, keyspace, opts)
return cassandra.new(opts)
end

local function check_peer_health(self, host, keyspace, retry)
local peer, err = spawn_peer(host, self.default_port,
keyspace or self.keyspace,
self.peers_opts)
local function check_peer_health(self, host, coordinator_options, retry)
local keyspace
if not coordinator_options.no_keyspace then
keyspace = coordinator_options.keyspace or self.keyspace
end

local peer, err = spawn_peer(host, self.default_port, keyspace, self.peers_opts)
if not peer then return nil, err
else
peer:settimeout(self.timeout_connect)
Expand Down Expand Up @@ -368,7 +371,9 @@ local function first_coordinator(self)
local cp = self.contact_points

for i = 1, #cp do
local peer, err = check_peer_health(self, cp[i])
local peer, err = check_peer_health(self, cp[i], {
no_keyspace = true
})
if not peer then
errors[cp[i]] = err
else
Expand All @@ -379,13 +384,13 @@ local function first_coordinator(self)
return nil, no_host_available_error(errors)
end

local function next_coordinator(self, keyspace)
local function next_coordinator(self, coordinator_options)
local errors = {}

for _, peer_rec in self.lb_policy:iter() do
local ok, err, retry = can_try_peer(self, peer_rec.host)
if ok then
local peer, err = check_peer_health(self, peer_rec.host, keyspace, retry)
local peer, err = check_peer_health(self, peer_rec.host, coordinator_options, retry)
if peer then
log(DEBUG, _log_prefix, 'load balancing policy chose host at ', peer.host)
return peer
Expand Down Expand Up @@ -747,7 +752,7 @@ do

coordinator_options = coordinator_options or empty_t

local coordinator, err = next_coordinator(self, coordinator_options.keyspace)
local coordinator, err = next_coordinator(self, coordinator_options)
if not coordinator then return nil, err end

local request
Expand Down Expand Up @@ -802,7 +807,7 @@ do

coordinator_options = coordinator_options or empty_t

local coordinator, err = next_coordinator(self, coordinator_options.keyspace)
local coordinator, err = next_coordinator(self, coordinator_options)
if not coordinator then return nil, err end

local opts = get_request_opts(options)
Expand Down

0 comments on commit cdc6607

Please sign in to comment.