Module: Mongo::Operation::Executable Private

Includes:
ResponseHandling
Included in:
OpMsgBase
Defined in:
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

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextOperation::Context | nil

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.

Returns the operation context used to execute this operation.

Returns:

  • the operation context used to execute this operation.

Since:

  • 2.5.2

API:

  • private



33
34
35
# File 'lib/mongo/operation/shared/executable.rb', line 33

def context
  @context
end

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

API:

  • private



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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/mongo/operation/shared/executable.rb', line 35

def do_execute(connection, context, options = {})
  # Save the context on the instance, to avoid having to pass it as a
  # parameter to every single method. There are many legacy methods that
  # still accept it as a parameter, which are left as-is for now to
  # minimize the impact of this change. Moving forward, it may be
  # reasonable to refactor things so this saved reference is used instead.
  @context = context

  session&.materialize_if_needed
  unpin_maybe(session, connection) do
    add_error_labels(connection, context) do
      check_for_network_error do
        add_server_diagnostics(connection) do
          get_result(connection, context, options) 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
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

API:

  • private



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/mongo/operation/shared/executable.rb', line 88

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