Skip to content

Commit

Permalink
fix(cluster) use 'safe_set' to set prepared query id
Browse files Browse the repository at this point in the history
We do not want to unintentionally override some cluster info and would
rather fail to cache the query id in the shm instead. Other workers will
fail to retrieve the key from it and will thus prepare the request
themselves, so we maintain a working state.
  • Loading branch information
thibaultcha committed Oct 18, 2016
1 parent e99ece3 commit 4520a3b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/resty/cassandra/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,15 @@ local function get_or_prepare(self, coordinator, query)
query_id, err = prepare(self, coordinator, query)
if not query_id then return nil, err end

local ok, err = shm:set(key, query_id)
if not ok then return nil, 'could not set query id in shm: '..err end
local ok, err = shm:safe_set(key, query_id)
if not ok then
if err == 'no memory' then
log(WARN, _log_prefix, 'could not set query id in shm: ',
'running out of memory, please increase the ',
self.dict_name, ' dict size')
else
return nil, 'could not set query id in shm: '..err end
end
end

local ok, err = lock:unlock()
Expand Down

0 comments on commit 4520a3b

Please sign in to comment.