Class: Mongo::Operation::Context Private
- Inherits:
-
CsotTimeoutHolder
- Object
- CsotTimeoutHolder
- Mongo::Operation::Context
- Defined in:
- lib/mongo/operation/context.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.
Context for operations.
Holds various objects needed to make decisions about operation execution in a single container, and provides facade methods for the contained objects.
The context contains parameters for operations, and as such while an operation is being prepared nothing in the context should change. When the result of the operation is being processed, the data returned by the context may change (for example, because a transaction is aborted), but at that point the operation should no longer read anything from the context. Because context data may change during operation execution, context objects should not be reused for multiple operations.
Instance Attribute Summary collapse
- #client ⇒ Object readonly private
- #options ⇒ Object readonly private
- #session ⇒ Object readonly private
- #view ⇒ Object readonly private
Attributes inherited from CsotTimeoutHolder
#deadline, #operation_timeouts, #timeout_sec
Instance Method Summary collapse
- #aborting_transaction? ⇒ Boolean private
- #any_retry_writes? ⇒ Boolean private
- #committing_transaction? ⇒ Boolean private
- #connection_global_id ⇒ Object private
- #decrypt(cmd) ⇒ Object private
- #decrypt? ⇒ Boolean private
- #encrypt(db_name, cmd) ⇒ Object private
- #encrypt? ⇒ Boolean private
- #encrypter ⇒ Object private
- #in_transaction? ⇒ Boolean private
-
#initialize(client: nil, session: nil, connection_global_id: nil, operation_timeouts: {}, view: nil, options: nil) ⇒ Context
constructor
private
A new instance of Context.
- #inspect ⇒ Object private
- #legacy_retry_writes? ⇒ Boolean private
- #modern_retry_writes? ⇒ Boolean private
-
#overload_only_retry? ⇒ Boolean
private
Whether every retry so far has been due to overload only.
-
#refresh(connection_global_id: @connection_global_id, timeout_ms: nil, view: nil) ⇒ Operation::Context
private
Returns a new Operation::Context with the deadline refreshed and relative to the current moment.
-
#retry? ⇒ Boolean
private
Whether the operation is a retry (true) or an initial attempt (false).
- #server_api ⇒ Object private
- #starting_transaction? ⇒ Boolean private
-
#with(**opts) ⇒ Object
private
Returns a new context with the parameters changed as per the provided arguments.
Methods inherited from CsotTimeoutHolder
#check_timeout!, #csot?, #remaining_timeout_ms, #remaining_timeout_ms!, #remaining_timeout_sec, #remaining_timeout_sec!, #timeout?, #timeout_expired?
Constructor Details
#initialize(client: nil, session: nil, connection_global_id: nil, operation_timeouts: {}, view: nil, options: nil) ⇒ Context
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 a new instance of Context.
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 |
# File 'lib/mongo/operation/context.rb', line 36 def initialize( client: nil, session: nil, connection_global_id: nil, operation_timeouts: {}, view: nil, options: nil ) if raise ArgumentError, 'Client and options cannot both be specified' if client raise ArgumentError, 'Session and options cannot both be specified' if session end if connection_global_id && session&.pinned_connection_global_id raise ArgumentError, 'Trying to pin context to a connection when the session is already pinned to a connection.' end @client = client @session = session @view = view @connection_global_id = connection_global_id @options = super(session: session, operation_timeouts: operation_timeouts) end |
Instance Attribute Details
#client ⇒ Object (readonly)
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.
63 64 65 |
# File 'lib/mongo/operation/context.rb', line 63 def client @client end |
#options ⇒ Object (readonly)
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.
63 64 65 |
# File 'lib/mongo/operation/context.rb', line 63 def @options end |
#session ⇒ Object (readonly)
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.
63 64 65 |
# File 'lib/mongo/operation/context.rb', line 63 def session @session end |
#view ⇒ Object (readonly)
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.
63 64 65 |
# File 'lib/mongo/operation/context.rb', line 63 def view @view end |
Instance Method Details
#aborting_transaction? ⇒ Boolean
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.
97 98 99 |
# File 'lib/mongo/operation/context.rb', line 97 def aborting_transaction? in_transaction? && session.aborting_transaction? end |
#any_retry_writes? ⇒ Boolean
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.
109 110 111 |
# File 'lib/mongo/operation/context.rb', line 109 def any_retry_writes? modern_retry_writes? || legacy_retry_writes? end |
#committing_transaction? ⇒ Boolean
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.
93 94 95 |
# File 'lib/mongo/operation/context.rb', line 93 def committing_transaction? in_transaction? && session.committing_transaction? end |
#connection_global_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.
81 82 83 |
# File 'lib/mongo/operation/context.rb', line 81 def connection_global_id @connection_global_id || session&.pinned_connection_global_id end |
#decrypt(cmd) ⇒ 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.
156 157 158 |
# File 'lib/mongo/operation/context.rb', line 156 def decrypt(cmd) encrypter.decrypt(cmd, self) end |
#decrypt? ⇒ Boolean
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.
152 153 154 |
# File 'lib/mongo/operation/context.rb', line 152 def decrypt? !!client&.encrypter end |
#encrypt(db_name, cmd) ⇒ 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.
148 149 150 |
# File 'lib/mongo/operation/context.rb', line 148 def encrypt(db_name, cmd) encrypter.encrypt(db_name, cmd, self) end |
#encrypt? ⇒ Boolean
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.
144 145 146 |
# File 'lib/mongo/operation/context.rb', line 144 def encrypt? client&.encrypter&.encrypt? || false end |
#encrypter ⇒ 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.
160 161 162 163 164 165 166 |
# File 'lib/mongo/operation/context.rb', line 160 def encrypter unless client&.encrypter raise Error::InternalDriverError, 'Encrypter should only be accessed when encryption is to be performed' end client.encrypter end |
#in_transaction? ⇒ Boolean
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.
85 86 87 |
# File 'lib/mongo/operation/context.rb', line 85 def in_transaction? session&.in_transaction? || false end |
#inspect ⇒ 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.
168 169 170 |
# File 'lib/mongo/operation/context.rb', line 168 def inspect "#<#{self.class} connection_global_id=#{connection_global_id.inspect} deadline=#{deadline.inspect} options=#{.inspect} operation_timeouts=#{operation_timeouts.inspect}>" end |
#legacy_retry_writes? ⇒ Boolean
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.
105 106 107 |
# File 'lib/mongo/operation/context.rb', line 105 def legacy_retry_writes? client && !client.[:retry_writes] && client.max_write_retries > 0 end |
#modern_retry_writes? ⇒ Boolean
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.
101 102 103 |
# File 'lib/mongo/operation/context.rb', line 101 def modern_retry_writes? client && client.[:retry_writes] end |
#overload_only_retry? ⇒ Boolean
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.
Whether every retry so far has been due to overload only.
127 128 129 |
# File 'lib/mongo/operation/context.rb', line 127 def overload_only_retry? !!@overload_only_retry end |
#refresh(connection_global_id: @connection_global_id, timeout_ms: nil, view: nil) ⇒ Operation::Context
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 a new Operation::Context with the deadline refreshed and relative to the current moment.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mongo/operation/context.rb', line 69 def refresh(connection_global_id: @connection_global_id, timeout_ms: nil, view: nil) operation_timeouts = @operation_timeouts operation_timeouts = operation_timeouts.merge(operation_timeout_ms: timeout_ms) if timeout_ms self.class.new(client: client, session: session, connection_global_id: connection_global_id, operation_timeouts: operation_timeouts, view: view || self.view, options: ) end |
#retry? ⇒ Boolean
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.
Whether the operation is a retry (true) or an initial attempt (false).
122 123 124 |
# File 'lib/mongo/operation/context.rb', line 122 def retry? !!@is_retry end |
#server_api ⇒ 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.
113 114 115 116 117 118 119 |
# File 'lib/mongo/operation/context.rb', line 113 def server_api if client client.[:server_api] elsif [:server_api] end end |
#starting_transaction? ⇒ Boolean
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.
89 90 91 |
# File 'lib/mongo/operation/context.rb', line 89 def starting_transaction? session&.starting_transaction? || false end |
#with(**opts) ⇒ 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.
Returns a new context with the parameters changed as per the provided arguments.
136 137 138 139 140 141 142 |
# File 'lib/mongo/operation/context.rb', line 136 def with(**opts) dup.tap do |copy| opts.each do |k, v| copy.instance_variable_set("@#{k}", v) end end end |