123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Retryable::RetryPolicy Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/retryable/retry_policy.rb

Overview

Encapsulates the retry policy for client backpressure with exponential backoff and jitter.

One instance is created per ::Mongo::Client and shared across all operations on that client.

Since:

  • 2.1.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#max_retriesInteger (readonly)

Returns:

  • (Integer)

    The maximum number of overload retries.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/retryable/retry_policy.rb', line 14

attr_reader :max_retries

Instance Method Details

#backoff_delay(attempt, jitter: rand) ⇒ Float

Calculate the backoff delay for a given retry attempt.

Parameters:

  • attempt (Integer)

    The retry attempt number (1-indexed).

  • jitter (Float)

    A random float in [0.0, 1.0).

Returns:

  • (Float)

    The backoff delay in seconds.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/retryable/retry_policy.rb', line 30

def backoff_delay(attempt, jitter: rand)
  Backpressure.backoff_delay(attempt, jitter: jitter)
end

#exceeds_deadline?(delay, context) ⇒ Boolean (private)

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/retryable/retry_policy.rb', line 51

def exceeds_deadline?(delay, context)
  return false unless context&.csot?

  deadline = context&.deadline
  deadline&.nonzero? && Utils.monotonic_time + delay > deadline
end

#should_retry_overload?(attempt, delay, context: nil) ⇒ true | false

Determine whether an overload retry should be attempted.

Parameters:

  • attempt (Integer)

    The retry attempt number (1-indexed).

  • delay (Float)

    The backoff delay in seconds.

  • context (Mongo::Operation::Context | nil)

    The operation context (for CSOT deadline checking).

Returns:

  • (true | false)

    Whether the retry should proceed.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/retryable/retry_policy.rb', line 42

def should_retry_overload?(attempt, delay, context: nil)
  return false if attempt > @max_retries
  return false if exceeds_deadline?(delay, context)

  true
end