Skip to content

Commit 3836771

Browse files
Cleanup and comments
1 parent e955eb4 commit 3836771

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/mongo/cluster/reapers/cursor_reaper.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class CursorReaper
3434
# @since 2.3.0
3535
FREQUENCY = 1.freeze
3636

37+
# Symbol for separating parts of scheduled kill spec messages.
38+
#
39+
# @api private
40+
MSG_SEPARATOR = "\t"
41+
3742
# Create a cursor reaper.
3843
#
3944
# @param [ Cluster ] cluster The cluster.
@@ -63,7 +68,7 @@ def schedule_kill_cursor(kill_spec, server)
6368
kill_spec.coll_name,
6469
kill_spec.db_name,
6570
kill_spec.service_id
66-
].join("\t")
71+
].join(MSG_SEPARATOR)
6772
@pipe_write.puts(msg)
6873
end
6974

@@ -113,10 +118,19 @@ def unregister_cursor(id)
113118
end
114119
end
115120

121+
# Read and decode scheduled kill cursors operations.
122+
#
123+
# This method mutates instance variables without locking, so is is not
124+
# thread safe. Generally, it should not be called itself, this is a helper
125+
# for `kill_cursor` method.
126+
#
127+
# @api private
116128
def read_scheduled_kill_specs
117-
while readable_io = IO.select([@pipe_read], nil, nil, 0.1)
118-
msg = readable_io.first[0].gets.strip
119-
seed, cursor_id, coll_name, db_name, service_id = msg.split("\t")
129+
while select_resp = IO.select([@pipe_read], nil, nil, 0.1)
130+
readable_io = select_resp&.first&.first
131+
next if readable_io.nil?
132+
msg = readable_io.gets.strip
133+
seed, cursor_id, coll_name, db_name, service_id = msg.split(MSG_SEPARATOR)
120134
kill_spec = Cursor::KillSpec.new(
121135
cursor_id: cursor_id.to_i,
122136
coll_name: coll_name,

0 commit comments

Comments
 (0)