module Mongo::Operation::Executable

Shared executable behavior of operations.

@since 2.5.2 @api private

Public Instance Methods

do_execute(connection, client, options = {}) click to toggle source
# File lib/mongo/operation/shared/executable.rb, line 26
def do_execute(connection, client, options = {})
  unpin_maybe(session) do
    add_error_labels(client, connection, session) do
      add_server_diagnostics(connection) do
        get_result(connection, client, options).tap do |result|
          process_result(result, connection)
        end
      end
    end
  end
end
execute(connection, client:, options: {}) click to toggle source
# File lib/mongo/operation/shared/executable.rb, line 38
def execute(connection, client:, options: {})
  if Lint.enabled?
    unless connection.is_a?(Mongo::Server::Connection)
      raise Error::LintError, "Connection argument is of wrong type: #{connection}"
    end
  end

  do_execute(connection, client, options).tap do |result|
    validate_result(result, client, connection)
  end
end

Private Instance Methods

build_message(connection) click to toggle source
# File lib/mongo/operation/shared/executable.rb, line 68
def build_message(connection)
  message(connection)
end
dispatch_message(connection, client, options = {}) click to toggle source

Returns a Protocol::Message or nil as reply.

# File lib/mongo/operation/shared/executable.rb, line 61
def dispatch_message(connection, client, options = {})
  message = build_message(connection)
  message = message.maybe_encrypt(connection, client)
  reply = connection.dispatch([ message ], operation_id, client, options)
  [reply, connection.description]
end
get_result(connection, client, options = {}) click to toggle source
# File lib/mongo/operation/shared/executable.rb, line 56
def get_result(connection, client, options = {})
  result_class.new(*dispatch_message(connection, client, options))
end
process_result(result, connection) click to toggle source
# File lib/mongo/operation/shared/executable.rb, line 72
def process_result(result, connection)
  connection.server.update_cluster_time(result)

  process_result_for_sdam(result, connection)

  if session
    session.process(result)
  end

  result
end
process_result_for_sdam(result, connection) click to toggle source
# File lib/mongo/operation/shared/executable.rb, line 84
def process_result_for_sdam(result, connection)
  if (result.not_master? || result.node_recovering?) &&
    connection.generation >= connection.server.pool.generation
  then
    if result.node_shutting_down?
      keep_pool = false
    else
      # Max wire version needs to be examined while the server is known
      keep_pool = connection.description.server_version_gte?('4.2')
    end

    connection.server.unknown!(
      keep_connection_pool: keep_pool,
      generation: connection.generation,
      topology_version: result.topology_version,
    )

    connection.server.scan_semaphore.signal
  end
end
result_class() click to toggle source
# File lib/mongo/operation/shared/executable.rb, line 52
def result_class
  Result
end