Skip to content

Commit

Permalink
fix(prepared) descriptive errors and nil query id catch
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Jan 16, 2016
1 parent b95d1f6 commit 502a3be
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/cassandra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ local function prepare_query(request_handler, query)
local prepared_key_lock = prepared_key.."_lock"
local lock, lock_err, elapsed = lock_mutex(request_handler.options.prepared_shm, prepared_key_lock)
if lock_err then
return nil, lock_err
return nil, "Could not create lock for prepare request: "..lock_err
end

if elapsed and elapsed == 0 then
Expand All @@ -767,26 +767,30 @@ local function prepare_query(request_handler, query)
local res, err = request_handler:send(prepare_request)
if err then
return nil, err
elseif res.query_id == nil then
return nil, "Could not retrieve query id from prepare request"
end
query_id = res.query_id
local ok, cache_err = cache.set_prepared_query_id(request_handler.options, query, query_id)
if not ok then
return nil, cache_err
return nil, "Could not insert query id in cache for prepared query: "..cache_err
end
log.info("Query prepared for host "..request_handler.coordinator.address)
else
-- once the lock is resolved, all other workers can retry to get the query, and should
-- instantly succeed. We then skip the preparation part.
query_id, cache_err = cache.get_prepared_query_id(request_handler.options, query)
if cache_err then
return nil, cache_err
return nil, "Could not get query id from cache for prepared query: "..cache_err
elseif query_id == nil then
return nil, "No query id found in cache for prepared query"
end
end

-- UNLOCK MUTEX
lock_err = unlock_mutex(lock)
if lock_err then
return nil, "Error unlocking mutex for query preparation: "..lock_err
return nil, "Error unlocking mutex for query for prepare request: "..lock_err
end
end

Expand Down

0 comments on commit 502a3be

Please sign in to comment.