lib/mongo/cluster/reapers/cursor_reaper.rb
# Execute all pending kill cursors operations.
#
# @example Execute pending kill cursors operations.
#   cursor_reaper.kill_cursors
#
# @api private
#
# @since 2.3.0
Execute all pending kill cursors operations.
Execute all pending kill cursors operations .
def kill_cursors
        loop do
          server_address_str = nil
          kill_spec = @mutex.synchronize do
            server_address_str, specs =
              @to_kill.detect { |server_address_str, specs| specs.any? }
            if specs.nil?
              return
            end
            spec = specs.take(1).tap do |arr|
              specs.subtract(arr)
            end.first
            unless @active_cursor_ids.include?(spec.cursor_id)
              spec = nil
            end
            spec
          end
          next unless kill_spec
          spec = {
            cursor_ids: [kill_spec.cursor_id],
            coll_name: kill_spec.coll_name,
            db_name: kill_spec.db_name,
          }
          op = Operation::KillCursors.new(spec)
          server = cluster.servers.detect do |server|
            server.address.seed == server_address_str
          end
          unless server
            next
          end
          options = {
            server_api: server.options[:server_api],
            service_id: kill_spec.service_id,
          }
          op.execute(server, context: Operation::Context.new(options: options))
        end
      end
def kill_cursors loop do server_address_str = nil kill_spec = @mutex . synchronize do server_address_str , specs = @to_kill . detect { | server_address_str , specs | specs . any? } if specs . nil? return end spec = specs . take ( 1 ) . tap do | arr | specs . subtract ( arr ) end . first unless @active_cursor_ids . include? ( spec . cursor_id ) spec = nil end spec end next unless kill_spec spec = { cursor_ids : [ kill_spec . cursor_id ] , coll_name : kill_spec . coll_name , db_name : kill_spec . db_name , } op = Operation :: KillCursors . new ( spec ) server = cluster . servers . detect do | server | server . address . seed == server_address_str end unless server next end options = { server_api : server . options [ :server_api ] , service_id : kill_spec . service_id , } op . execute ( server , context : Operation :: Context . new ( options : options ) ) end end
Execute all pending kill cursors operations.
Execute all pending kill cursors operations .
# TODO optimize this to batch kill cursor operations for the same # server/database/collection instead of killing each cursor # individually. # Find a server that has any cursors scheduled for destruction. # All servers have empty specs, nothing to do. # Note that this mutates the spec in the queue. # If the kill cursor operation fails, we don't attempt to # kill that cursor again. # The cursor was already killed, typically because it has # been iterated to completion. Remove the kill spec from # our records without doing any more work. # If there was a spec to kill but its cursor was already killed, # look for another spec. # We could also pass kill_spec directly into the KillCursors # operation, though this would make that operation have a # different API from all of the other ones which accept hashes. # TODO We currently don't have a server for the address that the # cursor is associated with. We should leave the cursor in the # queue to be killed at a later time (when the server comes back).
example
Execute pending kill cursors operations.
Execute pending kill cursors operations .
api
None
since
None