From 4520a3b034a7b4d9d00975c95ecf834ce263f048 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Mon, 17 Oct 2016 21:29:56 -0700 Subject: [PATCH] fix(cluster) use 'safe_set' to set prepared query id 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. --- lib/resty/cassandra/cluster.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/resty/cassandra/cluster.lua b/lib/resty/cassandra/cluster.lua index 254c168..468a062 100644 --- a/lib/resty/cassandra/cluster.lua +++ b/lib/resty/cassandra/cluster.lua @@ -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()