Class SeaCircuitBreakerManager


  • public class SeaCircuitBreakerManager
    extends Object
    Manages a circuit breaker for SEA (SQL Execution API) session creation.

    When SEA session creation fails with HTTP 429 (rate limit exceeded) after exhausting retries, this circuit breaker opens for 24 hours, forcing all subsequent connections to use Thrift client instead of SEA.

    This prevents cascading failures and gives the SEA service time to recover from rate limiting.

    Thread-safe: Uses volatile for visibility across threads without synchronization overhead.

    • Field Detail

      • HTTP_TOO_MANY_REQUESTS

        public static final int HTTP_TOO_MANY_REQUESTS
        HTTP status code for rate limiting
        See Also:
        Constant Field Values
    • Method Detail

      • record429Failure

        public static void record429Failure()
        Records a 429 failure during SEA session creation, opening the circuit breaker for 24 hours.

        This should be called only when session creation (not statement execution) fails with 429 after all retries have been exhausted.

        Thread-safe via volatile write semantics.

      • isCircuitOpen

        public static boolean isCircuitOpen()
        Checks if the circuit breaker is currently open (within 24 hours of last 429 failure).
        Returns:
        true if the circuit is open and connections should bypass SEA and use Thrift directly, false otherwise
      • getTimeRemainingMs

        public static long getTimeRemainingMs()
        Gets the time remaining (in milliseconds) until the circuit breaker closes.
        Returns:
        milliseconds until circuit closes, or 0 if circuit is closed or never opened
      • getTimeRemainingFormatted

        public static String getTimeRemainingFormatted()
        Gets the time remaining until circuit closes, formatted as human-readable string.
        Returns:
        formatted time remaining (e.g., "23 hours 45 minutes"), or "closed" if not open
      • reset

        public static void reset()
        Resets the circuit breaker state. FOR TESTING PURPOSES ONLY.

        This method should only be called from test code to reset state between tests.