Skip to content

Commit

Permalink
Merge pull request #87 from thibaultcha/feat/manual-peers
Browse files Browse the repository at this point in the history
feat(cluster) manually add and remove peers
  • Loading branch information
thibaultcha authored Mar 24, 2017
2 parents 106b6e5 + 156d90a commit 3692292
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/resty/cassandra/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ local function set_peer(self, host, up, reconn_delay, unhealthy_at,
return true
end

local function add_peer(self, host, data_center)
return set_peer(self, host, true, 0, 0, data_center, "")
end

local function get_peer(self, host, status)
local rec_v, err = self.shm:get(_rec_key .. host)
if err then
Expand Down Expand Up @@ -131,6 +135,11 @@ local function get_peers(self)
end
end

local function delete_peer(self, host)
self.shm:delete(_rec_key .. host) -- details
self.shm:delete(host) -- status bool
end

local function set_peer_down(self, host)
if self.logging then
log(WARN, _log_prefix, 'setting host at ', host, ' DOWN')
Expand Down Expand Up @@ -898,7 +907,7 @@ do
-- Perform auto-pagination for a query when used as a Lua iterator.
-- Load balancing, reconnection, and retry policies act the same as described
-- for `execute`.
--
--
-- @usage
-- local Cluster = require "resty.cassandra.cluster"
-- local cluster, err = Cluster.new()
Expand All @@ -919,14 +928,16 @@ do
-- @param[type=table] args (optional) Arguments to bind to the query.
-- @param[type=table] options (optional) Options from `query_options`
-- for this query.
function _Cluster:iterate(query, args, options)
function _Cluster:iterate(query, args, options)
return page_iterator(self, query, args, options)
end
end

_Cluster.set_peer = set_peer
_Cluster.get_peer = get_peer
_Cluster.add_peer = add_peer
_Cluster.get_peers = get_peers
_Cluster.delete_peer = delete_peer
_Cluster.set_peer_up = set_peer_up
_Cluster.can_try_peer = can_try_peer
_Cluster.handle_error = handle_error
Expand Down

0 comments on commit 3692292

Please sign in to comment.