From 1be765678d356197994a039e07ed0f22fe0ce436 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 20 Oct 2016 11:19:06 -0700 Subject: [PATCH 1/3] fix(cluster) properly validate timeout options --- lib/resty/cassandra/cluster.lua | 8 ++++---- t/06-cluster.t | 12 ++++++++++++ util/prove_ccm.sh | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/resty/cassandra/cluster.lua b/lib/resty/cassandra/cluster.lua index 468a062..ff9f062 100644 --- a/lib/resty/cassandra/cluster.lua +++ b/lib/resty/cassandra/cluster.lua @@ -330,13 +330,13 @@ function _Cluster.new(opts) if type(v) ~= 'table' then return nil, 'contact_points must be a table' end - elseif k == 'read_timeout' then + elseif k == 'timeout_read' then if type(v) ~= 'number' then - return nil, 'read_timeout must be a number' + return nil, 'timeout_read must be a number' end - elseif k == 'connect_timeout' then + elseif k == 'timeout_connect' then if type(v) ~= 'number' then - return nil, 'connect_timeout must be a number' + return nil, 'timeout_connect must be a number' end elseif k == 'max_schema_consensus_wait' then if type(v) ~= 'number' then diff --git a/t/06-cluster.t b/t/06-cluster.t index 0185591..98b7dc2 100644 --- a/t/06-cluster.t +++ b/t/06-cluster.t @@ -53,6 +53,16 @@ GET /t if not cluster then ngx.say(err) end + + cluster, err = Cluster.new({timeout_read = 'foo'}) + if not cluster then + ngx.say(err) + end + + cluster, err = Cluster.new({timeout_connect = 'foo'}) + if not cluster then + ngx.say(err) + end } } --- request @@ -62,6 +72,8 @@ opts must be a table shm must be a string no shared dict invalid_shm keyspace must be a string +timeout_read must be a number +timeout_connect must be a number --- no_error_log [error] diff --git a/util/prove_ccm.sh b/util/prove_ccm.sh index 939a44a..c6fff26 100755 --- a/util/prove_ccm.sh +++ b/util/prove_ccm.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -CASSANDRA=${1} +CASSANDRA=${1:-3.9} ccm stop if [[ ! $(ccm list | grep lua_cassandra_prove) ]]; then From d51e5fb5b0caacd063c8dff1f26ab24c87d72faf Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 20 Oct 2016 11:19:18 -0700 Subject: [PATCH 2/3] feat(cluster) log reason for retrying a request --- lib/resty/cassandra/cluster.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/resty/cassandra/cluster.lua b/lib/resty/cassandra/cluster.lua index ff9f062..a8b406e 100644 --- a/lib/resty/cassandra/cluster.lua +++ b/lib/resty/cassandra/cluster.lua @@ -635,12 +635,13 @@ end local send_request -function _Cluster:send_retry(request) +function _Cluster:send_retry(request, ...) local coordinator, err = next_coordinator(self) if not coordinator then return nil, err end if self.logging then - log(NOTICE, _log_prefix, 'retrying request on host at ', coordinator.host) + log(NOTICE, _log_prefix, 'retrying request on host at ', coordinator.host, + ' reason: ', ...) end request.retries = request.retries + 1 @@ -653,7 +654,7 @@ local function prepare_and_retry(self, coordinator, request) -- prepared batch if self.logging then log(NOTICE, _log_prefix, 'some requests from this batch were not prepared on host ', - coordinator.host, ', preparing and retrying') + coordinator.host, ', preparing and retrying') end for i = 1, #request.queries do local query_id, err = prepare(self, coordinator, request.queries[i][1]) @@ -697,18 +698,17 @@ local function handle_error(self, err, cql_code, coordinator, request) end if retry then - return self:send_retry(request) + return self:send_retry(request, 'CQL code: ', cql_code) end elseif err == 'timeout' then if self.retry_on_timeout then - return self:send_retry(request) + return self:send_retry(request, 'timeout') end else -- host seems down? local ok, err = set_peer_down(self, coordinator.host) if not ok then return nil, err end - - return self:send_retry(request) + return self:send_retry(request, 'coordinator seems down') end return nil, err, cql_code From c749b5d2de4986ef602a8b205330a3a201e313f8 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 20 Oct 2016 11:34:16 -0700 Subject: [PATCH 3/3] tests(iterate) increase timeout for sanity test --- t/06-cluster.t | 8 +++----- t/12-iterate.t | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/t/06-cluster.t b/t/06-cluster.t index 98b7dc2..46add25 100644 --- a/t/06-cluster.t +++ b/t/06-cluster.t @@ -1120,9 +1120,7 @@ can try peer 255.255.255.253: false location /t { content_by_lua_block { local Cluster = require 'resty.cassandra.cluster' - local cluster, err = Cluster.new { - timeout_connect = 100 - } + local cluster, err = Cluster.new() if not cluster then ngx.log(ngx.ERR, err) return @@ -1173,8 +1171,8 @@ can try peer 255.255.255.253: false for i = 1, #peers do local ok, err = cluster:can_try_peer(peers[i].host) if err then - ngx.log(ngx.ERR, 'error in can_try_peer ', peers[i].host..': ', err) - return + ngx.log(ngx.ERR, 'error in can_try_peer ', peers[i].host..': ', err) + return end ngx.say(peers[i].host, ' is back up: ', ok) end diff --git a/t/12-iterate.t b/t/12-iterate.t index 2a17fe4..8be3096 100644 --- a/t/12-iterate.t +++ b/t/12-iterate.t @@ -13,7 +13,7 @@ run_tests(); __DATA__ === TEST 1: cluster.iterate() sanity ---- timeout: 30 +--- timeout: 45 --- http_config eval qq{ $::HttpConfig