Class: Mongo::Operation::Context Private
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
|
|
|
Instance Chain:
|
|
| Inherits: |
Mongo::CsotTimeoutHolder
|
| Defined in: | lib/mongo/operation/context.rb |
Overview
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.
Class Method Summary
- .new(client: nil, session: nil, connection_global_id: nil, operation_timeouts: {}, view: nil, options: nil) ⇒ Context constructor Internal use only
::Mongo::CsotTimeoutHolder - Inherited
Instance Attribute Summary
- #aborting_transaction? ⇒ Boolean readonly Internal use only
- #any_retry_writes? ⇒ Boolean readonly Internal use only
- #client readonly Internal use only
- #committing_transaction? ⇒ Boolean readonly Internal use only
- #decrypt? ⇒ Boolean readonly Internal use only
- #encrypt? ⇒ Boolean readonly Internal use only
- #in_transaction? ⇒ Boolean readonly Internal use only
- #legacy_retry_writes? ⇒ Boolean readonly Internal use only
- #modern_retry_writes? ⇒ Boolean readonly Internal use only
- #options readonly Internal use only
-
#overload_only_retry? ⇒ Boolean
readonly
Internal use only
Whether every retry so far has been due to overload only.
-
#retry? ⇒ Boolean
readonly
Internal use only
Whether the operation is a retry (true) or an initial attempt (false).
- #session readonly Internal use only
- #starting_transaction? ⇒ Boolean readonly Internal use only
- #view readonly Internal use only
::Mongo::CsotTimeoutHolder - Inherited
Instance Method Summary
- #connection_global_id Internal use only
- #decrypt(cmd) readonly Internal use only
- #encrypt(db_name, cmd) readonly Internal use only
- #encrypter Internal use only
- #inspect Internal use only
-
#refresh(connection_global_id: @connection_global_id, timeout_ms: nil, view: nil) ⇒ Operation::Context
Internal use only
Returns a new
Contextwith the deadline refreshed and relative to the current moment. - #server_api Internal use only
-
#with(**opts)
Internal use only
Returns a new context with the parameters changed as per the provided arguments.
::Mongo::CsotTimeoutHolder - Inherited
| #check_timeout! | Check whether the operation timeout expired, and raises an appropriate error if yes. |
| #remaining_timeout_ms, #remaining_timeout_ms!, #remaining_timeout_sec, #remaining_timeout_sec!, #calculate_deadline, #calculate_deadline_from_timeout_ms, #check_no_override_inside_transaction! | |
Instance Attribute Details
#aborting_transaction? ⇒ Boolean (readonly)
# File 'lib/mongo/operation/context.rb', line 97
def aborting_transaction? in_transaction? && session.aborting_transaction? end
#any_retry_writes? ⇒ Boolean (readonly)
# File 'lib/mongo/operation/context.rb', line 109
def any_retry_writes? modern_retry_writes? || legacy_retry_writes? end
#client (readonly)
[ GitHub ]
#committing_transaction? ⇒ Boolean (readonly)
# File 'lib/mongo/operation/context.rb', line 93
def committing_transaction? in_transaction? && session.committing_transaction? end
#decrypt? ⇒ Boolean (readonly)
#encrypt? ⇒ Boolean (readonly)
#in_transaction? ⇒ Boolean (readonly)
# File 'lib/mongo/operation/context.rb', line 85
def in_transaction? session&.in_transaction? || false end
#legacy_retry_writes? ⇒ Boolean (readonly)
#modern_retry_writes? ⇒ Boolean (readonly)
#options (readonly)
[ GitHub ]
#overload_only_retry? ⇒ Boolean (readonly)
Whether every retry so far has been due to overload only.
# File 'lib/mongo/operation/context.rb', line 127
def overload_only_retry? !!@overload_only_retry end
#retry? ⇒ Boolean (readonly)
Whether the operation is a retry (true) or an initial attempt (false).
# File 'lib/mongo/operation/context.rb', line 122
def retry? !!@is_retry end
#session (readonly)
[ GitHub ]
#starting_transaction? ⇒ Boolean (readonly)
# File 'lib/mongo/operation/context.rb', line 89
def starting_transaction? session&.starting_transaction? || false end
#view (readonly)
[ GitHub ]Instance Method Details
#connection_global_id
[ GitHub ]# File 'lib/mongo/operation/context.rb', line 81
def connection_global_id @connection_global_id || session&.pinned_connection_global_id end
#decrypt(cmd) (readonly)
[ GitHub ]# File 'lib/mongo/operation/context.rb', line 156
def decrypt(cmd) encrypter.decrypt(cmd, self) end
#encrypt(db_name, cmd) (readonly)
[ GitHub ]# File 'lib/mongo/operation/context.rb', line 148
def encrypt(db_name, cmd) encrypter.encrypt(db_name, cmd, self) end
#encrypter
[ GitHub ]# 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
#inspect
[ GitHub ]# 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
#refresh(connection_global_id: @connection_global_id, timeout_ms: nil, view: nil) ⇒ Operation::Context
Returns a new Context with the deadline refreshed and relative to the current moment.
# 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
#server_api
[ GitHub ]#with(**opts)
Returns a new context with the parameters changed as per the provided arguments.
# 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