Class: Mongo::Retryable::RetryPolicy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/retryable/retry_policy.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.

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

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

Since:

  • 2.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_retries: Backpressure::DEFAULT_MAX_RETRIES) ⇒ RetryPolicy

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.

Create a new retry policy.

Parameters:

  • max_retries (Integer) (defaults to: Backpressure::DEFAULT_MAX_RETRIES)

    The maximum number of overload retry attempts. Defaults to Backpressure::DEFAULT_MAX_RETRIES.

Since:

  • 2.1.0



20
21
22
# File 'lib/mongo/retryable/retry_policy.rb', line 20

def initialize(max_retries: Backpressure::DEFAULT_MAX_RETRIES)
  @max_retries = max_retries
end

Instance Attribute Details

#max_retriesInteger (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.

Returns The maximum number of overload retries.

Returns:

  • (Integer)

    The maximum number of overload retries.

Since:

  • 2.1.0



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

def max_retries
  @max_retries
end

Instance Method Details

#backoff_delay(attempt, jitter: rand) ⇒ Float

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.

Calculate the backoff delay for a given retry attempt.

Parameters:

  • attempt (Integer)

    The retry attempt number (1-indexed).

  • jitter (Float) (defaults to: rand)

    A random float in [0.0, 1.0).

Returns:

  • (Float)

    The backoff delay in seconds.

Since:

  • 2.1.0



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

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

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

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.

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) (defaults to: nil)

    The operation context (for CSOT deadline checking).

Returns:

  • (true | false)

    Whether the retry should proceed.

Since:

  • 2.1.0



42
43
44
45
46
47
# 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