Skip to content

Commit

Permalink
fix: shuffling array of contact points
Browse files Browse the repository at this point in the history
Also provide the port number in socket error logs.
  • Loading branch information
thibaultcha committed Aug 6, 2015
1 parent 8d8fc27 commit bebc131
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/cassandra/protocol/reader_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function _M:receive_frame(session)

local header, err = session.socket:receive(8)
if not header then
return nil, string.format("Failed to read frame header from %s: %s", session.host, err)
return nil, string.format("Failed to read frame header from %s:%s : %s", session.host, session.port, err)
end
local header_buffer = unmarshaller:create_buffer(header)
local version = unmarshaller:read_raw_byte(header_buffer)
if version ~= self.constants.version_codes.RESPONSE then
return nil, string.format("Invalid response version received from %s", session.host)
return nil, string.format("Invalid response version received from %s:%s", session.host, session.port)
end
local flags = unmarshaller:read_raw_byte(header_buffer)
local stream = unmarshaller:read_raw_byte(header_buffer)
Expand All @@ -42,7 +42,7 @@ function _M:receive_frame(session)
if length > 0 then
body, err = session.socket:receive(length)
if not body then
return nil, string.format("Failed to read frame body from %s: %s", session.host, err)
return nil, string.format("Failed to read frame body from %s:%s : %s", session.host, session.port, err)
end
else
body = ""
Expand Down
2 changes: 1 addition & 1 deletion src/cassandra/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function _M:send_frame_and_get_response(op_code, frame_body, tracing)
local frame = self.writer:build_frame(op_code, frame_body, tracing)
bytes, err = self.socket:send(frame)
if not bytes then
return nil, cerror(string.format("Failed to send frame to %s: %s", self.host, err))
return nil, cerror(string.format("Failed to send frame to %s: %s:%s", self.host, self.port, err))
end
response, err = self.reader:receive_frame(self)
if not response then
Expand Down
2 changes: 2 additions & 0 deletions src/cassandra/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function _M.big_endian_representation(num, bytes)
return padding .. table.concat(t)
end

math.randomseed(os.time())

-- @see http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
function _M.shuffle_array(arr)
local n = #arr
Expand Down

0 comments on commit bebc131

Please sign in to comment.