Module: Mongo::Operation::Executable Private

Includes:
ResponseHandling
Included in:
OpMsgBase
Defined in:
build/ruby-driver-v2.19/lib/mongo/operation/shared/executable.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Shared executable behavior of operations.

Since:

  • 2.5.2

Instance Method Summary collapse

Instance Method Details

#do_execute(connection, context, options = {}) ⇒ 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.

Since:

  • 2.5.2



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'build/ruby-driver-v2.19/lib/mongo/operation/shared/executable.rb', line 29

def do_execute(connection, context, options = {})
  session&.materialize_if_needed
  unpin_maybe(session, connection) do
    add_error_labels(connection, context) do
      add_server_diagnostics(connection) do
        get_result(connection, context, options).tap do |result|
          if session
            if session.in_transaction? &&
              connection.description.load_balancer?
            then
              if session.pinned_connection_global_id
                unless session.pinned_connection_global_id == connection.global_id
                  raise(
                    Error::InternalDriverError,
                    "Expected operation to use connection #{session.pinned_connection_global_id} but it used #{connection.global_id}"
                  )
                end
              else
                session.pin_to_connection(connection.global_id)
                connection.pin
              end
            end

            if session.snapshot? && !session.snapshot_timestamp
              session.snapshot_timestamp = result.snapshot_timestamp
            end
          end

          if result.has_cursor_id? &&
            connection.description.load_balancer?
          then
            if result.cursor_id == 0
              connection.unpin
            else
              connection.pin
            end
          end
          process_result(result, connection)
        end
      end
    end
  end
end

#execute(connection, context:, options: {}) ⇒ 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.

Since:

  • 2.5.2



73
74
75
76
77
78
79
80
81
82
83
# File 'build/ruby-driver-v2.19/lib/mongo/operation/shared/executable.rb', line 73

def execute(connection, context:, 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, context, options).tap do |result|
    validate_result(result, connection, context)
  end
end