Skip to content

Commit

Permalink
Merge pull request #197 from Mashape/fix/reused-sockets
Browse files Browse the repository at this point in the history
fix: reused DAO sockets don't set the keyspace. fix #170
  • Loading branch information
thibaultcha committed May 1, 2015
2 parents 0382513 + 0739fb5 commit a3b9d3d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions kong/dao/cassandra/base_dao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,18 @@ function BaseDao:_open_session()
return nil, DaoError(err, error_types.DATABASE)
end

ok, err = session:set_keyspace(self._properties.keyspace)
if not ok then
local times, err = session:get_reused_times()
if err and err ~= "luasocket does not support reusable sockets" then
return nil, DaoError(err, error_types.DATABASE)
end

if times == 0 or not times then
ok, err = session:set_keyspace(self._properties.keyspace)
if not ok then
return nil, DaoError(err, error_types.DATABASE)
end
end

return session
end

Expand Down Expand Up @@ -322,7 +329,9 @@ function BaseDao:_execute_kong_query(operation, args_to_bind, options)
local results, err
results, err = self:_execute(statement, args, options)
if err and err.cassadra_err_code == cassandra_constants.error_codes.UNPREPARED then
ngx.log(ngx.NOTICE, "Cassandra did not recognize prepared statement \""..cache_key.."\". Re-preparing it and re-trying the query. (Error: "..err..")")
if ngx then
ngx.log(ngx.NOTICE, "Cassandra did not recognize prepared statement \""..cache_key.."\". Re-preparing it and re-trying the query. (Error: "..err..")")
end
-- If the statement was declared unprepared, clear it from the cache, and try again.
self._statements_cache[cache_key] = nil
return self:_execute_kong_query(operation, args_to_bind, options)
Expand Down

0 comments on commit a3b9d3d

Please sign in to comment.