Class: Mongo::Cluster::CursorReaper
- Inherits:
-
Object
- Object
- Mongo::Cluster::CursorReaper
- Extended by:
- Forwardable
- Includes:
- Retryable
- Defined in:
- lib/mongo/cluster/cursor_reaper.rb
Overview
A manager that sends kill cursors operations at regular intervals to close cursors that have been garbage collected without being exhausted.
Constant Summary collapse
- FREQUENCY =
The default time interval for the cursor reaper to send pending kill cursors operations.
1.freeze
Instance Method Summary collapse
-
#initialize ⇒ CursorReaper
constructor
private
Create a cursor reaper.
-
#kill_cursors ⇒ Object
private
Execute all pending kill cursors operations.
-
#register_cursor(id) ⇒ Object
private
Register a cursor id as active.
-
#run! ⇒ Object
(also: #restart!)
private
Start the cursor reaper’s thread.
-
#schedule_kill_cursor(id, op_spec, server) ⇒ Object
private
Schedule a kill cursors operation to be eventually executed.
-
#stop! ⇒ Object
private
Stop the cursor reaper’s thread.
-
#unregister_cursor(id) ⇒ Object
private
Unregister a cursor id, indicating that it’s no longer active.
Methods included from Retryable
#read_with_one_retry, #read_with_retry, #write_with_retry
Constructor Details
#initialize ⇒ CursorReaper
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a cursor reaper.
41 42 43 44 45 46 |
# File 'lib/mongo/cluster/cursor_reaper.rb', line 41 def initialize @to_kill = {} @active_cursors = Set.new @mutex = Mutex.new @thread = nil end |
Instance Method Details
#kill_cursors ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute all pending kill cursors operations.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/mongo/cluster/cursor_reaper.rb', line 136 def kill_cursors to_kill_copy = {} active_cursors_copy = [] @mutex.synchronize do to_kill_copy = @to_kill.dup active_cursors_copy = @active_cursors.dup @to_kill = {} end to_kill_copy.each do |server, op_specs| op_specs.each do |op_spec| if server.features.find_command_enabled? Cursor::Builder::KillCursorsCommand.update_cursors(op_spec, active_cursors_copy.to_a) if Cursor::Builder::KillCursorsCommand.get_cursors_list(op_spec).size > 0 Operation::Commands::Command.new(op_spec).execute(server) end else Cursor::Builder::OpKillCursors.update_cursors(op_spec, active_cursors_copy.to_a) if Cursor::Builder::OpKillCursors.get_cursors_list(op_spec).size > 0 Operation::KillCursors.new(op_spec).execute(server) end end end end end |
#register_cursor(id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Register a cursor id as active.
92 93 94 95 96 97 98 |
# File 'lib/mongo/cluster/cursor_reaper.rb', line 92 def register_cursor(id) if id && id > 0 @mutex.synchronize do @active_cursors << id end end end |
#run! ⇒ Object Also known as: restart!
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Start the cursor reaper’s thread.
56 57 58 |
# File 'lib/mongo/cluster/cursor_reaper.rb', line 56 def run! @thread && @thread.alive? ? @thread : start! end |
#schedule_kill_cursor(id, op_spec, server) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Schedule a kill cursors operation to be eventually executed.
73 74 75 76 77 78 79 80 |
# File 'lib/mongo/cluster/cursor_reaper.rb', line 73 def schedule_kill_cursor(id, op_spec, server) @mutex.synchronize do if @active_cursors.include?(id) @to_kill[server] ||= Set.new @to_kill[server] << op_spec end end end |
#stop! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Stop the cursor reaper’s thread.
124 125 126 |
# File 'lib/mongo/cluster/cursor_reaper.rb', line 124 def stop! @thread.kill && @thread.stop? end |
#unregister_cursor(id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Unregister a cursor id, indicating that it’s no longer active.
110 111 112 113 114 |
# File 'lib/mongo/cluster/cursor_reaper.rb', line 110 def unregister_cursor(id) @mutex.synchronize do @active_cursors.delete(id) end end |