Skip to content

Commit

Permalink
fix: reused DAO sockets don't set the keyspace. fix Kong#170
Browse files Browse the repository at this point in the history
DAO sockets now take advantage of the connection pool and if they are
coming from it (meaning they've been used before), they don't set their
keyspace anymore.
  • Loading branch information
thibaultcha committed May 1, 2015
1 parent afd37fb commit 5db1f76
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 5db1f76

Please sign in to comment.