Class: Mongo::Cluster::CursorReaper Private
- Inherits:
-
Object
- Object
- Mongo::Cluster::CursorReaper
- Includes:
- Retryable
- Defined in:
- lib/mongo/cluster/reapers/cursor_reaper.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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
(also: #execute, #flush)
private
Execute all pending kill cursors operations.
-
#register_cursor(id) ⇒ Object
private
Register a cursor id as active.
-
#schedule_kill_cursor(id, op_spec, server) ⇒ Object
private
Schedule a kill cursors operation to be eventually executed.
-
#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.
43 44 45 46 47 |
# File 'lib/mongo/cluster/reapers/cursor_reaper.rb', line 43 def initialize @to_kill = {} @active_cursors = Set.new @mutex = Mutex.new end |
Instance Method Details
#kill_cursors ⇒ Object Also known as: execute, flush
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.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/mongo/cluster/reapers/cursor_reaper.rb', line 112 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::KillCursors.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.
80 81 82 83 84 85 86 |
# File 'lib/mongo/cluster/reapers/cursor_reaper.rb', line 80 def register_cursor(id) if id && id > 0 @mutex.synchronize do @active_cursors << id end end 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.
61 62 63 64 65 66 67 68 |
# File 'lib/mongo/cluster/reapers/cursor_reaper.rb', line 61 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 |
#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.
98 99 100 101 102 |
# File 'lib/mongo/cluster/reapers/cursor_reaper.rb', line 98 def unregister_cursor(id) @mutex.synchronize do @active_cursors.delete(id) end end |